Skip to content

Commit 4f35296

Browse files
committed
Fix cumulative histogram generation and test.
Issue google#214
1 parent 041e773 commit 4f35296

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

internal/metrics/datum/buckets_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package datum_test
55

66
import (
7+
"math"
78
"testing"
89
"testing/quick"
910
"time"
@@ -36,4 +37,8 @@ func TestMakeBucket(t *testing.T) {
3637
if r := datum.GetBucketsCount(b); r != 1 {
3738
t.Errorf("count not 1, got %v", r)
3839
}
40+
bs := datum.GetBucketsByMax(b)
41+
if r := datum.GetBucketsCount(b); r != bs[math.Inf(+1)] {
42+
t.Errorf("Inf bucket des not equal total observation count: %v vs %v", r, bs[math.Inf(+1)])
43+
}
3944
}

internal/metrics/datum/datum.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,16 @@ func GetBucketsSum(d Datum) float64 {
262262
}
263263
}
264264

265-
// GetBucketsByMax returns a map of bucket observations by their upper bonds, or panics if d is not a BucketsDatum
265+
// GetBucketsByMax returns a map of cumulative bucket observations by their
266+
// upper bonds, or panics if d is not a BucketsDatum.
266267
func GetBucketsByMax(d Datum) map[float64]uint64 {
267268
switch d := d.(type) {
268269
case *BucketsDatum:
269270
buckets := make(map[float64]uint64)
271+
cum := uint64(0)
270272
for r, c := range d.Buckets() {
271-
buckets[r.Max] = c
273+
cum += c
274+
buckets[r.Max] = cum
272275
}
273276
return buckets
274277
default:

0 commit comments

Comments
 (0)