Skip to content

Commit 53c0518

Browse files
✨ Adopt native histograms (#3165)
* adopt native histograms * add native histograms to workqueue metrics too * adopt native histograms for admission histogram
1 parent 2f2e7d8 commit 53c0518

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

pkg/internal/controller/metrics/metrics.go

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

1919
import (
20+
"time"
21+
2022
"github.com/prometheus/client_golang/prometheus"
2123
"github.com/prometheus/client_golang/prometheus/collectors"
2224
"sigs.k8s.io/controller-runtime/pkg/metrics"
@@ -60,6 +62,9 @@ var (
6062
Help: "Length of time per reconciliation per controller",
6163
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
6264
1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40, 50, 60},
65+
NativeHistogramBucketFactor: 1.1,
66+
NativeHistogramMaxBucketNumber: 100,
67+
NativeHistogramMinResetDuration: 1 * time.Hour,
6368
}, []string{"controller"})
6469

6570
// WorkerCount is a prometheus metric which holds the number of

pkg/internal/metrics/workqueue.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"strconv"
21+
"time"
2122

2223
"github.com/prometheus/client_golang/prometheus"
2324
"k8s.io/client-go/util/workqueue"
@@ -54,17 +55,23 @@ var (
5455
}, []string{"name", "controller"})
5556

5657
latency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
57-
Subsystem: WorkQueueSubsystem,
58-
Name: QueueLatencyKey,
59-
Help: "How long in seconds an item stays in workqueue before being requested",
60-
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 12),
58+
Subsystem: WorkQueueSubsystem,
59+
Name: QueueLatencyKey,
60+
Help: "How long in seconds an item stays in workqueue before being requested",
61+
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 12),
62+
NativeHistogramBucketFactor: 1.1,
63+
NativeHistogramMaxBucketNumber: 100,
64+
NativeHistogramMinResetDuration: 1 * time.Hour,
6165
}, []string{"name", "controller"})
6266

6367
workDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
64-
Subsystem: WorkQueueSubsystem,
65-
Name: WorkDurationKey,
66-
Help: "How long in seconds processing an item from workqueue takes.",
67-
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 12),
68+
Subsystem: WorkQueueSubsystem,
69+
Name: WorkDurationKey,
70+
Help: "How long in seconds processing an item from workqueue takes.",
71+
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 12),
72+
NativeHistogramBucketFactor: 1.1,
73+
NativeHistogramMaxBucketNumber: 100,
74+
NativeHistogramMinResetDuration: 1 * time.Hour,
6875
}, []string{"name", "controller"})
6976

7077
unfinished = prometheus.NewGaugeVec(prometheus.GaugeOpts{

pkg/webhook/internal/metrics/metrics.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"net/http"
21+
"time"
2122

2223
"github.com/prometheus/client_golang/prometheus"
2324
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -30,8 +31,11 @@ var (
3031
// of processing admission requests.
3132
RequestLatency = prometheus.NewHistogramVec(
3233
prometheus.HistogramOpts{
33-
Name: "controller_runtime_webhook_latency_seconds",
34-
Help: "Histogram of the latency of processing admission requests",
34+
Name: "controller_runtime_webhook_latency_seconds",
35+
Help: "Histogram of the latency of processing admission requests",
36+
NativeHistogramBucketFactor: 1.1,
37+
NativeHistogramMaxBucketNumber: 100,
38+
NativeHistogramMinResetDuration: 1 * time.Hour,
3539
},
3640
[]string{"webhook"},
3741
)

0 commit comments

Comments
 (0)