mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 13:29:11 +01:00
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.
This commit is contained in:
@@ -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