@@ -130,6 +130,16 @@ func getNodeUsageSnapshot(
130
130
return nodesMap , nodesUsageMap , podListMap
131
131
}
132
132
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
+
133
143
// usageToKeysAndValues converts a ReferencedResourceList into a list of
134
144
// keys and values. this is useful for logging.
135
145
func usageToKeysAndValues (usage api.ReferencedResourceList ) []any {
@@ -487,25 +497,37 @@ func assessNodesUsagesAndRelativeThresholds(
487
497
rawUsages , rawCapacities , ResourceUsageToResourceThreshold ,
488
498
)
489
499
490
- // calculate the average usage and then deviate it according to the
491
- // user provided thresholds.
500
+ // calculate the average usage.
492
501
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
+ )
493
526
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.
498
528
thresholds := normalizer .Replicate (
499
529
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 },
509
531
)
510
532
511
533
return usage , thresholds
0 commit comments