From a188f5bf7e2b1fc6b7be9e1386f0506d3033e2a8 Mon Sep 17 00:00:00 2001 From: Damien Grisonnet Date: Thu, 18 Nov 2021 19:32:56 +0100 Subject: [PATCH] component-base: replace url in rest client metrics The `rest_client_request_duration_seconds` and `rest_client_rate_limiter_duration_seconds` metrics have a url label that used to contain the whole uri of the request. This is very dangerous and can lead to cardinality explosions since its values aren't bounded. We don't really need to expose the whole uri since these metrics are used to mesure the availability of the different proxy in front the apiserver. The most valuable information is the host to be able to differentiate between the different proxy. In the future, we might also want to add the path to be able to add some granularity, but since there is no immediate use case for that, so there is no need to add it now. Signed-off-by: Damien Grisonnet --- .../metrics/prometheus/restclient/metrics.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/staging/src/k8s.io/component-base/metrics/prometheus/restclient/metrics.go b/staging/src/k8s.io/component-base/metrics/prometheus/restclient/metrics.go index 21e4bb35998..e272333f859 100644 --- a/staging/src/k8s.io/component-base/metrics/prometheus/restclient/metrics.go +++ b/staging/src/k8s.io/component-base/metrics/prometheus/restclient/metrics.go @@ -29,24 +29,24 @@ import ( ) var ( - // requestLatency is a Prometheus Summary metric type partitioned by - // "verb" and "url" labels. It is used for the rest client latency metrics. + // requestLatency is a Prometheus Histogram metric type partitioned by + // "verb", and "host" labels. It is used for the rest client latency metrics. requestLatency = k8smetrics.NewHistogramVec( &k8smetrics.HistogramOpts{ Name: "rest_client_request_duration_seconds", - Help: "Request latency in seconds. Broken down by verb and URL.", + Help: "Request latency in seconds. Broken down by verb, and host.", Buckets: k8smetrics.ExponentialBuckets(0.001, 2, 10), }, - []string{"verb", "url"}, + []string{"verb", "host"}, ) rateLimiterLatency = k8smetrics.NewHistogramVec( &k8smetrics.HistogramOpts{ Name: "rest_client_rate_limiter_duration_seconds", - Help: "Client side rate limiter latency in seconds. Broken down by verb and URL.", + Help: "Client side rate limiter latency in seconds. Broken down by verb, and host.", Buckets: k8smetrics.ExponentialBuckets(0.001, 2, 10), }, - []string{"verb", "url"}, + []string{"verb", "host"}, ) requestResult = k8smetrics.NewCounterVec( @@ -140,7 +140,7 @@ type latencyAdapter struct { } func (l *latencyAdapter) Observe(ctx context.Context, verb string, u url.URL, latency time.Duration) { - l.m.WithContext(ctx).WithLabelValues(verb, u.String()).Observe(latency.Seconds()) + l.m.WithContext(ctx).WithLabelValues(verb, u.Host).Observe(latency.Seconds()) } type resultAdapter struct {