From 1aa372118b37ae7c266d257ebb036a14513bc96e Mon Sep 17 00:00:00 2001 From: Shibo Wang Date: Fri, 28 May 2021 11:57:44 -0700 Subject: [PATCH 1/4] Add metric_type as key which maps to the type of the metric --- .../splunkhecexporter/metricdata_to_splunk.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/exporter/splunkhecexporter/metricdata_to_splunk.go b/exporter/splunkhecexporter/metricdata_to_splunk.go index d968a67d80b8..73139b9437c7 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk.go @@ -29,6 +29,8 @@ import ( const ( // unknownHostName is the default host name when no hostname label is passed. unknownHostName = "unknown" + // splunkMetricType is the key which maps to the type of the metric. + splunkMetricType = "metric_type" // splunkMetricValue is the splunk metric value prefix. splunkMetricValue = "metric_name" // countSuffix is the count metric value suffix. @@ -89,7 +91,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() - + fields[splunkMetricType] = pdata.MetricDataTypeIntGauge.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -100,6 +102,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() + fields[splunkMetricType] = pdata.MetricDataTypeDoubleGauge.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -114,6 +117,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+sumSuffix] = dataPt.Sum() + fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -121,6 +125,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+countSuffix] = dataPt.Count() + fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -137,6 +142,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields["le"] = float64ToDimValue(bounds[bi]) value += counts[bi] fields[metricFieldName+bucketSuffix] = value + fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -146,6 +152,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) populateLabels(fields, dataPt.LabelsMap()) fields["le"] = float64ToDimValue(math.Inf(1)) fields[metricFieldName+bucketSuffix] = value + counts[len(counts)-1] + fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -161,6 +168,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+sumSuffix] = dataPt.Sum() + fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -168,6 +176,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+countSuffix] = dataPt.Count() + fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -184,6 +193,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields["le"] = float64ToDimValue(bounds[bi]) value += counts[bi] fields[metricFieldName+bucketSuffix] = value + fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -193,6 +203,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) populateLabels(fields, dataPt.LabelsMap()) fields["le"] = float64ToDimValue(math.Inf(1)) fields[metricFieldName+bucketSuffix] = value + counts[len(counts)-1] + fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -204,6 +215,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() + fields[splunkMetricType] = pdata.MetricDataTypeDoubleSum.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) @@ -215,6 +227,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() + fields[splunkMetricType] = pdata.MetricDataTypeIntSum.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) @@ -228,6 +241,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+sumSuffix] = dataPt.Sum() + fields[splunkMetricType] = pdata.MetricDataTypeSummary.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -235,6 +249,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+countSuffix] = dataPt.Count() + fields[splunkMetricType] = pdata.MetricDataTypeSummary.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -246,6 +261,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) dp := dataPt.QuantileValues().At(bi) fields["qt"] = float64ToDimValue(dp.Quantile()) fields[metricFieldName+"_"+strconv.FormatFloat(dp.Quantile(), 'f', -1, 64)] = dp.Value() + fields[splunkMetricType] = pdata.MetricDataTypeSummary.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } From ac0840fa7eb6295893ec953677bac9764de7dcf8 Mon Sep 17 00:00:00 2001 From: Shibo Wang Date: Tue, 1 Jun 2021 09:17:22 -0700 Subject: [PATCH 2/4] Modify existing unit tests --- exporter/splunkhecexporter/client_test.go | 6 ++--- .../metricdata_to_splunk_test.go | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/exporter/splunkhecexporter/client_test.go b/exporter/splunkhecexporter/client_test.go index 734204647fe2..0cf4704cc199 100644 --- a/exporter/splunkhecexporter/client_test.go +++ b/exporter/splunkhecexporter/client_test.go @@ -444,11 +444,11 @@ func TestReceiveLogs(t *testing.T) { func TestReceiveMetrics(t *testing.T) { actual, err := runMetricsExport(true, 3, t) assert.NoError(t, err) - expected := `{"host":"unknown","event":"metric","fields":{"k/n0":"vn0","k/n1":"vn1","k/r0":"vr0","k/r1":"vr1","k0":"v0","k1":"v1","metric_name:gauge_double_with_dims":1234.5678}}` + expected := `{"host":"unknown","event":"metric","fields":{"k/n0":"vn0","k/n1":"vn1","k/r0":"vr0","k/r1":"vr1","k0":"v0","k1":"v1","metric_name:gauge_double_with_dims":1234.5678,"metric_type":"DoubleGauge"}}` expected += "\n\r\n\r\n" - expected += `{"time":1.001,"host":"unknown","event":"metric","fields":{"k/n0":"vn0","k/n1":"vn1","k/r0":"vr0","k/r1":"vr1","k0":"v0","k1":"v1","metric_name:gauge_double_with_dims":1234.5678}}` + expected += `{"time":1.001,"host":"unknown","event":"metric","fields":{"k/n0":"vn0","k/n1":"vn1","k/r0":"vr0","k/r1":"vr1","k0":"v0","k1":"v1","metric_name:gauge_double_with_dims":1234.5678,"metric_type":"DoubleGauge"}}` expected += "\n\r\n\r\n" - expected += `{"time":2.002,"host":"unknown","event":"metric","fields":{"k/n0":"vn0","k/n1":"vn1","k/r0":"vr0","k/r1":"vr1","k0":"v0","k1":"v1","metric_name:gauge_double_with_dims":1234.5678}}` + expected += `{"time":2.002,"host":"unknown","event":"metric","fields":{"k/n0":"vn0","k/n1":"vn1","k/r0":"vr0","k/r1":"vr1","k0":"v0","k1":"v1","metric_name:gauge_double_with_dims":1234.5678,"metric_type":"DoubleGauge"}}` expected += "\n\r\n\r\n" assert.Equal(t, expected, actual) } diff --git a/exporter/splunkhecexporter/metricdata_to_splunk_test.go b/exporter/splunkhecexporter/metricdata_to_splunk_test.go index 2349b9bd8d3a..ab5f8ea57dcc 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk_test.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk_test.go @@ -241,8 +241,8 @@ func Test_metricDataToSplunk(t *testing.T) { return metrics }, wantSplunkMetrics: []*splunk.Event{ - commonSplunkMetric("gauge_double_with_dims", tsMSecs, []string{"com.splunk.index", "com.splunk.sourcetype", "host.name", "service.name", "k0", "k1"}, []interface{}{"myindex", "mysourcetype", "myhost", "mysource", "v0", "v1"}, doubleVal, "mysource", "mysourcetype", "myindex", "myhost"), - commonSplunkMetric("gauge_int_with_dims", tsMSecs, []string{"com.splunk.index", "com.splunk.sourcetype", "host.name", "service.name", "k0", "k1"}, []interface{}{"myindex", "mysourcetype", "myhost", "mysource", "v0", "v1"}, int64Val, "mysource", "mysourcetype", "myindex", "myhost"), + commonSplunkMetric("gauge_double_with_dims", tsMSecs, []string{"com.splunk.index", "com.splunk.sourcetype", "host.name", "service.name", "k0", "k1", "metric_type"}, []interface{}{"myindex", "mysourcetype", "myhost", "mysource", "v0", "v1", "DoubleGauge"}, doubleVal, "mysource", "mysourcetype", "myindex", "myhost"), + commonSplunkMetric("gauge_int_with_dims", tsMSecs, []string{"com.splunk.index", "com.splunk.sourcetype", "host.name", "service.name", "k0", "k1", "metric_type"}, []interface{}{"myindex", "mysourcetype", "myhost", "mysource", "v0", "v1", "IntGauge"}, int64Val, "mysource", "mysourcetype", "myindex", "myhost"), }, }, @@ -290,6 +290,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:double_histogram_with_dims_sum": float64(23), + "metric_type": "Histogram", }, }, { @@ -302,6 +303,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:double_histogram_with_dims_count": uint64(7), + "metric_type": "Histogram", }, }, { @@ -315,6 +317,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "1", "metric_name:double_histogram_with_dims_bucket": uint64(4), + "metric_type": "Histogram", }, }, { @@ -328,6 +331,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "2", "metric_name:double_histogram_with_dims_bucket": uint64(6), + "metric_type": "Histogram", }, }, { @@ -341,6 +345,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "4", "metric_name:double_histogram_with_dims_bucket": uint64(9), + "metric_type": "Histogram", }, }, { @@ -354,6 +359,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "+Inf", "metric_name:double_histogram_with_dims_bucket": uint64(14), + "metric_type": "Histogram", }, }, }, @@ -403,6 +409,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:int_histogram_with_dims_sum": int64(23), + "metric_type": "IntHistogram", }, }, { @@ -415,6 +422,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:int_histogram_with_dims_count": uint64(7), + "metric_type": "IntHistogram", }, }, { @@ -428,6 +436,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "1", "metric_name:int_histogram_with_dims_bucket": uint64(4), + "metric_type": "IntHistogram", }, }, { @@ -441,6 +450,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "2", "metric_name:int_histogram_with_dims_bucket": uint64(6), + "metric_type": "IntHistogram", }, }, { @@ -454,6 +464,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "4", "metric_name:int_histogram_with_dims_bucket": uint64(9), + "metric_type": "IntHistogram", }, }, { @@ -467,6 +478,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "le": "+Inf", "metric_name:int_histogram_with_dims_bucket": uint64(14), + "metric_type": "IntHistogram", }, }, }, @@ -495,6 +507,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:int_sum_with_dims": int64(62), + "metric_type": "IntSum", }, }, }, @@ -523,6 +536,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:double_sum_with_dims": float64(62), + "metric_type": "DoubleSum", }, }, }, @@ -559,6 +573,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:summary_sum": float64(42), + "metric_type": "Summary", }, }, { @@ -571,6 +586,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:summary_count": uint64(2), + "metric_type": "Summary", }, }, { @@ -584,6 +600,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "qt": "0.5", "metric_name:summary_0.5": float64(34), + "metric_type": "Summary", }, }, { @@ -597,6 +614,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "qt": "0.6", "metric_name:summary_0.6": float64(45), + "metric_type": "Summary", }, }, }, From 1b5ce13019f6690c98561e2f4f35ec3cc5ac7720 Mon Sep 17 00:00:00 2001 From: Shibo Wang Date: Wed, 2 Jun 2021 09:34:27 -0700 Subject: [PATCH 3/4] Update the const variable name --- .../splunkhecexporter/metricdata_to_splunk.go | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/exporter/splunkhecexporter/metricdata_to_splunk.go b/exporter/splunkhecexporter/metricdata_to_splunk.go index 73139b9437c7..25ce3c480186 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk.go @@ -29,8 +29,8 @@ import ( const ( // unknownHostName is the default host name when no hostname label is passed. unknownHostName = "unknown" - // splunkMetricType is the key which maps to the type of the metric. - splunkMetricType = "metric_type" + // splunkMetricTypeKey is the key which maps to the type of the metric. + splunkMetricTypeKey = "metric_type" // splunkMetricValue is the splunk metric value prefix. splunkMetricValue = "metric_name" // countSuffix is the count metric value suffix. @@ -91,7 +91,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() - fields[splunkMetricType] = pdata.MetricDataTypeIntGauge.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeIntGauge.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -102,7 +102,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() - fields[splunkMetricType] = pdata.MetricDataTypeDoubleGauge.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeDoubleGauge.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -117,7 +117,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+sumSuffix] = dataPt.Sum() - fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -125,7 +125,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+countSuffix] = dataPt.Count() - fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -142,7 +142,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields["le"] = float64ToDimValue(bounds[bi]) value += counts[bi] fields[metricFieldName+bucketSuffix] = value - fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -152,7 +152,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) populateLabels(fields, dataPt.LabelsMap()) fields["le"] = float64ToDimValue(math.Inf(1)) fields[metricFieldName+bucketSuffix] = value + counts[len(counts)-1] - fields[splunkMetricType] = pdata.MetricDataTypeHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -168,7 +168,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+sumSuffix] = dataPt.Sum() - fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -176,7 +176,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+countSuffix] = dataPt.Count() - fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -193,7 +193,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields["le"] = float64ToDimValue(bounds[bi]) value += counts[bi] fields[metricFieldName+bucketSuffix] = value - fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -203,7 +203,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) populateLabels(fields, dataPt.LabelsMap()) fields["le"] = float64ToDimValue(math.Inf(1)) fields[metricFieldName+bucketSuffix] = value + counts[len(counts)-1] - fields[splunkMetricType] = pdata.MetricDataTypeIntHistogram.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeIntHistogram.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -215,7 +215,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() - fields[splunkMetricType] = pdata.MetricDataTypeDoubleSum.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeDoubleSum.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) @@ -227,7 +227,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName] = dataPt.Value() - fields[splunkMetricType] = pdata.MetricDataTypeIntSum.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeIntSum.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) @@ -241,7 +241,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+sumSuffix] = dataPt.Sum() - fields[splunkMetricType] = pdata.MetricDataTypeSummary.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeSummary.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -249,7 +249,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) fields := cloneMap(commonFields) populateLabels(fields, dataPt.LabelsMap()) fields[metricFieldName+countSuffix] = dataPt.Count() - fields[splunkMetricType] = pdata.MetricDataTypeSummary.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeSummary.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } @@ -261,7 +261,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) dp := dataPt.QuantileValues().At(bi) fields["qt"] = float64ToDimValue(dp.Quantile()) fields[metricFieldName+"_"+strconv.FormatFloat(dp.Quantile(), 'f', -1, 64)] = dp.Value() - fields[splunkMetricType] = pdata.MetricDataTypeSummary.String() + fields[splunkMetricTypeKey] = pdata.MetricDataTypeSummary.String() sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } From ca7a1cb14d89bd530f2d27633457062dadeab485 Mon Sep 17 00:00:00 2001 From: Shibo Wang Date: Wed, 2 Jun 2021 14:55:53 -0700 Subject: [PATCH 4/4] Fix the go format error --- .../splunkhecexporter/metricdata_to_splunk_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exporter/splunkhecexporter/metricdata_to_splunk_test.go b/exporter/splunkhecexporter/metricdata_to_splunk_test.go index ab5f8ea57dcc..656e08868bae 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk_test.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk_test.go @@ -507,7 +507,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:int_sum_with_dims": int64(62), - "metric_type": "IntSum", + "metric_type": "IntSum", }, }, }, @@ -536,7 +536,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:double_sum_with_dims": float64(62), - "metric_type": "DoubleSum", + "metric_type": "DoubleSum", }, }, }, @@ -573,7 +573,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:summary_sum": float64(42), - "metric_type": "Summary", + "metric_type": "Summary", }, }, { @@ -586,7 +586,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k0": "v0", "k1": "v1", "metric_name:summary_count": uint64(2), - "metric_type": "Summary", + "metric_type": "Summary", }, }, { @@ -600,7 +600,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "qt": "0.5", "metric_name:summary_0.5": float64(34), - "metric_type": "Summary", + "metric_type": "Summary", }, }, { @@ -614,7 +614,7 @@ func Test_metricDataToSplunk(t *testing.T) { "k1": "v1", "qt": "0.6", "metric_name:summary_0.6": float64(45), - "metric_type": "Summary", + "metric_type": "Summary", }, }, },