Histogram with zero-width zero bucket

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2024-06-20 19:03:14 +02:00
parent 14259fa70c
commit 9c344085f9
1 changed files with 18 additions and 5 deletions

View File

@ -64,6 +64,7 @@ func NewMetrics(reg prometheus.Registerer, normMean, normDomain float64) *metric
Help: "RPC latency distributions.",
Buckets: prometheus.LinearBuckets(normMean-5*normDomain, .5*normDomain, 20),
NativeHistogramBucketFactor: 1.1,
NativeHistogramZeroThreshold: prometheus.NativeHistogramZeroThresholdZero,
}),
}
reg.MustRegister(m.rpcDurations)
@ -106,6 +107,18 @@ func main() {
}()
go func() {
m.rpcDurationsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
0, prometheus.Labels{"dummyID": fmt.Sprint(rand.Intn(100000))},
)
m.rpcDurationsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
0, prometheus.Labels{"dummyID": fmt.Sprint(rand.Intn(100000))},
)
m.rpcDurationsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
0, prometheus.Labels{"dummyID": fmt.Sprint(rand.Intn(100000))},
)
m.rpcDurationsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
0.01, prometheus.Labels{"dummyID": fmt.Sprint(rand.Intn(100000))},
)
for {
v := (rand.NormFloat64() * *normDomain) + *normMean
m.rpcDurations.WithLabelValues("normal").Observe(v)
@ -118,7 +131,7 @@ func main() {
m.rpcDurationsHistogram.(prometheus.ExemplarObserver).ObserveWithExemplar(
v, prometheus.Labels{"dummyID": fmt.Sprint(rand.Intn(100000))},
)
time.Sleep(time.Duration(75*oscillationFactor()) * time.Millisecond)
time.Sleep(time.Duration(oscillationFactor()) * time.Millisecond)
}
}()