Skip to content

Commit

Permalink
splunkhecexporter: update labels -> attributes (#4613)
Browse files Browse the repository at this point in the history
Following the changes in core to OTLP 0.9.0 to move away from `Labels` and on to `Attributes`

**Link to tracking Issue:** Part of open-telemetry/opentelemetry-collector#3535
  • Loading branch information
alrex committed Aug 13, 2021
1 parent 5e4c6d6 commit 9ae8a0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ func createMetricsData(numberOfDataPoints int) pdata.Metrics {
doublePt := metric.Gauge().DataPoints().AppendEmpty()
doublePt.SetTimestamp(pdata.TimestampFromTime(tsUnix))
doublePt.SetDoubleVal(doubleVal)
doublePt.LabelsMap().Insert("k/n0", "vn0")
doublePt.LabelsMap().Insert("k/n1", "vn1")
doublePt.LabelsMap().Insert("k/r0", "vr0")
doublePt.LabelsMap().Insert("k/r1", "vr1")
doublePt.Attributes().InsertString("k/n0", "vn0")
doublePt.Attributes().InsertString("k/n1", "vn1")
doublePt.Attributes().InsertString("k/r0", "vr0")
doublePt.Attributes().InsertString("k/r1", "vr1")
}

return metrics
Expand Down
24 changes: 12 additions & 12 deletions exporter/splunkhecexporter/metricdata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
for gi := 0; gi < pts.Len(); gi++ {
dataPt := pts.At(gi)
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
switch dataPt.Type() {
case pdata.MetricValueTypeInt:
fields[metricFieldName] = dataPt.IntVal()
Expand All @@ -108,15 +108,15 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
// first, add one event for sum, and one for count
{
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
fields[metricFieldName+sumSuffix] = dataPt.Sum()
fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String()
sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields)
splunkMetrics = append(splunkMetrics, sm)
}
{
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
fields[metricFieldName+countSuffix] = dataPt.Count()
fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String()
sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields)
Expand All @@ -131,7 +131,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
// now create buckets for each bound.
for bi := 0; bi < len(bounds); bi++ {
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
fields["le"] = float64ToDimValue(bounds[bi])
value += counts[bi]
fields[metricFieldName+bucketSuffix] = value
Expand All @@ -142,7 +142,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
// add an upper bound for +Inf
{
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
fields["le"] = float64ToDimValue(math.Inf(1))
fields[metricFieldName+bucketSuffix] = value + counts[len(counts)-1]
fields[splunkMetricTypeKey] = pdata.MetricDataTypeHistogram.String()
Expand All @@ -155,7 +155,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
for gi := 0; gi < pts.Len(); gi++ {
dataPt := pts.At(gi)
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
switch dataPt.Type() {
case pdata.MetricValueTypeInt:
fields[metricFieldName] = dataPt.IntVal()
Expand All @@ -173,15 +173,15 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
// first, add one event for sum, and one for count
{
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
fields[metricFieldName+sumSuffix] = dataPt.Sum()
fields[splunkMetricTypeKey] = pdata.MetricDataTypeSummary.String()
sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields)
splunkMetrics = append(splunkMetrics, sm)
}
{
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
fields[metricFieldName+countSuffix] = dataPt.Count()
fields[splunkMetricTypeKey] = pdata.MetricDataTypeSummary.String()
sm := createEvent(dataPt.Timestamp(), host, source, sourceType, index, fields)
Expand All @@ -191,7 +191,7 @@ func metricDataToSplunk(logger *zap.Logger, data pdata.Metrics, config *Config)
// now create values for each quantile.
for bi := 0; bi < dataPt.QuantileValues().Len(); bi++ {
fields := cloneMap(commonFields)
populateLabels(fields, dataPt.LabelsMap())
populateAttributes(fields, dataPt.Attributes())
dp := dataPt.QuantileValues().At(bi)
fields["qt"] = float64ToDimValue(dp.Quantile())
fields[metricFieldName+"_"+strconv.FormatFloat(dp.Quantile(), 'f', -1, 64)] = dp.Value()
Expand Down Expand Up @@ -228,9 +228,9 @@ func createEvent(timestamp pdata.Timestamp, host string, source string, sourceTy

}

func populateLabels(fields map[string]interface{}, labelsMap pdata.StringMap) {
labelsMap.Range(func(k string, v string) bool {
fields[k] = v
func populateAttributes(fields map[string]interface{}, attributeMap pdata.AttributeMap) {
attributeMap.Range(func(k string, v pdata.AttributeValue) bool {
fields[k] = v.StringVal()
return true
})
}
Expand Down

0 comments on commit 9ae8a0d

Please sign in to comment.