@@ -213,10 +213,16 @@ func Record(req *http.Request, requestInfo *request.RequestInfo, component, cont
213
213
requestInfo = & request.RequestInfo {Verb : req .Method , Path : req .URL .Path }
214
214
}
215
215
scope := CleanScope (requestInfo )
216
+ // We don't use verb from <requestInfo>, as for the healthy path
217
+ // MonitorRequest is called from InstrumentRouteFunc which is registered
218
+ // in installer.go with predefined list of verbs (different than those
219
+ // translated to RequestInfo).
220
+ // However, we need to tweak it e.g. to differentiate GET from LIST.
221
+ verb := canonicalVerb (strings .ToUpper (req .Method ), scope )
216
222
if requestInfo .IsResourceRequest {
217
- MonitorRequest (req , strings . ToUpper ( requestInfo . Verb ) , requestInfo .APIGroup , requestInfo .APIVersion , requestInfo .Resource , requestInfo .Subresource , scope , component , contentType , code , responseSizeInBytes , elapsed )
223
+ MonitorRequest (req , verb , requestInfo .APIGroup , requestInfo .APIVersion , requestInfo .Resource , requestInfo .Subresource , scope , component , contentType , code , responseSizeInBytes , elapsed )
218
224
} else {
219
- MonitorRequest (req , strings . ToUpper ( requestInfo . Verb ) , "" , "" , "" , requestInfo .Path , scope , component , contentType , code , responseSizeInBytes , elapsed )
225
+ MonitorRequest (req , verb , "" , "" , "" , requestInfo .Path , scope , component , contentType , code , responseSizeInBytes , elapsed )
220
226
}
221
227
}
222
228
@@ -228,7 +234,12 @@ func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, comp
228
234
}
229
235
var g prometheus.Gauge
230
236
scope := CleanScope (requestInfo )
231
- reportedVerb := cleanVerb (strings .ToUpper (requestInfo .Verb ), req )
237
+ // We don't use verb from <requestInfo>, as for the healthy path
238
+ // MonitorRequest is called from InstrumentRouteFunc which is registered
239
+ // in installer.go with predefined list of verbs (different than those
240
+ // translated to RequestInfo).
241
+ // However, we need to tweak it e.g. to differentiate GET from LIST.
242
+ reportedVerb := cleanVerb (canonicalVerb (strings .ToUpper (req .Method ), scope ), req )
232
243
if requestInfo .IsResourceRequest {
233
244
g = longRunningRequestGauge .WithLabelValues (reportedVerb , requestInfo .APIGroup , requestInfo .APIVersion , requestInfo .Resource , requestInfo .Subresource , scope , component )
234
245
} else {
@@ -320,6 +331,18 @@ func CleanScope(requestInfo *request.RequestInfo) string {
320
331
return ""
321
332
}
322
333
334
+ func canonicalVerb (verb string , scope string ) string {
335
+ switch verb {
336
+ case "GET" , "HEAD" :
337
+ if scope != "resource" {
338
+ return "LIST"
339
+ }
340
+ return "GET"
341
+ default :
342
+ return verb
343
+ }
344
+ }
345
+
323
346
func cleanVerb (verb string , request * http.Request ) string {
324
347
reportedVerb := verb
325
348
if verb == "LIST" {
0 commit comments