Skip to content

Commit 2cce60d

Browse files
authored
Merge pull request #1657 from ricardomaraschini/log
chore: log average and assessed thresholds
2 parents 7542cac + 98e6ed6 commit 2cce60d

File tree

3 files changed

+40
-35
lines changed

3 files changed

+40
-35
lines changed

pkg/framework/plugins/nodeutilization/highnodeutilization.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ func NewHighNodeUtilization(
7474
highThresholds[rname] = MaxResourcePercentage
7575
}
7676

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-
8477
podFilter, err := podutil.
8578
NewOptions().
8679
WithFilter(handle.Evictor().Filter).
@@ -106,7 +99,7 @@ func NewHighNodeUtilization(
10699
args: args,
107100
resourceNames: resourceNames,
108101
highThresholds: highThresholds,
109-
criteria: criteria,
102+
criteria: thresholdsToKeysAndValues(args.Thresholds),
110103
podFilter: podFilter,
111104
usageClient: newRequestedUsageClient(
112105
resourceNames,

pkg/framework/plugins/nodeutilization/lownodeutilization.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ func NewLowNodeUtilization(
9292
)
9393
}
9494

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-
10595
podFilter, err := podutil.
10696
NewOptions().
10797
WithFilter(handle.Evictor().Filter).
@@ -127,8 +117,8 @@ func NewLowNodeUtilization(
127117
return &LowNodeUtilization{
128118
handle: handle,
129119
args: args,
130-
underCriteria: underCriteria,
131-
overCriteria: overCriteria,
120+
underCriteria: thresholdsToKeysAndValues(args.Thresholds),
121+
overCriteria: thresholdsToKeysAndValues(args.TargetThresholds),
132122
resourceNames: resourceNames,
133123
extendedResourceNames: extendedResourceNames,
134124
podFilter: podFilter,

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+
lowerThresholds := 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(lowerThresholds)...,
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+
higherThresholds := normalizer.Clamp(
520+
normalizer.Sum(average, highSpan), 0, 100,
521+
)
522+
klog.V(3).InfoS(
523+
"Assessed thresholds for overutilized nodes",
524+
thresholdsToKeysAndValues(higherThresholds)...,
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{lowerThresholds, higherThresholds},
509531
)
510532

511533
return usage, thresholds

0 commit comments

Comments
 (0)