@@ -18,6 +18,8 @@ package metrics
1818
1919import (
2020 "context"
21+ "net/url"
22+ "time"
2123
2224 "github.com/prometheus/client_golang/prometheus"
2325 clientmetrics "k8s.io/client-go/tools/metrics"
@@ -30,6 +32,26 @@ import (
3032var (
3133 // client metrics.
3234
35+ requestLatency = prometheus .NewHistogramVec (
36+ prometheus.HistogramOpts {
37+ Name : "rest_client_request_duration_seconds" ,
38+ Help : "Request latency in seconds. Broken down by verb and URL." ,
39+ 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 ,
40+ 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 },
41+ },
42+ []string {"verb" , "host" , "path" },
43+ )
44+
45+ rateLimiterLatency = prometheus .NewHistogramVec (
46+ prometheus.HistogramOpts {
47+ Name : "rest_client_rate_limiter_duration_seconds" ,
48+ Help : "Client side rate limiter latency in seconds. Broken down by verb and URL." ,
49+ 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 ,
50+ 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 },
51+ },
52+ []string {"verb" , "host" , "path" },
53+ )
54+
3355 requestResult = prometheus .NewCounterVec (
3456 prometheus.CounterOpts {
3557 Name : "rest_client_requests_total" ,
@@ -50,7 +72,9 @@ func registerClientMetrics() {
5072
5173 // register the metrics with client-go
5274 clientmetrics .Register (clientmetrics.RegisterOpts {
53- RequestResult : & resultAdapter {metric : requestResult },
75+ RequestResult : & resultAdapter {metric : requestResult },
76+ RateLimiterLatency : & latencyAdapter {metric : rateLimiterLatency },
77+ RequestLatency : & latencyAdapter {metric : requestLatency },
5478 })
5579}
5680
@@ -69,3 +93,11 @@ type resultAdapter struct {
6993func (r * resultAdapter ) Increment (_ context.Context , code , method , host string ) {
7094 r .metric .WithLabelValues (code , method , host ).Inc ()
7195}
96+
97+ type latencyAdapter struct {
98+ metric * prometheus.HistogramVec
99+ }
100+
101+ func (l * latencyAdapter ) Observe (_ context.Context , verb string , u url.URL , latency time.Duration ) {
102+ l .metric .WithLabelValues (verb , u .Host , u .Path ).Observe (latency .Seconds ())
103+ }
0 commit comments