From e2cbce8b036d3d1f5af5a3766e464b72d6b6c9f3 Mon Sep 17 00:00:00 2001 From: Alex Dudko Date: Thu, 27 Mar 2025 15:19:49 -0500 Subject: [PATCH 1/2] metrics: add dry_run label to apiserver_request_sli_duration_seconds Signed-off-by: Alex Dudko Kubernetes-commit: 6f1abad18e5db7c4269f03fb4c41f35c9a1ab2cb --- pkg/endpoints/metrics/metrics.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/endpoints/metrics/metrics.go b/pkg/endpoints/metrics/metrics.go index b95e551d8..91ced5f10 100644 --- a/pkg/endpoints/metrics/metrics.go +++ b/pkg/endpoints/metrics/metrics.go @@ -111,7 +111,7 @@ var ( &compbasemetrics.HistogramOpts{ Subsystem: APIServerComponent, Name: "request_slo_duration_seconds", - Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, group, version, resource, subresource, scope and component.", + Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, dry run value, group, version, resource, subresource, scope and component.", // This metric is supplementary to the requestLatencies metric. // It measures request duration excluding webhooks as they are mostly // dependant on user configuration. @@ -120,13 +120,13 @@ var ( StabilityLevel: compbasemetrics.ALPHA, DeprecatedVersion: "1.27.0", }, - []string{"verb", "group", "version", "resource", "subresource", "scope", "component"}, + []string{"verb", "dry_run", "group", "version", "resource", "subresource", "scope", "component"}, ) requestSliLatencies = compbasemetrics.NewHistogramVec( &compbasemetrics.HistogramOpts{ Subsystem: APIServerComponent, Name: "request_sli_duration_seconds", - Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, group, version, resource, subresource, scope and component.", + Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, dry run value, group, version, resource, subresource, scope and component.", // This metric is supplementary to the requestLatencies metric. // It measures request duration excluding webhooks as they are mostly // dependant on user configuration. @@ -134,7 +134,7 @@ var ( 4, 5, 6, 8, 10, 15, 20, 30, 45, 60}, StabilityLevel: compbasemetrics.ALPHA, }, - []string{"verb", "group", "version", "resource", "subresource", "scope", "component"}, + []string{"verb", "dry_run", "group", "version", "resource", "subresource", "scope", "component"}, ) fieldValidationRequestLatencies = compbasemetrics.NewHistogramVec( &compbasemetrics.HistogramOpts{ @@ -619,8 +619,8 @@ func MonitorRequest(req *http.Request, verb, group, version, resource, subresour if wd, ok := request.LatencyTrackersFrom(req.Context()); ok { sliLatency := elapsedSeconds - (wd.MutatingWebhookTracker.GetLatency() + wd.ValidatingWebhookTracker.GetLatency() + wd.APFQueueWaitTracker.GetLatency()).Seconds() - requestSloLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sliLatency) - requestSliLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sliLatency) + requestSloLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component).Observe(sliLatency) + requestSliLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component).Observe(sliLatency) } // We are only interested in response sizes of read requests. if verb == MethodGet || verb == MethodList { From cb5a78f9ba555c470a74d0a5dd587f92933ef577 Mon Sep 17 00:00:00 2001 From: Alex Dudko Date: Thu, 22 May 2025 18:23:05 -0500 Subject: [PATCH 2/2] metrics: don't record apiserver_request_sli_duration_seconds for dryRun requests Kubernetes-commit: dd37ad1bc2cd9df470924d4891f5b4bc7405ab66 --- pkg/endpoints/metrics/metrics.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/endpoints/metrics/metrics.go b/pkg/endpoints/metrics/metrics.go index 91ced5f10..c76457175 100644 --- a/pkg/endpoints/metrics/metrics.go +++ b/pkg/endpoints/metrics/metrics.go @@ -111,7 +111,7 @@ var ( &compbasemetrics.HistogramOpts{ Subsystem: APIServerComponent, Name: "request_slo_duration_seconds", - Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, dry run value, group, version, resource, subresource, scope and component.", + Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, group, version, resource, subresource, scope and component.", // This metric is supplementary to the requestLatencies metric. // It measures request duration excluding webhooks as they are mostly // dependant on user configuration. @@ -120,13 +120,13 @@ var ( StabilityLevel: compbasemetrics.ALPHA, DeprecatedVersion: "1.27.0", }, - []string{"verb", "dry_run", "group", "version", "resource", "subresource", "scope", "component"}, + []string{"verb", "group", "version", "resource", "subresource", "scope", "component"}, ) requestSliLatencies = compbasemetrics.NewHistogramVec( &compbasemetrics.HistogramOpts{ Subsystem: APIServerComponent, Name: "request_sli_duration_seconds", - Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, dry run value, group, version, resource, subresource, scope and component.", + Help: "Response latency distribution (not counting webhook duration and priority & fairness queue wait times) in seconds for each verb, group, version, resource, subresource, scope and component.", // This metric is supplementary to the requestLatencies metric. // It measures request duration excluding webhooks as they are mostly // dependant on user configuration. @@ -134,7 +134,7 @@ var ( 4, 5, 6, 8, 10, 15, 20, 30, 45, 60}, StabilityLevel: compbasemetrics.ALPHA, }, - []string{"verb", "dry_run", "group", "version", "resource", "subresource", "scope", "component"}, + []string{"verb", "group", "version", "resource", "subresource", "scope", "component"}, ) fieldValidationRequestLatencies = compbasemetrics.NewHistogramVec( &compbasemetrics.HistogramOpts{ @@ -617,10 +617,10 @@ func MonitorRequest(req *http.Request, verb, group, version, resource, subresour fieldValidation := cleanFieldValidation(req.URL) fieldValidationRequestLatencies.WithContext(req.Context()).WithLabelValues(fieldValidation) - if wd, ok := request.LatencyTrackersFrom(req.Context()); ok { + if wd, ok := request.LatencyTrackersFrom(req.Context()); ok && dryRun == "" { sliLatency := elapsedSeconds - (wd.MutatingWebhookTracker.GetLatency() + wd.ValidatingWebhookTracker.GetLatency() + wd.APFQueueWaitTracker.GetLatency()).Seconds() - requestSloLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component).Observe(sliLatency) - requestSliLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component).Observe(sliLatency) + requestSloLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sliLatency) + requestSliLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, group, version, resource, subresource, scope, component).Observe(sliLatency) } // We are only interested in response sizes of read requests. if verb == MethodGet || verb == MethodList {