From 5095efd62831110e65cad79740bf302492756f1e Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Fri, 20 Dec 2024 08:07:54 -0600 Subject: [PATCH] prober: make histogram buckets cumulative Histogram buckets should include counts for all values under the bucket ceiling, not just those between the ceiling and the next lower ceiling. See https://prometheus.io/docs/tutorials/understanding_metric_types/\#histogram Updates tailscale/corp#24522 Signed-off-by: Percy Wegmann --- prober/histogram.go | 1 - prober/histogram_test.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/prober/histogram.go b/prober/histogram.go index e9005b452..c544a5f79 100644 --- a/prober/histogram.go +++ b/prober/histogram.go @@ -45,6 +45,5 @@ func (h *histogram) add(v float64) { continue } h.bucketedCounts[b] += 1 - break } } diff --git a/prober/histogram_test.go b/prober/histogram_test.go index a569167e6..dbb5eda67 100644 --- a/prober/histogram_test.go +++ b/prober/histogram_test.go @@ -23,7 +23,7 @@ func TestHistogram(t *testing.T) { if diff := cmp.Diff(h.sum, 7.5); diff != "" { t.Errorf("wrong sum; (-got+want):%v", diff) } - if diff := cmp.Diff(h.bucketedCounts, map[float64]uint64{1: 2, 2: 2}); diff != "" { + if diff := cmp.Diff(h.bucketedCounts, map[float64]uint64{1: 2, 2: 4}); diff != "" { t.Errorf("wrong bucketedCounts; (-got+want):%v", diff) } }