Skip to content

fix(cli): stat: explicitly specify resource SI prefix #8206

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

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

johnstcn
Copy link
Member

Previously we'd been attempting to automatically determine the correct SI prefix using go-humanize, but the library doesn't provide a convenient way to scale two numbers both with a consistent prefix. Adding explicit SI prefixes instead, and defaulting to Gi.

@johnstcn johnstcn self-assigned this Jun 26, 2023
Comment on lines +25 to +27
PrefixMebi = PrefixKibi * 1024.0
PrefixGibi = PrefixMebi * 1024.0
PrefixTebi = PrefixGibi * 1024.0
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the canonical prefix names according to NIST: https://physics.nist.gov/cuu/Units/binary.html

@johnstcn johnstcn requested review from mafredri and spikecurtis June 26, 2023 12:50
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Always enjoy more precision 🙏

_, _ = sb.WriteString(r.Prefix.String())
_, _ = sb.WriteString(r.Unit)

if r.Total != (*float64)(nil) && *r.Total > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Is the typed nil check really necessary here? I would expect this to be writable as r.Total != nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

I found it to be necessary, otherwise the unit tests fail.

@johnstcn johnstcn merged commit 80ef147 into main Jun 26, 2023
@johnstcn johnstcn deleted the cj/cli-stat-units-fix branch June 26, 2023 17:06
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants