Skip to content

Commit

Permalink
Update golangci-lint version (#3928) (#3936)
Browse files Browse the repository at this point in the history
(cherry picked from commit da96da3)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
  • Loading branch information
mergify[bot] and michel-laterman authored Sep 20, 2024
1 parent 25261ab commit e967cfc
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.55.2
version: v1.61.0

# Give the job more time to execute.
# Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but,
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ check-headers: ## - Check copyright headers

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

.PHONY: notice
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/api/handleAck.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (ack *AckT) processRequest(zlog zerolog.Logger, w http.ResponseWriter, r *h
return err
}

cntAcks.bodyOut.Add(uint64(nWritten))
cntAcks.bodyOut.Add(uint64(nWritten)) //nolint:gosec // disable G115

return nil
}
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/api/handleArtifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
"net/http"
"time"

"go.elastic.co/apm/v2"

"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
"github.com/elastic/fleet-server/v7/internal/pkg/cache"
"github.com/elastic/fleet-server/v7/internal/pkg/config"
"github.com/elastic/fleet-server/v7/internal/pkg/dl"
"github.com/elastic/fleet-server/v7/internal/pkg/logger"
"github.com/elastic/fleet-server/v7/internal/pkg/model"
"github.com/elastic/fleet-server/v7/internal/pkg/throttle"
"go.elastic.co/apm/v2"

"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -88,7 +89,7 @@ func (at ArtifactT) handleArtifacts(zlog zerolog.Logger, w http.ResponseWriter,
e = e.Int64(ECSEventDuration, time.Since(ts).Nanoseconds())
}
e.Msg("artifact response sent")
cntArtifacts.bodyOut.Add(uint64(n))
cntArtifacts.bodyOut.Add(uint64(n)) //nolint:gosec // disable G115
return nil
}

Expand Down Expand Up @@ -146,7 +147,7 @@ func (at ArtifactT) processRequest(ctx context.Context, zlog zerolog.Logger, age
//
// Initial implementation is dependent on security by obscurity; ie.
// it should be difficult for an attacker to guess a guid.
func (at ArtifactT) authorizeArtifact(ctx context.Context, _ *model.Agent, _, _ string) error { //nolint:unparam // remove if this is implemented
func (at ArtifactT) authorizeArtifact(ctx context.Context, _ *model.Agent, _, _ string) error {
span, _ := apm.StartSpan(ctx, "authorizeArtifacts", "auth") // TODO return and use span ctx if this is ever not a nop
defer span.End()
return nil // TODO
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/api/handleCheckin.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func (ct *CheckinT) writeResponse(zlog zerolog.Logger, w http.ResponseWriter, r
} else {
var nWritten int
nWritten, err = w.Write(payload)
cntCheckin.bodyOut.Add(uint64(nWritten))
cntCheckin.bodyOut.Add(uint64(nWritten)) //nolint:gosec // disable G115

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

//nolint:gosec // memory aliasing is used to convert from pointers to values and the other way
func convertActions(zlog zerolog.Logger, agentID string, actions []model.Action) ([]Action, string) {
var ackToken string
sz := len(actions)
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/api/handleEnroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"strings"
"time"

"go.elastic.co/apm/v2"

"github.com/elastic/elastic-agent-libs/str"
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
Expand All @@ -24,7 +26,6 @@ import (
"github.com/elastic/fleet-server/v7/internal/pkg/model"
"github.com/elastic/fleet-server/v7/internal/pkg/rollback"
"github.com/elastic/fleet-server/v7/internal/pkg/sqn"
"go.elastic.co/apm/v2"

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

numWritten, err := w.Write(data)
cntEnroll.bodyOut.Add(uint64(numWritten))
cntEnroll.bodyOut.Add(uint64(numWritten)) //nolint:gosec // disable G115

if err != nil {
return fmt.Errorf("fail send enroll response: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/api/handleStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"net/http"
"time"

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

"github.com/elastic/elastic-agent-client/v7/pkg/client"

"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
"github.com/elastic/fleet-server/v7/internal/pkg/build"
"github.com/elastic/fleet-server/v7/internal/pkg/bulk"
Expand Down Expand Up @@ -120,7 +121,7 @@ func (st StatusT) handleStatus(zlog zerolog.Logger, sm policy.SelfMonitor, bi bu
}
}

cntStatus.bodyOut.Add(uint64(nWritten))
cntStatus.bodyOut.Add(uint64(nWritten)) //nolint:gosec // disable G115
e := zlog.Debug().Int(ECSHTTPResponseBodyBytes, nWritten)
if ok {
e = e.Int64(ECSEventDuration, time.Since(ts).Nanoseconds())
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/api/openapi_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//nolint:goconst // don't care about repitition for tests
package api

// Test json encoding/decoding for all req/resp items
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/bulk/opMulti.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (b *Bulker) multiWaitBulkOp(ctx context.Context, action actionT, ops []Mult

bulk := &bulks[i]
bulk.ch = ch
bulk.idx = int32(i)
bulk.idx = int32(i) //nolint:gosec // disable G115
bulk.action = action
bulk.buf.Set(bodySlice)
if opt.Refresh {
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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

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

import (
Expand Down
17 changes: 9 additions & 8 deletions internal/pkg/config/env_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
"strings"
"time"

"github.com/elastic/go-ucfg/yaml"
"github.com/pbnjay/memory"
"github.com/rs/zerolog"

"github.com/elastic/go-ucfg/yaml"
)

const (
Expand Down Expand Up @@ -95,7 +96,7 @@ type valueRange struct {

type envLimits struct {
Agents valueRange `config:"num_agents"`
RecommendedRAM int `config:"recommended_min_ram"`
RecommendedRAM uint64 `config:"recommended_min_ram"`
Server *serverLimitDefaults `config:"server_limits"`
Cache *cacheLimits `config:"cache_limits"`
}
Expand Down Expand Up @@ -292,7 +293,7 @@ func loadLimits(agentLimit int) *envLimits {
// get nearest limits for configured agent numbers
if l.Agents.Min <= agentLimit && agentLimit <= l.Agents.Max {
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)
ramSize := int(memory.TotalMemory() / 1024 / 1024)
ramSize := memory.TotalMemory() / 1024 / 1024
if ramSize < l.RecommendedRAM {
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)
}
Expand All @@ -305,14 +306,14 @@ func loadLimits(agentLimit int) *envLimits {

// memMB returns the system total memory in MB
// It wraps memory.TotalMemory() so that we can replace the var in unit tests.
var memMB func() int = func() int {
return int(memory.TotalMemory() / 1024 / 1024)
var memMB func() uint64 = func() uint64 {
return memory.TotalMemory() / 1024 / 1024
}

func memEnvLimits() *envLimits {
mem := memMB()
k := 0
recRAM := 0
var recRAM uint64
log := zerolog.Ctx(context.TODO())
for i, l := range defaults {
if mem >= l.RecommendedRAM && l.RecommendedRAM > recRAM {
Expand All @@ -321,10 +322,10 @@ func memEnvLimits() *envLimits {
}
}
if recRAM == 0 {
log.Warn().Int("memory_mb", mem).Msg("No settings with recommended ram found, using default.")
log.Warn().Uint64("memory_mb", mem).Msg("No settings with recommended ram found, using default.")
return defaultEnvLimits()
}
log.Info().Int("memory_mb", mem).Int("recommended_mb", recRAM).Msg("Found settings with recommended ram.")
log.Info().Uint64("memory_mb", mem).Uint64("recommended_mb", recRAM).Msg("Found settings with recommended ram.")
return defaults[k]
}

Expand Down
1 change: 0 additions & 1 deletion internal/pkg/dl/migration_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

//go:build integration

//nolint:goconst // disable duplicate checking
package dl

import (
Expand Down
12 changes: 6 additions & 6 deletions internal/pkg/file/cbor/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func encodePreambleToCBOR(final bool, baseID string, chunkHash string, chunkSize
preamble[11] = 'p'
preamble[12] = 0x1b // uint64 to follow
// occupies 8 bytes, indexes 13-20
binary.BigEndian.PutUint64(preamble[13:], uint64(time.Now().UnixMilli()))
preamble[21] = 0x64 // string with 4 chars (key: last)
binary.BigEndian.PutUint64(preamble[13:], uint64(time.Now().UnixMilli())) //nolint:gosec // disable G115
preamble[21] = 0x64 // string with 4 chars (key: last)
preamble[22] = 'l'
preamble[23] = 'a'
preamble[24] = 's'
Expand Down Expand Up @@ -118,8 +118,8 @@ func encodePreambleToCBOR(final bool, baseID string, chunkHash string, chunkSize
}
if !final {
// byte data should be precisely chunkSize long, otherwise malformed
preamble[i] = 0x5A // say length descriptor will be 32-bit int
binary.BigEndian.PutUint32(preamble[i+1:], uint32(chunkSize))
preamble[i] = 0x5A // say length descriptor will be 32-bit int
binary.BigEndian.PutUint32(preamble[i+1:], uint32(chunkSize)) //nolint:gosec // disable G115
} else {
// final chunk may be less than full size, will need to determine length
preamble[i] = 0x5F // indeterminate-length byte sequence
Expand Down Expand Up @@ -150,8 +150,8 @@ func (c *ChunkEncoder) Read(buf []byte) (int, error) {
return 0, errors.New("buffer too small")
}
n, err := c.chunk.Read(buf[varLenHeaderSize:])
buf[0] = 0x5A // 4-byte length descriptor to follow
binary.BigEndian.PutUint32(buf[1:], uint32(n))
buf[0] = 0x5A // 4-byte length descriptor to follow
binary.BigEndian.PutUint32(buf[1:], uint32(n)) //nolint:gosec // disable G115

if errors.Is(err, io.EOF) {
if n == 0 { // chunk data has been exhausted, write the terminating byte and get out
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/file/cbor/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestChunkWriter(t *testing.T) {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, // contents
}

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

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

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

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

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

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

Expand Down
1 change: 0 additions & 1 deletion internal/pkg/file/uploader/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

//nolint:goconst // disable contstants checks for tests
package uploader

import (
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/logger/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
"github.com/gofrs/uuid"
"github.com/rs/zerolog"

"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
"go.elastic.co/apm/module/apmzerolog/v2"

"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
)

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

func (rd *ReaderCounter) Read(buf []byte) (int, error) {
n, err := rd.ReadCloser.Read(buf)
atomic.AddUint64(&rd.count, uint64(n))
atomic.AddUint64(&rd.count, uint64(n)) //nolint:gosec // disable G115
return n, err
}

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

n, err := rc.ResponseWriter.Write(buf)
atomic.AddUint64(&rc.count, uint64(n))
atomic.AddUint64(&rc.count, uint64(n)) //nolint:gosec // disable G115
return n, err
}

Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"github.com/elastic/fleet-server/v7/internal/pkg/sleep"
"github.com/elastic/fleet-server/v7/internal/pkg/sqn"

"github.com/elastic/go-elasticsearch/v8"
"github.com/rs/zerolog"
"go.elastic.co/apm/v2"

"github.com/elastic/go-elasticsearch/v8"
)

const (
Expand Down Expand Up @@ -462,7 +463,7 @@ func (m *simpleMonitorT) prepareCheckQuery() (*dsl.Tmpl, error) {
// Prepares full documents query
func (m *simpleMonitorT) prepareQuery() (*dsl.Tmpl, error) {
tmpl, root := m.prepareCommon(true)
root.Size(uint64(m.fetchSize))
root.Size(uint64(m.fetchSize)) //nolint:gosec // disable G115
root.Sort().SortOrder(fieldSeqNo, dsl.SortAscend)

if err := tmpl.Resolve(root); err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/policy/policy_output_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

//go:build integration

//nolint:goconst // disable constants checks for tests
package policy

import (
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func WithSplayPercent(splayPercent uint) OptFunc {
if splayPercent >= 100 {
return errors.New("invalid splay value, expected < 100")
}
s.splayPercent = int(splayPercent)
s.splayPercent = int(splayPercent) //nolint:gosec // disable G115
return nil
}
}
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/server/fleet_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (
"testing"
"time"

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/go-elasticsearch/v8"
"github.com/gofrs/uuid"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/go-cleanhttp"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"

"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/go-elasticsearch/v8"

"github.com/elastic/fleet-server/v7/internal/pkg/api"
"github.com/elastic/fleet-server/v7/internal/pkg/apikey"
"github.com/elastic/fleet-server/v7/internal/pkg/build"
Expand Down Expand Up @@ -236,7 +237,7 @@ func (s *tserver) waitServerUp(ctx context.Context, dur time.Duration) error {
}
resp, err := cli.Do(req)
if err != nil {
return false, nil //nolint:nilerr // we want to ignore the error in this case.
return false, nil
}
defer resp.Body.Close()

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/testing/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func FreePort() (uint16, error) {
}
defer l.Close()

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

0 comments on commit e967cfc

Please sign in to comment.