From 34d27b811248f58a3dbdd8e14caafcab47a5f643 Mon Sep 17 00:00:00 2001 From: Sunil Thaha Date: Thu, 29 Aug 2024 12:31:29 +1000 Subject: [PATCH] fix: do not probe for power-meters when disabled Previously, when DISABLE_POWER_METER is set, kepler would still probe system for power-meters resulting in kepler_node_info to produce incorrect results for components_power_source and platform_power_source. E.g. kepler_node_info{ components_power_source="rapl-sysfs", cpu_architecture="Skylake", instance="kepler-latest:8888", job="latest", platform_power_source="acpi", source="os" } The commit fixes this to use the fake power-meters so that kepler_node_info now shows ``` kepler_node_info{components_power_source="estimator", cpu_architecture="Skylake", instance="kepler-dev:8888", job="dev", platform_power_source="none", source="os" } ``` Signed-off-by: Sunil Thaha --- pkg/sensors/components/power.go | 6 ++++++ pkg/sensors/platform/power.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/sensors/components/power.go b/pkg/sensors/components/power.go index 9dc227ddb1..291a08504f 100644 --- a/pkg/sensors/components/power.go +++ b/pkg/sensors/components/power.go @@ -48,6 +48,12 @@ var ( ) func InitPowerImpl() { + if !enabled { + klog.V(1).Infoln("System power collection is disabled, using estimate method") + powerImpl = &source.PowerEstimate{} + return + } + sysfsImpl := &source.PowerSysfs{} if sysfsImpl.IsSystemCollectionSupported() /*&& false*/ { klog.V(1).Infoln("use sysfs to obtain power") diff --git a/pkg/sensors/platform/power.go b/pkg/sensors/platform/power.go index 18b8bdf1bc..bae186eeaf 100644 --- a/pkg/sensors/platform/power.go +++ b/pkg/sensors/platform/power.go @@ -37,8 +37,7 @@ type powerInterface interface { } // dummy satisfies the powerInterface and can be used as the default NOP source -type dummy struct { -} +type dummy struct{} func (dummy) GetName() string { return "none" @@ -47,6 +46,7 @@ func (dummy) GetName() string { func (dummy) IsSystemCollectionSupported() bool { return false } + func (dummy) StopPower() { } @@ -60,6 +60,12 @@ var ( ) func InitPowerImpl() { + if !enabled { + klog.V(1).Infoln("System power collection is disabled, using dummy method") + powerImpl = &dummy{} + return + } + // switch the platform power collector source to hmc if the system architecture is s390x // TODO: add redfish or ipmi as well. if runtime.GOARCH == "s390x" {