diff --git a/exporter/splunkhecexporter/metricdata_to_splunk.go b/exporter/splunkhecexporter/metricdata_to_splunk.go index fe85140c19dd..704c587b7222 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk.go @@ -219,6 +219,37 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config) sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) splunkMetrics = append(splunkMetrics, sm) } + case pdata.MetricDataTypeSummary: + pts := tm.Summary().DataPoints() + for gi := 0; gi < pts.Len(); gi++ { + dataPt := pts.At(gi) + // first, add one event for sum, and one for count + { + fields := cloneMap(commonFields) + populateLabels(fields, dataPt.LabelsMap()) + fields[metricFieldName+sumSuffix] = dataPt.Sum() + sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) + splunkMetrics = append(splunkMetrics, sm) + } + { + fields := cloneMap(commonFields) + populateLabels(fields, dataPt.LabelsMap()) + fields[metricFieldName+countSuffix] = dataPt.Count() + sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) + splunkMetrics = append(splunkMetrics, sm) + } + + // now create values for each quantile. + for bi := 0; bi < dataPt.QuantileValues().Len(); bi++ { + fields := cloneMap(commonFields) + populateLabels(fields, dataPt.LabelsMap()) + dp := dataPt.QuantileValues().At(bi) + fields["qt"] = float64ToDimValue(dp.Quantile()) + fields[metricFieldName+"_"+strconv.FormatFloat(dp.Quantile(), 'f', -1, 64)] = dp.Value() + sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields) + splunkMetrics = append(splunkMetrics, sm) + } + } case pdata.MetricDataTypeNone: fallthrough default: diff --git a/exporter/splunkhecexporter/metricdata_to_splunk_test.go b/exporter/splunkhecexporter/metricdata_to_splunk_test.go index c8b38eca079c..8274cd3e8b2e 100644 --- a/exporter/splunkhecexporter/metricdata_to_splunk_test.go +++ b/exporter/splunkhecexporter/metricdata_to_splunk_test.go @@ -527,6 +527,80 @@ func Test_metricDataToSplunk(t *testing.T) { }, }, }, + { + name: "summary", + metricsDataFn: func() pdata.Metrics { + metrics := newMetricsWithResources() + ilm := metrics.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0) + summary := ilm.Metrics().AppendEmpty() + summary.SetName("summary") + summary.SetDataType(pdata.MetricDataTypeSummary) + doubleDataPt := summary.Summary().DataPoints().AppendEmpty() + doubleDataPt.SetTimestamp(ts) + doubleDataPt.SetStartTimestamp(ts) + doubleDataPt.SetCount(2) + doubleDataPt.SetSum(42) + qt1 := doubleDataPt.QuantileValues().AppendEmpty() + qt1.SetQuantile(0.5) + qt1.SetValue(34) + qt2 := doubleDataPt.QuantileValues().AppendEmpty() + qt2.SetQuantile(0.6) + qt2.SetValue(45) + return metrics + }, + wantSplunkMetrics: []*splunk.Event{ + { + Host: "unknown", + Source: "", + SourceType: "", + Event: "metric", + Time: tsMSecs, + Fields: map[string]interface{}{ + "k0": "v0", + "k1": "v1", + "metric_name:summary_sum": float64(42), + }, + }, + { + Host: "unknown", + Source: "", + SourceType: "", + Event: "metric", + Time: tsMSecs, + Fields: map[string]interface{}{ + "k0": "v0", + "k1": "v1", + "metric_name:summary_count": uint64(2), + }, + }, + { + Host: "unknown", + Source: "", + SourceType: "", + Event: "metric", + Time: tsMSecs, + Fields: map[string]interface{}{ + "k0": "v0", + "k1": "v1", + "qt": "0.5", + "metric_name:summary_0.5": float64(34), + }, + }, + { + Host: "unknown", + Source: "", + SourceType: "", + Event: "metric", + Time: tsMSecs, + Fields: map[string]interface{}{ + "k0": "v0", + "k1": "v1", + "qt": "0.6", + "metric_name:summary_0.6": float64(45), + }, + }, + }, + }, { name: "unknown_type", metricsDataFn: func() pdata.Metrics { @@ -545,6 +619,7 @@ func Test_metricDataToSplunk(t *testing.T) { md := tt.metricsDataFn() gotMetrics, gotNumDroppedTimeSeries := metricDataToSplunk(logger, md, &Config{}) assert.Equal(t, tt.wantNumDroppedTimeseries, gotNumDroppedTimeSeries) + assert.Equal(t, len(gotMetrics), len(tt.wantSplunkMetrics)) for i, want := range tt.wantSplunkMetrics { assert.Equal(t, want, gotMetrics[i]) }