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
72 changes: 43 additions & 29 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
---
version: "2"
linters:
enable:
- errcheck
- forbidigo
- godot
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- testifylint
- unused

linters-settings:
forbidigo:
forbid:
- p: ^fmt\.Print.*$
msg: Do not commit print statements.
godot:
capital: true
exclude:
# Ignore "See: URL"
Comment thread
kakkoyun marked this conversation as resolved.
- 'See:'
goimports:
local-prefixes: github.com/prometheus/procfs
misspell:
locale: US
- forbidigo
- godot
- misspell
- revive
- testifylint
settings:
forbidigo:
forbid:
- pattern: ^fmt\.Print.*$
msg: Do not commit print statements.
godot:
exclude:
# Ignore "See: URL".
- 'See:'
capital: true
misspell:
locale: US
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/prometheus/procfs
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
4 changes: 2 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)

GO_VERSION ?= $(shell $(GO) version)
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))Error Parsing File
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')

PROMU := $(FIRST_GOPATH)/bin/promu
Expand Down 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
8 changes: 4 additions & 4 deletions buddyinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Node 0, zone
if err == nil {
t.Fatalf("expected error, but none occurred")
}
if want, got := "Error Parsing File: Invalid number of fields, found: [Node 0, zone]", err.Error(); want != got {
t.Fatalf("Error Parsing File: Invalid number of fields, found: [Node %q, %q]", want, got)
if want, got := "error parsing file: Invalid number of fields, found: [Node 0, zone]", err.Error(); want != got {
t.Fatalf("error parsing file: Invalid number of fields, found: [Node %q, %q]", want, got)
}
}

Expand All @@ -68,7 +68,7 @@ Node 0, zone Normal 4381 1093 185 1530 567 102 4 0
if err == nil {
t.Fatalf("expected error, but none occurred")
}
if want, got := "Error Parsing File: mismatch in number of buddyinfo buckets, previous count 11, new count 12", err.Error(); !strings.HasPrefix(got, want) {
t.Fatalf("Error Parsing File: mismatch in number of buddyinfo buckets, previous count %q, new count %q", want, got)
if want, got := "error parsing file: mismatch in number of buddyinfo buckets, previous count 11, new count 12", err.Error(); !strings.HasPrefix(got, want) {
t.Fatalf("error parsing file: mismatch in number of buddyinfo buckets, previous count %q, new count %q", want, got)
}
}
4 changes: 2 additions & 2 deletions ipvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestParseIPPort(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !(gotIP.Equal(ip) && port == gotPort) {
if !gotIP.Equal(ip) || port != gotPort {
t.Errorf("want %s:%d, have %s:%d", ip, port, gotIP, gotPort)
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestParseIPPortIPv6(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !(gotIP.Equal(ip) && port == gotPort) {
if !gotIP.Equal(ip) || port != gotPort {
t.Errorf("want %s:%d, have %s:%d", ip, port, gotIP, gotPort)
}
}
Expand Down
9 changes: 5 additions & 4 deletions iscsi/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func TestGetStats(t *testing.T) {
if !reflect.DeepEqual(readTests[i].iops, iops) {
t.Errorf("unexpected iSCSI iops data :\nwant:\n%v\nhave:\n%v", readTests[i].iops, iops)
}
if stat.Tpgt[0].Luns[0].Backstore == "rd_mcp" {
switch stat.Tpgt[0].Luns[0].Backstore {
case "rd_mcp":
haveRdmcp, err := sysconfigfs.GetRDMCPPath("119", "ramdisk_lio_1G")
if err != nil {
t.Errorf("fail rdmcp error %v", err)
Expand All @@ -170,7 +171,7 @@ func TestGetStats(t *testing.T) {
if !reflect.DeepEqual(wantRdmcp, haveRdmcp) {
t.Errorf("unexpected rdmcp data :\nwant:\n%v\nhave:\n%v", wantRdmcp, haveRdmcp)
}
} else if stat.Tpgt[0].Luns[0].Backstore == "iblock" {
case "iblock":
haveIblock, err := sysconfigfs.GetIblockUdev("0", "block_lio_rbd1")
if err != nil {
t.Errorf("fail iblock error %v", err)
Expand All @@ -180,7 +181,7 @@ func TestGetStats(t *testing.T) {
if !reflect.DeepEqual(wantIblock, haveIblock) {
t.Errorf("unexpected iblock data :\nwant:\n%v\nhave:\n%v", wantIblock, haveIblock)
}
} else if stat.Tpgt[0].Luns[0].Backstore == "fileio" {
case "fileio":
haveFileIO, err := sysconfigfs.GetFileioUdev("1", "file_lio_1G")
if err != nil {
t.Errorf("fail fileio error %v", err)
Expand All @@ -190,7 +191,7 @@ func TestGetStats(t *testing.T) {
if !reflect.DeepEqual(wantFileIO, haveFileIO) {
t.Errorf("unexpected fileio data :\nwant:\n%v\nhave:\n%v", wantFileIO, haveFileIO)
}
} else if stat.Tpgt[0].Luns[0].Backstore == "rbd" {
case "rbd":
haveRBD, err := sysconfigfs.GetRBDMatch("0", "iscsi-images-demo")
if err != nil {
t.Errorf("fail rbd error %v", err)
Expand Down
23 changes: 13 additions & 10 deletions mountstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,25 +601,27 @@ func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats
switch statVersion {
case statVersion10:
var expectedLength int
if protocol == "tcp" {
switch protocol {
case "tcp":
expectedLength = fieldTransport10TCPLen
} else if protocol == "udp" {
case "udp":
expectedLength = fieldTransport10UDPLen
} else {
default:
return nil, fmt.Errorf("%w: Invalid NFS protocol \"%s\" in stats 1.0 statement: %v", ErrFileParse, protocol, ss)
}
if len(ss) != expectedLength {
return nil, fmt.Errorf("%w: Invalid NFS transport stats 1.0 statement: %v", ErrFileParse, ss)
}
case statVersion11:
var expectedLength int
if protocol == "tcp" {
switch protocol {
case "tcp":
expectedLength = fieldTransport11TCPLen
} else if protocol == "udp" {
case "udp":
expectedLength = fieldTransport11UDPLen
} else if protocol == "rdma" {
case "rdma":
expectedLength = fieldTransport11RDMAMinLen
} else {
default:
return nil, fmt.Errorf("%w: invalid NFS protocol \"%s\" in stats 1.1 statement: %v", ErrFileParse, protocol, ss)
}
if (len(ss) != expectedLength && (protocol == "tcp" || protocol == "udp")) ||
Expand Down Expand Up @@ -655,11 +657,12 @@ func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats
// For the udp RPC transport there is no connection count, connect idle time,
// or idle time (fields #3, #4, and #5); all other fields are the same. So
// we set them to 0 here.
if protocol == "udp" {
switch protocol {
case "udp":
ns = append(ns[:2], append(make([]uint64, 3), ns[2:]...)...)
} else if protocol == "tcp" {
case "tcp":
ns = append(ns[:fieldTransport11TCPLen], make([]uint64, fieldTransport11RDMAMaxLen-fieldTransport11TCPLen+3)...)
} else if protocol == "rdma" {
case "rdma":
ns = append(ns[:fieldTransport10TCPLen], append(make([]uint64, 3), ns[fieldTransport10TCPLen:]...)...)
}

Expand Down
21 changes: 12 additions & 9 deletions net_protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,24 @@ func (ps NetProtocolStats) parseLine(rawLine string) (*NetProtocolStatLine, erro
if err != nil {
return nil, err
}
if fields[4] == enabled {
switch fields[4] {
case enabled:
line.Pressure = 1
} else if fields[4] == disabled {
case disabled:
line.Pressure = 0
} else {
default:
line.Pressure = -1
}
line.MaxHeader, err = strconv.ParseUint(fields[5], 10, 64)
if err != nil {
return nil, err
}
if fields[6] == enabled {
switch fields[6] {
case enabled:
line.Slab = true
} else if fields[6] == disabled {
case disabled:
line.Slab = false
} else {
default:
return nil, fmt.Errorf("%w: capability for protocol: %s", ErrFileParse, line.Name)
}
line.ModuleName = fields[7]
Expand Down Expand Up @@ -168,11 +170,12 @@ func (pc *NetProtocolCapabilities) parseCapabilities(capabilities []string) erro
}

for i := 0; i < len(capabilities); i++ {
if capabilities[i] == "y" {
switch capabilities[i] {
case "y":
*capabilityFields[i] = true
} else if capabilities[i] == "n" {
case "n":
*capabilityFields[i] = false
} else {
default:
return fmt.Errorf("%w: capability block for protocol: position %d", ErrFileParse, i)
}
}
Expand Down
8 changes: 4 additions & 4 deletions proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type Proc struct {
type Procs []Proc

var (
ErrFileParse = errors.New("Error Parsing File")
ErrFileRead = errors.New("Error Reading File")
ErrMountPoint = errors.New("Error Accessing Mount point")
ErrFileParse = errors.New("error parsing file")
ErrFileRead = errors.New("error reading file")
ErrMountPoint = errors.New("error accessing mount point")
)

func (p Procs) Len() int { return len(p) }
Expand Down Expand Up @@ -79,7 +79,7 @@ func (fs FS) Self() (Proc, error) {
if err != nil {
return Proc{}, err
}
pid, err := strconv.Atoi(strings.Replace(p, string(fs.proc), "", -1))
pid, err := strconv.Atoi(strings.ReplaceAll(p, string(fs.proc), ""))
if err != nil {
return Proc{}, err
}
Expand Down
Loading