diff --git a/CHANGELOG.md b/CHANGELOG.md index faeccbc936b..54a28deaad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - 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) ## [1.11.0/0.32.3] 2022-10-12 diff --git a/exporters/prometheus/exporter.go b/exporters/prometheus/exporter.go index 3fe848f1e03..8b4c7f56114 100644 --- a/exporters/prometheus/exporter.go +++ b/exporters/prometheus/exporter.go @@ -145,8 +145,11 @@ func getHistogramMetricData(histogram metricdata.Histogram, m metricdata.Metrics keys, values := getAttrs(dp.Attributes) desc := prometheus.NewDesc(sanitizeName(m.Name), m.Description, keys, nil) buckets := make(map[float64]uint64, len(dp.Bounds)) + + cumulativeCount := uint64(0) for i, bound := range dp.Bounds { - buckets[bound] = dp.BucketCounts[i] + cumulativeCount += dp.BucketCounts[i] + buckets[bound] = cumulativeCount } md := &metricData{ name: m.Name, diff --git a/exporters/prometheus/testdata/histogram.txt b/exporters/prometheus/testdata/histogram.txt index 3a8422bb573..95f202154a4 100644 --- a/exporters/prometheus/testdata/histogram.txt +++ b/exporters/prometheus/testdata/histogram.txt @@ -3,13 +3,13 @@ histogram_baz_bucket{A="B",C="D",le="0"} 0 histogram_baz_bucket{A="B",C="D",le="5"} 0 histogram_baz_bucket{A="B",C="D",le="10"} 1 -histogram_baz_bucket{A="B",C="D",le="25"} 1 -histogram_baz_bucket{A="B",C="D",le="50"} 0 -histogram_baz_bucket{A="B",C="D",le="75"} 0 -histogram_baz_bucket{A="B",C="D",le="100"} 0 -histogram_baz_bucket{A="B",C="D",le="250"} 2 -histogram_baz_bucket{A="B",C="D",le="500"} 0 -histogram_baz_bucket{A="B",C="D",le="1000"} 0 +histogram_baz_bucket{A="B",C="D",le="25"} 2 +histogram_baz_bucket{A="B",C="D",le="50"} 2 +histogram_baz_bucket{A="B",C="D",le="75"} 2 +histogram_baz_bucket{A="B",C="D",le="100"} 2 +histogram_baz_bucket{A="B",C="D",le="250"} 4 +histogram_baz_bucket{A="B",C="D",le="500"} 4 +histogram_baz_bucket{A="B",C="D",le="1000"} 4 histogram_baz_bucket{A="B",C="D",le="+Inf"} 4 histogram_baz_sum{A="B",C="D"} 236 histogram_baz_count{A="B",C="D"} 4 diff --git a/exporters/prometheus/testdata/sanitized_names.txt b/exporters/prometheus/testdata/sanitized_names.txt index 0158d17aeb6..509055705a3 100644 --- a/exporters/prometheus/testdata/sanitized_names.txt +++ b/exporters/prometheus/testdata/sanitized_names.txt @@ -13,17 +13,17 @@ invalid_hist_name_bucket{A="B",C="D",le="0"} 0 invalid_hist_name_bucket{A="B",C="D",le="5"} 0 invalid_hist_name_bucket{A="B",C="D",le="10"} 0 invalid_hist_name_bucket{A="B",C="D",le="25"} 1 -invalid_hist_name_bucket{A="B",C="D",le="50"} 0 -invalid_hist_name_bucket{A="B",C="D",le="75"} 0 -invalid_hist_name_bucket{A="B",C="D",le="100"} 0 -invalid_hist_name_bucket{A="B",C="D",le="250"} 0 -invalid_hist_name_bucket{A="B",C="D",le="500"} 0 -invalid_hist_name_bucket{A="B",C="D",le="750"} 0 -invalid_hist_name_bucket{A="B",C="D",le="1000"} 0 -invalid_hist_name_bucket{A="B",C="D",le="2500"} 0 -invalid_hist_name_bucket{A="B",C="D",le="5000"} 0 -invalid_hist_name_bucket{A="B",C="D",le="7500"} 0 -invalid_hist_name_bucket{A="B",C="D",le="10000"} 0 +invalid_hist_name_bucket{A="B",C="D",le="50"} 1 +invalid_hist_name_bucket{A="B",C="D",le="75"} 1 +invalid_hist_name_bucket{A="B",C="D",le="100"} 1 +invalid_hist_name_bucket{A="B",C="D",le="250"} 1 +invalid_hist_name_bucket{A="B",C="D",le="500"} 1 +invalid_hist_name_bucket{A="B",C="D",le="750"} 1 +invalid_hist_name_bucket{A="B",C="D",le="1000"} 1 +invalid_hist_name_bucket{A="B",C="D",le="2500"} 1 +invalid_hist_name_bucket{A="B",C="D",le="5000"} 1 +invalid_hist_name_bucket{A="B",C="D",le="7500"} 1 +invalid_hist_name_bucket{A="B",C="D",le="10000"} 1 invalid_hist_name_bucket{A="B",C="D",le="+Inf"} 1 invalid_hist_name_sum{A="B",C="D"} 23 invalid_hist_name_count{A="B",C="D"} 1