@@ -20,6 +20,7 @@ import (
20
20
"bufio"
21
21
"net"
22
22
"net/http"
23
+ "net/url"
23
24
"regexp"
24
25
"strconv"
25
26
"strings"
@@ -234,7 +235,7 @@ func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, comp
234
235
// a request. verb must be uppercase to be backwards compatible with existing monitoring tooling.
235
236
func MonitorRequest (req * http.Request , verb , group , version , resource , subresource , scope , component , contentType string , httpCode , respSize int , elapsed time.Duration ) {
236
237
reportedVerb := cleanVerb (verb , req )
237
- dryRun := cleanDryRun (req .URL . Query ()[ "dryRun" ] )
238
+ dryRun := cleanDryRun (req .URL )
238
239
client := cleanUserAgent (utilnet .GetHTTPClient (req ))
239
240
elapsedMicroseconds := float64 (elapsed / time .Microsecond )
240
241
elapsedSeconds := elapsed .Seconds ()
@@ -331,12 +332,19 @@ func cleanVerb(verb string, request *http.Request) string {
331
332
return reportedVerb
332
333
}
333
334
334
- func cleanDryRun (dryRun []string ) string {
335
+ func cleanDryRun (u * url.URL ) string {
336
+ // avoid allocating when we don't see dryRun in the query
337
+ if ! strings .Contains (u .RawQuery , "dryRun" ) {
338
+ return ""
339
+ }
340
+ dryRun := u .Query ()["dryRun" ]
335
341
if errs := validation .ValidateDryRun (nil , dryRun ); len (errs ) > 0 {
336
342
return "invalid"
337
343
}
338
344
// Since dryRun could be valid with any arbitrarily long length
339
345
// we have to dedup and sort the elements before joining them together
346
+ // TODO: this is a fairly large allocation for what it does, consider
347
+ // a sort and dedup in a single pass
340
348
return strings .Join (utilsets .NewString (dryRun ... ).List (), "," )
341
349
}
342
350
0 commit comments