-
Notifications
You must be signed in to change notification settings - Fork 725
Improve percentage calculation in ResourceUsageToResourceThreshold func #1683
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
Conversation
googs1025
commented
May 7, 2025
- Implemented precise calculation of resource usage percentages, rounding to two decimal places.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign @ingvagabund |
@@ -594,11 +595,18 @@ func ResourceUsageToResourceThreshold( | |||
percent = float64(used) / float64(capacity) * 100 | |||
} | |||
|
|||
result[rname] = api.Percentage(percent) | |||
roundedPercent := roundFloat(percent, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's thresholdsToKeysAndValues
function used for printing percentages to 2 decimals. Is there another place where printing/computing with rounded numbers is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks 😄
I am trying to understand the implementation of nodeutilization. I'm curious Why is float64 not always rounded to two decimal places when used, but only used when printing logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rounding leads to a loss of precision. The less rounding the better. Though, the losses are probably very small. Yet, why take chances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got this. I have no further questions about this explanation. 😄
/close
@googs1025: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |