Skip to content

Commit da96da3

Browse files
Update golangci-lint version (#3928)
1 parent 6c14449 commit da96da3

21 files changed

+47
-46
lines changed

.github/workflows/golangci-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: golangci/golangci-lint-action@v2
3939
with:
4040
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
41-
version: v1.55.2
41+
version: v1.61.0
4242

4343
# Give the job more time to execute.
4444
# Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but,

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ check-headers: ## - Check copyright headers
121121

122122
.PHONY: check-go
123123
check-go: ## - Run golangci-lint
124-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/d58dbde584c801091e74a00940e11ff18c6c68bd/install.sh | sh -s v1.55.2
124+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/d58dbde584c801091e74a00940e11ff18c6c68bd/install.sh | sh -s v1.61.0
125125
@./bin/golangci-lint run -v
126126

127127
.PHONY: notice

internal/pkg/api/handleAck.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (ack *AckT) processRequest(zlog zerolog.Logger, w http.ResponseWriter, r *h
135135
return err
136136
}
137137

138-
cntAcks.bodyOut.Add(uint64(nWritten))
138+
cntAcks.bodyOut.Add(uint64(nWritten)) //nolint:gosec // disable G115
139139

140140
return nil
141141
}

internal/pkg/api/handleArtifacts.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ import (
1717
"net/http"
1818
"time"
1919

20+
"go.elastic.co/apm/v2"
21+
2022
"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
2123
"github.com/elastic/fleet-server/v7/internal/pkg/cache"
2224
"github.com/elastic/fleet-server/v7/internal/pkg/config"
2325
"github.com/elastic/fleet-server/v7/internal/pkg/dl"
2426
"github.com/elastic/fleet-server/v7/internal/pkg/logger"
2527
"github.com/elastic/fleet-server/v7/internal/pkg/model"
2628
"github.com/elastic/fleet-server/v7/internal/pkg/throttle"
27-
"go.elastic.co/apm/v2"
2829

2930
"github.com/rs/zerolog"
3031
)
@@ -88,7 +89,7 @@ func (at ArtifactT) handleArtifacts(zlog zerolog.Logger, w http.ResponseWriter,
8889
e = e.Int64(ECSEventDuration, time.Since(ts).Nanoseconds())
8990
}
9091
e.Msg("artifact response sent")
91-
cntArtifacts.bodyOut.Add(uint64(n))
92+
cntArtifacts.bodyOut.Add(uint64(n)) //nolint:gosec // disable G115
9293
return nil
9394
}
9495

@@ -146,7 +147,7 @@ func (at ArtifactT) processRequest(ctx context.Context, zlog zerolog.Logger, age
146147
//
147148
// Initial implementation is dependent on security by obscurity; ie.
148149
// it should be difficult for an attacker to guess a guid.
149-
func (at ArtifactT) authorizeArtifact(ctx context.Context, _ *model.Agent, _, _ string) error { //nolint:unparam // remove if this is implemented
150+
func (at ArtifactT) authorizeArtifact(ctx context.Context, _ *model.Agent, _, _ string) error {
150151
span, _ := apm.StartSpan(ctx, "authorizeArtifacts", "auth") // TODO return and use span ctx if this is ever not a nop
151152
defer span.End()
152153
return nil // TODO

internal/pkg/api/handleCheckin.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func (ct *CheckinT) writeResponse(zlog zerolog.Logger, w http.ResponseWriter, r
600600
} else {
601601
var nWritten int
602602
nWritten, err = w.Write(payload)
603-
cntCheckin.bodyOut.Add(uint64(nWritten))
603+
cntCheckin.bodyOut.Add(uint64(nWritten)) //nolint:gosec // disable G115
604604

605605
if err != nil {
606606
err = fmt.Errorf("writeResponse payload: %w", err)
@@ -740,7 +740,6 @@ func convertActionData(aType ActionType, raw json.RawMessage) (ad Action_Data, e
740740
}
741741
}
742742

743-
//nolint:gosec // memory aliasing is used to convert from pointers to values and the other way
744743
func convertActions(zlog zerolog.Logger, agentID string, actions []model.Action) ([]Action, string) {
745744
var ackToken string
746745
sz := len(actions)

internal/pkg/api/handleEnroll.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"strings"
1515
"time"
1616

17+
"go.elastic.co/apm/v2"
18+
1719
"github.com/elastic/elastic-agent-libs/str"
1820
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
1921
"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
@@ -24,7 +26,6 @@ import (
2426
"github.com/elastic/fleet-server/v7/internal/pkg/model"
2527
"github.com/elastic/fleet-server/v7/internal/pkg/rollback"
2628
"github.com/elastic/fleet-server/v7/internal/pkg/sqn"
27-
"go.elastic.co/apm/v2"
2829

2930
"github.com/gofrs/uuid"
3031
"github.com/hashicorp/go-version"
@@ -395,7 +396,7 @@ func writeResponse(ctx context.Context, zlog zerolog.Logger, w http.ResponseWrit
395396
}
396397

397398
numWritten, err := w.Write(data)
398-
cntEnroll.bodyOut.Add(uint64(numWritten))
399+
cntEnroll.bodyOut.Add(uint64(numWritten)) //nolint:gosec // disable G115
399400

400401
if err != nil {
401402
return fmt.Errorf("fail send enroll response: %w", err)

internal/pkg/api/handleStatus.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"net/http"
1212
"time"
1313

14-
"github.com/elastic/elastic-agent-client/v7/pkg/client"
1514
"go.elastic.co/apm/v2"
1615

16+
"github.com/elastic/elastic-agent-client/v7/pkg/client"
17+
1718
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
1819
"github.com/elastic/fleet-server/v7/internal/pkg/build"
1920
"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
@@ -120,7 +121,7 @@ func (st StatusT) handleStatus(zlog zerolog.Logger, sm policy.SelfMonitor, bi bu
120121
}
121122
}
122123

123-
cntStatus.bodyOut.Add(uint64(nWritten))
124+
cntStatus.bodyOut.Add(uint64(nWritten)) //nolint:gosec // disable G115
124125
e := zlog.Debug().Int(ECSHTTPResponseBodyBytes, nWritten)
125126
if ok {
126127
e = e.Int64(ECSEventDuration, time.Since(ts).Nanoseconds())

internal/pkg/api/openapi_spec_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5-
//nolint:goconst // don't care about repitition for tests
65
package api
76

87
// Test json encoding/decoding for all req/resp items

internal/pkg/bulk/opMulti.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (b *Bulker) multiWaitBulkOp(ctx context.Context, action actionT, ops []Mult
7979

8080
bulk := &bulks[i]
8181
bulk.ch = ch
82-
bulk.idx = int32(i)
82+
bulk.idx = int32(i) //nolint:gosec // disable G115
8383
bulk.action = action
8484
bulk.buf.Set(bodySlice)
8585
if opt.Refresh {

internal/pkg/cache/cache.go

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// Package cache implements an in-memory cache used to track API keys, actions, and artifacts.
66

7-
//nolint:goconst // easier to read scoped keys if no constants are used
87
package cache
98

109
import (

internal/pkg/config/env_defaults.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import (
1515
"strings"
1616
"time"
1717

18-
"github.com/elastic/go-ucfg/yaml"
1918
"github.com/pbnjay/memory"
2019
"github.com/rs/zerolog"
20+
21+
"github.com/elastic/go-ucfg/yaml"
2122
)
2223

2324
const (
@@ -95,7 +96,7 @@ type valueRange struct {
9596

9697
type envLimits struct {
9798
Agents valueRange `config:"num_agents"`
98-
RecommendedRAM int `config:"recommended_min_ram"`
99+
RecommendedRAM uint64 `config:"recommended_min_ram"`
99100
Server *serverLimitDefaults `config:"server_limits"`
100101
Cache *cacheLimits `config:"cache_limits"`
101102
}
@@ -292,7 +293,7 @@ func loadLimits(agentLimit int) *envLimits {
292293
// get nearest limits for configured agent numbers
293294
if l.Agents.Min <= agentLimit && agentLimit <= l.Agents.Max {
294295
log.Info().Msgf("Using system limits for %d to %d agents for a configured value of %d agents", l.Agents.Min, l.Agents.Max, agentLimit)
295-
ramSize := int(memory.TotalMemory() / 1024 / 1024)
296+
ramSize := memory.TotalMemory() / 1024 / 1024
296297
if ramSize < l.RecommendedRAM {
297298
log.Warn().Msgf("Detected %d MB of system RAM, which is lower than the recommended amount (%d MB) for the configured agent limit", ramSize, l.RecommendedRAM)
298299
}
@@ -305,14 +306,14 @@ func loadLimits(agentLimit int) *envLimits {
305306

306307
// memMB returns the system total memory in MB
307308
// It wraps memory.TotalMemory() so that we can replace the var in unit tests.
308-
var memMB func() int = func() int {
309-
return int(memory.TotalMemory() / 1024 / 1024)
309+
var memMB func() uint64 = func() uint64 {
310+
return memory.TotalMemory() / 1024 / 1024
310311
}
311312

312313
func memEnvLimits() *envLimits {
313314
mem := memMB()
314315
k := 0
315-
recRAM := 0
316+
var recRAM uint64
316317
log := zerolog.Ctx(context.TODO())
317318
for i, l := range defaults {
318319
if mem >= l.RecommendedRAM && l.RecommendedRAM > recRAM {
@@ -321,10 +322,10 @@ func memEnvLimits() *envLimits {
321322
}
322323
}
323324
if recRAM == 0 {
324-
log.Warn().Int("memory_mb", mem).Msg("No settings with recommended ram found, using default.")
325+
log.Warn().Uint64("memory_mb", mem).Msg("No settings with recommended ram found, using default.")
325326
return defaultEnvLimits()
326327
}
327-
log.Info().Int("memory_mb", mem).Int("recommended_mb", recRAM).Msg("Found settings with recommended ram.")
328+
log.Info().Uint64("memory_mb", mem).Uint64("recommended_mb", recRAM).Msg("Found settings with recommended ram.")
328329
return defaults[k]
329330
}
330331

internal/pkg/dl/migration_integration_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
//go:build integration
66

7-
//nolint:goconst // disable duplicate checking
87
package dl
98

109
import (

internal/pkg/file/cbor/chunk.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func encodePreambleToCBOR(final bool, baseID string, chunkHash string, chunkSize
8080
preamble[11] = 'p'
8181
preamble[12] = 0x1b // uint64 to follow
8282
// occupies 8 bytes, indexes 13-20
83-
binary.BigEndian.PutUint64(preamble[13:], uint64(time.Now().UnixMilli()))
84-
preamble[21] = 0x64 // string with 4 chars (key: last)
83+
binary.BigEndian.PutUint64(preamble[13:], uint64(time.Now().UnixMilli())) //nolint:gosec // disable G115
84+
preamble[21] = 0x64 // string with 4 chars (key: last)
8585
preamble[22] = 'l'
8686
preamble[23] = 'a'
8787
preamble[24] = 's'
@@ -118,8 +118,8 @@ func encodePreambleToCBOR(final bool, baseID string, chunkHash string, chunkSize
118118
}
119119
if !final {
120120
// byte data should be precisely chunkSize long, otherwise malformed
121-
preamble[i] = 0x5A // say length descriptor will be 32-bit int
122-
binary.BigEndian.PutUint32(preamble[i+1:], uint32(chunkSize))
121+
preamble[i] = 0x5A // say length descriptor will be 32-bit int
122+
binary.BigEndian.PutUint32(preamble[i+1:], uint32(chunkSize)) //nolint:gosec // disable G115
123123
} else {
124124
// final chunk may be less than full size, will need to determine length
125125
preamble[i] = 0x5F // indeterminate-length byte sequence
@@ -150,8 +150,8 @@ func (c *ChunkEncoder) Read(buf []byte) (int, error) {
150150
return 0, errors.New("buffer too small")
151151
}
152152
n, err := c.chunk.Read(buf[varLenHeaderSize:])
153-
buf[0] = 0x5A // 4-byte length descriptor to follow
154-
binary.BigEndian.PutUint32(buf[1:], uint32(n))
153+
buf[0] = 0x5A // 4-byte length descriptor to follow
154+
binary.BigEndian.PutUint32(buf[1:], uint32(n)) //nolint:gosec // disable G115
155155

156156
if errors.Is(err, io.EOF) {
157157
if n == 0 { // chunk data has been exhausted, write the terminating byte and get out

internal/pkg/file/cbor/chunk_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func TestChunkWriter(t *testing.T) {
3838
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // contents
3939
}
4040

41-
assert.Equal(t, expected[:13], outbuf[:13]) // up to 0x1b after timestamp
42-
assert.WithinDuration(t, time.Now(), time.UnixMilli(int64(binary.BigEndian.Uint64(outbuf[13:]))), time.Second*5)
41+
assert.Equal(t, expected[:13], outbuf[:13]) // up to 0x1b after timestamp
42+
assert.WithinDuration(t, time.Now(), time.UnixMilli(int64(binary.BigEndian.Uint64(outbuf[13:]))), time.Second*5) //nolint:gosec // disable G115
4343

4444
assert.Equal(t, expected[21:], outbuf[21:])
4545

@@ -68,7 +68,7 @@ func TestChunkWriterLastChunk(t *testing.T) {
6868

6969
// assert equality up to the constant set point
7070
assert.Equal(t, expected[:13], outbuf[:13])
71-
assert.WithinDuration(t, time.Now(), time.UnixMilli(int64(binary.BigEndian.Uint64(outbuf[13:]))), time.Second*5)
71+
assert.WithinDuration(t, time.Now(), time.UnixMilli(int64(binary.BigEndian.Uint64(outbuf[13:]))), time.Second*5) //nolint:gosec // disable G115
7272
assert.Equal(t, expected[21:], outbuf[21:len(expected)])
7373
assert.Equal(t, uint8(0xFF), outbuf[len(outbuf)-1]) // final byte MUST be a 0xFF terminating byte when using indeterminate-length style
7474

@@ -116,7 +116,7 @@ func TestChunkWriterLargeLastChunk(t *testing.T) {
116116

117117
// assert equality up to the constant set point
118118
assert.Equal(t, expected[:13], outbuf[:13])
119-
assert.WithinDuration(t, time.Now(), time.UnixMilli(int64(binary.BigEndian.Uint64(outbuf[13:]))), time.Second*5)
119+
assert.WithinDuration(t, time.Now(), time.UnixMilli(int64(binary.BigEndian.Uint64(outbuf[13:]))), time.Second*5) //nolint:gosec // disable G115
120120
assert.Equal(t, expected[21:], outbuf[21:len(expected)])
121121
assert.Equal(t, uint8(0xFF), outbuf[len(outbuf)-1]) // final byte MUST be a 0xFF terminating byte when using indeterminate-length style
122122

internal/pkg/file/uploader/upload_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// or more contributor license agreements. Licensed under the Elastic License;
33
// you may not use this file except in compliance with the Elastic License.
44

5-
//nolint:goconst // disable contstants checks for tests
65
package uploader
76

87
import (

internal/pkg/logger/http.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
"github.com/gofrs/uuid"
2020
"github.com/rs/zerolog"
2121

22-
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
2322
"go.elastic.co/apm/module/apmzerolog/v2"
23+
24+
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
2425
)
2526

2627
const (
@@ -41,7 +42,7 @@ func NewReaderCounter(r io.ReadCloser) *ReaderCounter {
4142

4243
func (rd *ReaderCounter) Read(buf []byte) (int, error) {
4344
n, err := rd.ReadCloser.Read(buf)
44-
atomic.AddUint64(&rd.count, uint64(n))
45+
atomic.AddUint64(&rd.count, uint64(n)) //nolint:gosec // disable G115
4546
return n, err
4647
}
4748

@@ -67,7 +68,7 @@ func (rc *ResponseCounter) Write(buf []byte) (int, error) {
6768
}
6869

6970
n, err := rc.ResponseWriter.Write(buf)
70-
atomic.AddUint64(&rc.count, uint64(n))
71+
atomic.AddUint64(&rc.count, uint64(n)) //nolint:gosec // disable G115
7172
return n, err
7273
}
7374

internal/pkg/monitor/monitor.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import (
2121
"github.com/elastic/fleet-server/v7/internal/pkg/sleep"
2222
"github.com/elastic/fleet-server/v7/internal/pkg/sqn"
2323

24-
"github.com/elastic/go-elasticsearch/v8"
2524
"github.com/rs/zerolog"
2625
"go.elastic.co/apm/v2"
26+
27+
"github.com/elastic/go-elasticsearch/v8"
2728
)
2829

2930
const (
@@ -462,7 +463,7 @@ func (m *simpleMonitorT) prepareCheckQuery() (*dsl.Tmpl, error) {
462463
// Prepares full documents query
463464
func (m *simpleMonitorT) prepareQuery() (*dsl.Tmpl, error) {
464465
tmpl, root := m.prepareCommon(true)
465-
root.Size(uint64(m.fetchSize))
466+
root.Size(uint64(m.fetchSize)) //nolint:gosec // disable G115
466467
root.Sort().SortOrder(fieldSeqNo, dsl.SortAscend)
467468

468469
if err := tmpl.Resolve(root); err != nil {

internal/pkg/policy/policy_output_integration_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
//go:build integration
66

7-
//nolint:goconst // disable constants checks for tests
87
package policy
98

109
import (

internal/pkg/scheduler/scheduler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func WithSplayPercent(splayPercent uint) OptFunc {
5050
if splayPercent >= 100 {
5151
return errors.New("invalid splay value, expected < 100")
5252
}
53-
s.splayPercent = int(splayPercent)
53+
s.splayPercent = int(splayPercent) //nolint:gosec // disable G115
5454
return nil
5555
}
5656
}

internal/pkg/server/fleet_integration_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ import (
2222
"testing"
2323
"time"
2424

25-
"github.com/elastic/elastic-agent-client/v7/pkg/client"
26-
"github.com/elastic/go-elasticsearch/v8"
2725
"github.com/gofrs/uuid"
2826
"github.com/google/go-cmp/cmp"
2927
"github.com/hashicorp/go-cleanhttp"
3028
"github.com/stretchr/testify/mock"
3129
"github.com/stretchr/testify/require"
3230
"golang.org/x/sync/errgroup"
3331

32+
"github.com/elastic/elastic-agent-client/v7/pkg/client"
33+
"github.com/elastic/go-elasticsearch/v8"
34+
3435
"github.com/elastic/fleet-server/v7/internal/pkg/api"
3536
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
3637
"github.com/elastic/fleet-server/v7/internal/pkg/build"
@@ -236,7 +237,7 @@ func (s *tserver) waitServerUp(ctx context.Context, dur time.Duration) error {
236237
}
237238
resp, err := cli.Do(req)
238239
if err != nil {
239-
return false, nil //nolint:nilerr // we want to ignore the error in this case.
240+
return false, nil
240241
}
241242
defer resp.Body.Close()
242243

internal/pkg/testing/port.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ func FreePort() (uint16, error) {
1818
}
1919
defer l.Close()
2020

21-
return uint16(l.Addr().(*net.TCPAddr).Port), nil
21+
return uint16(l.Addr().(*net.TCPAddr).Port), nil //nolint:gosec // disable G115
2222
}

0 commit comments

Comments
 (0)