Skip to content

Commit 4aa7a70

Browse files
committed
Add Prometheus Native Histogram defaults
Add some new default values to the metrics package for the Prometheus Native Histogram support. * Use the upstream documented recommendation for a 10% bucket factor. * Set an arbitrary limit of 160 buckets to avoid unbounded memory growth. * Set a 1 hour minimum reset interval to avoid frequent resets which would affect efficiency of the 120 sample per hour Prometheus chunks given a 30s scrape interval. See: #128842 Signed-off-by: SuperQ <superq@gmail.com>
1 parent 7fc8a86 commit 4aa7a70

File tree

1 file changed

+22
-0
lines changed
  • staging/src/k8s.io/component-base/metrics

1 file changed

+22
-0
lines changed

staging/src/k8s.io/component-base/metrics/buckets.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,34 @@ limitations under the License.
1717
package metrics
1818

1919
import (
20+
"time"
21+
2022
"github.com/prometheus/client_golang/prometheus"
2123
)
2224

2325
// DefBuckets is a wrapper for prometheus.DefBuckets
2426
var DefBuckets = prometheus.DefBuckets
2527

28+
// DefNativeHistogramBucketFactor defines a sane default for the Prometheus
29+
// native histogram exponential bucket factor. The value of 1.1 means each
30+
// bucket is 10% wider than the previous bucket.
31+
//
32+
// For more information on Prometheus Native Histograms, see the upstream
33+
// client_golang documentation.
34+
//
35+
// https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#HistogramOpts
36+
var DefNativeHistogramBucketFactor = 1.1
37+
38+
// DefNativeHistogramMaxBucketNumber defines a sane default for the Prometheus
39+
// native histogram limit to the number of sparse buckets. This avoids
40+
// unbounded memory requirements for native histogram tracking.
41+
var DefNativeHistogramMaxBucketNumber = 160
42+
43+
// DefNativeHistogramMinResetDuration defines a sane default for the Prometheus
44+
// native histogram minimum reset duration. This is used to reset the histogram
45+
// buckets in case the max bucket number value is reached.
46+
var DefNativeHistogramMinResetDuration = time.Hour
47+
2648
// LinearBuckets is a wrapper for prometheus.LinearBuckets.
2749
func LinearBuckets(start, width float64, count int) []float64 {
2850
return prometheus.LinearBuckets(start, width, count)

0 commit comments

Comments
 (0)