Skip to content

Commit

Permalink
Add guardrails to exponentialBucketRange (#7218)
Browse files Browse the repository at this point in the history
  • Loading branch information
bduffany authored Aug 12, 2024
1 parent ce16409 commit 6d72df4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package metrics

import (
"fmt"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -2690,6 +2691,12 @@ var (
// terms of a min and max value, rather than needing to explicitly calculate the
// number of buckets.
func exponentialBucketRange(min, max, factor float64) []float64 {
if min < 0 || min >= max {
panic(fmt.Sprintf("exponentialBucketRange: expected 0 < min < max, got min=%f, max=%f", min, max))
}
if factor <= 1 {
panic(fmt.Sprintf("exponentialBucketRange: expected factor > 1, got factor=%f", factor))
}
buckets := []float64{}
current := min
for current < max {
Expand Down

0 comments on commit 6d72df4

Please sign in to comment.