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

add support for nanocpus (fixes issue #18) #19

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

philgebhardt
Copy link
Contributor

fixes: #18

Copy link
Owner

@ThomasK33 ThomasK33 left a comment

Choose a reason for hiding this comment

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

Thanks for this PR.

Could you please add unit tests to the unit parsing and arithmetics with different scales?

Funnily enough, I initially derived the supported suffixes from the code comment in the apimachinery repo, yet that comment does not include the "u" and "n" scales.
Would you also add the "u" one, including tests? (see: https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/suffix.go line 94)

src/parser.rs Show resolved Hide resolved
@philgebhardt philgebhardt force-pushed the pag/support-nanocpus branch from 9d9cc66 to 7e32d85 Compare August 3, 2024 02:31
@philgebhardt philgebhardt force-pushed the pag/support-nanocpus branch from 7e32d85 to 079550d Compare August 3, 2024 02:34
@philgebhardt philgebhardt requested a review from ThomasK33 August 3, 2024 02:35
Comment on lines +7 to +8
Scale::Nano => "n".to_owned(),
Scale::Micro => "u".to_owned(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, like Milli, I suppose these should be "", given they aren't applicable?

Copy link
Owner

Choose a reason for hiding this comment

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

That's a good question.
I'll have to look into the kube source and how they are handling it.

In the current implementation in this crate, I assumed that Milli would be the smallest unit, and then I "upgraded" it to a simple decimal. However, considering there are smaller denominations, this might need to be changed, and the smaller units should be returned. (Or add modulo logic so that if the value modulo 1000 is 0, the next higher unit is used, and the number is divided by 1000).

Copy link
Owner

Choose a reason for hiding this comment

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

But this should not block this PR from getting merged, as from a mathematical point of view, the results are correct.

@ThomasK33
Copy link
Owner

Hey, sorry for the delay. I was out due to a prolonged health issue. I am taking a look now.

@ThomasK33
Copy link
Owner

Thanks for this PR, @philgebhardt 👍

I'll soon cut a release, as I want to fix multiplication before including it in a release (currently, multiplication does not multiply the factors together).

@ThomasK33 ThomasK33 merged commit d0dc37c into ThomasK33:main Aug 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failure to parse quantities that are in nano units (e.g. nanocpus)
2 participants