Skip to content

Update golangci-lint config for v2 #1034

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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@4696ba8babb6127d732c3c6dde519db15edab9ea # v6.5.1
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
with:
args: --verbose
version: v1.64.6
version: v2.0.2
129 changes: 117 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,124 @@
---
version: "2"

formatters:
enable:
- gci
- gofumpt
settings:
gci:
sections:
- standard
- prefix(github.com/prometheus-community/elasticsearch_exporter)
- default

linters:
enable:
- depguard
# TODO(@sysadmind): Enable and fix the issues.
# - errorlint
- exptostd
# TODO(@sysadmind): Enable and fix the issues.
# - gocritic
# - godot
- loggercheck
# TODO(@sysadmind): Enable and fix the issues.
# - misspell
- nilnesserr
- nolintlint
# TODO(@sysadmind): Enable and fix the issues.
# - perfsprint
- predeclared
- revive
- sloglint
- testifylint
- unconvert
- unused
- usestdlibvars
- whitespace
exclusions:
rules:
# Disable errcheck for test files.
- linters:
- errcheck
path: _test.go

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck
# Disable errcheck rule for some specific functions.
- linters:
- errcheck
# Taken from the default exclusions in v1.
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked

linters-settings:
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
- name: unused-parameter
severity: warning
disabled: true
settings:
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
- name: blank-imports
- name: comment-spacings
- name: context-as-argument
arguments:
# Allow functions with test or bench signatures.
- allowTypesBefore: '*testing.T,testing.TB'
- name: context-keys-type
- name: dot-imports
- name: early-return
arguments:
- "preserveScope"
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
# See https://github.com/mgechev/revive/issues/386
- name: empty-block
disabled: true
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
# TODO(@sysadmind): Enable and fix the issues.
# - name: exported
- name: increment-decrement
- name: indent-error-flow
arguments:
- "preserveScope"
- name: package-comments
# TODO(beorn7/sysadmind): Currently, we have a lot of missing package doc comments. Maybe we should have them.
disabled: true
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: superfluous-else
arguments:
- "preserveScope"
- name: time-naming
# TODO(@sysadmind): Enable and fix the issues.
# - name: unexported-return
- name: unreachable-code
- name: unused-parameter
severity: warning
disabled: true
- name: var-declaration
- name: var-naming

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"
- pkg: "github.com/pkg/errors"
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
- pkg: "gzip"
desc: "Use github.com/klauspost/compress instead of gzip"
- pkg: "zlib"
desc: "Use github.com/klauspost/compress instead of zlib"
- pkg: "golang.org/x/exp/slices"
desc: "Use 'slices' instead."
issues:
max-issues-per-linter: 0
max-same-issues: 0
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
2 changes: 1 addition & 1 deletion collector/cluster_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *ClusterSettingsCollector) Update(ctx context.Context, ch chan<- prometh
q.Set("include_defaults", "true")
u.RawQuery = q.Encode()

req, err := http.NewRequestWithContext(ctx, "GET", u.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions collector/data_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ func (ds *DataStream) Update(ctx context.Context, ch chan<- prometheus.Metric) e
float64(dataStream.StoreSizeBytes),
dataStream.DataStream,
)

}

return nil

}
1 change: 0 additions & 1 deletion collector/data_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
)

func TestDataStream(t *testing.T) {

tests := []struct {
name string
file string
Expand Down
1 change: 0 additions & 1 deletion collector/ilm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (i *ILM) Update(ctx context.Context, ch chan<- prometheus.Metric) error {
bool2Float(statusActive),
status,
)

}

return nil
Expand Down
3 changes: 0 additions & 3 deletions collector/ilm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ func TestILM(t *testing.T) {
indexF, err := os.Open(path.Join("../fixtures/ilm_indices", tt.file))
if err != nil {
t.Fatal(err)

}
defer indexF.Close()

statusF, err := os.Open(path.Join("../fixtures/ilm_status", tt.file))
if err != nil {
t.Fatal(err)

}
defer statusF.Close()

Expand All @@ -75,7 +73,6 @@ func TestILM(t *testing.T) {
})

sm.ServeHTTP(w, r)

}))
defer ts.Close()

Expand Down
5 changes: 2 additions & 3 deletions collector/indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"sort"
"strconv"

"github.com/prometheus-community/elasticsearch_exporter/pkg/clusterinfo"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/elasticsearch_exporter/pkg/clusterinfo"
)

var (
Expand Down Expand Up @@ -448,7 +449,6 @@ type Indices struct {

// NewIndices defines Indices Prometheus metrics
func NewIndices(logger *slog.Logger, client *http.Client, url *url.URL, shards bool, includeAliases bool) *Indices {

indices := &Indices{
logger: logger,
client: client,
Expand Down Expand Up @@ -661,7 +661,6 @@ func (i *Indices) Collect(ch chan<- prometheus.Metric) {

// Index stats
for indexName, indexStats := range indexStatsResp.Indices {

ch <- prometheus.MustNewConstMetric(
indicesDocsPrimary,
prometheus.GaugeValue,
Expand Down
5 changes: 1 addition & 4 deletions collector/indices_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var (
defaultIndicesMappingsLabels = []string{"index"}
)
var defaultIndicesMappingsLabels = []string{"index"}

type indicesMappingsMetric struct {
Type prometheus.ValueType
Expand Down Expand Up @@ -72,7 +70,6 @@ func NewIndicesMappings(logger *slog.Logger, client *http.Client, url *url.URL)
func countFieldsRecursive(properties IndexMappingProperties, fieldCounter float64) float64 {
// iterate over all properties
for _, property := range properties {

if property.Type != nil && *property.Type != "object" {
// property has a type set - counts as a field unless the value is object
// as the recursion below will handle counting that
Expand Down
5 changes: 2 additions & 3 deletions collector/indices_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type IndicesSettings struct {

var (
defaultIndicesTotalFieldsLabels = []string{"index"}
defaultTotalFieldsValue = 1000 //es default configuration for total fields
defaultDateCreation = 0 //es index default creation date
defaultTotalFieldsValue = 1000 // es default configuration for total fields
defaultDateCreation = 0 // es index default creation date
)

type indicesSettingsMetric struct {
Expand Down Expand Up @@ -153,7 +153,6 @@ func (cs *IndicesSettings) getAndParseURL(u *url.URL, data interface{}) error {
}

func (cs *IndicesSettings) fetchAndDecodeIndicesSettings() (IndicesSettingsResponse, error) {

u := *cs.url
u.Path = path.Join(u.Path, "/_all/_settings")
var asr IndicesSettingsResponse
Expand Down
1 change: 0 additions & 1 deletion collector/indices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,6 @@ func TestIndices(t *testing.T) {
default:
http.Error(w, "Not Found", http.StatusNotFound)
}

}))
defer ts.Close()

Expand Down
11 changes: 4 additions & 7 deletions collector/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,10 @@ func getRoles(node NodeStatsNodeResponse) map[string]bool {
return roles
}

var (
nodesRolesMetric = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "nodes", "roles"),
"Node roles",
append(defaultRoleLabels, "role"), nil,
)
var nodesRolesMetric = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "nodes", "roles"),
"Node roles",
append(defaultRoleLabels, "role"), nil,
)

var (
Expand Down Expand Up @@ -2012,6 +2010,5 @@ func (c *Nodes) Collect(ch chan<- prometheus.Metric) {
)
}
}

}
}
10 changes: 4 additions & 6 deletions collector/shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"net/url"
"path"

"github.com/prometheus-community/elasticsearch_exporter/pkg/clusterinfo"

"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/elasticsearch_exporter/pkg/clusterinfo"
)

// ShardResponse has shard's node and index info
Expand Down Expand Up @@ -66,7 +66,6 @@ type nodeShardMetric struct {

// NewShards defines Shards Prometheus metrics
func NewShards(logger *slog.Logger, client *http.Client, url *url.URL) *Shards {

nodeLabels := labels{
keys: func(...string) []string {
return []string{"node", "cluster"}
Expand Down Expand Up @@ -103,7 +102,8 @@ func NewShards(logger *slog.Logger, client *http.Client, url *url.URL) *Shards {
return shards
},
Labels: nodeLabels,
}},
},
},

jsonParseFailures: prometheus.NewCounter(prometheus.CounterOpts{
Name: prometheus.BuildFQName(namespace, "node_shards", "json_parse_failures"),
Expand Down Expand Up @@ -164,7 +164,6 @@ func (s *Shards) getAndParseURL(u *url.URL) ([]ShardResponse, error) {
}

func (s *Shards) fetchAndDecodeShards() ([]ShardResponse, error) {

u := *s.url
u.Path = path.Join(u.Path, "/_cat/shards")
q := u.Query()
Expand All @@ -179,7 +178,6 @@ func (s *Shards) fetchAndDecodeShards() ([]ShardResponse, error) {

// Collect number of shards on each node
func (s *Shards) Collect(ch chan<- prometheus.Metric) {

defer func() {
ch <- s.jsonParseFailures
}()
Expand Down
1 change: 0 additions & 1 deletion collector/shards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,5 @@ func TestShards(t *testing.T) {
t.Fatal(err)
}
})

}
}
8 changes: 2 additions & 6 deletions collector/slm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

var (
statuses = []string{"RUNNING", "STOPPING", "STOPPED"}
)
var statuses = []string{"RUNNING", "STOPPING", "STOPPED"}

var (
slmRetentionRunsTotal = prometheus.NewDesc(
Expand Down Expand Up @@ -173,7 +171,7 @@ func (s *SLM) Update(ctx context.Context, ch chan<- prometheus.Metric) error {
}

for _, status := range statuses {
var value float64 = 0
var value float64
if slmStatusResp.OperationMode == status {
value = 1
}
Expand Down Expand Up @@ -253,9 +251,7 @@ func (s *SLM) Update(ctx context.Context, ch chan<- prometheus.Metric) error {
float64(policy.SnapshotDeletionFailures),
policy.Policy,
)

}

return nil

}
Loading