Skip to content

Commit a1e24f1

Browse files
Merge pull request #1511 from prometheus/superq/go_1.25
Update Go
2 parents b696347 + 1aa4ce0 commit a1e24f1

File tree

13 files changed

+33
-43
lines changed

13 files changed

+33
-43
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ executors:
99
# should also be updated.
1010
golang:
1111
docker:
12-
- image: cimg/go:1.24
12+
- image: cimg/go:1.25
1313
parameters:
1414
working_dir:
1515
type: string

.promu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
go:
22
# Whenever the Go version is updated here,
33
# .circle/config.yml should also be updated.
4-
version: 1.24
4+
version: 1.25
55
repository:
66
path: github.com/prometheus/snmp_exporter
77
build:

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ ARG ARCH="amd64"
77
ARG OS="linux"
88
COPY .build/${OS}-${ARCH}/snmp_exporter /bin/snmp_exporter
99
COPY snmp.yml /etc/snmp_exporter/snmp.yml
10+
COPY LICENSE /LICENSE
11+
COPY NOTICE /NOTICE
12+
1013

1114
EXPOSE 9116
1215
ENTRYPOINT [ "/bin/snmp_exporter" ]

collector/collector.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var combinedTypeMapping = map[string]map[int]string{
6363

6464
func oidToList(oid string) []int {
6565
result := []int{}
66-
for _, x := range strings.Split(oid, ".") {
66+
for x := range strings.SplitSeq(oid, ".") {
6767
o, _ := strconv.Atoi(x)
6868
result = append(result, o)
6969
}
@@ -118,10 +118,7 @@ func ScrapeTarget(snmp scraper.SNMPScraper, target string, auth *config.Auth, mo
118118
maxOids = 1
119119
}
120120
for len(getOids) > 0 {
121-
oids := len(getOids)
122-
if oids > maxOids {
123-
oids = maxOids
124-
}
121+
oids := min(len(getOids), maxOids)
125122

126123
packet, err := snmp.Get(getOids[:oids])
127124
if err != nil {
@@ -355,7 +352,7 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger *slog.Logger, cli
355352
g.MaxRepetitions = module.WalkParams.MaxRepetitions
356353
g.UseUnconnectedUDPSocket = module.WalkParams.UseUnconnectedUDPSocket
357354
if module.WalkParams.AllowNonIncreasingOIDs {
358-
g.AppOpts = map[string]interface{}{
355+
g.AppOpts = map[string]any{
359356
"c": true,
360357
}
361358
}
@@ -423,10 +420,7 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger *slog.Logger, cli
423420
// Collect implements Prometheus.Collector.
424421
func (c Collector) Collect(ch chan<- prometheus.Metric) {
425422
wg := sync.WaitGroup{}
426-
workerCount := c.concurrency
427-
if workerCount < 1 {
428-
workerCount = 1
429-
}
423+
workerCount := max(c.concurrency, 1)
430424
ctx, cancel := context.WithCancel(c.ctx)
431425
defer cancel()
432426
workerChan := make(chan *NamedModule)
@@ -764,7 +758,7 @@ func enumAsStateSet(metric *config.Metric, value int, labelnames, labelvalues []
764758
return results
765759
}
766760

767-
func bits(metric *config.Metric, value interface{}, labelnames, labelvalues []string) []prometheus.Metric {
761+
func bits(metric *config.Metric, value any, labelnames, labelvalues []string) []prometheus.Metric {
768762
bytes, ok := value.([]byte)
769763
if !ok {
770764
return []prometheus.Metric{prometheus.NewInvalidMetric(prometheus.NewDesc("snmp_error", "BITS type was not a BISTRING on the wire.", nil, nil),
@@ -936,7 +930,7 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool,
936930
return strings.Join(parts, "."), subOid, indexOids
937931
case "InetAddressIPv6":
938932
subOid, indexOids := splitOid(indexOids, 16)
939-
parts := make([]interface{}, 16)
933+
parts := make([]any, 16)
940934
for i, o := range subOid {
941935
parts[i] = o
942936
}

config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/gosnmp/gosnmp"
26-
"gopkg.in/yaml.v2"
26+
"go.yaml.in/yaml/v2"
2727
)
2828

2929
type Auth struct {
@@ -138,7 +138,7 @@ type Module struct {
138138
Filters []DynamicFilter `yaml:"filters,omitempty"`
139139
}
140140

141-
func (c *Module) UnmarshalYAML(unmarshal func(interface{}) error) error {
141+
func (c *Module) UnmarshalYAML(unmarshal func(any) error) error {
142142
*c = DefaultModule
143143
type plain Module
144144
return unmarshal((*plain)(c))
@@ -273,7 +273,7 @@ var (
273273
)
274274

275275
// MarshalYAML implements the yaml.Marshaler interface.
276-
func (s Secret) MarshalYAML() (interface{}, error) {
276+
func (s Secret) MarshalYAML() (any, error) {
277277
if DoNotHideSecrets {
278278
return string(s), nil
279279
}
@@ -283,7 +283,7 @@ func (s Secret) MarshalYAML() (interface{}, error) {
283283
return nil, nil
284284
}
285285

286-
func (c *Auth) UnmarshalYAML(unmarshal func(interface{}) error) error {
286+
func (c *Auth) UnmarshalYAML(unmarshal func(any) error) error {
287287
*c = DefaultAuth
288288
type plain Auth
289289
if err := unmarshal((*plain)(c)); err != nil {
@@ -327,7 +327,7 @@ type RegexpExtract struct {
327327
Regex Regexp `yaml:"regex"`
328328
}
329329

330-
func (c *RegexpExtract) UnmarshalYAML(unmarshal func(interface{}) error) error {
330+
func (c *RegexpExtract) UnmarshalYAML(unmarshal func(any) error) error {
331331
*c = DefaultRegexpExtract
332332
type plain RegexpExtract
333333
return unmarshal((*plain)(c))
@@ -339,15 +339,15 @@ type Regexp struct {
339339
}
340340

341341
// MarshalYAML implements the yaml.Marshaler interface.
342-
func (re Regexp) MarshalYAML() (interface{}, error) {
342+
func (re Regexp) MarshalYAML() (any, error) {
343343
if re.Regexp != nil {
344344
return re.String(), nil
345345
}
346346
return nil, nil
347347
}
348348

349349
// UnmarshalYAML implements the yaml.Unmarshaler interface.
350-
func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error {
350+
func (re *Regexp) UnmarshalYAML(unmarshal func(any) error) error {
351351
var s string
352352
if err := unmarshal(&s); err != nil {
353353
return err

config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/prometheus/common/promslog"
21-
yaml "gopkg.in/yaml.v2"
21+
"go.yaml.in/yaml/v2"
2222
)
2323

2424
var nopLogger = promslog.NewNopLogger()

generator/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type MetricOverrides struct {
3939
}
4040

4141
// UnmarshalYAML implements the yaml.Unmarshaler interface.
42-
func (c *MetricOverrides) UnmarshalYAML(unmarshal func(interface{}) error) error {
42+
func (c *MetricOverrides) UnmarshalYAML(unmarshal func(any) error) error {
4343
type plain MetricOverrides
4444
if err := unmarshal((*plain)(c)); err != nil {
4545
return err
@@ -62,7 +62,7 @@ type ModuleConfig struct {
6262
}
6363

6464
// UnmarshalYAML implements the yaml.Unmarshaler interface.
65-
func (c *ModuleConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
65+
func (c *ModuleConfig) UnmarshalYAML(unmarshal func(any) error) error {
6666
type plain ModuleConfig
6767
if err := unmarshal((*plain)(c)); err != nil {
6868
return err

generator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/alecthomas/kingpin/v2"
2525
"github.com/prometheus/common/promslog"
2626
"github.com/prometheus/common/promslog/flag"
27-
"gopkg.in/yaml.v2"
27+
"go.yaml.in/yaml/v2"
2828

2929
"github.com/prometheus/snmp_exporter/config"
3030
)

generator/tree.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"fmt"
1818
"log/slog"
1919
"regexp"
20+
"slices"
2021
"sort"
2122
"strconv"
2223
"strings"
@@ -466,12 +467,9 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
466467

467468
// If lookup label is used as source index in another lookup,
468469
// we need to add this new label as another index.
469-
for _, sourceIndex := range requiredAsIndex {
470-
if sourceIndex == l.Labelname {
471-
idx := &config.Index{Labelname: l.Labelname, Type: l.Type}
472-
metric.Indexes = append(metric.Indexes, idx)
473-
break
474-
}
470+
if slices.Contains(requiredAsIndex, l.Labelname) {
471+
idx := &config.Index{Labelname: l.Labelname, Type: l.Type}
472+
metric.Indexes = append(metric.Indexes, idx)
475473
}
476474

477475
// Make sure we walk the lookup OID(s).

generator/tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"testing"
2020

2121
"github.com/prometheus/common/promslog"
22-
yaml "gopkg.in/yaml.v2"
22+
"go.yaml.in/yaml/v2"
2323

2424
"github.com/prometheus/snmp_exporter/config"
2525
)

0 commit comments

Comments
 (0)