From d3ae64fb137ab61de24c36f49cd511407b396b38 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sat, 18 Jan 2025 23:33:33 -0800 Subject: [PATCH] [chore] fieldalignment for internal/splunk --- exporter/splunkhecexporter/client_test.go | 2 +- internal/splunk/common.go | 25 +++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/exporter/splunkhecexporter/client_test.go b/exporter/splunkhecexporter/client_test.go index 62c8f67508d3..549c41efca3c 100644 --- a/exporter/splunkhecexporter/client_test.go +++ b/exporter/splunkhecexporter/client_test.go @@ -533,7 +533,7 @@ func TestReceiveTracesBatches(t *testing.T) { z.Close() require.NoError(t, err) } - timeStr := fmt.Sprintf(`"time":%d,`, i+1) + timeStr := fmt.Sprintf(`"time":%d}`, i+1) if strings.Contains(string(batchBody), timeStr) { assert.False(t, eventFound, "span event %d found in multiple batches", i) eventFound = true diff --git a/internal/splunk/common.go b/internal/splunk/common.go index e57ecaf53e15..086b3e110888 100644 --- a/internal/splunk/common.go +++ b/internal/splunk/common.go @@ -48,13 +48,20 @@ type AccessTokenPassthroughConfig struct { // Event represents a metric in Splunk HEC format type Event struct { - Time float64 `json:"time,omitempty"` // optional epoch time - set to zero if the event timestamp is missing or unknown (will be added at indexing time) - Host string `json:"host"` // hostname - Source string `json:"source,omitempty"` // optional description of the source of the event; typically the app's name - SourceType string `json:"sourcetype,omitempty"` // optional name of a Splunk parsing configuration; this is usually inferred by Splunk - Index string `json:"index,omitempty"` // optional name of the Splunk index to store the event in; not required if the token has a default index set in Splunk - Event any `json:"event"` // type of event: set to "metric" or nil if the event represents a metric, or is the payload of the event. - Fields map[string]any `json:"fields,omitempty"` // dimensions and metric data + // type of event: set to "metric" or nil if the event represents a metric, or is the payload of the event. + Event any `json:"event"` + // dimensions and metric data + Fields map[string]any `json:"fields,omitempty"` + // hostname + Host string `json:"host"` + // optional description of the source of the event; typically the app's name + Source string `json:"source,omitempty"` + // optional name of a Splunk parsing configuration; this is usually inferred by Splunk + SourceType string `json:"sourcetype,omitempty"` + // optional name of the Splunk index to store the event in; not required if the token has a default index set in Splunk + Index string `json:"index,omitempty"` + // optional epoch time - set to zero if the event timestamp is missing or unknown (will be added at indexing time) + Time float64 `json:"time,omitempty"` } // IsMetric returns true if the Splunk event is a metric. @@ -93,12 +100,12 @@ func (e *Event) GetMetricValues() map[string]any { func (e *Event) UnmarshalJSON(b []byte) error { rawEvent := struct { Time any `json:"time,omitempty"` + Event any `json:"event"` + Fields map[string]any `json:"fields,omitempty"` Host string `json:"host"` Source string `json:"source,omitempty"` SourceType string `json:"sourcetype,omitempty"` Index string `json:"index,omitempty"` - Event any `json:"event"` - Fields map[string]any `json:"fields,omitempty"` }{} err := json.Unmarshal(b, &rawEvent) if err != nil {