Skip to content

Commit beb521e

Browse files
committed
Update Go
* Update Go to 1.24. * Update golangci-lint to v2. * Fixup linting issues. Signed-off-by: SuperQ <superq@gmail.com>
1 parent 9e86f1e commit beb521e

File tree

9 files changed

+56
-43
lines changed

9 files changed

+56
-43
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ executors:
88
# This must match .promu.yml.
99
golang:
1010
docker:
11-
- image: cimg/go:1.23
11+
- image: cimg/go:1.24
1212

1313
jobs:
1414
test:
@@ -23,7 +23,7 @@ jobs:
2323

2424
integration:
2525
docker:
26-
- image: cimg/go:1.23
26+
- image: cimg/go:1.24
2727
- image: << parameters.postgres_image >>
2828
environment:
2929
POSTGRES_DB: circle_test

.github/workflows/golangci-lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
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

.golangci.yml

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1-
---
1+
version: "2"
22
linters:
33
enable:
4-
- misspell
5-
- revive
6-
7-
issues:
8-
exclude-rules:
9-
- path: _test.go
10-
linters:
11-
- errcheck
12-
13-
linters-settings:
14-
errcheck:
15-
exclude-functions:
16-
# Never check for logger errors.
17-
- (github.com/go-kit/log.Logger).Log
18-
revive:
4+
- misspell
5+
- revive
6+
settings:
7+
errcheck:
8+
exclude-functions:
9+
- (github.com/go-kit/log.Logger).Log
10+
revive:
11+
rules:
12+
- name: unused-parameter
13+
severity: warning
14+
disabled: true
15+
exclusions:
16+
generated: lax
17+
presets:
18+
- comments
19+
- common-false-positives
20+
- legacy
21+
- std-error-handling
1922
rules:
20-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
21-
- name: unused-parameter
22-
severity: warning
23-
disabled: true
23+
- linters:
24+
- errcheck
25+
path: _test.go
26+
paths:
27+
- third_party$
28+
- builtin$
29+
- examples$
30+
formatters:
31+
exclusions:
32+
generated: lax
33+
paths:
34+
- third_party$
35+
- builtin$
36+
- examples$

.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/postgres_exporter
66
build:

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))

cmd/postgres_exporter/pg_setting.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type pgSetting struct {
6767
func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
6868
var (
6969
err error
70-
name = strings.Replace(strings.Replace(s.name, ".", "_", -1), "-", "_", -1)
70+
name = strings.ReplaceAll(strings.ReplaceAll(s.name, ".", "_"), "-", "_")
7171
unit = s.unit // nolint: ineffassign
7272
shortDesc = fmt.Sprintf("Server Parameter: %s", s.name)
7373
subsystem = "settings"
@@ -131,7 +131,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
131131
case "B", "kB", "MB", "GB", "TB", "1kB", "2kB", "4kB", "8kB", "16kB", "32kB", "64kB", "16MB", "32MB", "64MB":
132132
unit = "bytes"
133133
default:
134-
err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit)
134+
err = fmt.Errorf("unknown unit for runtime variable: %q", s.unit)
135135
return
136136
}
137137

collector/collector_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ func readMetric(m prometheus.Metric) MetricResult {
4848

4949
func sanitizeQuery(q string) string {
5050
q = strings.Join(strings.Fields(q), " ")
51-
q = strings.Replace(q, "(", "\\(", -1)
52-
q = strings.Replace(q, "?", "\\?", -1)
53-
q = strings.Replace(q, ")", "\\)", -1)
54-
q = strings.Replace(q, "[", "\\[", -1)
55-
q = strings.Replace(q, "]", "\\]", -1)
56-
q = strings.Replace(q, "{", "\\{", -1)
57-
q = strings.Replace(q, "}", "\\}", -1)
58-
q = strings.Replace(q, "*", "\\*", -1)
59-
q = strings.Replace(q, "^", "\\^", -1)
60-
q = strings.Replace(q, "$", "\\$", -1)
51+
q = strings.ReplaceAll(q, "(", "\\(")
52+
q = strings.ReplaceAll(q, "?", "\\?")
53+
q = strings.ReplaceAll(q, ")", "\\)")
54+
q = strings.ReplaceAll(q, "[", "\\[")
55+
q = strings.ReplaceAll(q, "]", "\\]")
56+
q = strings.ReplaceAll(q, "{", "\\{")
57+
q = strings.ReplaceAll(q, "}", "\\}")
58+
q = strings.ReplaceAll(q, "*", "\\*")
59+
q = strings.ReplaceAll(q, "^", "\\^")
60+
q = strings.ReplaceAll(q, "$", "\\$")
6161
return q
6262
}

config/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ func (ch *Handler) ReloadConfig(f string, logger *slog.Logger) error {
7979

8080
yamlReader, err := os.Open(f)
8181
if err != nil {
82-
return fmt.Errorf("Error opening config file %q: %s", f, err)
82+
return fmt.Errorf("error opening config file %q: %s", f, err)
8383
}
8484
defer yamlReader.Close()
8585
decoder := yaml.NewDecoder(yamlReader)
8686
decoder.KnownFields(true)
8787

8888
if err = decoder.Decode(config); err != nil {
89-
return fmt.Errorf("Error parsing config file %q: %s", f, err)
89+
return fmt.Errorf("error parsing config file %q: %s", f, err)
9090
}
9191

9292
ch.Lock()

config/config_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestLoadConfig(t *testing.T) {
2424

2525
err := ch.ReloadConfig("testdata/config-good.yaml", nil)
2626
if err != nil {
27-
t.Errorf("Error loading config: %s", err)
27+
t.Errorf("error loading config: %s", err)
2828
}
2929
}
3030

@@ -39,11 +39,11 @@ func TestLoadBadConfigs(t *testing.T) {
3939
}{
4040
{
4141
input: "testdata/config-bad-auth-module.yaml",
42-
want: "Error parsing config file \"testdata/config-bad-auth-module.yaml\": yaml: unmarshal errors:\n line 3: field pretendauth not found in type config.AuthModule",
42+
want: "error parsing config file \"testdata/config-bad-auth-module.yaml\": yaml: unmarshal errors:\n line 3: field pretendauth not found in type config.AuthModule",
4343
},
4444
{
4545
input: "testdata/config-bad-extra-field.yaml",
46-
want: "Error parsing config file \"testdata/config-bad-extra-field.yaml\": yaml: unmarshal errors:\n line 8: field doesNotExist not found in type config.AuthModule",
46+
want: "error parsing config file \"testdata/config-bad-extra-field.yaml\": yaml: unmarshal errors:\n line 8: field doesNotExist not found in type config.AuthModule",
4747
},
4848
}
4949

0 commit comments

Comments
 (0)