@@ -52,7 +52,24 @@ const (
52
52
53
53
var (
54
54
// 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 {
56
73
Subsystem : RestClientSubsystem ,
57
74
Name : LatencyKey ,
58
75
Help : "Request latency in seconds. Broken down by verb and URL." ,
@@ -127,13 +144,11 @@ func init() {
127
144
// registerClientMetrics sets up the client latency metrics from client-go.
128
145
func registerClientMetrics () {
129
146
// register the metrics with our registry
130
- Registry .MustRegister (requestLatency )
131
147
Registry .MustRegister (requestResult )
132
148
133
149
// register the metrics with client-go
134
150
clientmetrics .Register (clientmetrics.RegisterOpts {
135
- RequestLatency : & latencyAdapter {metric : requestLatency },
136
- RequestResult : & resultAdapter {metric : requestResult },
151
+ RequestResult : & resultAdapter {metric : requestResult },
137
152
})
138
153
}
139
154
@@ -159,11 +174,13 @@ func registerReflectorMetrics() {
159
174
// copied (more-or-less directly) from k8s.io/kubernetes setup code
160
175
// (which isn't anywhere in an easily-importable place).
161
176
162
- type latencyAdapter struct {
177
+ // LatencyAdapter implements LatencyMetric.
178
+ type LatencyAdapter struct {
163
179
metric * prometheus.HistogramVec
164
180
}
165
181
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 ) {
167
184
l .metric .WithLabelValues (verb , u .String ()).Observe (latency .Seconds ())
168
185
}
169
186
0 commit comments