Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

googs1025
Copy link
Member

  • Implemented precise calculation of resource usage percentages, rounding to two decimal places.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 7, 2025
@k8s-ci-robot k8s-ci-robot requested a review from JaneLiuL May 7, 2025 06:20
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign knelasevero for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested a review from seanmalloy May 7, 2025 06:20
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 7, 2025
@googs1025
Copy link
Member Author

/assign @ingvagabund

@@ -594,11 +595,18 @@ func ResourceUsageToResourceThreshold(
percent = float64(used) / float64(capacity) * 100
}

result[rname] = api.Percentage(percent)
roundedPercent := roundFloat(percent, 2)
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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

@k8s-ci-robot
Copy link
Contributor

@googs1025: Closed this PR.

In response to this:

got this. I have no further questions about this explanation. 😄

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants