Skip to content

Commit 650ea59

Browse files
authored
Merge pull request #1587 from 2uasimojo/issues/1423/optional
⚠️ Disable the `rest_client_request_latency_seconds` metric by default
2 parents 81309dc + a6ced42 commit 650ea59

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

pkg/metrics/client_go_adapter.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,24 @@ const (
5252

5353
var (
5454
// client metrics.
55-
requestLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
55+
56+
// RequestLatency reports the request latency in seconds per verb/URL.
57+
// Deprecated: This metric is deprecated for removal in a future release: using the URL as a
58+
// dimension results in cardinality explosion for some consumers. It was deprecated upstream
59+
// in k8s v1.14 and hidden in v1.17 via https://github.com/kubernetes/kubernetes/pull/83836.
60+
// It is not registered by default. To register:
61+
// import (
62+
// clientmetrics "k8s.io/client-go/tools/metrics"
63+
// clmetrics "sigs.k8s.io/controller-runtime/metrics"
64+
// )
65+
//
66+
// func init() {
67+
// clmetrics.Registry.MustRegister(clmetrics.RequestLatency)
68+
// clientmetrics.Register(clientmetrics.RegisterOpts{
69+
// RequestLatency: clmetrics.LatencyAdapter
70+
// })
71+
// }
72+
RequestLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
5673
Subsystem: RestClientSubsystem,
5774
Name: LatencyKey,
5875
Help: "Request latency in seconds. Broken down by verb and URL.",
@@ -127,13 +144,11 @@ func init() {
127144
// registerClientMetrics sets up the client latency metrics from client-go.
128145
func registerClientMetrics() {
129146
// register the metrics with our registry
130-
Registry.MustRegister(requestLatency)
131147
Registry.MustRegister(requestResult)
132148

133149
// register the metrics with client-go
134150
clientmetrics.Register(clientmetrics.RegisterOpts{
135-
RequestLatency: &latencyAdapter{metric: requestLatency},
136-
RequestResult: &resultAdapter{metric: requestResult},
151+
RequestResult: &resultAdapter{metric: requestResult},
137152
})
138153
}
139154

@@ -159,11 +174,13 @@ func registerReflectorMetrics() {
159174
// copied (more-or-less directly) from k8s.io/kubernetes setup code
160175
// (which isn't anywhere in an easily-importable place).
161176

162-
type latencyAdapter struct {
177+
// LatencyAdapter implements LatencyMetric.
178+
type LatencyAdapter struct {
163179
metric *prometheus.HistogramVec
164180
}
165181

166-
func (l *latencyAdapter) Observe(_ context.Context, verb string, u url.URL, latency time.Duration) {
182+
// Observe increments the request latency metric for the given verb/URL.
183+
func (l *LatencyAdapter) Observe(_ context.Context, verb string, u url.URL, latency time.Duration) {
167184
l.metric.WithLabelValues(verb, u.String()).Observe(latency.Seconds())
168185
}
169186

0 commit comments

Comments
 (0)