Skip to content

Commit

Permalink
promtheus exporter will sum hist buckets (#3281) (#3282)
Browse files Browse the repository at this point in the history
Signed-off-by: albertlockett <[email protected]>
  • Loading branch information
albertlockett authored Oct 14, 2022
1 parent 84e28fd commit 1e72af4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions exporters/prometheus/testdata/histogram.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions exporters/prometheus/testdata/sanitized_names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1e72af4

Please sign in to comment.