Skip to content
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

fix: correctly parse resource config #3072

Merged
merged 5 commits into from
Dec 6, 2023
Merged

fix: correctly parse resource config #3072

merged 5 commits into from
Dec 6, 2023

Conversation

frrist
Copy link
Member

@frrist frrist commented Dec 6, 2023

This change modifies models.ResourceConfig to use go-humanize instead of datasize for more accurate parsing of human-readable strings into bytes. go-humanize can parse mebibyte strings and megabytes strings (ditto that for the rest of the SI units). Also updated the 'String' method of 'ResourceConfig' to reflect these changes.

I noticed this issue when bacalhau config auto-resources produced a config that failed to parse. The bacalhau config system uses go-humanize for parsing values, and had modified model.ResourceConfig to do the same. When #3061 landed it replaced usage of model.ResourceConfig with models.ResourceConfig which broke the behavior implemented in #3012. The change resolves this breakage.

Additionally, when making this change I noticed the models.ResourceConfig.Normalize() method erroneously converted Mebibytes (Mi/MiB) to Megabyte (MB) when parsing the string representation. The datasize package doesn't distinguish these types. The model.ResourceConfig implementation did not have this behavior. go-humanize does distinguish between these types. I have removed the incorrect behavior from models.ResourceConfig.Normalize() and update the test for it.

Comment on lines -240 to -242
// this will give us a numerator and denominator that should end up at the
// same 0.1 value that 100m means
// https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications_managing-monitoring-and-updating-the-kernel#proc_controlling-distribution-of-cpu-time-for-applications-by-adjusting-cpu-bandwidth_using-cgroups-v2-to-control-distribution-of-cpu-time-for-applications
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only relevant to the CPU test case above. Removed from here (it appears to have been copied)

@frrist frrist requested a review from simonwo December 6, 2023 21:39
@frrist frrist marked this pull request as ready for review December 6, 2023 21:50
Copy link
Contributor

@simonwo simonwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix.

@frrist frrist merged commit 85ca17b into main Dec 6, 2023
13 checks passed
@frrist frrist deleted the frrist/resource-encodin branch December 6, 2023 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants