fix: correctly parse resource config #3072
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change modifies
models.ResourceConfig
to usego-humanize
instead ofdatasize
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 usesgo-humanize
for parsing values, and had modifiedmodel.ResourceConfig
to do the same. When #3061 landed it replaced usage ofmodel.ResourceConfig
withmodels.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. Thedatasize
package doesn't distinguish these types. Themodel.ResourceConfig
implementation did not have this behavior.go-humanize
does distinguish between these types. I have removed the incorrect behavior frommodels.ResourceConfig.Normalize()
and update the test for it.