mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-03-31 21:55:32 +02:00
Fix prometheus name duplicate _total suffix (#3369)
Signed-off-by: Bing Han <h.bing612@gmail.com> Signed-off-by: Bing Han <h.bing612@gmail.com>
This commit is contained in:
parent
1133977556
commit
ccbc38e66e
@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- The `go.opentelemetry.io/otel/exporters/prometheus` exporter fixes duplicated `_total` suffixes. (#3369)
|
||||||
|
|
||||||
## [1.11.1/0.33.0] 2022-10-19
|
## [1.11.1/0.33.0] 2022-10-19
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -162,11 +162,11 @@ func addSumMetric[N int64 | float64](ch chan<- prometheus.Metric, sum metricdata
|
|||||||
if !sum.IsMonotonic {
|
if !sum.IsMonotonic {
|
||||||
valueType = prometheus.GaugeValue
|
valueType = prometheus.GaugeValue
|
||||||
}
|
}
|
||||||
|
if sum.IsMonotonic {
|
||||||
|
// Add _total suffix for counters
|
||||||
|
name += counterSuffix
|
||||||
|
}
|
||||||
for _, dp := range sum.DataPoints {
|
for _, dp := range sum.DataPoints {
|
||||||
if sum.IsMonotonic {
|
|
||||||
// Add _total suffix for counters
|
|
||||||
name += counterSuffix
|
|
||||||
}
|
|
||||||
keys, values := getAttrs(dp.Attributes)
|
keys, values := getAttrs(dp.Attributes)
|
||||||
desc := prometheus.NewDesc(name, m.Description, keys, nil)
|
desc := prometheus.NewDesc(name, m.Description, keys, nil)
|
||||||
m, err := prometheus.NewConstMetric(desc, valueType, float64(dp.Value), values...)
|
m, err := prometheus.NewConstMetric(desc, valueType, float64(dp.Value), values...)
|
||||||
|
@ -62,6 +62,14 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
counter.Add(ctx, 5, attrs...)
|
counter.Add(ctx, 5, attrs...)
|
||||||
counter.Add(ctx, 10.3, attrs...)
|
counter.Add(ctx, 10.3, attrs...)
|
||||||
counter.Add(ctx, 9, attrs...)
|
counter.Add(ctx, 9, attrs...)
|
||||||
|
|
||||||
|
attrs2 := []attribute.KeyValue{
|
||||||
|
attribute.Key("A").String("D"),
|
||||||
|
attribute.Key("C").String("B"),
|
||||||
|
attribute.Key("E").Bool(true),
|
||||||
|
attribute.Key("F").Int(42),
|
||||||
|
}
|
||||||
|
counter.Add(ctx, 5, attrs2...)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
1
exporters/prometheus/testdata/counter.txt
vendored
1
exporters/prometheus/testdata/counter.txt
vendored
@ -1,6 +1,7 @@
|
|||||||
# HELP foo_milliseconds_total a simple counter
|
# HELP foo_milliseconds_total a simple counter
|
||||||
# TYPE foo_milliseconds_total counter
|
# TYPE foo_milliseconds_total counter
|
||||||
foo_milliseconds_total{A="B",C="D",E="true",F="42"} 24.3
|
foo_milliseconds_total{A="B",C="D",E="true",F="42"} 24.3
|
||||||
|
foo_milliseconds_total{A="D",C="B",E="true",F="42"} 5
|
||||||
# HELP target_info Target metadata
|
# HELP target_info Target metadata
|
||||||
# TYPE target_info gauge
|
# TYPE target_info gauge
|
||||||
target_info{service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1
|
target_info{service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user