diff --git a/pkg/koordlet/metricsadvisor/metrics_advisor.go b/pkg/koordlet/metricsadvisor/metrics_advisor.go index 86d3604d6..c804387b3 100644 --- a/pkg/koordlet/metricsadvisor/metrics_advisor.go +++ b/pkg/koordlet/metricsadvisor/metrics_advisor.go @@ -109,16 +109,28 @@ func (m *metricAdvisor) Run(stopCh <-chan struct{}) error { } func (m *metricAdvisor) setup() { - for _, device := range m.context.DeviceCollectors { - device.Setup(m.context) + for name, dc := range m.context.DeviceCollectors { + if !dc.Enabled() { + klog.V(4).Infof("device collector %v is not enabled, skip setup", name) + continue + } + dc.Setup(m.context) } - for _, collector := range m.context.Collectors { + for name, collector := range m.context.Collectors { + if !collector.Enabled() { + klog.V(4).Infof("collector %v is not enabled, skip setup", name) + continue + } collector.Setup(m.context) } } func (m *metricAdvisor) shutdown() { - for _, dc := range m.context.DeviceCollectors { + for name, dc := range m.context.DeviceCollectors { + if !dc.Enabled() { + klog.V(4).Infof("device collector %v is not enabled, skip shutdown", name) + continue + } dc.Shutdown() } } diff --git a/pkg/koordlet/util/cpuinfo.go b/pkg/koordlet/util/cpuinfo.go index 67a5f1c64..f5a720f70 100644 --- a/pkg/koordlet/util/cpuinfo.go +++ b/pkg/koordlet/util/cpuinfo.go @@ -117,6 +117,9 @@ func getHyperThreadEnabled() (bool, error) { klog.V(5).Infof("read %s err: %v, try `lscpu`", hyperThreadEnabledPath, err) lsCPUStr, err := lsCPU("-y") + if err != nil { + return false, err + } for _, line := range strings.Split(lsCPUStr, "\n") { items := strings.Split(line, ":") if len(items) != 2 || !strings.Contains(items[0], "Thread(s) per core") { @@ -128,7 +131,7 @@ func getHyperThreadEnabled() (bool, error) { } return threadsPerCore > 1, nil } - klog.Warningf("failed to get HyperThreadEnabled, considered as disabled, err: %s", err) + klog.Warningf("failed to get HyperThreadEnabled, considered as disabled, lscpu output: %s", lsCPUStr) return false, nil } @@ -179,7 +182,7 @@ func lsCPU(option string) (string, error) { executable, err := exec.LookPath("lscpu") if err != nil { - return "", err + return "", fmt.Errorf("failed to lookup lscpu path, err: %w", err) } output, err := exec.CommandContext(ctx, executable, option).Output() if err != nil {