Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed May 23, 2024
1 parent 18614c3 commit c205d34
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 87 deletions.
12 changes: 10 additions & 2 deletions cmd/healthchecker/health_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ func main() {
}
})
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.CommandLine.MarkHidden("vmodule")
pflag.CommandLine.MarkHidden("logtostderr")
err := pflag.CommandLine.MarkHidden("vmodule")
if err != nil {
fmt.Println(err)
os.Exit(int(types.Unknown))
}
err = pflag.CommandLine.MarkHidden("logtostderr")
if err != nil {
fmt.Println(err)
os.Exit(int(types.Unknown))
}

hco := options.NewHealthCheckerOptions()
hco.AddFlags(pflag.CommandLine)
Expand Down
2 changes: 1 addition & 1 deletion cmd/healthchecker/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
"The component to check health for. Supports kubelet, docker, kube-proxy, and cri")
// Deprecated: For backward compatibility on linux environment. Going forward "service" will be used instead of systemd-service
if runtime.GOOS == "linux" {
fs.MarkDeprecated("systemd-service", "please use --service flag instead")
_ = fs.MarkDeprecated("systemd-service", "please use --service flag instead")
fs.StringVar(&hco.Service, "systemd-service", "",
"The underlying service responsible for the component. Set to the corresponding component for docker and kubelet, containerd for cri.")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/nodeproblemdetector/node_problem_detector_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func main() {
}
})
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.CommandLine.MarkHidden("vmodule")
pflag.CommandLine.MarkHidden("logtostderr")
_ = pflag.CommandLine.MarkHidden("vmodule")
_ = pflag.CommandLine.MarkHidden("logtostderr")

npdo := options.NewNodeProblemDetectorOptions()
npdo.AddFlags(pflag.CommandLine)
Expand Down
4 changes: 2 additions & 2 deletions cmd/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func NewNodeProblemDetectorOptions() *NodeProblemDetectorOptions {
func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringSliceVar(&npdo.SystemLogMonitorConfigPaths, "system-log-monitors",
[]string{}, "List of paths to system log monitor config files, comma separated.")
fs.MarkDeprecated("system-log-monitors", "replaced by --config.system-log-monitor. NPD will panic if both --system-log-monitors and --config.system-log-monitor are set.")
_ = fs.MarkDeprecated("system-log-monitors", "replaced by --config.system-log-monitor. NPD will panic if both --system-log-monitors and --config.system-log-monitor are set.")
fs.StringSliceVar(&npdo.CustomPluginMonitorConfigPaths, "custom-plugin-monitors",
[]string{}, "List of paths to custom plugin monitor config files, comma separated.")
fs.MarkDeprecated("custom-plugin-monitors", "replaced by --config.custom-plugin-monitor. NPD will panic if both --custom-plugin-monitors and --config.custom-plugin-monitor are set.")
_ = fs.MarkDeprecated("custom-plugin-monitors", "replaced by --config.custom-plugin-monitor. NPD will panic if both --custom-plugin-monitors and --config.custom-plugin-monitor are set.")
fs.BoolVar(&npdo.EnableK8sExporter, "enable-k8s-exporter", true, "Enables reporting to Kubernetes API server.")
fs.StringVar(&npdo.EventNamespace, "event-namespace", "", "Namespace for recorded Kubernetes events.")
fs.StringVar(&npdo.ApiServerOverride, "apiserver-override",
Expand Down
5 changes: 4 additions & 1 deletion pkg/custompluginmonitor/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func TestNewPluginRun(t *testing.T) {
utMeta := v
t.Run(desp, func(t *testing.T) {
conf := cpmtypes.CustomPluginConfig{}
(&conf).ApplyConfiguration()
err := (&conf).ApplyConfiguration()
if err != nil {
t.Errorf("Error in applying configuration: %v", err)
}
p := Plugin{config: conf}
gotExitStatus, gotOutput := p.run(utMeta.Rule)
// cut at position max_output_length if expected output is longer than max_output_length bytes
Expand Down
5 changes: 4 additions & 1 deletion pkg/custompluginmonitor/types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ func TestCustomPluginConfigApplyConfiguration(t *testing.T) {
}

for desp, utMeta := range utMetas {
(&utMeta.Orig).ApplyConfiguration()
err := (&utMeta.Orig).ApplyConfiguration()
if err != nil {
t.Errorf("Error in apply configuration for %q. Error: %v", desp, err)
}
if !reflect.DeepEqual(utMeta.Orig, utMeta.Wanted) {
t.Errorf("Error in apply configuration for %q", desp)
t.Errorf("Wanted: %+v. \nGot: %+v", utMeta.Wanted, utMeta.Orig)
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporters/k8sexporter/k8s_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (ke *k8sExporter) startHTTPReporting(npdo *options.NodeProblemDetectorOptio
// logic in the future.
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
_, _ = w.Write([]byte("ok"))
})

// Add the handler to serve condition http request.
Expand Down
1 change: 0 additions & 1 deletion pkg/exporters/prometheusexporter/prometheus_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ func NewExporterOrDie(npdo *options.NodeProblemDetectorOptions) types.Exporter {
// ExportProblems does nothing.
// Prometheus exporter only exports metrics.
func (pe *prometheusExporter) ExportProblems(status *types.Status) {
return
}
1 change: 0 additions & 1 deletion pkg/exporters/stackdriver/stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ func (se *stackdriverExporter) populateMetadataOrDie() {
// ExportProblems does nothing.
// Stackdriver exporter only exports metrics.
func (se *stackdriverExporter) ExportProblems(status *types.Status) {
return
}

type commandLineOptions struct {
Expand Down
10 changes: 8 additions & 2 deletions pkg/problemmetrics/problem_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ func TestNewProblem(t *testing.T) {
pmm, fakeProblemCounter, fakeProblemGauge := NewProblemMetricsManagerStub()

for idx, reason := range test.reasons {
pmm.IncrementProblemCounter(reason, test.counts[idx])
err := pmm.IncrementProblemCounter(reason, test.counts[idx])
if err != nil {
t.Fatalf("failed to increment problem counter: %v", err)
}
}

gotMetrics := append(fakeProblemCounter.ListMetrics(), fakeProblemGauge.ListMetrics()...)
Expand Down Expand Up @@ -266,7 +269,10 @@ func TestSetProblemGauge(t *testing.T) {
pmm, fakeProblemCounter, fakeProblemGauge := NewProblemMetricsManagerStub()

for _, argument := range test.arguments {
pmm.SetProblemGauge(argument.problemType, argument.reason, argument.value)
err := pmm.SetProblemGauge(argument.problemType, argument.reason, argument.value)
if err != nil {
t.Fatalf("failed to set problem gauge: %v", err)
}
}

gotMetrics := append(fakeProblemCounter.ListMetrics(), fakeProblemGauge.ListMetrics()...)
Expand Down
4 changes: 2 additions & 2 deletions pkg/systemlogmonitor/log_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type logBuffer struct {
// lines of patterns we support.
func NewLogBuffer(maxLines int) *logBuffer {
return &logBuffer{
buffer: make([]*types.Log, maxLines, maxLines),
msg: make([]string, maxLines, maxLines),
buffer: make([]*types.Log, maxLines),
msg: make([]string, maxLines),
max: maxLines,
}
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/systemstatsmonitor/cpu_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,34 @@ func (cc *cpuCollector) recordUsage() {
}
timersStat := timersStats[0]

cc.mUsageTime.Record(map[string]string{stateLabel: "user"}, clockTick*timersStat.User-cc.lastUsageTime["user"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "user"}, clockTick*timersStat.User-cc.lastUsageTime["user"])
cc.lastUsageTime["user"] = clockTick * timersStat.User

cc.mUsageTime.Record(map[string]string{stateLabel: "system"}, clockTick*timersStat.System-cc.lastUsageTime["system"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "system"}, clockTick*timersStat.System-cc.lastUsageTime["system"])
cc.lastUsageTime["system"] = clockTick * timersStat.System

cc.mUsageTime.Record(map[string]string{stateLabel: "idle"}, clockTick*timersStat.Idle-cc.lastUsageTime["idle"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "idle"}, clockTick*timersStat.Idle-cc.lastUsageTime["idle"])
cc.lastUsageTime["idle"] = clockTick * timersStat.Idle

cc.mUsageTime.Record(map[string]string{stateLabel: "nice"}, clockTick*timersStat.Nice-cc.lastUsageTime["nice"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "nice"}, clockTick*timersStat.Nice-cc.lastUsageTime["nice"])
cc.lastUsageTime["nice"] = clockTick * timersStat.Nice

cc.mUsageTime.Record(map[string]string{stateLabel: "iowait"}, clockTick*timersStat.Iowait-cc.lastUsageTime["iowait"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "iowait"}, clockTick*timersStat.Iowait-cc.lastUsageTime["iowait"])
cc.lastUsageTime["iowait"] = clockTick * timersStat.Iowait

cc.mUsageTime.Record(map[string]string{stateLabel: "irq"}, clockTick*timersStat.Irq-cc.lastUsageTime["irq"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "irq"}, clockTick*timersStat.Irq-cc.lastUsageTime["irq"])
cc.lastUsageTime["irq"] = clockTick * timersStat.Irq

cc.mUsageTime.Record(map[string]string{stateLabel: "softirq"}, clockTick*timersStat.Softirq-cc.lastUsageTime["softirq"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "softirq"}, clockTick*timersStat.Softirq-cc.lastUsageTime["softirq"])
cc.lastUsageTime["softirq"] = clockTick * timersStat.Softirq

cc.mUsageTime.Record(map[string]string{stateLabel: "steal"}, clockTick*timersStat.Steal-cc.lastUsageTime["steal"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "steal"}, clockTick*timersStat.Steal-cc.lastUsageTime["steal"])
cc.lastUsageTime["steal"] = clockTick * timersStat.Steal

cc.mUsageTime.Record(map[string]string{stateLabel: "guest"}, clockTick*timersStat.Guest-cc.lastUsageTime["guest"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "guest"}, clockTick*timersStat.Guest-cc.lastUsageTime["guest"])
cc.lastUsageTime["guest"] = clockTick * timersStat.Guest

cc.mUsageTime.Record(map[string]string{stateLabel: "guest_nice"}, clockTick*timersStat.GuestNice-cc.lastUsageTime["guest_nice"])
_ = cc.mUsageTime.Record(map[string]string{stateLabel: "guest_nice"}, clockTick*timersStat.GuestNice-cc.lastUsageTime["guest_nice"])
cc.lastUsageTime["guest_nice"] = clockTick * timersStat.GuestNice
}

Expand Down
40 changes: 22 additions & 18 deletions pkg/systemstatsmonitor/cpu_collector_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ func (cc *cpuCollector) recordLoad() {
}

if cc.mRunnableTaskCount != nil {
cc.mRunnableTaskCount.Record(map[string]string{}, loadAvg.Load1)
_ = cc.mRunnableTaskCount.Record(map[string]string{}, loadAvg.Load1)
}
if cc.mCpuLoad1m != nil {
cc.mCpuLoad1m.Record(map[string]string{}, loadAvg.Load1)
_ = cc.mCpuLoad1m.Record(map[string]string{}, loadAvg.Load1)
}
if cc.mCpuLoad5m != nil {
cc.mCpuLoad5m.Record(map[string]string{}, loadAvg.Load5)
_ = cc.mCpuLoad5m.Record(map[string]string{}, loadAvg.Load5)
}
if cc.mCpuLoad15m != nil {
cc.mCpuLoad15m.Record(map[string]string{}, loadAvg.Load15)
_ = cc.mCpuLoad15m.Record(map[string]string{}, loadAvg.Load15)
}
}

Expand All @@ -62,26 +62,30 @@ func (cc *cpuCollector) recordSystemStats() {
}

fs, err := procfs.NewFS(cc.procPath)
if err != nil {
klog.Errorf("Failed to open procfs: %v", err)
return
}
stats, err := fs.Stat()
if err != nil {
klog.Errorf("Failed to retrieve cpu/process stats: %v", err)
return
}

if cc.mSystemProcessesTotal != nil {
cc.mSystemProcessesTotal.Record(map[string]string{}, int64(stats.ProcessCreated))
_ = cc.mSystemProcessesTotal.Record(map[string]string{}, int64(stats.ProcessCreated))
}

if cc.mSystemProcsRunning != nil {
cc.mSystemProcsRunning.Record(map[string]string{}, int64(stats.ProcessesRunning))
_ = cc.mSystemProcsRunning.Record(map[string]string{}, int64(stats.ProcessesRunning))
}

if cc.mSystemProcsBlocked != nil {
cc.mSystemProcsBlocked.Record(map[string]string{}, int64(stats.ProcessesBlocked))
_ = cc.mSystemProcsBlocked.Record(map[string]string{}, int64(stats.ProcessesBlocked))
}

if cc.mSystemInterruptsTotal != nil {
cc.mSystemInterruptsTotal.Record(map[string]string{}, int64(stats.IRQTotal))
_ = cc.mSystemInterruptsTotal.Record(map[string]string{}, int64(stats.IRQTotal))
}

if cc.mSystemCPUStat != nil {
Expand All @@ -90,25 +94,25 @@ func (cc *cpuCollector) recordSystemStats() {
tags[cpuLabel] = fmt.Sprintf("cpu%d", i)

tags[stageLabel] = "user"
cc.mSystemCPUStat.Record(tags, c.User)
_ = cc.mSystemCPUStat.Record(tags, c.User)
tags[stageLabel] = "nice"
cc.mSystemCPUStat.Record(tags, c.Nice)
_ = cc.mSystemCPUStat.Record(tags, c.Nice)
tags[stageLabel] = "system"
cc.mSystemCPUStat.Record(tags, c.System)
_ = cc.mSystemCPUStat.Record(tags, c.System)
tags[stageLabel] = "idle"
cc.mSystemCPUStat.Record(tags, c.Idle)
_ = cc.mSystemCPUStat.Record(tags, c.Idle)
tags[stageLabel] = "iowait"
cc.mSystemCPUStat.Record(tags, c.Iowait)
_ = cc.mSystemCPUStat.Record(tags, c.Iowait)
tags[stageLabel] = "iRQ"
cc.mSystemCPUStat.Record(tags, c.IRQ)
_ = cc.mSystemCPUStat.Record(tags, c.IRQ)
tags[stageLabel] = "softIRQ"
cc.mSystemCPUStat.Record(tags, c.SoftIRQ)
_ = cc.mSystemCPUStat.Record(tags, c.SoftIRQ)
tags[stageLabel] = "steal"
cc.mSystemCPUStat.Record(tags, c.Steal)
_ = cc.mSystemCPUStat.Record(tags, c.Steal)
tags[stageLabel] = "guest"
cc.mSystemCPUStat.Record(tags, c.Guest)
_ = cc.mSystemCPUStat.Record(tags, c.Guest)
tags[stageLabel] = "guestNice"
cc.mSystemCPUStat.Record(tags, c.GuestNice)
_ = cc.mSystemCPUStat.Record(tags, c.GuestNice)
}
}
}
28 changes: 14 additions & 14 deletions pkg/systemstatsmonitor/disk_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ func (dc *diskCollector) recordIOCounters(ioCountersStats map[string]disk.IOCoun
dc.lastWeightedIO[deviceName] = ioCountersStat.WeightedIO

if dc.mIOTime != nil {
dc.mIOTime.Record(tags, int64(ioCountersStat.IoTime-lastIOTime))
_ = dc.mIOTime.Record(tags, int64(ioCountersStat.IoTime-lastIOTime))
}
if dc.mWeightedIO != nil {
dc.mWeightedIO.Record(tags, int64(ioCountersStat.WeightedIO-lastWeightedIO))
_ = dc.mWeightedIO.Record(tags, int64(ioCountersStat.WeightedIO-lastWeightedIO))
}
if historyExist {
avgQueueLen := float64(0.0)
Expand All @@ -200,47 +200,47 @@ func (dc *diskCollector) recordIOCounters(ioCountersStats map[string]disk.IOCoun
avgQueueLen = float64(ioCountersStat.WeightedIO-lastWeightedIO) / diffSampleTimeMs
}
if dc.mAvgQueueLen != nil {
dc.mAvgQueueLen.Record(tags, avgQueueLen)
_ = dc.mAvgQueueLen.Record(tags, avgQueueLen)
}
}

// Attach label {"device_name": deviceName, "direction": "read"} to the following metrics.
tags = map[string]string{deviceNameLabel: deviceName, directionLabel: "read"}

if dc.mOpsCount != nil {
dc.mOpsCount.Record(tags, int64(ioCountersStat.ReadCount-dc.lastReadCount[deviceName]))
_ = dc.mOpsCount.Record(tags, int64(ioCountersStat.ReadCount-dc.lastReadCount[deviceName]))
dc.lastReadCount[deviceName] = ioCountersStat.ReadCount
}
if dc.mMergedOpsCount != nil {
dc.mMergedOpsCount.Record(tags, int64(ioCountersStat.MergedReadCount-dc.lastMergedReadCount[deviceName]))
_ = dc.mMergedOpsCount.Record(tags, int64(ioCountersStat.MergedReadCount-dc.lastMergedReadCount[deviceName]))
dc.lastMergedReadCount[deviceName] = ioCountersStat.MergedReadCount
}
if dc.mOpsBytes != nil {
dc.mOpsBytes.Record(tags, int64(ioCountersStat.ReadBytes-dc.lastReadBytes[deviceName]))
_ = dc.mOpsBytes.Record(tags, int64(ioCountersStat.ReadBytes-dc.lastReadBytes[deviceName]))
dc.lastReadBytes[deviceName] = ioCountersStat.ReadBytes
}
if dc.mOpsTime != nil {
dc.mOpsTime.Record(tags, int64(ioCountersStat.ReadTime-dc.lastReadTime[deviceName]))
_ = dc.mOpsTime.Record(tags, int64(ioCountersStat.ReadTime-dc.lastReadTime[deviceName]))
dc.lastReadTime[deviceName] = ioCountersStat.ReadTime
}

// Attach label {"device_name": deviceName, "direction": "write"} to the following metrics.
tags = map[string]string{deviceNameLabel: deviceName, directionLabel: "write"}

if dc.mOpsCount != nil {
dc.mOpsCount.Record(tags, int64(ioCountersStat.WriteCount-dc.lastWriteCount[deviceName]))
_ = dc.mOpsCount.Record(tags, int64(ioCountersStat.WriteCount-dc.lastWriteCount[deviceName]))
dc.lastWriteCount[deviceName] = ioCountersStat.WriteCount
}
if dc.mMergedOpsCount != nil {
dc.mMergedOpsCount.Record(tags, int64(ioCountersStat.MergedWriteCount-dc.lastMergedWriteCount[deviceName]))
_ = dc.mMergedOpsCount.Record(tags, int64(ioCountersStat.MergedWriteCount-dc.lastMergedWriteCount[deviceName]))
dc.lastMergedWriteCount[deviceName] = ioCountersStat.MergedWriteCount
}
if dc.mOpsBytes != nil {
dc.mOpsBytes.Record(tags, int64(ioCountersStat.WriteBytes-dc.lastWriteBytes[deviceName]))
_ = dc.mOpsBytes.Record(tags, int64(ioCountersStat.WriteBytes-dc.lastWriteBytes[deviceName]))
dc.lastWriteBytes[deviceName] = ioCountersStat.WriteBytes
}
if dc.mOpsTime != nil {
dc.mOpsTime.Record(tags, int64(ioCountersStat.WriteTime-dc.lastWriteTime[deviceName]))
_ = dc.mOpsTime.Record(tags, int64(ioCountersStat.WriteTime-dc.lastWriteTime[deviceName]))
dc.lastWriteTime[deviceName] = ioCountersStat.WriteTime
}
}
Expand Down Expand Up @@ -301,10 +301,10 @@ func (dc *diskCollector) collect() {
deviceName := strings.TrimPrefix(partition.Device, "/dev/")
fstype := partition.Fstype
opttypes := strings.Join(partition.Opts, ",")
dc.mBytesUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "free"}, int64(usageStat.Free))
dc.mBytesUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, int64(usageStat.Used))
_ = dc.mBytesUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "free"}, int64(usageStat.Free))
_ = dc.mBytesUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, int64(usageStat.Used))
if dc.mPercentUsed != nil {
dc.mPercentUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, float64(usageStat.UsedPercent))
_ = dc.mPercentUsed.Record(map[string]string{deviceNameLabel: deviceName, fsTypeLabel: fstype, mountOptionLabel: opttypes, stateLabel: "used"}, float64(usageStat.UsedPercent))
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/systemstatsmonitor/host_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ func (hc *hostCollector) collect() {
}

if hc.uptime != nil {
hc.uptime.Record(hc.tags, int64(uptime))
_ = hc.uptime.Record(hc.tags, int64(uptime))
}
}
Loading

0 comments on commit c205d34

Please sign in to comment.