@@ -222,10 +222,16 @@ func Record(req *http.Request, requestInfo *request.RequestInfo, component, cont
222
222
requestInfo = & request.RequestInfo {Verb : req .Method , Path : req .URL .Path }
223
223
}
224
224
scope := CleanScope (requestInfo )
225
+ // We don't use verb from <requestInfo>, as for the healthy path
226
+ // MonitorRequest is called from InstrumentRouteFunc which is registered
227
+ // in installer.go with predefined list of verbs (different than those
228
+ // translated to RequestInfo).
229
+ // However, we need to tweak it e.g. to differentiate GET from LIST.
230
+ verb := canonicalVerb (strings .ToUpper (req .Method ), scope )
225
231
if requestInfo .IsResourceRequest {
226
- MonitorRequest (req , strings . ToUpper ( requestInfo . Verb ) , requestInfo .APIGroup , requestInfo .APIVersion , requestInfo .Resource , requestInfo .Subresource , scope , component , contentType , code , responseSizeInBytes , elapsed )
232
+ MonitorRequest (req , verb , requestInfo .APIGroup , requestInfo .APIVersion , requestInfo .Resource , requestInfo .Subresource , scope , component , contentType , code , responseSizeInBytes , elapsed )
227
233
} else {
228
- MonitorRequest (req , strings . ToUpper ( requestInfo . Verb ) , "" , "" , "" , requestInfo .Path , scope , component , contentType , code , responseSizeInBytes , elapsed )
234
+ MonitorRequest (req , verb , "" , "" , "" , requestInfo .Path , scope , component , contentType , code , responseSizeInBytes , elapsed )
229
235
}
230
236
}
231
237
@@ -237,7 +243,12 @@ func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, comp
237
243
}
238
244
var g prometheus.Gauge
239
245
scope := CleanScope (requestInfo )
240
- reportedVerb := cleanVerb (strings .ToUpper (requestInfo .Verb ), req )
246
+ // We don't use verb from <requestInfo>, as for the healthy path
247
+ // MonitorRequest is called from InstrumentRouteFunc which is registered
248
+ // in installer.go with predefined list of verbs (different than those
249
+ // translated to RequestInfo).
250
+ // However, we need to tweak it e.g. to differentiate GET from LIST.
251
+ reportedVerb := cleanVerb (canonicalVerb (strings .ToUpper (req .Method ), scope ), req )
241
252
if requestInfo .IsResourceRequest {
242
253
g = longRunningRequestGauge .WithLabelValues (reportedVerb , requestInfo .APIGroup , requestInfo .APIVersion , requestInfo .Resource , requestInfo .Subresource , scope , component )
243
254
} else {
@@ -329,6 +340,18 @@ func CleanScope(requestInfo *request.RequestInfo) string {
329
340
return ""
330
341
}
331
342
343
+ func canonicalVerb (verb string , scope string ) string {
344
+ switch verb {
345
+ case "GET" , "HEAD" :
346
+ if scope != "resource" {
347
+ return "LIST"
348
+ }
349
+ return "GET"
350
+ default :
351
+ return verb
352
+ }
353
+ }
354
+
332
355
func cleanVerb (verb string , request * http.Request ) string {
333
356
reportedVerb := verb
334
357
if verb == "LIST" {
0 commit comments