@@ -18,8 +18,6 @@ package metrics
18
18
19
19
import (
20
20
"context"
21
- "net/url"
22
- "time"
23
21
24
22
"github.com/prometheus/client_golang/prometheus"
25
23
clientmetrics "k8s.io/client-go/tools/metrics"
@@ -29,70 +27,9 @@ import (
29
27
// that client-go registers metrics. We copy the names and formats
30
28
// from Kubernetes so that we match the core controllers.
31
29
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
-
39
30
var (
40
31
// client metrics.
41
32
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
-
96
33
requestResult = prometheus .NewCounterVec (
97
34
prometheus.CounterOpts {
98
35
Name : "rest_client_requests_total" ,
@@ -109,17 +46,11 @@ func init() {
109
46
// registerClientMetrics sets up the client latency metrics from client-go.
110
47
func registerClientMetrics () {
111
48
// register the metrics with our registry
112
- Registry .MustRegister (requestLatency )
113
- Registry .MustRegister (requestSize )
114
- Registry .MustRegister (responseSize )
115
49
Registry .MustRegister (requestResult )
116
50
117
51
// register the metrics with client-go
118
52
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 },
123
54
})
124
55
}
125
56
@@ -131,24 +62,6 @@ func registerClientMetrics() {
131
62
// copied (more-or-less directly) from k8s.io/kubernetes setup code
132
63
// (which isn't anywhere in an easily-importable place).
133
64
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
-
152
65
type resultAdapter struct {
153
66
metric * prometheus.CounterVec
154
67
}
0 commit comments