Skip to content

Commit d4155d5

Browse files
committed
Update Go
* Update Go to 1.24. * Update golangci-lint to v2. * Fixup linting issues. Signed-off-by: SuperQ <[email protected]>
1 parent 58bed38 commit d4155d5

File tree

10 files changed

+49
-36
lines changed

10 files changed

+49
-36
lines changed

Diff for: .github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Go tests
1515
runs-on: ubuntu-latest
1616
container:
17-
image: quay.io/prometheus/golang-builder:1.23-base
17+
image: quay.io/prometheus/golang-builder:1.24-base
1818
steps:
1919
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2020
- uses: prometheus/promci@443c7fc2397e946bc9f5029e313a9c3441b9b86d # v0.4.7
@@ -62,7 +62,7 @@ jobs:
6262
name: Verify
6363
runs-on: ubuntu-latest
6464
container:
65-
image: quay.io/prometheus/golang-builder:1.23-base
65+
image: quay.io/prometheus/golang-builder:1.24-base
6666
steps:
6767
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6868
- run: make build

Diff for: .github/workflows/golangci-lint.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2828
- name: Install Go
29-
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
29+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
3030
with:
3131
go-version: 1.24.x
3232
- name: Install snmp_exporter/generator dependencies
3333
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
3434
if: github.repository == 'prometheus/snmp_exporter'
3535
- name: Lint
36-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
36+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
3737
with:
3838
args: --verbose
39-
version: v1.64.6
39+
version: v2.0.2

Diff for: .golangci.yml

+31-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
run:
2-
timeout: 5m
3-
1+
version: "2"
42
output:
53
formats:
6-
- format: line-number
4+
text:
75
path: stderr
8-
6+
colors: false
97
linters:
10-
disable-all: true
8+
default: none
119
enable:
1210
- asasalint
1311
- bodyclose
1412
- copyloopvar
1513
- errcheck
1614
- errorlint
1715
- exhaustive
18-
- gofmt
19-
- gofumpt
20-
- goimports
21-
- gosimple
2216
- govet
2317
- ineffassign
2418
- misspell
@@ -27,12 +21,33 @@ linters:
2721
- nonamedreturns
2822
- predeclared
2923
- revive
24+
- sloglint
3025
- staticcheck
31-
- typecheck
3226
- unconvert
3327
- unused
34-
- sloglint
35-
36-
linters-settings:
37-
goimports:
38-
local-prefixes: "github.com/prometheus-community/yet-another-cloudwatch-exporter"
28+
exclusions:
29+
generated: lax
30+
presets:
31+
- comments
32+
- common-false-positives
33+
- legacy
34+
- std-error-handling
35+
paths:
36+
- third_party$
37+
- builtin$
38+
- examples$
39+
formatters:
40+
enable:
41+
- gofmt
42+
- gofumpt
43+
- goimports
44+
settings:
45+
goimports:
46+
local-prefixes:
47+
- github.com/prometheus-community/yet-another-cloudwatch-exporter
48+
exclusions:
49+
generated: lax
50+
paths:
51+
- third_party$
52+
- builtin$
53+
- examples$

Diff for: .promu.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go:
22
# This must match .circle/config.yml.
3-
version: 1.23
3+
version: 1.24
44
repository:
55
path: github.com/prometheus-community/yet-another-cloudwatch-exporter
66
build:

Diff for: Makefile.common

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v1.64.6
64+
GOLANGCI_LINT_VERSION ?= v2.0.2
6565
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
6666
# windows isn't included here because of the path separator being different.
6767
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))

Diff for: cmd/yace/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func startScraper(c *cli.Context) error {
260260
cfg := config.ScrapeConf{}
261261
jobsCfg, err := cfg.Load(configFile, logger)
262262
if err != nil {
263-
return fmt.Errorf("Couldn't read %s: %w", configFile, err)
263+
return fmt.Errorf("couldn't read %s: %w", configFile, err)
264264
}
265265

266266
featureFlags := c.StringSlice(enableFeatureFlag)
@@ -269,7 +269,7 @@ func startScraper(c *cli.Context) error {
269269
var cache cachingFactory
270270
cache, err = v2.NewFactory(logger, jobsCfg, fips)
271271
if err != nil {
272-
return fmt.Errorf("Failed to construct aws sdk v2 client cache: %w", err)
272+
return fmt.Errorf("failed to construct aws sdk v2 client cache: %w", err)
273273
}
274274

275275
// Switch to v1 SDK if feature flag is enabled
@@ -301,7 +301,7 @@ func startScraper(c *cli.Context) error {
301301
pprofLink = htmlPprof
302302
}
303303

304-
_, _ = w.Write([]byte(fmt.Sprintf(htmlVersion, version.Version, pprofLink)))
304+
_, _ = fmt.Fprintf(w, htmlVersion, version.Version, pprofLink)
305305
})
306306

307307
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {

Diff for: pkg/clients/v2/factory.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ var _ clients.Factory = &CachingFactory{}
7979
func NewFactory(logger *slog.Logger, jobsCfg model.JobsConfig, fips bool) (*CachingFactory, error) {
8080
var options []func(*aws_config.LoadOptions) error
8181
options = append(options, aws_config.WithLogger(aws_logging.LoggerFunc(func(classification aws_logging.Classification, format string, v ...interface{}) {
82-
if classification == aws_logging.Debug {
82+
switch classification {
83+
case aws_logging.Debug:
8384
if logger.Enabled(context.Background(), slog.LevelDebug) {
8485
logger.Debug(fmt.Sprintf(format, v...))
8586
}
86-
} else if classification == aws_logging.Warn {
87+
case aws_logging.Warn:
8788
logger.Warn(fmt.Sprintf(format, v...))
88-
} else { // AWS logging only supports debug or warn, log everything else as error
89+
default: // AWS logging only supports debug or warn, log everything else as error
8990
logger.Error(fmt.Sprintf(format, v...), "err", "unexected aws error classification", "classification", classification)
9091
}
9192
})))

Diff for: pkg/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (c *ScrapeConf) Load(file string, logger *slog.Logger) (model.JobsConfig, e
154154

155155
func (c *ScrapeConf) Validate(logger *slog.Logger) (model.JobsConfig, error) {
156156
if c.Discovery.Jobs == nil && c.Static == nil && c.CustomNamespace == nil {
157-
return model.JobsConfig{}, fmt.Errorf("At least 1 Discovery job, 1 Static or one CustomNamespace must be defined")
157+
return model.JobsConfig{}, fmt.Errorf("at least 1 Discovery job, 1 Static or one CustomNamespace must be defined")
158158
}
159159

160160
if c.Discovery.Jobs != nil {

Diff for: pkg/job/maxdimassociator/associator.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,8 @@ func (assoc Associator) AssociateMetricToResource(cwMetric *model.Metric) (*mode
185185
mappingFound = true
186186
dimFixApplied := false
187187
shouldTryFixDimension := true
188-
for {
189-
if !dimFixApplied && !shouldTryFixDimension {
190-
// If no dimension fixes were applied, no need to try running again without the fixer
191-
break
192-
}
188+
// If no dimension fixes were applied, no need to try running again without the fixer.
189+
for dimFixApplied || shouldTryFixDimension {
193190

194191
var labels map[string]string
195192
labels, dimFixApplied = buildLabelsMap(cwMetric, regexpMapping, shouldTryFixDimension)

Diff for: pkg/job/scraper_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ func TestScrapeRunner_Run(t *testing.T) {
556556

557557
// We don't want to check the exact error just the message
558558
changelog, err = diff.Diff(tc.expectedErrs, errs, diff.Filter(func(_ []string, _ reflect.Type, field reflect.StructField) bool {
559-
return !(field.Name == "Err")
559+
return field.Name != "Err"
560560
}))
561561
assert.NoError(t, err, "failed to diff errs")
562562
assert.Len(t, changelog, 0, changelog)

0 commit comments

Comments
 (0)