mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-09 01:27:42 +00:00
5095efd628
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>
30 lines
632 B
Go
30 lines
632 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package prober
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestHistogram(t *testing.T) {
|
|
h := newHistogram([]float64{1, 2})
|
|
h.add(0.5)
|
|
h.add(1)
|
|
h.add(1.5)
|
|
h.add(2)
|
|
h.add(2.5)
|
|
|
|
if diff := cmp.Diff(h.count, uint64(5)); diff != "" {
|
|
t.Errorf("wrong count; (-got+want):%v", diff)
|
|
}
|
|
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: 4}); diff != "" {
|
|
t.Errorf("wrong bucketedCounts; (-got+want):%v", diff)
|
|
}
|
|
}
|