Skip to content

Commit 942d53b

Browse files
authored
Merge pull request #2299 from k8s-infra-cherrypick-robot/cherry-pick-2298-to-release-0.14
[release-0.14] ⚠ Remove metrics with high cardinality
2 parents fb3c6fd + a5cf140 commit 942d53b

File tree

1 file changed

+1
-88
lines changed

1 file changed

+1
-88
lines changed

pkg/metrics/client_go_adapter.go

+1-88
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package metrics
1818

1919
import (
2020
"context"
21-
"net/url"
22-
"time"
2321

2422
"github.com/prometheus/client_golang/prometheus"
2523
clientmetrics "k8s.io/client-go/tools/metrics"
@@ -29,70 +27,9 @@ import (
2927
// that client-go registers metrics. We copy the names and formats
3028
// from Kubernetes so that we match the core controllers.
3129

32-
// Metrics subsystem and all of the keys used by the rest client.
33-
const (
34-
RestClientSubsystem = "rest_client"
35-
LatencyKey = "request_latency_seconds"
36-
ResultKey = "requests_total"
37-
)
38-
3930
var (
4031
// client metrics.
4132

42-
// RequestLatency reports the request latency in seconds per verb/URL.
43-
// Deprecated: This metric is deprecated for removal in a future release: using the URL as a
44-
// dimension results in cardinality explosion for some consumers. It was deprecated upstream
45-
// in k8s v1.14 and hidden in v1.17 via https://github.com/kubernetes/kubernetes/pull/83836.
46-
// It is not registered by default. To register:
47-
// import (
48-
// clientmetrics "k8s.io/client-go/tools/metrics"
49-
// clmetrics "sigs.k8s.io/controller-runtime/metrics"
50-
// )
51-
//
52-
// func init() {
53-
// clmetrics.Registry.MustRegister(clmetrics.RequestLatency)
54-
// clientmetrics.Register(clientmetrics.RegisterOpts{
55-
// RequestLatency: clmetrics.LatencyAdapter
56-
// })
57-
// }
58-
RequestLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
59-
Subsystem: RestClientSubsystem,
60-
Name: LatencyKey,
61-
Help: "Request latency in seconds. Broken down by verb and URL.",
62-
Buckets: prometheus.ExponentialBuckets(0.001, 2, 10),
63-
}, []string{"verb", "url"})
64-
65-
// requestLatency is a Prometheus Histogram metric type partitioned by
66-
// "verb", and "host" labels. It is used for the rest client latency metrics.
67-
requestLatency = prometheus.NewHistogramVec(
68-
prometheus.HistogramOpts{
69-
Name: "rest_client_request_duration_seconds",
70-
Help: "Request latency in seconds. Broken down by verb, and host.",
71-
Buckets: []float64{0.005, 0.025, 0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 15.0, 30.0, 60.0},
72-
},
73-
[]string{"verb", "host"},
74-
)
75-
76-
requestSize = prometheus.NewHistogramVec(
77-
prometheus.HistogramOpts{
78-
Name: "rest_client_request_size_bytes",
79-
Help: "Request size in bytes. Broken down by verb and host.",
80-
// 64 bytes to 16MB
81-
Buckets: []float64{64, 256, 512, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216},
82-
},
83-
[]string{"verb", "host"},
84-
)
85-
86-
responseSize = prometheus.NewHistogramVec(
87-
prometheus.HistogramOpts{
88-
Name: "rest_client_response_size_bytes",
89-
Help: "Response size in bytes. Broken down by verb and host.",
90-
// 64 bytes to 16MB
91-
Buckets: []float64{64, 256, 512, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216},
92-
},
93-
[]string{"verb", "host"},
94-
)
95-
9633
requestResult = prometheus.NewCounterVec(
9734
prometheus.CounterOpts{
9835
Name: "rest_client_requests_total",
@@ -109,17 +46,11 @@ func init() {
10946
// registerClientMetrics sets up the client latency metrics from client-go.
11047
func registerClientMetrics() {
11148
// register the metrics with our registry
112-
Registry.MustRegister(requestLatency)
113-
Registry.MustRegister(requestSize)
114-
Registry.MustRegister(responseSize)
11549
Registry.MustRegister(requestResult)
11650

11751
// register the metrics with client-go
11852
clientmetrics.Register(clientmetrics.RegisterOpts{
119-
RequestLatency: &LatencyAdapter{metric: requestLatency},
120-
RequestSize: &sizeAdapter{metric: requestSize},
121-
ResponseSize: &sizeAdapter{metric: responseSize},
122-
RequestResult: &resultAdapter{metric: requestResult},
53+
RequestResult: &resultAdapter{metric: requestResult},
12354
})
12455
}
12556

@@ -131,24 +62,6 @@ func registerClientMetrics() {
13162
// copied (more-or-less directly) from k8s.io/kubernetes setup code
13263
// (which isn't anywhere in an easily-importable place).
13364

134-
// LatencyAdapter implements LatencyMetric.
135-
type LatencyAdapter struct {
136-
metric *prometheus.HistogramVec
137-
}
138-
139-
// Observe increments the request latency metric for the given verb/URL.
140-
func (l *LatencyAdapter) Observe(_ context.Context, verb string, u url.URL, latency time.Duration) {
141-
l.metric.WithLabelValues(verb, u.String()).Observe(latency.Seconds())
142-
}
143-
144-
type sizeAdapter struct {
145-
metric *prometheus.HistogramVec
146-
}
147-
148-
func (s *sizeAdapter) Observe(ctx context.Context, verb string, host string, size float64) {
149-
s.metric.WithLabelValues(verb, host).Observe(size)
150-
}
151-
15265
type resultAdapter struct {
15366
metric *prometheus.CounterVec
15467
}

0 commit comments

Comments
 (0)