diff --git a/.golangci.yml b/.golangci.yml index d2453ff4d..151b9b270 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,6 +19,20 @@ issues: max-issues-per-linter: 0 max-same-issues: 0 formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + settings: + gci: + sections: + - standard + - default + - localmodule + goimports: + local-prefixes: + - k8s.io/node-problem-detector exclusions: generated: lax paths: diff --git a/Makefile b/Makefile index 087d4191c..7b9e97c64 100644 --- a/Makefile +++ b/Makefile @@ -130,8 +130,9 @@ vet: grep -v "./vendor/*" | \ xargs go vet -tags "$(HOST_PLATFORM_BUILD_TAGS)" -fmt: +fmt: $(GOLANGCI_LINT) find . -type f -name "*.go" | grep -v "./vendor/*" | xargs gofmt -s -w -l + $(GOLANGCI_LINT) run --config .golangci.yml --fix ./... version: @echo $(VERSION) diff --git a/cmd/healthchecker/health_checker.go b/cmd/healthchecker/health_checker.go index cd7b64bdd..ad0bb0747 100644 --- a/cmd/healthchecker/health_checker.go +++ b/cmd/healthchecker/health_checker.go @@ -22,8 +22,8 @@ import ( "os" "github.com/spf13/pflag" - "k8s.io/klog/v2" + "k8s.io/node-problem-detector/cmd/healthchecker/options" "k8s.io/node-problem-detector/pkg/custompluginmonitor/types" "k8s.io/node-problem-detector/pkg/healthchecker" diff --git a/cmd/nodeproblemdetector/node_problem_detector_test.go b/cmd/nodeproblemdetector/node_problem_detector_test.go index 47a5ff2e2..02f7fb539 100644 --- a/cmd/nodeproblemdetector/node_problem_detector_test.go +++ b/cmd/nodeproblemdetector/node_problem_detector_test.go @@ -71,8 +71,7 @@ func init() { }) } -type nullExporter struct { -} +type nullExporter struct{} func (ne *nullExporter) ExportProblems(*types.Status) { } @@ -96,7 +95,7 @@ func writeTempFile(t *testing.T, ext string, contents string) (string, error) { fileName := f.Name() - if err := os.WriteFile(fileName, []byte(contents), 0644); err != nil { + if err := os.WriteFile(fileName, []byte(contents), 0o644); err != nil { os.Remove(fileName) return "", fmt.Errorf("cannot write config to temp file %s, %v", fileName, err) } diff --git a/cmd/nodeproblemdetector/node_problem_detector_unix.go b/cmd/nodeproblemdetector/node_problem_detector_unix.go index 0ea4bc07b..3b3b52727 100644 --- a/cmd/nodeproblemdetector/node_problem_detector_unix.go +++ b/cmd/nodeproblemdetector/node_problem_detector_unix.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/pflag" "k8s.io/klog/v2" + "k8s.io/node-problem-detector/cmd/options" ) diff --git a/cmd/options/options.go b/cmd/options/options.go index 3d90bfdec..b55d70ede 100644 --- a/cmd/options/options.go +++ b/cmd/options/options.go @@ -19,11 +19,10 @@ package options import ( "flag" "fmt" + "net/url" "os" "time" - "net/url" - "github.com/spf13/pflag" "k8s.io/node-problem-detector/pkg/exporters" diff --git a/pkg/custompluginmonitor/custom_plugin_monitor.go b/pkg/custompluginmonitor/custom_plugin_monitor.go index b5ad08a82..ea383d7c9 100644 --- a/pkg/custompluginmonitor/custom_plugin_monitor.go +++ b/pkg/custompluginmonitor/custom_plugin_monitor.go @@ -39,7 +39,8 @@ func init() { CustomPluginMonitorName, types.ProblemDaemonHandler{ CreateProblemDaemonOrDie: NewCustomPluginMonitorOrDie, - CmdOptionDescription: "Set to config file paths."}) + CmdOptionDescription: "Set to config file paths.", + }) } type customPluginMonitor struct { diff --git a/pkg/custompluginmonitor/plugin/plugin.go b/pkg/custompluginmonitor/plugin/plugin.go index 0b90e9c01..d3ec3e3e5 100644 --- a/pkg/custompluginmonitor/plugin/plugin.go +++ b/pkg/custompluginmonitor/plugin/plugin.go @@ -27,6 +27,7 @@ import ( "time" "k8s.io/klog/v2" + cpmtypes "k8s.io/node-problem-detector/pkg/custompluginmonitor/types" "k8s.io/node-problem-detector/pkg/util" "k8s.io/node-problem-detector/pkg/util/tomb" diff --git a/pkg/custompluginmonitor/types/config_test.go b/pkg/custompluginmonitor/types/config_test.go index 2649910f6..c474c8cc6 100644 --- a/pkg/custompluginmonitor/types/config_test.go +++ b/pkg/custompluginmonitor/types/config_test.go @@ -197,9 +197,10 @@ func TestCustomPluginConfigApplyConfiguration(t *testing.T) { }, }, "disable status update during initialization": { - Orig: CustomPluginConfig{PluginGlobalConfig: pluginGlobalConfig{ - SkipInitialStatus: &disableInitialStatusUpdate, - }, + Orig: CustomPluginConfig{ + PluginGlobalConfig: pluginGlobalConfig{ + SkipInitialStatus: &disableInitialStatusUpdate, + }, }, Wanted: CustomPluginConfig{ PluginGlobalConfig: pluginGlobalConfig{ diff --git a/pkg/exporters/k8sexporter/condition/manager.go b/pkg/exporters/k8sexporter/condition/manager.go index 1b593da31..b29fa0c86 100644 --- a/pkg/exporters/k8sexporter/condition/manager.go +++ b/pkg/exporters/k8sexporter/condition/manager.go @@ -22,14 +22,13 @@ import ( "sync" "time" - "k8s.io/node-problem-detector/pkg/exporters/k8sexporter/problemclient" - "k8s.io/node-problem-detector/pkg/types" - problemutil "k8s.io/node-problem-detector/pkg/util" - v1 "k8s.io/api/core/v1" + "k8s.io/klog/v2" "k8s.io/utils/clock" - "k8s.io/klog/v2" + "k8s.io/node-problem-detector/pkg/exporters/k8sexporter/problemclient" + "k8s.io/node-problem-detector/pkg/types" + problemutil "k8s.io/node-problem-detector/pkg/util" ) const ( diff --git a/pkg/exporters/k8sexporter/condition/manager_test.go b/pkg/exporters/k8sexporter/condition/manager_test.go index bea833f93..fcaf07262 100644 --- a/pkg/exporters/k8sexporter/condition/manager_test.go +++ b/pkg/exporters/k8sexporter/condition/manager_test.go @@ -23,13 +23,12 @@ import ( "time" "github.com/stretchr/testify/assert" + v1 "k8s.io/api/core/v1" + testclock "k8s.io/utils/clock/testing" "k8s.io/node-problem-detector/pkg/exporters/k8sexporter/problemclient" "k8s.io/node-problem-detector/pkg/types" problemutil "k8s.io/node-problem-detector/pkg/util" - - v1 "k8s.io/api/core/v1" - testclock "k8s.io/utils/clock/testing" ) const heartbeatPeriod = 1 * time.Minute diff --git a/pkg/exporters/k8sexporter/k8s_exporter.go b/pkg/exporters/k8sexporter/k8s_exporter.go index f033886e6..7d97c88cd 100644 --- a/pkg/exporters/k8sexporter/k8s_exporter.go +++ b/pkg/exporters/k8sexporter/k8s_exporter.go @@ -23,9 +23,8 @@ import ( "net/http/pprof" "strconv" - "k8s.io/klog/v2" - "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/klog/v2" "k8s.io/utils/clock" "k8s.io/node-problem-detector/cmd/options" diff --git a/pkg/exporters/k8sexporter/problemclient/problem_client_test.go b/pkg/exporters/k8sexporter/problemclient/problem_client_test.go index 9f80c5d81..5552d58ee 100644 --- a/pkg/exporters/k8sexporter/problemclient/problem_client_test.go +++ b/pkg/exporters/k8sexporter/problemclient/problem_client_test.go @@ -22,12 +22,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/record" testclock "k8s.io/utils/clock/testing" - - "github.com/stretchr/testify/assert" ) const ( diff --git a/pkg/exporters/register.go b/pkg/exporters/register.go index 82839dade..9075b46a6 100644 --- a/pkg/exporters/register.go +++ b/pkg/exporters/register.go @@ -22,9 +22,7 @@ import ( "k8s.io/node-problem-detector/pkg/types" ) -var ( - handlers = make(map[types.ExporterType]types.ExporterHandler) -) +var handlers = make(map[types.ExporterType]types.ExporterHandler) // Register registers a exporter factory method, which will be used to create the exporter. func Register(exporterType types.ExporterType, handler types.ExporterHandler) { diff --git a/pkg/exporters/stackdriver/stackdriver_exporter.go b/pkg/exporters/stackdriver/stackdriver_exporter.go index f418dfae6..a1b258c03 100644 --- a/pkg/exporters/stackdriver/stackdriver_exporter.go +++ b/pkg/exporters/stackdriver/stackdriver_exporter.go @@ -25,12 +25,12 @@ import ( "contrib.go.opencensus.io/exporter/stackdriver" monitoredres "contrib.go.opencensus.io/exporter/stackdriver/monitoredresource" + "github.com/avast/retry-go/v4" "github.com/spf13/pflag" "go.opencensus.io/stats/view" "google.golang.org/api/option" "k8s.io/klog/v2" - "github.com/avast/retry-go/v4" "k8s.io/node-problem-detector/pkg/exporters" seconfig "k8s.io/node-problem-detector/pkg/exporters/stackdriver/config" "k8s.io/node-problem-detector/pkg/types" @@ -41,7 +41,8 @@ func init() { clo := commandLineOptions{} exporters.Register(exporterName, types.ExporterHandler{ CreateExporterOrDie: NewExporterOrDie, - Options: &clo}) + Options: &clo, + }) } const exporterName = "stackdriver" @@ -95,7 +96,6 @@ var NPDMetricToSDMetric = map[metrics.MetricID]string{ } func getMetricTypeConversionFunction(customMetricPrefix string) func(*view.View) string { - return func(view *view.View) string { viewName := view.Measure.Name() diff --git a/pkg/healthchecker/health_checker.go b/pkg/healthchecker/health_checker.go index 94b718c8e..b81a63ad0 100644 --- a/pkg/healthchecker/health_checker.go +++ b/pkg/healthchecker/health_checker.go @@ -24,6 +24,7 @@ import ( "time" "k8s.io/klog/v2" + "k8s.io/node-problem-detector/cmd/healthchecker/options" "k8s.io/node-problem-detector/pkg/healthchecker/types" ) diff --git a/pkg/healthchecker/health_checker_linux.go b/pkg/healthchecker/health_checker_linux.go index 724f966b3..3dc3728be 100644 --- a/pkg/healthchecker/health_checker_linux.go +++ b/pkg/healthchecker/health_checker_linux.go @@ -38,7 +38,6 @@ func getUptimeFunc(service string) func() (time.Duration, error) { // RestartSec of systemd and invoke interval of plugin got in sync. The service was repeatedly killed in // activating state and hence ActiveEnterTimestamp was never updated. out, err := execCommand(types.CmdTimeout, "systemctl", "show", service, "--property=InactiveExitTimestamp") - if err != nil { return time.Duration(0), err } diff --git a/pkg/healthchecker/health_checker_test.go b/pkg/healthchecker/health_checker_test.go index 03d51c51a..ec47455ab 100644 --- a/pkg/healthchecker/health_checker_test.go +++ b/pkg/healthchecker/health_checker_test.go @@ -150,8 +150,6 @@ func TestComponentsSupported(t *testing.T) { if checkFunc == nil { t.Errorf("component %v should be supported", tc.component) } - }) } - } diff --git a/pkg/healthchecker/types/types.go b/pkg/healthchecker/types/types.go index c3617dcb4..89b91e1cc 100644 --- a/pkg/healthchecker/types/types.go +++ b/pkg/healthchecker/types/types.go @@ -81,12 +81,12 @@ func setKubeEndpoints() { kubeletHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeletPort)) kubeProxyHealthCheckEndpoint = fmt.Sprintf("http://%s/healthz", net.JoinHostPort(hostAddress, kubeProxyPort)) - } func KubeProxyHealthCheckEndpoint() string { return kubeProxyHealthCheckEndpoint } + func KubeletHealthCheckEndpoint() string { return kubeletHealthCheckEndpoint } diff --git a/pkg/problemdaemon/problem_daemon.go b/pkg/problemdaemon/problem_daemon.go index d3c4150e6..1bf107e1d 100644 --- a/pkg/problemdaemon/problem_daemon.go +++ b/pkg/problemdaemon/problem_daemon.go @@ -24,9 +24,7 @@ import ( "k8s.io/node-problem-detector/pkg/types" ) -var ( - handlers = make(map[types.ProblemDaemonType]types.ProblemDaemonHandler) -) +var handlers = make(map[types.ProblemDaemonType]types.ProblemDaemonHandler) // Register registers a problem daemon factory method, which will be used to create the problem daemon. func Register(problemDaemonType types.ProblemDaemonType, handler types.ProblemDaemonHandler) { diff --git a/pkg/systemlogmonitor/log_monitor.go b/pkg/systemlogmonitor/log_monitor.go index cb0cdd0b4..2fc5dd0c6 100644 --- a/pkg/systemlogmonitor/log_monitor.go +++ b/pkg/systemlogmonitor/log_monitor.go @@ -41,7 +41,8 @@ func init() { SystemLogMonitorName, types.ProblemDaemonHandler{ CreateProblemDaemonOrDie: NewLogMonitorOrDie, - CmdOptionDescription: "Set to config file paths."}) + CmdOptionDescription: "Set to config file paths.", + }) } type logMonitor struct { diff --git a/pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go b/pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go index f0b8259be..976ae268c 100644 --- a/pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go +++ b/pkg/systemlogmonitor/logwatchers/filelog/log_watcher.go @@ -134,7 +134,7 @@ func (s *filelogWatcher) watchLoop() { } func (s *filelogWatcher) filterSkipList(line string) bool { - for _ , skipItem := range s.cfg.SkipList { + for _, skipItem := range s.cfg.SkipList { if strings.Contains(line, skipItem) { return true } diff --git a/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_linux.go b/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_linux.go index 68615e63d..f4e3773b2 100644 --- a/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_linux.go +++ b/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_linux.go @@ -19,8 +19,9 @@ package filelog import ( "fmt" "io" - "k8s.io/node-problem-detector/third_party/forked/cadvisor/tail" "os" + + "k8s.io/node-problem-detector/third_party/forked/cadvisor/tail" ) // getLogReader returns log reader for filelog log. Note that getLogReader doesn't look back diff --git a/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go b/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go index c59f86e80..f58db0bdb 100644 --- a/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go +++ b/pkg/systemlogmonitor/logwatchers/filelog/log_watcher_test.go @@ -21,12 +21,12 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + testclock "k8s.io/utils/clock/testing" + "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types" logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types" "k8s.io/node-problem-detector/pkg/util" - - "github.com/stretchr/testify/assert" - testclock "k8s.io/utils/clock/testing" ) // getTestPluginConfig returns a plugin config for test. Use configuration for @@ -185,22 +185,21 @@ func TestFilterSkipList(t *testing.T) { }, }, } - testcase := []struct{ - log string + testcase := []struct { + log string expect bool }{ { - log: `Jan 2 03:04:03 kernel: [0.000000] 1`, + log: `Jan 2 03:04:03 kernel: [0.000000] 1`, expect: false, }, { - log: `Jan 2 03:04:04 audit: [1.000000] 2`, + log: `Jan 2 03:04:04 audit: [1.000000] 2`, expect: true, }, { - log: `Jan 2 03:04:05 kubelet: [2.000000] 3`, + log: `Jan 2 03:04:05 kubelet: [2.000000] 3`, expect: true, - }, } for i, test := range testcase { diff --git a/pkg/systemlogmonitor/logwatchers/filelog/translator.go b/pkg/systemlogmonitor/logwatchers/filelog/translator.go index f56076799..894453f42 100644 --- a/pkg/systemlogmonitor/logwatchers/filelog/translator.go +++ b/pkg/systemlogmonitor/logwatchers/filelog/translator.go @@ -20,9 +20,9 @@ import ( "regexp" "time" - logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types" - "k8s.io/klog/v2" + + logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types" ) // translator translates log line into internal log type based on user defined diff --git a/pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_linux_test.go b/pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_linux_test.go index 85c956524..fac08aea1 100644 --- a/pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_linux_test.go +++ b/pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_linux_test.go @@ -17,12 +17,12 @@ limitations under the License. package kmsg import ( - testclock "k8s.io/utils/clock/testing" "testing" + "time" "github.com/euank/go-kmsg-parser/kmsgparser" "github.com/stretchr/testify/assert" - "time" + testclock "k8s.io/utils/clock/testing" "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types" logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types" diff --git a/pkg/systemlogmonitor/logwatchers/log_watchers.go b/pkg/systemlogmonitor/logwatchers/log_watchers.go index 05258e3e3..2d5db0b31 100644 --- a/pkg/systemlogmonitor/logwatchers/log_watchers.go +++ b/pkg/systemlogmonitor/logwatchers/log_watchers.go @@ -17,9 +17,9 @@ limitations under the License. package logwatchers import ( - "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types" - "k8s.io/klog/v2" + + "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types" ) // createFuncs is a table of createFuncs for all supported log watchers. diff --git a/pkg/systemstatsmonitor/disk_collector.go b/pkg/systemstatsmonitor/disk_collector.go index b3b55f8a5..462f58607 100644 --- a/pkg/systemstatsmonitor/disk_collector.go +++ b/pkg/systemstatsmonitor/disk_collector.go @@ -307,7 +307,6 @@ func (dc *diskCollector) collect() { dc.mPercentUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, float64(usageStat.UsedPercent)) } } - } // listRootBlockDevices lists all block devices that's not a slave or holder. diff --git a/pkg/systemstatsmonitor/net_collector.go b/pkg/systemstatsmonitor/net_collector.go index 542865115..da7974a3b 100644 --- a/pkg/systemstatsmonitor/net_collector.go +++ b/pkg/systemstatsmonitor/net_collector.go @@ -19,11 +19,11 @@ package systemstatsmonitor import ( "fmt" - ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types" - "k8s.io/node-problem-detector/pkg/util/metrics" - "github.com/prometheus/procfs" "k8s.io/klog/v2" + + ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types" + "k8s.io/node-problem-detector/pkg/util/metrics" ) type newInt64MetricFn func(metricID metrics.MetricID, viewName string, description string, unit string, aggregation metrics.Aggregation, tagNames []string) (metrics.Int64MetricInterface, error) @@ -205,7 +205,8 @@ func NewNetCollectorOrDie(netConfig *ssmtypes.NetStatsConfig, procPath string) * } func (nc *netCollector) mustRegisterMetric(metricID metrics.MetricID, description, unit string, - aggregation metrics.Aggregation, exporter func(stat procfs.NetDevLine) int64) { + aggregation metrics.Aggregation, exporter func(stat procfs.NetDevLine) int64, +) { metricConfig, ok := nc.config.MetricsConfigs[string(metricID)] if !ok { klog.Fatalf("Metric config `%q` not found", metricID) @@ -265,7 +266,8 @@ func newIfaceStatRecorder(newInt64Metric newInt64MetricFn) *ifaceStatRecorder { } func (r *ifaceStatRecorder) Register(metricID metrics.MetricID, viewName string, description string, - unit string, aggregation metrics.Aggregation, tagNames []string, exporter func(procfs.NetDevLine) int64) error { + unit string, aggregation metrics.Aggregation, tagNames []string, exporter func(procfs.NetDevLine) int64, +) error { if _, ok := r.collectors[metricID]; ok { // Check duplication return fmt.Errorf("metric %q already registered", metricID) diff --git a/pkg/systemstatsmonitor/net_collector_test.go b/pkg/systemstatsmonitor/net_collector_test.go index 15e87fc2e..58a3b4501 100644 --- a/pkg/systemstatsmonitor/net_collector_test.go +++ b/pkg/systemstatsmonitor/net_collector_test.go @@ -51,7 +51,7 @@ func testCollectAux(t *testing.T, name string, excludeInterfaceRegexp ssmtypes.N // mkdir -C /tmp/proc-X/net procNetDir := path.Join(procDir, "net") - if err := os.Mkdir(procNetDir, 0777); err != nil { + if err := os.Mkdir(procNetDir, 0o777); err != nil { t.Fatalf("Failed to create directory %q: %v", procNetDir, err) } diff --git a/pkg/systemstatsmonitor/osfeature_collector.go b/pkg/systemstatsmonitor/osfeature_collector.go index 0de0c05e0..f15222d6c 100644 --- a/pkg/systemstatsmonitor/osfeature_collector.go +++ b/pkg/systemstatsmonitor/osfeature_collector.go @@ -21,6 +21,7 @@ import ( "strings" "k8s.io/klog/v2" + ssmtypes "k8s.io/node-problem-detector/pkg/systemstatsmonitor/types" "k8s.io/node-problem-detector/pkg/util/metrics" "k8s.io/node-problem-detector/pkg/util/metrics/system" @@ -61,7 +62,7 @@ func NewOsFeatureCollectorOrDie(osFeatureConfig *ssmtypes.OSFeatureStatsConfig, // 2. UnifiedCgroupHierarchy based on systemd.unified_cgroup_hierarchy // 3. KernelModuleIntegrity based on the loadpin enabled and a module signed. func (ofc *osFeatureCollector) recordFeaturesFromCmdline(cmdlineArgs []system.CmdlineArg) { - var featuresMap = map[string]int64{ + featuresMap := map[string]int64{ "KTD": 0, "UnifiedCgroupHierarchy": 0, "ModuleSigned": 0, @@ -118,7 +119,7 @@ func (ofc *osFeatureCollector) recordFeaturesFromModules(modules []system.Module knownModules = []system.Module{} } - var hasGPUSupport = 0 + hasGPUSupport := 0 unknownModules := []string{} // Collect UnknownModules and check GPUSupport @@ -136,8 +137,10 @@ func (ofc *osFeatureCollector) recordFeaturesFromModules(modules []system.Module } // record the UnknownModules and GPUSupport if len(unknownModules) > 0 { - ofc.osFeature.Record(map[string]string{featureLabel: "UnknownModules", - valueLabel: strings.Join(unknownModules, ",")}, 1) + ofc.osFeature.Record(map[string]string{ + featureLabel: "UnknownModules", + valueLabel: strings.Join(unknownModules, ","), + }, 1) } else { ofc.osFeature.Record(map[string]string{featureLabel: "UnknownModules"}, 0) diff --git a/pkg/systemstatsmonitor/system_stats_monitor.go b/pkg/systemstatsmonitor/system_stats_monitor.go index 4c99cbcd9..5b956574e 100644 --- a/pkg/systemstatsmonitor/system_stats_monitor.go +++ b/pkg/systemstatsmonitor/system_stats_monitor.go @@ -35,7 +35,8 @@ const SystemStatsMonitorName = "system-stats-monitor" func init() { problemdaemon.Register(SystemStatsMonitorName, types.ProblemDaemonHandler{ CreateProblemDaemonOrDie: NewSystemStatsMonitorOrDie, - CmdOptionDescription: "Set to config file paths."}) + CmdOptionDescription: "Set to config file paths.", + }) } type systemStatsMonitor struct { diff --git a/pkg/util/convert_test.go b/pkg/util/convert_test.go index e112c16c8..54b640fed 100644 --- a/pkg/util/convert_test.go +++ b/pkg/util/convert_test.go @@ -22,6 +22,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/node-problem-detector/pkg/types" ) diff --git a/pkg/util/metrics/helpers.go b/pkg/util/metrics/helpers.go index 6597e2093..065641510 100644 --- a/pkg/util/metrics/helpers.go +++ b/pkg/util/metrics/helpers.go @@ -25,8 +25,10 @@ import ( "go.opencensus.io/tag" ) -var tagMap map[string]tag.Key -var tagMapMutex sync.RWMutex +var ( + tagMap map[string]tag.Key + tagMapMutex sync.RWMutex +) func init() { tagMapMutex.Lock() @@ -105,7 +107,8 @@ func ParsePrometheusMetrics(metricsText string) ([]Float64MetricRepresentation, // When strictLabelMatching is set to true, the founded metric labels are identical to the provided labels; // when strictLabelMatching is set to false, the founded metric labels are a superset of the provided labels. func GetFloat64Metric(metrics []Float64MetricRepresentation, name string, labels map[string]string, - strictLabelMatching bool) (Float64MetricRepresentation, error) { + strictLabelMatching bool, +) (Float64MetricRepresentation, error) { for _, metric := range metrics { if metric.Name != name { continue diff --git a/pkg/util/metrics/system/cmdline_args.go b/pkg/util/metrics/system/cmdline_args.go index 48e0681b4..46e6d0e6e 100644 --- a/pkg/util/metrics/system/cmdline_args.go +++ b/pkg/util/metrics/system/cmdline_args.go @@ -42,7 +42,7 @@ func splitAfterSpace(inputChar rune) bool { withinQuotes = !withinQuotes return false } - //ignore spaces when it is within quotes. + // ignore spaces when it is within quotes. if withinQuotes { return false } @@ -59,7 +59,7 @@ func CmdlineArgs(cmdlineFilePath string) ([]CmdlineArg, error) { return nil, fmt.Errorf("no lines are returned") } cmdlineArgs := strings.FieldsFunc(lines[0], splitAfterSpace) - var result = make([]CmdlineArg, 0, len(cmdlineArgs)) + result := make([]CmdlineArg, 0, len(cmdlineArgs)) // for commandline only one line is returned. for _, words := range cmdlineArgs { // Ignore the keys that start with double quotes @@ -68,14 +68,14 @@ func CmdlineArgs(cmdlineFilePath string) ([]CmdlineArg, error) { } tokens := strings.Split(words, "=") if len(tokens) < 2 { - var stats = CmdlineArg{ + stats := CmdlineArg{ Key: tokens[0], } result = append(result, stats) } else { - //remove quotes in the values + // remove quotes in the values trimmedValue := strings.Trim(tokens[1], "\"'") - var stats = CmdlineArg{ + stats := CmdlineArg{ Key: tokens[0], Value: trimmedValue, } diff --git a/pkg/util/metrics/system/cmdline_args_test.go b/pkg/util/metrics/system/cmdline_args_test.go index 2e8da95ca..9473a17aa 100644 --- a/pkg/util/metrics/system/cmdline_args_test.go +++ b/pkg/util/metrics/system/cmdline_args_test.go @@ -91,5 +91,4 @@ func TestCmdlineStats_String(t *testing.T) { e := `{"key":"test","value":"test"}` assert.Equal(t, e, fmt.Sprintf("%v", v), "CmdlineArg string is invalid: %v", v) - } diff --git a/pkg/util/metrics/system/module_stats.go b/pkg/util/metrics/system/module_stats.go index 4cdf6211c..b9e98eab2 100644 --- a/pkg/util/metrics/system/module_stats.go +++ b/pkg/util/metrics/system/module_stats.go @@ -40,7 +40,7 @@ func Modules(modulesFilePath string) ([]Module, error) { if err != nil { return nil, fmt.Errorf("error reading the contents of %s: %s", modulesFilePath, err) } - var result = make([]Module, 0, len(lines)) + result := make([]Module, 0, len(lines)) /* a line of /proc/modules has the following structure nf_nat 61440 2 xt_MASQUERADE,iptable_nat, Live 0x0000000000000000 (O) @@ -55,14 +55,13 @@ func Modules(modulesFilePath string) ([]Module, error) { */ for _, line := range lines { fields := strings.Fields(line) - moduleName := fields[0] // name of the module - numberOfInstances, err := - strconv.ParseUint((fields[2]), 10, 64) // instances of the module are currently loaded + moduleName := fields[0] // name of the module + numberOfInstances, err := strconv.ParseUint((fields[2]), 10, 64) // instances of the module are currently loaded if err != nil { numberOfInstances = 0 } - var module = Module{ + module := Module{ ModuleName: moduleName, Instances: numberOfInstances, } diff --git a/pkg/util/metrics/system/module_stats_test.go b/pkg/util/metrics/system/module_stats_test.go index d08048e8c..cad77cab9 100644 --- a/pkg/util/metrics/system/module_stats_test.go +++ b/pkg/util/metrics/system/module_stats_test.go @@ -116,5 +116,4 @@ func TestModuleStat_String(t *testing.T) { e := `{"moduleName":"test","instances":2,"proprietary":false,"outOfTree":false,"unsigned":false}` assert.Equal(t, e, fmt.Sprintf("%v", v), "Module string is invalid: %v", v) - }