From f6cebcc414b21926e9849a7f1bc2666f55de68c3 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 20 Aug 2024 11:09:21 +0300 Subject: [PATCH] golangci-lint: enable fatcontext and canonicalheader - fatcontext prevents a problem we had in the past where you keep adding variables to a context canonicalheader has some performance improvements as it doesn't require go to canonize the header on each invocation Those are the only new linters since last we updated --- .golangci.yml | 3 +++ cloudapi/client.go | 2 +- cloudapi/logs.go | 2 +- lib/executor/vu_handle.go | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 91f1a57d5b8..468bc54eff1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,6 +19,7 @@ issues: # files (due to common repeats and long functions in test code) - path: _(test|gen)\.go linters: + - canonicalheader - cyclop - dupl - gocognit @@ -68,6 +69,7 @@ linters: - asciicheck - bidichk - bodyclose + - canonicalheader - contextcheck - cyclop - dogsled @@ -79,6 +81,7 @@ linters: - errorlint - exhaustive - exportloopref + - fatcontext - forbidigo - forcetypeassert - funlen diff --git a/cloudapi/client.go b/cloudapi/client.go index 1c6628bad7d..0292564a4f9 100644 --- a/cloudapi/client.go +++ b/cloudapi/client.go @@ -20,7 +20,7 @@ const ( // MaxRetries specifies max retry attempts MaxRetries = 3 - k6IdempotencyKeyHeader = "k6-Idempotency-Key" + k6IdempotencyKeyHeader = "K6-Idempotency-Key" ) // Client handles communication with the k6 Cloud API. diff --git a/cloudapi/logs.go b/cloudapi/logs.go index 2f215f99b58..129c6500d5c 100644 --- a/cloudapi/logs.go +++ b/cloudapi/logs.go @@ -101,7 +101,7 @@ func (c *Config) logtailConn(ctx context.Context, referenceID string, since time headers := make(http.Header) headers.Add("Sec-WebSocket-Protocol", "token="+c.Token.String) headers.Add("Authorization", "token "+c.Token.String) - headers.Add("X-K6TestRun-Id", referenceID) + headers.Add("X-K6testrun-Id", referenceID) var conn *websocket.Conn err = retry(sleeperFunc(time.Sleep), 3, 5*time.Second, 2*time.Minute, func() (err error) { diff --git a/lib/executor/vu_handle.go b/lib/executor/vu_handle.go index a5c40ea43a7..8a3c57fdf6a 100644 --- a/lib/executor/vu_handle.go +++ b/lib/executor/vu_handle.go @@ -225,7 +225,7 @@ func (vh *vuHandle) runLoopsIfPossible(runIter func(context.Context, lib.ActiveV // we need to cancel the context, to return the vu // and because *we* did, lets reinitialize it cancel() - vh.ctx, vh.cancel = context.WithCancel(vh.parentCtx) + vh.ctx, vh.cancel = context.WithCancel(vh.parentCtx) //nolint:fatcontext // isn't actually on the same context } fallthrough // to set the state case toHardStop: