Skip to content

chore: log average and assessed thresholds #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions pkg/framework/plugins/nodeutilization/highnodeutilization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -106,7 +99,7 @@ func NewHighNodeUtilization(
args: args,
resourceNames: resourceNames,
highThresholds: highThresholds,
criteria: criteria,
criteria: thresholdsToKeysAndValues(args.Thresholds),
podFilter: podFilter,
usageClient: newRequestedUsageClient(
resourceNames,
Expand Down
14 changes: 2 additions & 12 deletions pkg/framework/plugins/nodeutilization/lownodeutilization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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,
Expand Down
52 changes: 37 additions & 15 deletions pkg/framework/plugins/nodeutilization/nodeutilization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...,
)

// 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)...,
)

// 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.
// 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
Expand Down