Update Go

* Update Go build to 1.24.
* Update minimum Go to 1.23.0.
* Update golangci-lint to v2.
* Fixup linter issues.

Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
SuperQ 2025-04-15 13:34:19 +02:00
parent e1cef5e7a7
commit dbf1dba353
No known key found for this signature in database
GPG key ID: C646B23C9E3245F1
9 changed files with 43 additions and 33 deletions

View file

@ -5,7 +5,7 @@ executors:
# Whenever the Go version is updated here, .promu.yml should also be updated.
golang:
docker:
- image: cimg/go:1.23
- image: cimg/go:1.24
jobs:
test:
executor: golang

View file

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

View file

@ -1,26 +1,36 @@
version: "2"
run:
issues-exit-code: 1
tests: true
linters:
enable:
- nakedret
- whitespace
disable:
- errcheck
enable:
- goimports
- gosimple
- govet
- ineffassign
- nakedret
- staticcheck
- unused
- whitespace
linters-settings:
govet:
enable-all: true
disable:
- fieldalignment
settings:
govet:
disable:
- fieldalignment
enable-all: true
exclusions:
generated: lax
rules:
- path: (.+)\.go$
text: 'shadow: declaration of "err" shadows declaration at line (\d+)'
paths:
- third_party$
- builtin$
- examples$
issues:
exclude-use-default: false
exclude:
- 'shadow: declaration of "err" shadows declaration at line (\d+)'
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

View file

@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml should also
# be updated.
version: 1.23
version: 1.24
repository:
path: github.com/prometheus/statsd_exporter
build:

View file

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

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/prometheus/statsd_exporter
go 1.22
go 1.23.0
require (
github.com/alecthomas/kingpin/v2 v2.4.0

View file

@ -31,18 +31,18 @@ func (f *FSM) DumpFSM(w io.Writer) {
for idx < len(states) {
for field, transition := range states[idx].transitions {
states[len(states)] = transition
w.Write([]byte(fmt.Sprintf("%d -> %d [label = \"%s\"];\n", idx, len(states)-1, field)))
fmt.Fprintf(w, "%d -> %d [label = \"%s\"];\n", idx, len(states)-1, field)
if idx == 0 {
// color for metric types
w.Write([]byte(fmt.Sprintf("%d [color=\"#D6B656\",fillcolor=\"#FFF2CC\"];\n", len(states)-1)))
fmt.Fprintf(w, "%d [color=\"#D6B656\",fillcolor=\"#FFF2CC\"];\n", len(states)-1)
} else if len(transition.transitions) == 0 {
// color for end state
w.Write([]byte(fmt.Sprintf("%d [color=\"#82B366\",fillcolor=\"#D5E8D4\"];\n", len(states)-1)))
fmt.Fprintf(w, "%d [color=\"#82B366\",fillcolor=\"#D5E8D4\"];\n", len(states)-1)
}
}
idx++
}
// color for start state
w.Write([]byte(fmt.Sprintln("0 [color=\"#a94442\",fillcolor=\"#f2dede\"];")))
fmt.Fprintln(w, "0 [color=\"#a94442\",fillcolor=\"#f2dede\"];")
w.Write([]byte("}"))
}

View file

@ -46,9 +46,9 @@ func NewTemplateFormatter(template string, captureCount int) *TemplateFormatter
if err != nil || idx > captureCount || idx < 1 {
// if index larger than captured count or using unsupported named capture group,
// replace with empty string
valueFormatter = strings.Replace(valueFormatter, match[0], "", -1)
valueFormatter = strings.ReplaceAll(valueFormatter, match[0], "")
} else {
valueFormatter = strings.Replace(valueFormatter, match[0], "%s", -1)
valueFormatter = strings.ReplaceAll(valueFormatter, match[0], "%s")
// note: the regex reference variable $? starts from 1
indexes = append(indexes, idx-1)
}

View file

@ -243,8 +243,8 @@ func TestIfNeedBacktracking(mappings []string, orderingDisabled bool, logger *sl
l := len(strings.Split(mapping, "."))
ruleByLength[l] = append(ruleByLength[l], mapping)
metricRe := strings.Replace(mapping, ".", "\\.", -1)
metricRe = strings.Replace(metricRe, "*", "([^.]*)", -1)
metricRe := strings.ReplaceAll(mapping, ".", "\\.")
metricRe = strings.ReplaceAll(metricRe, "*", "([^.]*)")
regex, err := regexp.Compile("^" + metricRe + "$")
if err != nil {
logger.Warn("Invalid match, cannot compile regex in mapping", "mapping", mapping, "err", err)
@ -272,8 +272,8 @@ func TestIfNeedBacktracking(mappings []string, orderingDisabled bool, logger *sl
}
// translate the substring of r1 from 0 to the index of current * into regex
// A.B.C.*.E.* will becomes ^A\.B\.C\. and ^A\.B\.C\.\*\.E\.
reStr := strings.Replace(r1[:index], ".", "\\.", -1)
reStr = strings.Replace(reStr, "*", "\\*", -1)
reStr := strings.ReplaceAll(r1[:index], ".", "\\.")
reStr = strings.ReplaceAll(reStr, "*", "\\*")
re := regexp.MustCompile("^" + reStr)
for i2, r2 := range rules {
if i2 == i1 {