Skip to content

Commit

Permalink
exporters/prometheusremotewrite: Do not append '_total' to counter me…
Browse files Browse the repository at this point in the history
…tric names.

This appears to have been enforcing convention but isn't actually required.

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
  • Loading branch information
Aneurysm9 committed Apr 22, 2021
1 parent 0694cac commit 233114c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
33 changes: 6 additions & 27 deletions exporter/prometheusremotewriteexporter/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const (
leStr = "le"
quantileStr = "quantile"
pInfStr = "+Inf"
counterSuffix = "_total"
delimiter = "_"
keyStr = "key"
)
Expand Down Expand Up @@ -178,34 +177,14 @@ func getPromMetricName(metric *otlp.Metric, ns string) string {
return ""
}

// if the metric is counter, _total suffix should be applied
_, isCounter1 := metric.Data.(*otlp.Metric_DoubleSum)
_, isCounter2 := metric.Data.(*otlp.Metric_IntSum)
isCounter := isCounter1 || isCounter2

b := strings.Builder{}

b.WriteString(ns)

if b.Len() > 0 {
b.WriteString(delimiter)
var name string
if len(ns) > 0 {
name = ns + delimiter + metric.GetName()
} else {
name = metric.GetName()
}
name := metric.GetName()
b.WriteString(name)

// Including units makes two metrics with the same name and label set belong to two different TimeSeries if the
// units are different.
/*
if b.Len() > 0 && len(desc.GetUnit()) > 0{
fmt.Fprintf(&b, delimeter)
fmt.Fprintf(&b, desc.GetUnit())
}
*/

if b.Len() > 0 && isCounter && !strings.HasSuffix(name, counterSuffix) {
b.WriteString(counterSuffix)
}
return sanitize(b.String())
return sanitize(name)
}

// batchTimeSeries splits series into multiple batch write requests.
Expand Down
4 changes: 2 additions & 2 deletions exporter/prometheusremotewriteexporter/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ func Test_getPromMetricName(t *testing.T) {
validDoubleGauge,
},
{
"total_suffix",
"no_counter_suffix",
validMetrics1[validIntSum],
ns1,
"test_ns_" + validIntSum + counterSuffix,
"test_ns_" + validIntSum,
},
{
"already_has_total_suffix",
Expand Down

0 comments on commit 233114c

Please sign in to comment.