From 5296dd2953ebe59da394d08dd349e227171651ed Mon Sep 17 00:00:00 2001 From: Abdullah Gharaibeh Date: Thu, 4 Jun 2020 10:44:29 -0400 Subject: [PATCH] Added +inf bucket for quantile computations --- .../k8s.io/component-base/metrics/testutil/metrics.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/component-base/metrics/testutil/metrics.go b/staging/src/k8s.io/component-base/metrics/testutil/metrics.go index ea910dc5ee3..828063d6aab 100644 --- a/staging/src/k8s.io/component-base/metrics/testutil/metrics.go +++ b/staging/src/k8s.io/component-base/metrics/testutil/metrics.go @@ -286,8 +286,14 @@ func (hist *Histogram) Quantile(q float64) float64 { }) } - // bucketQuantile expects the upper bound of the last bucket to be +inf - // buckets[len(buckets)-1].upperBound = math.Inf(+1) + if len(buckets) == 0 || buckets[len(buckets)-1].upperBound != math.Inf(+1) { + // The list of buckets in dto.Histogram doesn't include the final +Inf bucket, so we + // add it here for the reset of the samples. + buckets = append(buckets, bucket{ + count: float64(hist.GetSampleCount()), + upperBound: math.Inf(+1), + }) + } return bucketQuantile(q, buckets) }