Skip to content

Commit

Permalink
chore: Linting updates in prep for Go 1.23 (#14071)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul1r authored Sep 6, 2024
1 parent 73cbbb0 commit 18cef21
Show file tree
Hide file tree
Showing 160 changed files with 406 additions and 403 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ nix/result

# helm test
production/helm/loki/src/helm-test/helm-test

# Go telemetry
.config
2 changes: 1 addition & 1 deletion clients/cmd/docker-driver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func handlers(h *sdk.Handler, d *driver) {
respond(nil, w)
})

h.HandleFunc("/LogDriver.Capabilities", func(w http.ResponseWriter, r *http.Request) {
h.HandleFunc("/LogDriver.Capabilities", func(w http.ResponseWriter, _ *http.Request) {
_ = json.NewEncoder(w).Encode(&CapabilitiesResponse{
Cap: logger.Capability{ReadLogs: true},
})
Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/logentry/stages/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func validateMatcherConfig(cfg *MatcherConfig) (logql.Expr, error) {
return nil, errors.New(ErrUnknownMatchAction)
}

if cfg.Action == MatchActionKeep && (cfg.Stages == nil || len(cfg.Stages) == 0) {
if cfg.Action == MatchActionKeep && (len(cfg.Stages) == 0) {
return nil, errors.New(ErrMatchRequiresStages)
}
if cfg.Action == MatchActionDrop && (cfg.Stages != nil && len(cfg.Stages) != 0) {
if cfg.Action == MatchActionDrop && (len(cfg.Stages) != 0) {
return nil, errors.New(ErrStagesWithDropLine)
}

Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ func Test_Tripperware(t *testing.T) {
var called bool
c, err := NewWithTripperware(metrics, Config{
URL: flagext.URLValue{URL: url},
}, 0, 0, false, log.NewNopLogger(), func(rt http.RoundTripper) http.RoundTripper {
}, 0, 0, false, log.NewNopLogger(), func(_ http.RoundTripper) http.RoundTripper {
return RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
require.Equal(t, r.URL.String(), "http://foo.com")
called = true
Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/promtail/discovery/consulagent/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,14 @@ func TestGetDatacenterShouldReturnError(t *testing.T) {
}{
{
// Define a handler that will return status 500.
handler: func(w http.ResponseWriter, r *http.Request) {
handler: func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(500)
},
errMessage: "Unexpected response code: 500 ()",
},
{
// Define a handler that will return incorrect response.
handler: func(w http.ResponseWriter, r *http.Request) {
handler: func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte(`{"Config": {"Not-Datacenter": "test-dc"}}`))
require.NoError(t, err)
},
Expand Down
10 changes: 5 additions & 5 deletions clients/pkg/promtail/targets/cloudflare/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Test_CloudflareTarget(t *testing.T) {
logs: []string{},
}, nil)
// replace the client.
getClient = func(apiKey, zoneID string, fields []string) (Client, error) {
getClient = func(_, _ string, _ []string) (Client, error) {
return cfClient, nil
}

Expand Down Expand Up @@ -114,7 +114,7 @@ func Test_RetryErrorLogpullReceived(t *testing.T) {
err: ErrorLogpullReceived,
}, nil).Times(2) // just retry once
// replace the client
getClient = func(apiKey, zoneID string, fields []string) (Client, error) {
getClient = func(_, _ string, _ []string) (Client, error) {
return cfClient, nil
}
defaultBackoff.MinBackoff = 0
Expand Down Expand Up @@ -159,7 +159,7 @@ func Test_RetryErrorIterating(t *testing.T) {
err: ErrorLogpullReceived,
}, nil).Once()
// replace the client.
getClient = func(apiKey, zoneID string, fields []string) (Client, error) {
getClient = func(_, _ string, _ []string) (Client, error) {
return cfClient, nil
}
// retries as fast as possible.
Expand Down Expand Up @@ -210,7 +210,7 @@ func Test_CloudflareTargetError(t *testing.T) {
// setup errors for all retries
cfClient.On("LogpullReceived", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("no logs"))
// replace the client.
getClient = func(apiKey, zoneID string, fields []string) (Client, error) {
getClient = func(_, _ string, _ []string) (Client, error) {
return cfClient, nil
}

Expand Down Expand Up @@ -263,7 +263,7 @@ func Test_CloudflareTargetError168h(t *testing.T) {
// setup errors for all retries
cfClient.On("LogpullReceived", mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("HTTP status 400: bad query: error parsing time: invalid time range: too early: logs older than 168h0m0s are not available"))
// replace the client.
getClient = func(apiKey, zoneID string, fields []string) (Client, error) {
getClient = func(_, _ string, _ []string) (Client, error) {
return cfClient, nil
}

Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/gcplog/pull_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (t *pullTarget) consumeSubscription() {
defer t.cancel()

for t.backoff.Ongoing() {
err := t.sub.Receive(t.ctx, func(ctx context.Context, m *pubsub.Message) {
err := t.sub.Receive(t.ctx, func(_ context.Context, m *pubsub.Message) {
t.msgs <- m
t.backoff.Reset()
})
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/journal/journaltarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *mockJournalReader) Follow(until <-chan time.Time, _ io.Writer) error {
}

func newMockJournalEntry(entry *sdjournal.JournalEntry) journalEntryFunc {
return func(c sdjournal.JournalReaderConfig, cursor string) (*sdjournal.JournalEntry, error) {
return func(_ sdjournal.JournalReaderConfig, _ string) (*sdjournal.JournalEntry, error) {
return entry, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/kafka/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Test_ComsumerConsume(t *testing.T) {
ctx: context.Background(),
cancel: func() {},
ConsumerGroup: group,
discoverer: DiscovererFn(func(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) (RunnableTarget, error) {
discoverer: DiscovererFn(func(_ sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) (RunnableTarget, error) {
if claim.Topic() != "dropped" {
return &fakeTarget{
ctx: ctx,
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/kafka/target_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Test_TopicDiscovery(t *testing.T) {
cancel: func() {},
ConsumerGroup: group,
logger: log.NewNopLogger(),
discoverer: DiscovererFn(func(s sarama.ConsumerGroupSession, c sarama.ConsumerGroupClaim) (RunnableTarget, error) {
discoverer: DiscovererFn(func(_ sarama.ConsumerGroupSession, _ sarama.ConsumerGroupClaim) (RunnableTarget, error) {
return nil, nil
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func TestParseStream_NewlineSeparated(t *testing.T) {
func TestParseStream_InvalidStream(t *testing.T) {
r := strings.NewReader("invalid")

err := syslogparser.ParseStream(false, r, func(res *syslog.Result) {}, defaultMaxMessageLength)
err := syslogparser.ParseStream(false, r, func(_ *syslog.Result) {}, defaultMaxMessageLength)
require.EqualError(t, err, "invalid or unsupported framing. first byte: 'i'")
}

func TestParseStream_EmptyStream(t *testing.T) {
r := strings.NewReader("")

err := syslogparser.ParseStream(false, r, func(res *syslog.Result) {}, defaultMaxMessageLength)
err := syslogparser.ParseStream(false, r, func(_ *syslog.Result) {}, defaultMaxMessageLength)
require.Equal(t, err, io.EOF)
}
10 changes: 5 additions & 5 deletions cmd/logcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func newQueryClient(app *kingpin.Application) client.Client {
}

// extract host
addressAction := func(c *kingpin.ParseContext) error {
addressAction := func(_ *kingpin.ParseContext) error {
// If a proxy is to be used do not set TLS ServerName. In the case of HTTPS proxy this ensures
// the http client validates both the proxy's cert and the cert used by loki behind the proxy
// using the ServerName's from the provided --addr and --proxy-url flags.
Expand Down Expand Up @@ -494,7 +494,7 @@ func newLabelQuery(cmd *kingpin.CmdClause) *labelquery.LabelQuery {
q := &labelquery.LabelQuery{}

// executed after all command flags are parsed
cmd.Action(func(c *kingpin.ParseContext) error {
cmd.Action(func(_ *kingpin.ParseContext) error {

defaultEnd := time.Now()
defaultStart := defaultEnd.Add(-since)
Expand Down Expand Up @@ -522,7 +522,7 @@ func newSeriesQuery(cmd *kingpin.CmdClause) *seriesquery.SeriesQuery {
q := &seriesquery.SeriesQuery{}

// executed after all command flags are parsed
cmd.Action(func(c *kingpin.ParseContext) error {
cmd.Action(func(_ *kingpin.ParseContext) error {

defaultEnd := time.Now()
defaultStart := defaultEnd.Add(-since)
Expand Down Expand Up @@ -550,7 +550,7 @@ func newQuery(instant bool, cmd *kingpin.CmdClause) *query.Query {
q := &query.Query{}

// executed after all command flags are parsed
cmd.Action(func(c *kingpin.ParseContext) error {
cmd.Action(func(_ *kingpin.ParseContext) error {

if instant {
q.SetInstant(mustParse(now, time.Now()))
Expand Down Expand Up @@ -698,7 +698,7 @@ func newDetectedFieldsQuery(cmd *kingpin.CmdClause) *detected.FieldsQuery {
q := &detected.FieldsQuery{}

// executed after all command flags are parsed
cmd.Action(func(c *kingpin.ParseContext) error {
cmd.Action(func(_ *kingpin.ParseContext) error {
defaultEnd := time.Now()
defaultStart := defaultEnd.Add(-since)

Expand Down
2 changes: 1 addition & 1 deletion cmd/lokitool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
ruleCommand.Register(app)
auditCommand.Register(app)

app.Command("version", "Get the version of the lokitool CLI").Action(func(k *kingpin.ParseContext) error {
app.Command("version", "Get the version of the lokitool CLI").Action(func(_ *kingpin.ParseContext) error {
fmt.Println(version.Print("loki"))
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion integration/loki_rule_eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func testRuleEval(t *testing.T, mode string) {

// this is the function that will be called when the remote-write receiver receives a request.
// it tests that the expected payload is received.
expectedResults := func(w http.ResponseWriter, r *http.Request) {
expectedResults := func(_ http.ResponseWriter, r *http.Request) {
wr, err := remote.DecodeWriteRequest(r.Body)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/bloombuild/builder/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (i *blockLoadingIter) init() {

// set "match all" filter function if not present
if i.filter == nil {
i.filter = func(cbq *bloomshipper.CloseableBlockQuerier) bool { return true }
i.filter = func(_ *bloomshipper.CloseableBlockQuerier) bool { return true }
}

// done
Expand Down
2 changes: 1 addition & 1 deletion pkg/bloombuild/builder/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestBatchedLoader(t *testing.T) {
t.Parallel()

errMapper := func(i int) (int, error) {
errMapper := func(_ int) (int, error) {
return 0, errors.New("bzzt")
}
successMapper := func(i int) (int, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/canary/comparator/comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (c *Comparator) spotCheckEntries(currTime time.Time) {
func(_ int, t *time.Time) bool {
return t.Before(currTime.Add(-c.spotCheckMax))
},
func(_ int, t *time.Time) {
func(_ int, _ *time.Time) {

})

Expand Down Expand Up @@ -513,7 +513,7 @@ func (c *Comparator) pruneEntries(currentTime time.Time) {
func(_ int, t *time.Time) bool {
return t.Before(currentTime.Add(-c.wait))
},
func(_ int, t *time.Time) {
func(_ int, _ *time.Time) {

})
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ func TestMemChunk_ReboundAndFilter_with_filter(t *testing.T) {
{
name: "no matches - chunk without structured metadata",
testMemChunk: buildFilterableTestMemChunk(t, chkFrom, chkThrough, &chkFrom, &chkThroughPlus1, false),
filterFunc: func(_ time.Time, in string, structuredMetadata ...labels.Label) bool {
filterFunc: func(_ time.Time, _ string, structuredMetadata ...labels.Label) bool {
return labels.Labels(structuredMetadata).Get(lblPing) == lblPong
},
nrMatching: 0,
Expand All @@ -1548,7 +1548,7 @@ func TestMemChunk_ReboundAndFilter_with_filter(t *testing.T) {
{
name: "structured metadata not matching",
testMemChunk: buildFilterableTestMemChunk(t, chkFrom, chkThrough, &chkFrom, &chkThroughPlus1, true),
filterFunc: func(_ time.Time, in string, structuredMetadata ...labels.Label) bool {
filterFunc: func(_ time.Time, _ string, structuredMetadata ...labels.Label) bool {
return labels.Labels(structuredMetadata).Get("ding") == "dong"
},
nrMatching: 0,
Expand All @@ -1557,7 +1557,7 @@ func TestMemChunk_ReboundAndFilter_with_filter(t *testing.T) {
{
name: "some lines removed - with structured metadata",
testMemChunk: buildFilterableTestMemChunk(t, chkFrom, chkThrough, &chkFrom, &chkFromPlus5, true),
filterFunc: func(_ time.Time, in string, structuredMetadata ...labels.Label) bool {
filterFunc: func(_ time.Time, _ string, structuredMetadata ...labels.Label) bool {
return labels.Labels(structuredMetadata).Get(lblPing) == lblPong
},
nrMatching: 5,
Expand Down
10 changes: 5 additions & 5 deletions pkg/compactor/deletion/delete_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
},
expectedResp: resp{
isDeleted: true,
expectedFilter: func(ts time.Time, s string, structuredMetadata ...labels.Label) bool {
expectedFilter: func(ts time.Time, _ string, structuredMetadata ...labels.Label) bool {
tsUnixNano := ts.UnixNano()
if labels.Labels(structuredMetadata).Get(lblPing) == lblPong && now.Add(-3*time.Hour).UnixNano() <= tsUnixNano && tsUnixNano <= now.Add(-time.Hour).UnixNano() {
return true
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
},
expectedResp: resp{
isDeleted: true,
expectedFilter: func(ts time.Time, s string, _ ...labels.Label) bool {
expectedFilter: func(ts time.Time, _ string, _ ...labels.Label) bool {
tsUnixNano := ts.UnixNano()
if now.Add(-3*time.Hour).UnixNano() <= tsUnixNano && tsUnixNano <= now.Add(-2*time.Hour).UnixNano() {
return true
Expand All @@ -150,7 +150,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
},
expectedResp: resp{
isDeleted: true,
expectedFilter: func(ts time.Time, s string, _ ...labels.Label) bool {
expectedFilter: func(ts time.Time, _ string, _ ...labels.Label) bool {
tsUnixNano := ts.UnixNano()
if now.Add(-2*time.Hour).UnixNano() <= tsUnixNano && tsUnixNano <= now.UnixNano() {
return true
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
},
expectedResp: resp{
isDeleted: true,
expectedFilter: func(ts time.Time, s string, structuredMetadata ...labels.Label) bool {
expectedFilter: func(ts time.Time, _ string, structuredMetadata ...labels.Label) bool {
tsUnixNano := ts.UnixNano()
if labels.Labels(structuredMetadata).Get(lblPing) == lblPong && now.Add(-2*time.Hour).UnixNano() <= tsUnixNano && tsUnixNano <= now.UnixNano() {
return true
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestDeleteRequest_IsDeleted(t *testing.T) {
},
expectedResp: resp{
isDeleted: true,
expectedFilter: func(ts time.Time, s string, _ ...labels.Label) bool {
expectedFilter: func(ts time.Time, _ string, _ ...labels.Label) bool {
tsUnixNano := ts.UnixNano()
if now.Add(-(2*time.Hour+30*time.Minute)).UnixNano() <= tsUnixNano && tsUnixNano <= now.Add(-(time.Hour+30*time.Minute)).UnixNano() {
return true
Expand Down
Loading

0 comments on commit 18cef21

Please sign in to comment.