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 <dgrisonn@redhat.com>
This commit is contained in:
Damien Grisonnet 2021-11-18 19:32:56 +01:00
parent 6c45f6e32b
commit a188f5bf7e

View File

@ -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 {