Skip to content

Commit

Permalink
Convert UpDownCounters to Prometheus gauges (#3358)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dashpole and MrAlias committed Oct 19, 2022
1 parent 6c0a7c4 commit 430f558
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion exporters/prometheus/exporter.go
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/testdata/gauge.txt
@@ -1,3 +1,3 @@
# HELP bar a fun little gauge
# TYPE bar counter
# TYPE bar gauge
bar{A="B",C="D"} 75
4 changes: 2 additions & 2 deletions exporters/prometheus/testdata/sanitized_names.txt
@@ -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
Expand Down

0 comments on commit 430f558

Please sign in to comment.