Fix normal request metric verb correctly

Signed-off-by: kkkkun <scuzk373x@gmail.com>

Kubernetes-commit: 0b6e641810fb7a24a74b8068fb772c1bb1eb447c
This commit is contained in:
kkkkun 2023-01-03 13:16:46 +00:00 committed by Kubernetes Publisher
parent 3cd8de3b76
commit c465dcc9ec
1 changed files with 5 additions and 1 deletions

View File

@ -516,11 +516,15 @@ func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, comp
// MonitorRequest handles standard transformations for client and the reported verb and then invokes Monitor to record
// a request. verb must be uppercase to be backwards compatible with existing monitoring tooling.
func MonitorRequest(req *http.Request, verb, group, version, resource, subresource, scope, component string, deprecated bool, removedRelease string, httpCode, respSize int, elapsed time.Duration) {
requestInfo, ok := request.RequestInfoFrom(req.Context())
if !ok || requestInfo == nil {
requestInfo = &request.RequestInfo{Verb: req.Method, Path: req.URL.Path}
}
// We don't use verb from <requestInfo>, as this may be propagated 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), verb, req, nil)
reportedVerb := cleanVerb(CanonicalVerb(strings.ToUpper(req.Method), scope), verb, req, requestInfo)
dryRun := cleanDryRun(req.URL)
elapsedSeconds := elapsed.Seconds()