mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-08-20 18:33:52 -07:00
chore: Upgrade golangci-lint to v2
- Migrate the configuration file - Update the tooling version and CI - Apply auto-fixes Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
This commit is contained in:
parent
38d32a3977
commit
9afcb7de39
4
.github/workflows/golangci-lint.yml
vendored
4
.github/workflows/golangci-lint.yml
vendored
|
@ -33,7 +33,7 @@ jobs:
|
||||||
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
||||||
if: github.repository == 'prometheus/snmp_exporter'
|
if: github.repository == 'prometheus/snmp_exporter'
|
||||||
- name: Lint
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
|
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
|
||||||
with:
|
with:
|
||||||
args: --verbose
|
args: --verbose
|
||||||
version: v1.64.6
|
version: v2.0.2
|
||||||
|
|
|
@ -1,32 +1,47 @@
|
||||||
|
version: "2"
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- depguard
|
- depguard
|
||||||
- goimports
|
|
||||||
- misspell
|
- misspell
|
||||||
- revive
|
- revive
|
||||||
|
settings:
|
||||||
issues:
|
|
||||||
exclude-rules:
|
|
||||||
- path: _test.go
|
|
||||||
linters:
|
|
||||||
- errcheck
|
|
||||||
|
|
||||||
linters-settings:
|
|
||||||
depguard:
|
depguard:
|
||||||
rules:
|
rules:
|
||||||
no_exec_policy:
|
no_exec_policy:
|
||||||
files:
|
files:
|
||||||
- "!$test"
|
- '!$test'
|
||||||
deny:
|
deny:
|
||||||
- pkg: "os/exec"
|
- pkg: os/exec
|
||||||
desc: "Using os/exec to run sub processes it not allowed by policy"
|
desc: Using os/exec to run sub processes it not allowed by policy
|
||||||
errcheck:
|
errcheck:
|
||||||
exclude-functions:
|
exclude-functions:
|
||||||
# Used in HTTP handlers, any error is handled by the server itself.
|
|
||||||
- (net/http.ResponseWriter).Write
|
- (net/http.ResponseWriter).Write
|
||||||
revive:
|
revive:
|
||||||
rules:
|
rules:
|
||||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
|
|
||||||
- name: unused-parameter
|
- name: unused-parameter
|
||||||
severity: warning
|
severity: warning
|
||||||
disabled: true
|
disabled: true
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
presets:
|
||||||
|
- comments
|
||||||
|
- common-false-positives
|
||||||
|
- legacy
|
||||||
|
- std-error-handling
|
||||||
|
rules:
|
||||||
|
- linters:
|
||||||
|
- errcheck
|
||||||
|
path: _test.go
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
formatters:
|
||||||
|
enable:
|
||||||
|
- goimports
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
paths:
|
||||||
|
- third_party$
|
||||||
|
- builtin$
|
||||||
|
- examples$
|
||||||
|
|
|
@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
|
||||||
SKIP_GOLANGCI_LINT :=
|
SKIP_GOLANGCI_LINT :=
|
||||||
GOLANGCI_LINT :=
|
GOLANGCI_LINT :=
|
||||||
GOLANGCI_LINT_OPTS ?=
|
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.
|
# 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.
|
# windows isn't included here because of the path separator being different.
|
||||||
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
|
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"log/slog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type bootTimeCollector struct {
|
type bootTimeCollector struct {
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
|
||||||
&infoCount,
|
&infoCount,
|
||||||
)
|
)
|
||||||
if ret != C.KERN_SUCCESS {
|
if ret != C.KERN_SUCCESS {
|
||||||
return nil, fmt.Errorf("Couldn't get memory statistics, host_statistics returned %d", ret)
|
return nil, fmt.Errorf("couldn't get memory statistics, host_statistics returned %d", ret)
|
||||||
}
|
}
|
||||||
totalb, err := unix.Sysctl("hw.memsize")
|
totalb, err := unix.Sysctl("hw.memsize")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.Warn("Couldn't create filtered metrics handler:", "err", err)
|
h.logger.Warn("Couldn't create filtered metrics handler:", "err", err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err)))
|
fmt.Fprintf(w, "Couldn't create filtered metrics handler: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
filteredHandler.ServeHTTP(w, r)
|
filteredHandler.ServeHTTP(w, r)
|
||||||
|
|
Loading…
Reference in a new issue