Skip to content

ci: Upgrade golangci-linter to v2 #6739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .errcheck-exclude

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/test-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
lint:
runs-on: ubuntu-24.04
container:
image: quay.io/cortexproject/build-image:master-281284ac1
image: quay.io/cortexproject/build-image:master-7ce1d1b12
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
test:
runs-on: ubuntu-24.04
container:
image: quay.io/cortexproject/build-image:master-281284ac1
image: quay.io/cortexproject/build-image:master-7ce1d1b12
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand All @@ -64,7 +64,7 @@ jobs:
test-no-race:
runs-on: ubuntu-24.04
container:
image: quay.io/cortexproject/build-image:master-281284ac1
image: quay.io/cortexproject/build-image:master-7ce1d1b12
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
build:
runs-on: ubuntu-24.04
container:
image: quay.io/cortexproject/build-image:master-281284ac1
image: quay.io/cortexproject/build-image:master-7ce1d1b12
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -247,14 +247,14 @@ jobs:
run: |
touch build-image/.uptodate
MIGRATIONS_DIR=$(pwd)/cmd/cortex/migrations
make BUILD_IMAGE=quay.io/cortexproject/build-image:master-281284ac1 TTY='' configs-integration-test
make BUILD_IMAGE=quay.io/cortexproject/build-image:master-7ce1d1b12 TTY='' configs-integration-test

deploy_website:
needs: [build, test]
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex'
runs-on: ubuntu-24.04
container:
image: quay.io/cortexproject/build-image:master-281284ac1
image: quay.io/cortexproject/build-image:master-7ce1d1b12
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -296,7 +296,7 @@ jobs:
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.repository == 'cortexproject/cortex'
runs-on: ubuntu-24.04
container:
image: quay.io/cortexproject/build-image:master-281284ac1
image: quay.io/cortexproject/build-image:master-7ce1d1b12
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down
89 changes: 49 additions & 40 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
output:
format: line-number

linters:
enable:
- goimports
- revive
- gofmt
- misspell
- depguard
- sloglint
- unused

linters-settings:
staticcheck:
checks:
- all
errcheck:
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
exclude: ./.errcheck-exclude
goimports:
local-prefixes: "github.com/cortexproject/cortex"
revive:
severity: error # We only want critical issues.
govet:
disable:
- printf

depguard:
rules:
main:
list-mode: lax
files:
- $all
deny:
- pkg: "github.com/go-kit/kit/log"
desc: Use github.com/go-kit/log instead of github.com/go-kit/kit/log"

version: "2"
run:
timeout: 5m

# List of build tags, all linters use it.
build-tags:
- netgo
Expand All @@ -51,3 +12,51 @@ run:
- integration_querier
- integration_ruler
- integration_query_fuzz
output:
formats:
text:
path: stdout
colors: false
linters:
enable:
- depguard
- misspell
- revive
- sloglint
settings:
depguard:
rules:
main:
list-mode: lax
files:
- $all
deny:
- pkg: github.com/go-kit/kit/log
desc: Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
errcheck:
exclude-functions:
- io/ioutil.WriteFile
- io/ioutil.ReadFile
- io.Copy
- (github.com/go-kit/log.Logger).Log
- (*github.com/cortexproject/cortex/pkg/util/spanlogger.SpanLogger).Error
- (github.com/opentracing/opentracing-go.Tracer).Inject
govet:
disable:
- printf
revive:
severity: error
exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/cortexproject/cortex
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ build-image/$(UPTODATE): build-image/*
SUDO := $(shell docker info >/dev/null 2>&1 || echo "sudo -E")
BUILD_IN_CONTAINER := true
BUILD_IMAGE ?= $(IMAGE_PREFIX)build-image
LATEST_BUILD_IMAGE_TAG ?= master-281284ac1
LATEST_BUILD_IMAGE_TAG ?= master-7ce1d1b12

# TTY is parameterized to allow Google Cloud Builder to run builds,
# as it currently disallows TTY devices. This value needs to be overridden
Expand Down
10 changes: 6 additions & 4 deletions integration/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ func NewHTTPReadinessProbe(port int, path string, expectedStatusRangeStart, expe

func (p *HTTPReadinessProbe) Ready(service *ConcreteService) (err error) {
endpoint := service.Endpoint(p.port)
if endpoint == "" {
switch endpoint {
case "":
return fmt.Errorf("cannot get service endpoint for port %d", p.port)
} else if endpoint == "stopped" {
case "stopped":
return errors.New("service has stopped")
}

Expand Down Expand Up @@ -467,9 +468,10 @@ func NewTCPReadinessProbe(port int) *TCPReadinessProbe {

func (p *TCPReadinessProbe) Ready(service *ConcreteService) (err error) {
endpoint := service.Endpoint(p.port)
if endpoint == "" {
switch endpoint {
case "":
return fmt.Errorf("cannot get service endpoint for port %d", p.port)
} else if endpoint == "stopped" {
case "stopped":
return errors.New("service has stopped")
}

Expand Down
20 changes: 12 additions & 8 deletions integration/e2ecortex/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ func NewDistributorWithConfigFile(name string, store RingStore, address, configF

// Configure the ingesters ring backend
flags["-ring.store"] = string(store)
if store == RingStoreConsul {
switch store {
case RingStoreConsul:
flags["-consul.hostname"] = address
} else if store == RingStoreEtcd {
case RingStoreEtcd:
flags["-etcd.endpoints"] = address
}

Expand Down Expand Up @@ -82,10 +83,11 @@ func NewQuerierWithConfigFile(name string, store RingStore, address, configFile
"-store-gateway.sharding-ring.store": string(store),
}

if store == RingStoreConsul {
switch store {
case RingStoreConsul:
ringBackendFlags["-consul.hostname"] = address
ringBackendFlags["-store-gateway.sharding-ring.consul.hostname"] = address
} else if store == RingStoreEtcd {
case RingStoreEtcd:
ringBackendFlags["-etcd.endpoints"] = address
ringBackendFlags["-store-gateway.sharding-ring.etcd.endpoints"] = address
}
Expand Down Expand Up @@ -130,10 +132,11 @@ func NewStoreGatewayWithConfigFile(name string, store RingStore, address string,
flags["-config.file"] = filepath.Join(e2e.ContainerSharedDir, configFile)
}

if store == RingStoreConsul {
switch store {
case RingStoreConsul:
flags["-consul.hostname"] = address
flags["-store-gateway.sharding-ring.consul.hostname"] = address
} else if store == RingStoreEtcd {
case RingStoreEtcd:
flags["-etcd.endpoints"] = address
flags["-store-gateway.sharding-ring.etcd.endpoints"] = address
}
Expand Down Expand Up @@ -173,9 +176,10 @@ func NewIngesterWithConfigFile(name string, store RingStore, address, configFile

// Configure the ingesters ring backend
flags["-ring.store"] = string(store)
if store == RingStoreConsul {
switch store {
case RingStoreConsul:
flags["-consul.hostname"] = address
} else if store == RingStoreEtcd {
case RingStoreEtcd:
flags["-etcd.endpoints"] = address
}

Expand Down
2 changes: 1 addition & 1 deletion integration/querier_tenant_federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func mergeResults(tenantIDs []string, resultsPerTenant []model.Vector) model.Vec
var v model.Vector
for pos, tenantID := range tenantIDs {
for _, r := range resultsPerTenant[pos] {
var s model.Sample = *r
var s = *r
s.Metric = r.Metric.Clone()
s.Metric[model.LabelName("__tenant_id__")] = model.LabelValue(tenantID)
v = append(v, &s)
Expand Down
5 changes: 3 additions & 2 deletions integration/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,10 @@ func TestQuerierWithBlocksStorageRunningInSingleBinaryMode(t *testing.T) {
require.NoError(t, writeFileToSharedDir(s, "alertmanager_configs/user-1.yaml", []byte(cortexAlertmanagerUserConfigYaml)))

// Add the cache address to the flags.
if testCfg.indexCacheBackend == tsdb.IndexCacheBackendMemcached {
switch testCfg.indexCacheBackend {
case tsdb.IndexCacheBackendMemcached:
flags["-blocks-storage.bucket-store.index-cache.memcached.addresses"] = "dns+" + memcached.NetworkEndpoint(e2ecache.MemcachedPort)
} else if testCfg.indexCacheBackend == tsdb.IndexCacheBackendRedis {
case tsdb.IndexCacheBackendRedis:
flags["-blocks-storage.bucket-store.index-cache.redis.addresses"] = redis.NetworkEndpoint(e2ecache.RedisPort)
}

Expand Down
21 changes: 12 additions & 9 deletions integration/query_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,12 @@ func TestVerticalShardingFuzz(t *testing.T) {
// Generate another set of series for testing binary expression and vector matching.
for i := numSeries; i < 2*numSeries; i++ {
prompbLabels := []prompb.Label{{Name: "job", Value: "test"}, {Name: "series", Value: strconv.Itoa(i)}}
if i%3 == 0 {
switch i % 3 {
case 0:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "200"})
} else if i%3 == 1 {
case 1:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "400"})
} else {
default:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "500"})
}
series := e2e.GenerateSeriesWithSamples("test_series_b", start, scrapeInterval, i*numSamples, numSamples, prompbLabels...)
Expand Down Expand Up @@ -874,11 +875,12 @@ func TestProtobufCodecFuzz(t *testing.T) {
// Generate another set of series for testing binary expression and vector matching.
for i := numSeries; i < 2*numSeries; i++ {
prompbLabels := []prompb.Label{{Name: "job", Value: "test"}, {Name: "series", Value: strconv.Itoa(i)}}
if i%3 == 0 {
switch i % 3 {
case 0:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "200"})
} else if i%3 == 1 {
case 1:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "400"})
} else {
default:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "500"})
}
series := e2e.GenerateSeriesWithSamples("test_series_b", start, scrapeInterval, i*numSamples, numSamples, prompbLabels...)
Expand Down Expand Up @@ -1532,11 +1534,12 @@ func TestBackwardCompatibilityQueryFuzz(t *testing.T) {
// Generate another set of series for testing binary expression and vector matching.
for i := numSeries; i < 2*numSeries; i++ {
prompbLabels := []prompb.Label{{Name: "job", Value: "test"}, {Name: "series", Value: strconv.Itoa(i)}}
if i%3 == 0 {
switch i % 3 {
case 0:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "200"})
} else if i%3 == 1 {
case 1:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "400"})
} else {
default:
prompbLabels = append(prompbLabels, prompb.Label{Name: "status_code", Value: "500"})
}
series := e2e.GenerateSeriesWithSamples("test_series_b", start, scrapeInterval, i*numSamples, numSamples, prompbLabels...)
Expand Down
6 changes: 3 additions & 3 deletions pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (am *MultitenantAlertmanager) GetUserConfig(w http.ResponseWriter, r *http.

cfg, err := am.store.GetAlertConfig(r.Context(), userID)
if err != nil {
switch {
case err == alertspb.ErrNotFound:
switch err {
case alertspb.ErrNotFound:
http.Error(w, err.Error(), http.StatusNotFound)
case err == alertspb.ErrAccessDenied:
case alertspb.ErrAccessDenied:
http.Error(w, err.Error(), http.StatusForbidden)
default:
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down
6 changes: 2 additions & 4 deletions pkg/alertmanager/multitenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,8 @@ receivers:
// Ensure the server endpoint has not been called if firewall is enabled. Since the alert is delivered
// asynchronously, we should pool it for a short period.
deadline := time.Now().Add(3 * time.Second)
for {
if time.Now().After(deadline) || serverInvoked.Load() {
break
}
for !time.Now().After(deadline) && !serverInvoked.Load() {

time.Sleep(100 * time.Millisecond)
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/alertmanager/rate_limited_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ func runNotifications(t *testing.T, rateLimitedNotifier *rateLimitedNotifier, co
for i := 0; i < count; i++ {
retry, err := rateLimitedNotifier.Notify(context.Background(), &types.Alert{})

if err == nil {
switch err {
case nil:
success++
} else if err == errRateLimited {
case errRateLimited:
rateLimited++
assert.False(t, retry)
} else {
default:
assert.NotNil(t, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/alertmanager/state_persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestStatePersister_Position0ShouldWrite(t *testing.T) {
{
time.Sleep(5 * time.Second)

assert.Equal(t, services.Starting, s.Service.State())
assert.Equal(t, services.Starting, s.State())
assert.Equal(t, 0, len(store.getWrites()))
}

Expand Down Expand Up @@ -139,13 +139,13 @@ func TestStatePersister_Position1ShouldNotWrite(t *testing.T) {

// Start the persister.
{
require.Equal(t, services.Starting, s.Service.State())
require.Equal(t, services.Starting, s.State())

state.getResult = makeTestFullState()
close(state.readyc)

require.NoError(t, s.AwaitRunning(context.Background()))
require.Equal(t, services.Running, s.Service.State())
require.Equal(t, services.Running, s.State())
}

// Should not have stored anything, having passed the interval multiple times.
Expand Down
Loading
Loading