From 8ee1d1ca44e355bf1177df807b8605936399d45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Fri, 4 Sep 2020 12:16:48 +0200 Subject: [PATCH] Call URL.Clean() only once when setting metric tags Resolves https://github.com/loadimpact/k6/pull/1570#discussion_r483510309 --- lib/netext/httpext/transport.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/netext/httpext/transport.go b/lib/netext/httpext/transport.go index f6e1e4a23ea2..13da5bb3f254 100644 --- a/lib/netext/httpext/transport.go +++ b/lib/netext/httpext/transport.go @@ -115,14 +115,16 @@ func (t *transport) measureAndEmitMetrics(unfReq *unfinishedRequest) *finishedRe tags["status"] = "0" } } else { - if enabledTags.Has(stats.TagURL) { + urlEnabled := enabledTags.Has(stats.TagURL) + nameEnabled := enabledTags.Has(stats.TagName) + if urlEnabled || nameEnabled { cleanURL := URL{u: unfReq.request.URL, URL: unfReq.request.URL.String()}.Clean() - tags["url"] = cleanURL - } - - if _, ok := tags["name"]; !ok && enabledTags.Has(stats.TagName) { - cleanURL := URL{u: unfReq.request.URL, URL: unfReq.request.URL.String()}.Clean() - tags["name"] = cleanURL + if urlEnabled { + tags["url"] = cleanURL + } + if _, ok := tags["name"]; !ok && nameEnabled { + tags["name"] = cleanURL + } } if enabledTags.Has(stats.TagMethod) {