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 <percy@tailscale.com>
This commit is contained in:
Percy Wegmann 2024-12-20 08:07:54 -06:00 committed by Percy Wegmann
parent 3adad364f1
commit 5095efd628
2 changed files with 1 additions and 2 deletions

View File

@ -45,6 +45,5 @@ func (h *histogram) add(v float64) {
continue
}
h.bucketedCounts[b] += 1
break
}
}

View File

@ -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)
}
}