mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-23 22:26:27 +00:00
enabled a few more linter rules
This commit is contained in:
@@ -126,9 +126,22 @@ func logPatternHealthCheck(service string, loopBackTime time.Duration, logPatter
|
||||
// healthCheckEndpointOKFunc returns a function to check the status of an http endpoint
|
||||
func healthCheckEndpointOKFunc(endpoint string, timeout time.Duration) 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}
|
||||
response, err := httpClient.Get(endpoint)
|
||||
if err != nil || response.StatusCode != http.StatusOK {
|
||||
response, err := httpClient.Do(req)
|
||||
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 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)
|
||||
}
|
||||
}()
|
||||
_, err = f.Write([]byte(test.log))
|
||||
_, err = f.WriteString(test.log)
|
||||
assert.NoError(t, err)
|
||||
|
||||
w := NewSyslogWatcherOrDie(types.WatcherConfig{
|
||||
|
||||
@@ -85,6 +85,7 @@ func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.N
|
||||
}
|
||||
|
||||
func TestCollect(t *testing.T) {
|
||||
t.Parallel()
|
||||
tcs := []struct {
|
||||
Name string
|
||||
ExcludeInterfaceRegexp ssmtypes.NetStatsInterfaceRegexp
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetOSVersionLinux(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := []struct {
|
||||
name string
|
||||
fakeOSReleasePath string
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestPrometheusMetricsParsingAndMatching(t *testing.T) {
|
||||
// Metric with non-existent label.
|
||||
{
|
||||
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.
|
||||
{
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type CmdlineArg struct {
|
||||
@@ -25,7 +27,11 @@ type CmdlineArg struct {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
@@ -29,7 +31,11 @@ type Module struct {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user