mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add additional init checks to ExponentialBucketer.
PiperOrigin-RevId: 441529868
This commit is contained in:
committed by
gVisor bot
parent
edbd203027
commit
717f78b014
@@ -551,6 +551,9 @@ func NewExponentialBucketer(numFiniteBuckets int, width uint64, scale, growth fl
|
||||
if numFiniteBuckets < exponentialMinBuckets || numFiniteBuckets > exponentialMaxBuckets {
|
||||
panic(fmt.Sprintf("number of finite buckets must be in [%d, %d]", exponentialMinBuckets, exponentialMaxBuckets))
|
||||
}
|
||||
if scale < 0 || growth < 0 {
|
||||
panic(fmt.Sprintf("scale and growth for exponential buckets must be >0, got scale=%f and growth=%f", scale, growth))
|
||||
}
|
||||
b := &ExponentialBucketer{
|
||||
numFiniteBuckets: numFiniteBuckets,
|
||||
width: float64(width),
|
||||
@@ -562,6 +565,9 @@ func NewExponentialBucketer(numFiniteBuckets int, width uint64, scale, growth fl
|
||||
b.lowerBounds[0] = 0
|
||||
for i := 1; i <= numFiniteBuckets; i++ {
|
||||
b.lowerBounds[i] = int64(b.width*float64(i) + b.scale*math.Pow(b.growth, float64(i-1)))
|
||||
if b.lowerBounds[i] < 0 {
|
||||
panic(fmt.Sprintf("encountered bucket width overflow at bucket %d", i))
|
||||
}
|
||||
}
|
||||
b.maxSample = b.lowerBounds[numFiniteBuckets] - 1
|
||||
return b
|
||||
|
||||
@@ -830,6 +830,9 @@ func TestBucketerPanics(t *testing.T) {
|
||||
"NewDurationBucketer @ 2": func() {
|
||||
NewDurationBucketer(2, time.Second, time.Minute)
|
||||
},
|
||||
"NewDurationBucketer @ 80": func() {
|
||||
NewDurationBucketer(80, time.Microsecond, 50*time.Microsecond)
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
var recovered interface{}
|
||||
|
||||
Reference in New Issue
Block a user