Skip to content
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 .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
142 changes: 73 additions & 69 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,90 @@
---
run:
timeout: 5m

output:
sort-results: true
version: "2"
issues:
max-same-issues: 0

linters:
enable:
- copyloopvar
- depguard
- durationcheck
- errorlint
# The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
# - exportloopref
- gofmt
- gofumpt
- goimports
- gosimple
- ineffassign
- misspell
- nolintlint
- perfsprint
- predeclared
- revive
- staticcheck
- unconvert
- unused
- usestdlibvars
- wastedassign
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- errcheck
- govet
- structcheck
- nolintlint
path: _test.go
paths:
- ^.*\.(pb|y)\.go$
- third_party$
- builtin$
- examples$
settings:
depguard:
rules:
main:
deny:
- pkg: github.com/stretchr/testify/assert
desc: Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert
- pkg: github.com/go-kit/kit/log
desc: Use github.com/go-kit/log instead of github.com/go-kit/kit/log
- pkg: io/ioutil
desc: Use corresponding 'os' or 'io' functions instead.
errcheck:
exclude-functions:
# The following 2 methods always return nil as the error
- (*github.com/cespare/xxhash/v2.Digest).Write
- (*github.com/cespare/xxhash/v2.Digest).WriteString
- (*bufio.Writer).WriteRune
perfsprint:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: true
# Optimizes `fmt.Errorf`.
errorf: true
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: true
# Optimizes into strings concatenation.
strconcat: true
revive:
rules:

issues:
max-same-issues: 0
exclude-rules:
- path: _test.go
linters:
- errcheck
- govet
- structcheck
# The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.
exclude-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
- name: unused-parameter
severity: warning
disabled: true

linters-settings:
depguard:
rules:
main:
deny:
#- pkg: "sync/atomic"
# desc: "Use go.uber.org/atomic instead of sync/atomic"
- pkg: "github.com/stretchr/testify/assert"
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
- pkg: "github.com/go-kit/kit/log"
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
- pkg: "io/ioutil"
desc: "Use corresponding 'os' or 'io' functions instead."
#- pkg: "regexp"
# desc: "Use github.com/grafana/regexp instead of regexp"
errcheck:
exclude-functions:
# The following 2 methods always return nil as the error
- (*github.com/cespare/xxhash/v2.Digest).Write
- (*github.com/cespare/xxhash/v2.Digest).WriteString
- (*bufio.Writer).WriteRune
goimports:
local-prefixes: github.com/prometheus/client_golang
gofumpt:
extra-rules: true
perfsprint:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: true
# Optimizes `fmt.Errorf`.
errorf: true
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: true
# Optimizes into strings concatenation.
strconcat: true
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true
formatters:
enable:
- gofmt
- gofumpt
- goimports
settings:
gofumpt:
extra-rules: true
goimports:
local-prefixes:
- github.com/prometheus/client_golang
exclusions:
generated: lax
paths:
- ^.*\.(pb|y)\.go$
- third_party$
- builtin$
- examples$
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
3 changes: 2 additions & 1 deletion prometheus/graphite/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ func replaceInvalidRune(c rune) rune {
if c == ' ' {
return '.'
}
if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == ':' || c == '-' || (c >= '0' && c <= '9')) {
// TODO: Apply De Morgan's law to the condition. Make sure to test the condition first.
if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == ':' || c == '-' || (c >= '0' && c <= '9')) { //nolint:staticcheck
return '_'
}
return c
Expand Down
4 changes: 2 additions & 2 deletions prometheus/internal/difflib.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
}
group = append(group, OpCode{c.Tag, i1, i2, j1, j2})
}
if len(group) > 0 && !(len(group) == 1 && group[0].Tag == 'e') {
if len(group) > 0 && (len(group) != 1 || group[0].Tag != 'e') {
groups = append(groups, group)
}
return groups
Expand Down Expand Up @@ -568,7 +568,7 @@ func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
buf := bufio.NewWriter(writer)
defer buf.Flush()
wf := func(format string, args ...interface{}) error {
_, err := buf.WriteString(fmt.Sprintf(format, args...))
_, err := fmt.Fprintf(buf, format, args...)
return err
}
ws := func(s string) error {
Expand Down
6 changes: 3 additions & 3 deletions prometheus/process_collector_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"golang.org/x/sys/unix"
)

// notImplementedErr is returned by stub functions that replace cgo functions, when cgo
// errNotImplemented is returned by stub functions that replace cgo functions, when cgo
// isn't available.
var notImplementedErr = errors.New("not implemented")
var errNotImplemented = errors.New("not implemented")

type memoryInfo struct {
vsize uint64 // Virtual memory size in bytes
Expand Down Expand Up @@ -101,7 +101,7 @@ func (c *processCollector) processCollect(ch chan<- Metric) {
if memInfo, err := getMemory(); err == nil {
ch <- MustNewConstMetric(c.rss, GaugeValue, float64(memInfo.rss))
ch <- MustNewConstMetric(c.vsize, GaugeValue, float64(memInfo.vsize))
} else if !errors.Is(err, notImplementedErr) {
} else if !errors.Is(err, errNotImplemented) {
// Don't report an error when support is not compiled in.
c.reportError(ch, c.rss, err)
c.reportError(ch, c.vsize, err)
Expand Down
8 changes: 4 additions & 4 deletions prometheus/process_collector_procfsenabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func (c *processCollector) processCollect(ch chan<- Metric) {

if netstat, err := p.Netstat(); err == nil {
var inOctets, outOctets float64
if netstat.IpExt.InOctets != nil {
inOctets = *netstat.IpExt.InOctets
if netstat.InOctets != nil {
inOctets = *netstat.InOctets
}
if netstat.IpExt.OutOctets != nil {
outOctets = *netstat.IpExt.OutOctets
if netstat.OutOctets != nil {
outOctets = *netstat.OutOctets
}
ch <- MustNewConstMetric(c.inBytes, CounterValue, inOctets)
ch <- MustNewConstMetric(c.outBytes, CounterValue, outOctets)
Expand Down
2 changes: 1 addition & 1 deletion prometheus/promhttp/instrument_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func isLabelCurried(c prometheus.Collector, label string) bool {
func labels(code, method bool, reqMethod string, status int, extraMethods ...string) prometheus.Labels {
labels := prometheus.Labels{}

if !(code || method) {
if !code && !method {
return labels
}

Expand Down
10 changes: 5 additions & 5 deletions prometheus/vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (m *MetricVec) DeleteLabelValues(lvs ...string) bool {
return false
}

return m.metricMap.deleteByHashWithLabelValues(h, lvs, m.curry)
return m.deleteByHashWithLabelValues(h, lvs, m.curry)
}

// Delete deletes the metric where the variable labels are the same as those
Expand All @@ -101,7 +101,7 @@ func (m *MetricVec) Delete(labels Labels) bool {
return false
}

return m.metricMap.deleteByHashWithLabels(h, labels, m.curry)
return m.deleteByHashWithLabels(h, labels, m.curry)
}

// DeletePartialMatch deletes all metrics where the variable labels contain all of those
Expand All @@ -114,7 +114,7 @@ func (m *MetricVec) DeletePartialMatch(labels Labels) int {
labels, closer := constrainLabels(m.desc, labels)
defer closer()

return m.metricMap.deleteByLabels(labels, m.curry)
return m.deleteByLabels(labels, m.curry)
}

// Without explicit forwarding of Describe, Collect, Reset, those methods won't
Expand Down Expand Up @@ -216,7 +216,7 @@ func (m *MetricVec) GetMetricWithLabelValues(lvs ...string) (Metric, error) {
return nil, err
}

return m.metricMap.getOrCreateMetricWithLabelValues(h, lvs, m.curry), nil
return m.getOrCreateMetricWithLabelValues(h, lvs, m.curry), nil
}

// GetMetricWith returns the Metric for the given Labels map (the label names
Expand Down Expand Up @@ -244,7 +244,7 @@ func (m *MetricVec) GetMetricWith(labels Labels) (Metric, error) {
return nil, err
}

return m.metricMap.getOrCreateMetricWithLabels(h, labels, m.curry), nil
return m.getOrCreateMetricWithLabels(h, labels, m.curry), nil
}

func (m *MetricVec) hashLabelValues(vals []string) (uint64, error) {
Expand Down
18 changes: 9 additions & 9 deletions prometheus/vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestDeletePartialMatchWithConstraints(t *testing.T) {

func testDeletePartialMatch(t *testing.T, baseVec *GaugeVec) {
assertNoMetric := func(t *testing.T) {
if n := len(baseVec.metricMap.metrics); n != 0 {
if n := len(baseVec.metrics); n != 0 {
t.Error("expected no metrics, got", n)
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func testMetricVec(t *testing.T, vec *GaugeVec) {
}

var total int
for _, metrics := range vec.metricMap.metrics {
for _, metrics := range vec.metrics {
for _, metric := range metrics {
total++
copy(pair[:], metric.values)
Expand Down Expand Up @@ -336,7 +336,7 @@ func testMetricVec(t *testing.T, vec *GaugeVec) {

vec.Reset()

if len(vec.metricMap.metrics) > 0 {
if len(vec.metrics) > 0 {
t.Fatalf("reset failed")
}
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func testConstrainedMetricVec(t *testing.T, vec *GaugeVec, constrain func(string
}

var total int
for _, metrics := range vec.metricMap.metrics {
for _, metrics := range vec.metrics {
for _, metric := range metrics {
total++
copy(pair[:], metric.values)
Expand Down Expand Up @@ -408,7 +408,7 @@ func testConstrainedMetricVec(t *testing.T, vec *GaugeVec, constrain func(string

vec.Reset()

if len(vec.metricMap.metrics) > 0 {
if len(vec.metrics) > 0 {
t.Fatalf("reset failed")
}
}
Expand Down Expand Up @@ -506,7 +506,7 @@ func TestCurryVecWithConstraints(t *testing.T) {
func testCurryVec(t *testing.T, vec *CounterVec) {
assertMetrics := func(t *testing.T) {
n := 0
for _, m := range vec.metricMap.metrics {
for _, m := range vec.metrics {
n += len(m)
}
if n != 2 {
Expand All @@ -533,7 +533,7 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
}

assertNoMetric := func(t *testing.T) {
if n := len(vec.metricMap.metrics); n != 0 {
if n := len(vec.metrics); n != 0 {
t.Error("expected no metrics, got", n)
}
}
Expand Down Expand Up @@ -703,7 +703,7 @@ func testCurryVec(t *testing.T, vec *CounterVec) {
func testConstrainedCurryVec(t *testing.T, vec *CounterVec, constraint func(string) string) {
assertMetrics := func(t *testing.T) {
n := 0
for _, m := range vec.metricMap.metrics {
for _, m := range vec.metrics {
n += len(m)
}
if n != 2 {
Expand Down Expand Up @@ -744,7 +744,7 @@ func testConstrainedCurryVec(t *testing.T, vec *CounterVec, constraint func(stri
}

assertNoMetric := func(t *testing.T) {
if n := len(vec.metricMap.metrics); n != 0 {
if n := len(vec.metrics); n != 0 {
t.Error("expected no metrics, got", n)
}
}
Expand Down
Loading