diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go b/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go index 36b4df510cc..9071fc0d561 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go @@ -213,10 +213,16 @@ func Record(req *http.Request, requestInfo *request.RequestInfo, component, cont requestInfo = &request.RequestInfo{Verb: req.Method, Path: req.URL.Path} } scope := CleanScope(requestInfo) + // We don't use verb from , as for the healthy path + // MonitorRequest is called from InstrumentRouteFunc which is registered + // in installer.go with predefined list of verbs (different than those + // translated to RequestInfo). + // However, we need to tweak it e.g. to differentiate GET from LIST. + verb := canonicalVerb(strings.ToUpper(req.Method), scope) if requestInfo.IsResourceRequest { - MonitorRequest(req, strings.ToUpper(requestInfo.Verb), requestInfo.APIGroup, requestInfo.APIVersion, requestInfo.Resource, requestInfo.Subresource, scope, component, contentType, code, responseSizeInBytes, elapsed) + MonitorRequest(req, verb, requestInfo.APIGroup, requestInfo.APIVersion, requestInfo.Resource, requestInfo.Subresource, scope, component, contentType, code, responseSizeInBytes, elapsed) } else { - MonitorRequest(req, strings.ToUpper(requestInfo.Verb), "", "", "", requestInfo.Path, scope, component, contentType, code, responseSizeInBytes, elapsed) + MonitorRequest(req, verb, "", "", "", requestInfo.Path, scope, component, contentType, code, responseSizeInBytes, elapsed) } } @@ -228,7 +234,12 @@ func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, comp } var g prometheus.Gauge scope := CleanScope(requestInfo) - reportedVerb := cleanVerb(strings.ToUpper(requestInfo.Verb), req) + // We don't use verb from , as for the healthy path + // MonitorRequest is called from InstrumentRouteFunc which is registered + // in installer.go with predefined list of verbs (different than those + // translated to RequestInfo). + // However, we need to tweak it e.g. to differentiate GET from LIST. + reportedVerb := cleanVerb(canonicalVerb(strings.ToUpper(req.Method), scope), req) if requestInfo.IsResourceRequest { g = longRunningRequestGauge.WithLabelValues(reportedVerb, requestInfo.APIGroup, requestInfo.APIVersion, requestInfo.Resource, requestInfo.Subresource, scope, component) } else { @@ -320,6 +331,18 @@ func CleanScope(requestInfo *request.RequestInfo) string { return "" } +func canonicalVerb(verb string, scope string) string { + switch verb { + case "GET", "HEAD": + if scope != "resource" { + return "LIST" + } + return "GET" + default: + return verb + } +} + func cleanVerb(verb string, request *http.Request) string { reportedVerb := verb if verb == "LIST" {