Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix open-telemetry#3281: promtheus exporter will cumulatively sum his…
Browse files Browse the repository at this point in the history
…t buckets
albertlockett committed Oct 13, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 84e28fd commit 4106fd9
Showing 3 changed files with 22 additions and 19 deletions.
5 changes: 4 additions & 1 deletion exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
@@ -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,
14 changes: 7 additions & 7 deletions exporters/prometheus/testdata/histogram.txt
Original file line number Diff line number Diff line change
@@ -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
@@ -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 4106fd9

Please sign in to comment.