Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert UpDownCounters to Prometheus gauges #3358

Merged
merged 3 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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