Skip to content

Commit af02ca5

Browse files
committed
optimized performance: dropped size metrics, dropped buckets
1 parent b9e8b85 commit af02ca5

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

pkg/metrics/client_go_adapter.go

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package metrics
1818

1919
import (
2020
"context"
21+
"math"
2122
"net/url"
2223
"time"
2324

@@ -32,27 +33,7 @@ var (
3233
prometheus.HistogramOpts{
3334
Name: "rest_client_request_duration_seconds",
3435
Help: "Request latency in seconds. Broken down by verb, and host.",
35-
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},
36-
},
37-
[]string{"verb", "host"},
38-
)
39-
40-
requestSize = prometheus.NewHistogramVec(
41-
prometheus.HistogramOpts{
42-
Name: "rest_client_request_size_bytes",
43-
Help: "Request size in bytes. Broken down by verb and host.",
44-
// 64 bytes to 16MB
45-
Buckets: []float64{64, 256, 512, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216},
46-
},
47-
[]string{"verb", "host"},
48-
)
49-
50-
responseSize = prometheus.NewHistogramVec(
51-
prometheus.HistogramOpts{
52-
Name: "rest_client_response_size_bytes",
53-
Help: "Response size in bytes. Broken down by verb and host.",
54-
// 64 bytes to 16MB
55-
Buckets: []float64{64, 256, 512, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216},
36+
Buckets: []float64{math.Inf(+1)}, // Intentionally using minimum buckets for better performance / lower cardinality.
5637
},
5738
[]string{"verb", "host"},
5839
)
@@ -61,7 +42,7 @@ var (
6142
prometheus.HistogramOpts{
6243
Name: "rest_client_rate_limiter_duration_seconds",
6344
Help: "Client side rate limiter latency in seconds. Broken down by verb, and host.",
64-
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},
45+
Buckets: []float64{math.Inf(+1)}, // Intentionally using minimum buckets for better performance / lower cardinality.
6546
},
6647
[]string{"verb", "host"},
6748
)
@@ -91,17 +72,13 @@ func init() {
9172
func registerClientMetrics() {
9273
// register the metrics with our registry
9374
Registry.MustRegister(requestLatency)
94-
Registry.MustRegister(requestSize)
95-
Registry.MustRegister(responseSize)
9675
Registry.MustRegister(rateLimiterLatency)
9776
Registry.MustRegister(requestResult)
9877
Registry.MustRegister(requestRetry)
9978

10079
// register the metrics with client-go
10180
clientmetrics.Register(clientmetrics.RegisterOpts{
10281
RequestLatency: &LatencyAdapter{metric: requestLatency},
103-
RequestSize: &sizeAdapter{metric: requestSize},
104-
ResponseSize: &sizeAdapter{metric: responseSize},
10582
RateLimiterLatency: &LatencyAdapter{metric: rateLimiterLatency},
10683
RequestResult: &resultAdapter{metric: requestResult},
10784
RequestRetry: &retryAdapter{requestRetry},
@@ -126,14 +103,6 @@ func (l *LatencyAdapter) Observe(_ context.Context, verb string, u url.URL, late
126103
l.metric.WithLabelValues(verb, u.String()).Observe(latency.Seconds())
127104
}
128105

129-
type sizeAdapter struct {
130-
metric *prometheus.HistogramVec
131-
}
132-
133-
func (s *sizeAdapter) Observe(ctx context.Context, verb string, host string, size float64) {
134-
s.metric.WithLabelValues(verb, host).Observe(size)
135-
}
136-
137106
type resultAdapter struct {
138107
metric *prometheus.CounterVec
139108
}

0 commit comments

Comments
 (0)