1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-12 10:04:29 +02:00

Convert UpDownCounters to Prometheus gauges (#3358)

* updown counters are now converted to prometheus gauges

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
David Ashpole 2022-10-19 12:07:53 -04:00 committed by GitHub
parent 6c0a7c4dc8
commit 430f55878b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 4 deletions

View File

@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Slice attributes of `attribute` package are now comparable based on their value, not instance. (#3108 #3252)
- Prometheus exporter will now cumulatively sum histogram buckets. (#3281)
- Export the sum of each histogram datapoint uniquely with the `go.opentelemetry.io/otel/exporters/otlpmetric` exporters. (#3284, #3293)
- UpDownCounters are now correctly output as prometheus gauges in the `go.opentelemetry.io/otel/exporters/prometheus` exporter. (#3358)
## [1.11.0/0.32.3] 2022-10-12

View File

@ -168,6 +168,10 @@ func getHistogramMetricData(histogram metricdata.Histogram, m metricdata.Metrics
}
func getSumMetricData[N int64 | float64](sum metricdata.Sum[N], m metricdata.Metrics) []*metricData {
valueType := prometheus.CounterValue
if !sum.IsMonotonic {
valueType = prometheus.GaugeValue
}
dataPoints := make([]*metricData, 0, len(sum.DataPoints))
for _, dp := range sum.DataPoints {
keys, values := getAttrs(dp.Attributes)
@ -176,7 +180,7 @@ func getSumMetricData[N int64 | float64](sum metricdata.Sum[N], m metricdata.Met
name: m.Name,
description: desc,
attributeValues: values,
valueType: prometheus.CounterValue,
valueType: valueType,
value: float64(dp.Value),
}
dataPoints = append(dataPoints, md)

View File

@ -1,3 +1,3 @@
# HELP bar a fun little gauge
# TYPE bar counter
# TYPE bar gauge
bar{A="B",C="D"} 75

View File

@ -1,11 +1,11 @@
# HELP bar a fun little gauge
# TYPE bar counter
# TYPE bar gauge
bar{A="B",C="D"} 75
# HELP _0invalid_counter_name a counter with an invalid name
# TYPE _0invalid_counter_name counter
_0invalid_counter_name{A="B",C="D"} 100
# HELP invalid_gauge_name a gauge with an invalid name
# TYPE invalid_gauge_name counter
# TYPE invalid_gauge_name gauge
invalid_gauge_name{A="B",C="D"} 100
# HELP invalid_hist_name a histogram with an invalid name
# TYPE invalid_hist_name histogram