Skip to content

Commit

Permalink
Make percentages human-readable
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSzegedi committed Nov 21, 2023
1 parent 2fee121 commit 0ea6b44
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/framework/plugins/nodeutilization/nodeutilization.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nodeutilization

import (
"context"
"math"
"sort"

"sigs.k8s.io/descheduler/pkg/api"
Expand Down Expand Up @@ -163,6 +164,10 @@ func resourceThreshold(nodeCapacity v1.ResourceList, resourceName v1.ResourceNam
return resource.NewQuantity(resourceCapacityFraction(resourceCapacityQuantity.Value()), defaultFormat)
}

func roundTo2Digits(percentage float64) float64 {
return math.Round(percentage*100) / 100
}

func resourceUsagePercentages(nodeUsage NodeUsage) map[v1.ResourceName]float64 {
nodeCapacity := nodeUsage.node.Status.Capacity
if len(nodeUsage.node.Status.Allocatable) > 0 {
Expand All @@ -174,6 +179,7 @@ func resourceUsagePercentages(nodeUsage NodeUsage) map[v1.ResourceName]float64 {
cap := nodeCapacity[resourceName]
if !cap.IsZero() {
resourceUsagePercentage[resourceName] = 100 * float64(resourceUsage.MilliValue()) / float64(cap.MilliValue())
resourceUsagePercentage[resourceName] = roundTo2Digits(resourceUsagePercentage[resourceName])
}
}

Expand Down

0 comments on commit 0ea6b44

Please sign in to comment.