Skip to content

Commit

Permalink
Map summary metrics to Splunk hec metrics (#3344)
Browse files Browse the repository at this point in the history
* Add support for mapping summary metrics to splunk hec metrics

* Remove extra check
  • Loading branch information
atoulme authored May 11, 2021
1 parent 04f3e1b commit 63796d8
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
31 changes: 31 additions & 0 deletions exporter/splunkhecexporter/metricdata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
74 changes: 74 additions & 0 deletions exporter/splunkhecexporter/metricdata_to_splunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 63796d8

Please sign in to comment.