Skip to content

Commit 7019cce

Browse files
committed
feat(disable-power-model): Clean unnecessary model disabling code
Metrics that have source "trained_power_model" can be disabled by preventing them from being exported to prometheus. This PR removes verbose code that disables models from being created when DisablePowerModel is enabled as this is unnecessary. Signed-off-by: Kaiyi <[email protected]>
1 parent d984b79 commit 7019cce

File tree

9 files changed

+16
-50
lines changed

9 files changed

+16
-50
lines changed

pkg/metrics/metricfactory/metric_factory.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ func EnergyMetricsPromDesc(context string) (descriptions map[string]*prometheus.
4141
if gpu := acc.GetActiveAcceleratorByType(config.GPU); gpu != nil {
4242
source = gpu.Device().Name()
4343
}
44-
} else if strings.Contains(name, config.PLATFORM) && platform.IsSystemCollectionSupported() {
44+
} else if platform.IsSystemCollectionSupported() && strings.Contains(name, config.PLATFORM) {
4545
source = platform.GetSourceName()
46-
} else if strings.Contains(allComponents, name) && components.IsSystemCollectionSupported() {
46+
} else if components.IsSystemCollectionSupported() && strings.Contains(allComponents, name) {
4747
// TODO: need to update condition when we have more type of energy metric such as network, disk.
4848
source = components.GetSourceName()
4949
}
50-
// check if trained power model in use here
5150
if !config.DisablePowerModels() || source != modeltypes.TrainedPowerModelSource {
5251
descriptions[name] = energyMetricsPromDesc(context, name, source)
5352
}

pkg/model/estimator/local/ratio.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ type RatioPowerModel struct {
7070
processFeatureValues [][]float64 // metrics per process/process/pod
7171
nodeFeatureValues []float64 // node metrics
7272
// xidx represents the features slide window position
73-
xidx int
74-
enabled bool
73+
xidx int
7574
}
7675

7776
func (r *RatioPowerModel) getPowerByRatio(processIdx, resUsageFeature, nodePowerFeature int, numProcesses float64) uint64 {
@@ -238,12 +237,7 @@ func (r *RatioPowerModel) Train() error {
238237

239238
// IsEnabled returns if ratio power model is active or not
240239
func (r *RatioPowerModel) IsEnabled() bool {
241-
return r.enabled
242-
}
243-
244-
// SetEnabled modifies the enabled flag to activate or deactivate the ratio power model
245-
func (r *RatioPowerModel) SetEnabled(enable bool) {
246-
r.enabled = enable
240+
return true
247241
}
248242

249243
// GetModelType returns the model type

pkg/model/estimator/local/ratio_model_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ var _ = Describe("Test Ratio Unit", func() {
8787
config.IdleEnergyInGPU, // for idle GPU power consumption
8888
},
8989
}
90-
model.SetEnabled(true)
9190
model.ResetSampleIdx()
9291
// Add process metrics
9392
for _, c := range processStats {

pkg/model/estimator/local/regressor/regressor.go

-5
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,6 @@ func (r *Regressor) IsEnabled() bool {
406406
return r.enabled
407407
}
408408

409-
// SetEnabled modifies the enabled flag to activate or deactivate the regressor power model
410-
func (r *Regressor) SetEnabled(enable bool) {
411-
r.enabled = enable
412-
}
413-
414409
// GetModelType returns the model type
415410
func (r *Regressor) GetModelType() types.ModelType {
416411
return types.Regressor

pkg/model/estimator/sidecar/estimate.go

-5
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,6 @@ func (c *EstimatorSidecar) IsEnabled() bool {
262262
return c.enabled
263263
}
264264

265-
// SetEnabled modifies the enabled flag to activate or deactivate the power model
266-
func (c *EstimatorSidecar) SetEnabled(enable bool) {
267-
c.enabled = enable
268-
}
269-
270265
// GetModelType returns the model type
271266
func (c *EstimatorSidecar) GetModelType() types.ModelType {
272267
return types.EstimatorSidecar

pkg/model/model.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ type PowerModelInterface interface {
5252
Train() error
5353
// IsEnabled returns true if the power model was trained and is active
5454
IsEnabled() bool
55-
// SetEnabled modifies the enabled flag to activate or deactivate the power model
56-
SetEnabled(enable bool)
5755
// GetModelType returns if the model is Ratio, Regressor or EstimatorSidecar
5856
GetModelType() types.ModelType
5957
// GetProcessFeatureNamesList returns the list of process features that the model was configured to use
@@ -90,7 +88,6 @@ func createPowerModelEstimator(modelConfig *types.ModelConfig) (PowerModelInterf
9088
ProcessFeatureNames: modelConfig.ProcessFeatureNames,
9189
NodeFeatureNames: modelConfig.NodeFeatureNames,
9290
}
93-
model.SetEnabled(true)
9491
klog.V(3).Infof("Using Power Model Ratio")
9592
return model, nil
9693

@@ -192,17 +189,15 @@ func getModelConfigKey(modelItem, attribute string) string {
192189
// getPowerModelType return the model type for a given power source, such as platform or components power sources
193190
// The default power model type is Ratio
194191
func getPowerModelType(powerSourceTarget string) (modelType types.ModelType) {
195-
if !config.DisablePowerModels() {
196-
useEstimatorSidecarStr := config.ModelConfigValues(getModelConfigKey(powerSourceTarget, config.EstimatorEnabledKey))
197-
if strings.EqualFold(useEstimatorSidecarStr, "true") {
198-
modelType = types.EstimatorSidecar
199-
return
200-
}
201-
useLocalRegressor := config.ModelConfigValues(getModelConfigKey(powerSourceTarget, config.LocalRegressorEnabledKey))
202-
if strings.EqualFold(useLocalRegressor, "true") {
203-
modelType = types.Regressor
204-
return
205-
}
192+
useEstimatorSidecarStr := config.ModelConfigValues(getModelConfigKey(powerSourceTarget, config.EstimatorEnabledKey))
193+
if strings.EqualFold(useEstimatorSidecarStr, "true") {
194+
modelType = types.EstimatorSidecar
195+
return
196+
}
197+
useLocalRegressor := config.ModelConfigValues(getModelConfigKey(powerSourceTarget, config.LocalRegressorEnabledKey))
198+
if strings.EqualFold(useLocalRegressor, "true") {
199+
modelType = types.Regressor
200+
return
206201
}
207202
// set the default node power model as Regressor
208203
if powerSourceTarget == config.NodePlatformPowerKey() || powerSourceTarget == config.NodeComponentsPowerKey() {

pkg/model/node_component_energy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func createNodeComponentPowerModelConfig(nodeFeatureNames []string) *types.Model
4949
// CreateNodeComponentPowerEstimatorModel only create a new power model estimator if node components power metrics are not available
5050
func CreateNodeComponentPowerEstimatorModel(nodeFeatureNames []string) {
5151
var err error
52-
if !components.IsSystemCollectionSupported() && !config.DisablePowerModels() {
52+
if !components.IsSystemCollectionSupported() {
5353
modelConfig := createNodeComponentPowerModelConfig(nodeFeatureNames)
5454
// init func for NodeComponentPower
5555
nodeComponentPowerModel, err = createPowerModelEstimator(modelConfig)
@@ -59,7 +59,7 @@ func CreateNodeComponentPowerEstimatorModel(nodeFeatureNames []string) {
5959
klog.Infof("Failed to create %s Power Model to estimate Node Component Power: %v\n", modelConfig.ModelType.String()+"/"+modelConfig.ModelOutputType.String(), err)
6060
}
6161
} else {
62-
klog.Infof("Skipping creation of Node Component Power Model since the system collection is supported or models are disabled")
62+
klog.Infof("Skipping creation of Node Component Power Model since the system collection is supported")
6363
return
6464
}
6565
}

pkg/model/node_platform_energy.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var nodePlatformPowerModel PowerModelInterface
3737
func CreateNodePlatformPoweEstimatorModel(nodeFeatureNames []string) {
3838
systemMetaDataFeatureNames := node.MetadataFeatureNames()
3939
systemMetaDataFeatureValues := node.MetadataFeatureValues()
40-
if !platform.IsSystemCollectionSupported() && !config.DisablePowerModels() {
40+
if !platform.IsSystemCollectionSupported() {
4141
modelConfig := CreatePowerModelConfig(config.NodePlatformPowerKey())
4242
if modelConfig.InitModelURL == "" {
4343
modelConfig.InitModelFilepath = config.GetDefaultPowerModelURL(modelConfig.ModelOutputType.String(), types.PlatformEnergySource)
@@ -54,8 +54,6 @@ func CreateNodePlatformPoweEstimatorModel(nodeFeatureNames []string) {
5454
} else {
5555
klog.Infof("Failed to create %s Power Model to estimate Node Platform Power: %v\n", modelConfig.ModelType.String()+"/"+modelConfig.ModelOutputType.String(), err)
5656
}
57-
} else {
58-
klog.Infof("Skipping creation of Node Platform Power Model since the system collection is supported or models are disabled")
5957
}
6058
}
6159

pkg/model/process_energy.go

-9
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ import (
2525
"github.com/sustainable-computing-io/kepler/pkg/model/types"
2626
"github.com/sustainable-computing-io/kepler/pkg/node"
2727
acc "github.com/sustainable-computing-io/kepler/pkg/sensors/accelerator"
28-
"github.com/sustainable-computing-io/kepler/pkg/sensors/components"
2928
"github.com/sustainable-computing-io/kepler/pkg/sensors/components/source"
30-
"github.com/sustainable-computing-io/kepler/pkg/sensors/platform"
3129
"github.com/sustainable-computing-io/kepler/pkg/utils"
3230
"k8s.io/klog/v2"
3331
)
@@ -120,18 +118,11 @@ func CreateProcessPowerEstimatorModel(processFeatureNames []string) {
120118
modelConfig := createProcessPowerModelConfig(k, processFeatureNames, v)
121119
modelConfig.IsNodePowerModel = false
122120
m, err := createPowerModelEstimator(modelConfig)
123-
klog.V(5).Infof("Generating Process models now")
124121
switch k {
125122
case config.ProcessPlatformPowerKey():
126123
processPlatformPowerModel = m
127-
if !platform.IsSystemCollectionSupported() && config.DisablePowerModels() {
128-
processPlatformPowerModel.SetEnabled(false)
129-
}
130124
case config.ProcessComponentsPowerKey():
131125
processComponentPowerModel = m
132-
if !components.IsSystemCollectionSupported() && config.DisablePowerModels() {
133-
processComponentPowerModel.SetEnabled(false)
134-
}
135126
}
136127
if err != nil {
137128
klog.Infof("Failed to create %s Power Model to estimate %s Power: %v\n", modelConfig.ModelType.String()+"/"+modelConfig.ModelOutputType.String(), k, err)

0 commit comments

Comments
 (0)