MCPcopy
hub / github.com/prometheus/client_golang / ExponentialBucketsRange

Function ExponentialBucketsRange

prometheus/histogram.go:339–359  ·  view source on GitHub ↗

ExponentialBucketsRange creates 'count' buckets, where the lowest bucket is 'min' and the highest bucket is 'max'. The final +Inf bucket is not counted and not included in the returned slice. The returned slice is meant to be used for the Buckets field of HistogramOpts. The function panics if 'coun

(minBucket, maxBucket float64, count int)

Source from the content-addressed store, hash-verified

337//
338// The function panics if 'count' is 0 or negative, if 'min' is 0 or negative.
339func ExponentialBucketsRange(minBucket, maxBucket float64, count int) []float64 {
340 if count < 1 {
341 panic("ExponentialBucketsRange count needs a positive count")
342 }
343 if minBucket <= 0 {
344 panic("ExponentialBucketsRange min needs to be greater than 0")
345 }
346
347 // Formula for exponential buckets.
348 // max = min*growthFactor^(bucketCount-1)
349
350 // We know max/min and highest bucket. Solve for growthFactor.
351 growthFactor := math.Pow(maxBucket/minBucket, 1.0/float64(count-1))
352
353 // Now that we know growthFactor, solve for each bucket.
354 buckets := make([]float64, count)
355 for i := 1; i <= count; i++ {
356 buckets[i-1] = minBucket * math.Pow(growthFactor, float64(i-1))
357 }
358 return buckets
359}
360
361// HistogramOpts bundles the options for creating a Histogram metric. It is
362// mandatory to set Name to a non-empty string. All other fields are optional

Callers 1

TestBucketsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestBucketsFunction · 0.68