mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-27 14:01:12 +01:00
Merge pull request #1657 from ricardomaraschini/log
chore: log average and assessed thresholds
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user