Skip to content

Update Go #1147

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

Merged
merged 1 commit into from
Apr 3, 2025
Merged
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ executors:
# This must match .promu.yml.
golang:
docker:
- image: cimg/go:1.23
- image: cimg/go:1.24

jobs:
test:
Expand All @@ -23,7 +23,7 @@ jobs:

integration:
docker:
- image: cimg/go:1.23
- image: cimg/go:1.24
- image: << parameters.postgres_image >>
environment:
POSTGRES_DB: circle_test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
with:
args: --verbose
version: v1.64.6
version: v2.0.2
53 changes: 33 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
---
version: "2"
linters:
enable:
- misspell
- revive

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
exclude-functions:
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
revive:
- misspell
- revive
settings:
errcheck:
exclude-functions:
- (github.com/go-kit/log.Logger).Log
revive:
rules:
- name: unused-parameter
severity: warning
disabled: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true
- linters:
- errcheck
path: _test.go
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
go:
# This must match .circle/config.yml.
version: 1.23
version: 1.24
repository:
path: github.com/prometheus-community/postgres_exporter
build:
Expand Down
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.64.6
GOLANGCI_LINT_VERSION ?= v2.0.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
Expand Down
4 changes: 2 additions & 2 deletions cmd/postgres_exporter/pg_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type pgSetting struct {
func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
var (
err error
name = strings.Replace(strings.Replace(s.name, ".", "_", -1), "-", "_", -1)
name = strings.ReplaceAll(strings.ReplaceAll(s.name, ".", "_"), "-", "_")
unit = s.unit // nolint: ineffassign
shortDesc = fmt.Sprintf("Server Parameter: %s", s.name)
subsystem = "settings"
Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
case "B", "kB", "MB", "GB", "TB", "1kB", "2kB", "4kB", "8kB", "16kB", "32kB", "64kB", "16MB", "32MB", "64MB":
unit = "bytes"
default:
err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit)
err = fmt.Errorf("unknown unit for runtime variable: %q", s.unit)
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/postgres_exporter/pg_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var fixtures = []fixture{
n: normalised{
val: 10,
unit: "",
err: `Unknown unit for runtime variable: "nonexistent"`,
err: `unknown unit for runtime variable: "nonexistent"`,
},
},
}
Expand All @@ -240,7 +240,7 @@ func (s *PgSettingSuite) TestNormaliseUnit(c *C) {
func (s *PgSettingSuite) TestMetric(c *C) {
defer func() {
if r := recover(); r != nil {
if r.(error).Error() != `Unknown unit for runtime variable: "nonexistent"` {
if r.(error).Error() != `unknown unit for runtime variable: "nonexistent"` {
panic(r)
}
}
Expand Down
20 changes: 10 additions & 10 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func readMetric(m prometheus.Metric) MetricResult {

func sanitizeQuery(q string) string {
q = strings.Join(strings.Fields(q), " ")
q = strings.Replace(q, "(", "\\(", -1)
q = strings.Replace(q, "?", "\\?", -1)
q = strings.Replace(q, ")", "\\)", -1)
q = strings.Replace(q, "[", "\\[", -1)
q = strings.Replace(q, "]", "\\]", -1)
q = strings.Replace(q, "{", "\\{", -1)
q = strings.Replace(q, "}", "\\}", -1)
q = strings.Replace(q, "*", "\\*", -1)
q = strings.Replace(q, "^", "\\^", -1)
q = strings.Replace(q, "$", "\\$", -1)
q = strings.ReplaceAll(q, "(", "\\(")
q = strings.ReplaceAll(q, "?", "\\?")
q = strings.ReplaceAll(q, ")", "\\)")
q = strings.ReplaceAll(q, "[", "\\[")
q = strings.ReplaceAll(q, "]", "\\]")
q = strings.ReplaceAll(q, "{", "\\{")
q = strings.ReplaceAll(q, "}", "\\}")
q = strings.ReplaceAll(q, "*", "\\*")
q = strings.ReplaceAll(q, "^", "\\^")
q = strings.ReplaceAll(q, "$", "\\$")
return q
}
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ func (ch *Handler) ReloadConfig(f string, logger *slog.Logger) error {

yamlReader, err := os.Open(f)
if err != nil {
return fmt.Errorf("Error opening config file %q: %s", f, err)
return fmt.Errorf("error opening config file %q: %s", f, err)
}
defer yamlReader.Close()
decoder := yaml.NewDecoder(yamlReader)
decoder.KnownFields(true)

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

ch.Lock()
Expand Down
6 changes: 3 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestLoadConfig(t *testing.T) {

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

Expand All @@ -39,11 +39,11 @@ func TestLoadBadConfigs(t *testing.T) {
}{
{
input: "testdata/config-bad-auth-module.yaml",
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",
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",
},
{
input: "testdata/config-bad-extra-field.yaml",
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",
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",
},
}

Expand Down