mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-14 09:59:56 +00:00
enabled a few more linter rules
This commit is contained in:
109
.golangci.yml
109
.golangci.yml
@@ -6,11 +6,114 @@ run:
|
|||||||
linters:
|
linters:
|
||||||
default: none
|
default: none
|
||||||
enable:
|
enable:
|
||||||
- ineffassign
|
- arangolint
|
||||||
- unused
|
- asasalint
|
||||||
- govet
|
- asciicheck
|
||||||
|
- bidichk
|
||||||
|
- bodyclose
|
||||||
|
- canonicalheader
|
||||||
|
- containedctx
|
||||||
|
- contextcheck
|
||||||
|
# - copyloopvar 1
|
||||||
|
# - cyclop 15
|
||||||
|
- decorder
|
||||||
|
# - depguard 265
|
||||||
|
- dogsled
|
||||||
|
# - dupl 2
|
||||||
|
- dupword
|
||||||
|
- durationcheck
|
||||||
|
# - embeddedstructfieldcheck 5
|
||||||
|
# - err113 64
|
||||||
- errcheck
|
- errcheck
|
||||||
|
- errchkjson
|
||||||
|
- errname
|
||||||
|
# - errorlint 4
|
||||||
|
# - exhaustive 2
|
||||||
|
# - exhaustruct 260
|
||||||
|
- exptostd
|
||||||
|
- fatcontext
|
||||||
|
# - forbidigo 6
|
||||||
|
# - forcetypeassert: 5
|
||||||
|
# - funcorder: 5
|
||||||
|
# - funlen: 24
|
||||||
|
- ginkgolinter
|
||||||
|
- gocheckcompilerdirectives
|
||||||
|
# - gochecknoglobals 31
|
||||||
|
# - gochecknoinits 14
|
||||||
|
- gochecksumtype
|
||||||
|
# - gocognit 5
|
||||||
|
- goconst
|
||||||
|
# - gocritic 3
|
||||||
|
# - gocyclo 1
|
||||||
|
# - godot 24
|
||||||
|
# - godox 8
|
||||||
|
- goheader
|
||||||
|
- gomoddirectives
|
||||||
|
- gomodguard
|
||||||
|
- goprintffuncname
|
||||||
|
# - gosec 55
|
||||||
|
# - gosmopolitan 5
|
||||||
|
- govet
|
||||||
|
- grouper
|
||||||
|
- iface
|
||||||
|
- importas
|
||||||
|
# - inamedparam 6
|
||||||
|
- ineffassign
|
||||||
|
- interfacebloat
|
||||||
|
# - intrange 1
|
||||||
|
# - ireturn 15
|
||||||
|
# - lll 59
|
||||||
|
- loggercheck
|
||||||
|
- maintidx
|
||||||
|
- makezero
|
||||||
|
- mirror
|
||||||
|
- misspell
|
||||||
|
# - mnd 29
|
||||||
|
- musttag
|
||||||
|
- nakedret
|
||||||
|
# - nestif 7
|
||||||
|
# - nilerr 2
|
||||||
|
# - nilnesserr 2
|
||||||
|
# - nilnil 3
|
||||||
|
# - nlreturn 149
|
||||||
|
- noctx
|
||||||
|
# - noinlineerr 81
|
||||||
|
- nolintlint
|
||||||
|
# - nonamedreturns 2
|
||||||
|
- nosprintfhostport
|
||||||
|
# - paralleltest 54
|
||||||
|
# - perfsprint 14
|
||||||
|
# - prealloc 5
|
||||||
|
# - predeclared 1
|
||||||
|
- promlinter
|
||||||
|
# - protogetter 7
|
||||||
|
- reassign
|
||||||
|
# - recvcheck 3
|
||||||
|
# - revive 133
|
||||||
|
- rowserrcheck
|
||||||
|
- sloglint
|
||||||
|
- spancheck
|
||||||
|
- sqlclosecheck
|
||||||
- staticcheck
|
- staticcheck
|
||||||
|
- tagalign
|
||||||
|
# - tagliatelle 6
|
||||||
|
- testableexamples
|
||||||
|
# - testifylint 10
|
||||||
|
# - testpackage 34
|
||||||
|
# - thelper 4
|
||||||
|
- tparallel
|
||||||
|
- unconvert
|
||||||
|
# - unparam 1
|
||||||
|
- unused
|
||||||
|
- usestdlibvars
|
||||||
|
# - usetesting 3
|
||||||
|
# - varnamelen 33
|
||||||
|
- wastedassign
|
||||||
|
- whitespace
|
||||||
|
# - wrapcheck 26
|
||||||
|
# - wsl 403
|
||||||
|
# - wsl_v5 58
|
||||||
|
- zerologlint
|
||||||
exclusions:
|
exclusions:
|
||||||
generated: lax
|
generated: lax
|
||||||
paths:
|
paths:
|
||||||
|
|||||||
@@ -126,9 +126,22 @@ func logPatternHealthCheck(service string, loopBackTime time.Duration, logPatter
|
|||||||
// healthCheckEndpointOKFunc returns a function to check the status of an http endpoint
|
// healthCheckEndpointOKFunc returns a function to check the status of an http endpoint
|
||||||
func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) func() (bool, error) {
|
func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) func() (bool, error) {
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
|
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, endpoint, nil)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
httpClient := http.Client{Timeout: timeout}
|
httpClient := http.Client{Timeout: timeout}
|
||||||
response, err := httpClient.Get(endpoint)
|
response, err := httpClient.Do(req)
|
||||||
if err != nil || response.StatusCode != http.StatusOK {
|
if err != nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
err := response.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
klog.Warningf("failed to close http client: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if response.StatusCode != http.StatusOK {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ Jan 2 03:04:05 kernel: [2.000000] 3
|
|||||||
t.Logf("failed to remove temporary file %s: %v", f.Name(), err)
|
t.Logf("failed to remove temporary file %s: %v", f.Name(), err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
_, err = f.Write([]byte(test.log))
|
_, err = f.WriteString(test.log)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
w := NewSyslogWatcherOrDie(types.WatcherConfig{
|
w := NewSyslogWatcherOrDie(types.WatcherConfig{
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.N
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCollect(t *testing.T) {
|
func TestCollect(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
tcs := []struct {
|
tcs := []struct {
|
||||||
Name string
|
Name string
|
||||||
ExcludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp
|
ExcludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetOSVersionLinux(t *testing.T) {
|
func TestGetOSVersionLinux(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
fakeOSReleasePath string
|
fakeOSReleasePath string
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func TestPrometheusMetricsParsingAndMatching(t *testing.T) {
|
|||||||
// Metric with non-existent label.
|
// Metric with non-existent label.
|
||||||
{
|
{
|
||||||
Name: "host_uptime",
|
Name: "host_uptime",
|
||||||
Labels: map[string]string{"non-existant-version": "0.0.1"},
|
Labels: map[string]string{"non-existent-version": "0.0.1"},
|
||||||
},
|
},
|
||||||
// Metric with incorrect label.
|
// Metric with incorrect label.
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdlineArg struct {
|
type CmdlineArg struct {
|
||||||
@@ -25,7 +27,11 @@ type CmdlineArg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d CmdlineArg) String() string {
|
func (d CmdlineArg) String() string {
|
||||||
s, _ := json.Marshal(d)
|
s, err := json.Marshal(d)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("failed to marshal cmdline arg: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return string(s)
|
return string(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
@@ -29,7 +31,11 @@ type Module struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d Module) String() string {
|
func (d Module) String() string {
|
||||||
s, _ := json.Marshal(d)
|
s, err := json.Marshal(d)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("failed to marshal module stat: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return string(s)
|
return string(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user