Skip to content

Commit 5b41161

Browse files
chore: log average and assessed thresholds
when calculating the average an applying the deviations it would be nice to also see the assessed values. this commit makes the descheduler logs these values when using level 3.
1 parent 7542cac commit 5b41161

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

pkg/framework/plugins/nodeutilization/highnodeutilization.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type HighNodeUtilization struct {
4646
handle frameworktypes.Handle
4747
args *HighNodeUtilizationArgs
4848
podFilter func(pod *v1.Pod) bool
49-
criteria []any
5049
resourceNames []v1.ResourceName
5150
highThresholds api.ResourceThresholds
5251
usageClient usageClient
@@ -74,13 +73,6 @@ func NewHighNodeUtilization(
7473
highThresholds[rname] = MaxResourcePercentage
7574
}
7675

77-
// criteria is a list of thresholds that are used to determine if a node
78-
// is underutilized. it is used only for logging purposes.
79-
criteria := []any{}
80-
for rname, rvalue := range args.Thresholds {
81-
criteria = append(criteria, rname, rvalue)
82-
}
83-
8476
podFilter, err := podutil.
8577
NewOptions().
8678
WithFilter(handle.Evictor().Filter).
@@ -106,7 +98,6 @@ func NewHighNodeUtilization(
10698
args: args,
10799
resourceNames: resourceNames,
108100
highThresholds: highThresholds,
109-
criteria: criteria,
110101
podFilter: podFilter,
111102
usageClient: newRequestedUsageClient(
112103
resourceNames,
@@ -197,7 +188,7 @@ func (h *HighNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fr
197188

198189
lowNodes, schedulableNodes := nodeInfos[0], nodeInfos[1]
199190

200-
klog.V(1).InfoS("Criteria for a node below target utilization", h.criteria...)
191+
klog.V(1).InfoS("Criteria for a node below target utilization", thresholdsToKeysAndValues(h.args.Thresholds)...)
201192
klog.V(1).InfoS("Number of underutilized nodes", "totalNumber", len(lowNodes))
202193

203194
if len(lowNodes) == 0 {

pkg/framework/plugins/nodeutilization/lownodeutilization.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ type LowNodeUtilization struct {
4646
handle frameworktypes.Handle
4747
args *LowNodeUtilizationArgs
4848
podFilter func(pod *v1.Pod) bool
49-
underCriteria []any
50-
overCriteria []any
5149
resourceNames []v1.ResourceName
5250
extendedResourceNames []v1.ResourceName
5351
usageClient usageClient
@@ -92,16 +90,6 @@ func NewLowNodeUtilization(
9290
)
9391
}
9492

95-
// underCriteria and overCriteria are slices used for logging purposes.
96-
// we assemble them only once.
97-
underCriteria, overCriteria := []any{}, []any{}
98-
for name := range args.Thresholds {
99-
underCriteria = append(underCriteria, name, args.Thresholds[name])
100-
}
101-
for name := range args.TargetThresholds {
102-
overCriteria = append(overCriteria, name, args.TargetThresholds[name])
103-
}
104-
10593
podFilter, err := podutil.
10694
NewOptions().
10795
WithFilter(handle.Evictor().Filter).
@@ -127,8 +115,6 @@ func NewLowNodeUtilization(
127115
return &LowNodeUtilization{
128116
handle: handle,
129117
args: args,
130-
underCriteria: underCriteria,
131-
overCriteria: overCriteria,
132118
resourceNames: resourceNames,
133119
extendedResourceNames: extendedResourceNames,
134120
podFilter: podFilter,
@@ -255,9 +241,9 @@ func (l *LowNodeUtilization) Balance(ctx context.Context, nodes []*v1.Node) *fra
255241
lowNodes, highNodes := nodeInfos[0], nodeInfos[1]
256242

257243
// log messages for nodes with low and high utilization
258-
klog.V(1).InfoS("Criteria for a node under utilization", l.underCriteria...)
244+
klog.V(1).InfoS("Criteria for a node under utilization", thresholdsToKeysAndValues(l.args.Thresholds)...)
259245
klog.V(1).InfoS("Number of underutilized nodes", "totalNumber", len(lowNodes))
260-
klog.V(1).InfoS("Criteria for a node above target utilization", l.overCriteria...)
246+
klog.V(1).InfoS("Criteria for a node above target utilization", thresholdsToKeysAndValues(l.args.TargetThresholds)...)
261247
klog.V(1).InfoS("Number of overutilized nodes", "totalNumber", len(highNodes))
262248

263249
if len(lowNodes) == 0 {

pkg/framework/plugins/nodeutilization/nodeutilization.go

+37-15
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ func getNodeUsageSnapshot(
130130
return nodesMap, nodesUsageMap, podListMap
131131
}
132132

133+
// thresholdsToKeysAndValues converts a ResourceThresholds into a list of keys
134+
// and values. this is useful for logging.
135+
func thresholdsToKeysAndValues(thresholds api.ResourceThresholds) []any {
136+
result := []any{}
137+
for name, value := range thresholds {
138+
result = append(result, name, fmt.Sprintf("%.2f%%", value))
139+
}
140+
return result
141+
}
142+
133143
// usageToKeysAndValues converts a ReferencedResourceList into a list of
134144
// keys and values. this is useful for logging.
135145
func usageToKeysAndValues(usage api.ReferencedResourceList) []any {
@@ -487,25 +497,37 @@ func assessNodesUsagesAndRelativeThresholds(
487497
rawUsages, rawCapacities, ResourceUsageToResourceThreshold,
488498
)
489499

490-
// calculate the average usage and then deviate it according to the
491-
// user provided thresholds.
500+
// calculate the average usage.
492501
average := normalizer.Average(usage)
502+
klog.V(3).InfoS(
503+
"Assessed average usage",
504+
thresholdsToKeysAndValues(average)...,
505+
)
506+
507+
// decrease the provided threshold from the average to get the low
508+
// span. also make sure the resulting values are between 0 and 100.
509+
lowSpan = normalizer.Clamp(
510+
normalizer.Sum(average, normalizer.Negate(lowSpan)), 0, 100,
511+
)
512+
klog.V(3).InfoS(
513+
"Assessed thresholds for underutilized nodes",
514+
thresholdsToKeysAndValues(lowSpan)...,
515+
)
516+
517+
// increase the provided threshold from the average to get the high
518+
// span. also make sure the resulting values are between 0 and 100.
519+
highSpan = normalizer.Clamp(
520+
normalizer.Sum(average, highSpan), 0, 100,
521+
)
522+
klog.V(3).InfoS(
523+
"Assessed thresholds for overutilized nodes",
524+
thresholdsToKeysAndValues(highSpan)...,
525+
)
493526

494-
// calculate the average usage and then deviate it according to the
495-
// user provided thresholds. We also ensure that the value after the
496-
// deviation is at least 1%. this call also replicates the thresholds
497-
// across all nodes.
527+
// replicate the same assessed thresholds to all nodes.
498528
thresholds := normalizer.Replicate(
499529
slices.Collect(maps.Keys(usage)),
500-
normalizer.Map(
501-
[]api.ResourceThresholds{
502-
normalizer.Sum(average, normalizer.Negate(lowSpan)),
503-
normalizer.Sum(average, highSpan),
504-
},
505-
func(thresholds api.ResourceThresholds) api.ResourceThresholds {
506-
return normalizer.Clamp(thresholds, 0, 100)
507-
},
508-
),
530+
[]api.ResourceThresholds{lowSpan, highSpan},
509531
)
510532

511533
return usage, thresholds

0 commit comments

Comments
 (0)