diff --git a/pkg/framework/plugins/nodeutilization/highnodeutilization.go b/pkg/framework/plugins/nodeutilization/highnodeutilization.go index 992f8516a..55ea9d032 100644 --- a/pkg/framework/plugins/nodeutilization/highnodeutilization.go +++ b/pkg/framework/plugins/nodeutilization/highnodeutilization.go @@ -74,13 +74,6 @@ func NewHighNodeUtilization( highThresholds[rname] = MaxResourcePercentage } - // criteria is a list of thresholds that are used to determine if a node - // is underutilized. it is used only for logging purposes. - criteria := []any{} - for rname, rvalue := range args.Thresholds { - criteria = append(criteria, rname, rvalue) - } - podFilter, err := podutil. NewOptions(). WithFilter(handle.Evictor().Filter). @@ -106,7 +99,7 @@ func NewHighNodeUtilization( args: args, resourceNames: resourceNames, highThresholds: highThresholds, - criteria: criteria, + criteria: thresholdsToKeysAndValues(args.Thresholds), podFilter: podFilter, usageClient: newRequestedUsageClient( resourceNames, diff --git a/pkg/framework/plugins/nodeutilization/lownodeutilization.go b/pkg/framework/plugins/nodeutilization/lownodeutilization.go index edb6b3d9a..abc37aaf9 100644 --- a/pkg/framework/plugins/nodeutilization/lownodeutilization.go +++ b/pkg/framework/plugins/nodeutilization/lownodeutilization.go @@ -92,16 +92,6 @@ func NewLowNodeUtilization( ) } - // underCriteria and overCriteria are slices used for logging purposes. - // we assemble them only once. - underCriteria, overCriteria := []any{}, []any{} - for name := range args.Thresholds { - underCriteria = append(underCriteria, name, args.Thresholds[name]) - } - for name := range args.TargetThresholds { - overCriteria = append(overCriteria, name, args.TargetThresholds[name]) - } - podFilter, err := podutil. NewOptions(). WithFilter(handle.Evictor().Filter). @@ -127,8 +117,8 @@ func NewLowNodeUtilization( return &LowNodeUtilization{ handle: handle, args: args, - underCriteria: underCriteria, - overCriteria: overCriteria, + underCriteria: thresholdsToKeysAndValues(args.Thresholds), + overCriteria: thresholdsToKeysAndValues(args.TargetThresholds), resourceNames: resourceNames, extendedResourceNames: extendedResourceNames, podFilter: podFilter, diff --git a/pkg/framework/plugins/nodeutilization/nodeutilization.go b/pkg/framework/plugins/nodeutilization/nodeutilization.go index 62995b8c0..705cbc32f 100644 --- a/pkg/framework/plugins/nodeutilization/nodeutilization.go +++ b/pkg/framework/plugins/nodeutilization/nodeutilization.go @@ -130,6 +130,16 @@ func getNodeUsageSnapshot( return nodesMap, nodesUsageMap, podListMap } +// thresholdsToKeysAndValues converts a ResourceThresholds into a list of keys +// and values. this is useful for logging. +func thresholdsToKeysAndValues(thresholds api.ResourceThresholds) []any { + result := []any{} + for name, value := range thresholds { + result = append(result, name, fmt.Sprintf("%.2f%%", value)) + } + return result +} + // usageToKeysAndValues converts a ReferencedResourceList into a list of // keys and values. this is useful for logging. func usageToKeysAndValues(usage api.ReferencedResourceList) []any { @@ -487,25 +497,37 @@ func assessNodesUsagesAndRelativeThresholds( rawUsages, rawCapacities, ResourceUsageToResourceThreshold, ) - // calculate the average usage and then deviate it according to the - // user provided thresholds. + // calculate the average usage. average := normalizer.Average(usage) + klog.V(3).InfoS( + "Assessed average usage", + thresholdsToKeysAndValues(average)..., + ) - // calculate the average usage and then deviate it according to the - // user provided thresholds. We also ensure that the value after the - // deviation is at least 1%. this call also replicates the thresholds - // across all nodes. + // decrease the provided threshold from the average to get the low + // span. also make sure the resulting values are between 0 and 100. + lowerThresholds := normalizer.Clamp( + normalizer.Sum(average, normalizer.Negate(lowSpan)), 0, 100, + ) + klog.V(3).InfoS( + "Assessed thresholds for underutilized nodes", + thresholdsToKeysAndValues(lowerThresholds)..., + ) + + // increase the provided threshold from the average to get the high + // span. also make sure the resulting values are between 0 and 100. + higherThresholds := normalizer.Clamp( + normalizer.Sum(average, highSpan), 0, 100, + ) + klog.V(3).InfoS( + "Assessed thresholds for overutilized nodes", + thresholdsToKeysAndValues(higherThresholds)..., + ) + + // replicate the same assessed thresholds to all nodes. thresholds := normalizer.Replicate( slices.Collect(maps.Keys(usage)), - normalizer.Map( - []api.ResourceThresholds{ - normalizer.Sum(average, normalizer.Negate(lowSpan)), - normalizer.Sum(average, highSpan), - }, - func(thresholds api.ResourceThresholds) api.ResourceThresholds { - return normalizer.Clamp(thresholds, 0, 100) - }, - ), + []api.ResourceThresholds{lowerThresholds, higherThresholds}, ) return usage, thresholds