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

Support Mi units #667

Closed
wants to merge 2 commits into from
Closed

Conversation

jetersen
Copy link

@jetersen jetersen commented Nov 3, 2023

This PR fixes #522

Checklist

  • I have signed the CLA
  • I have updated/added any relevant documentation

Description

What's the goal of this PR?

Add support for using BinarySI since due to the use of RoundUp converts the Memory units to DecimalSI

What changes did you make?

The main issue is RoundUp which converts the units to DecimalSI to do the rounding.
So I created a basic method that uses math to convert the unit back to BinarySI although due to the difference in the units there is a slight difference like 124M turns into 119Mi.
Perhaps a different approach is to simply replace K,M,G,T with Ki, Mi, Gi, Ti 🤔

What alternative solution should we consider, if any?

See #522 (comment)

Perhaps there is a different approach to rounding 🤔
I tried other solutions but did not get the desired result from String method 😓

This applies to this PR:

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2023

CLA assistant check
All committers have signed the CLA.

basePath string
insightsHost string
enableCost bool
useMemoryBinarySI bool
Copy link
Author

Choose a reason for hiding this comment

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

Not sure about naming here 😅

@@ -43,6 +44,7 @@ func init() {
dashboardCmd.PersistentFlags().StringVar(&basePath, "base-path", "/", "Path on which the dashboard is served.")
dashboardCmd.PersistentFlags().BoolVar(&enableCost, "enable-cost", true, "If set to false, the cost integration will be disabled on the dashboard.")
dashboardCmd.PersistentFlags().StringVar(&insightsHost, "insights-host", "https://insights.fairwinds.com", "Insights host for retrieving optional cost data.")
dashboardCmd.PersistentFlags().BoolVar(&useMemoryBinarySI, "binary-si", false, "Use binary SI units for memory (base 2) instead of decimal SI units (base 10).")
Copy link
Author

Choose a reason for hiding this comment

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

Suggestion please, naming is hard 😓

for len(mem.String()) > maxAllowableStringLen && i < len(memoryScales)-1 {
maxLength := 5
if len(mem.String()) <= maxLength {
return rl
Copy link
Author

Choose a reason for hiding this comment

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

Since RoundUp is the issue in this case I decided to simply return early here 🤔

Comment on lines +90 to +97
case resource.Kilo:
scaleValue = Kibibyte
case resource.Mega:
scaleValue = Mebibyte
case resource.Giga:
scaleValue = Gibibyte
case resource.Tera:
scaleValue = Tebibyte
Copy link
Author

Choose a reason for hiding this comment

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

Followed the scaled used below

resource.Kilo,
resource.Mega,
resource.Giga,
resource.Tera,

@jetersen
Copy link
Author

jetersen commented Nov 3, 2023

Not sure if it helpful to add things to the docs about the command flag for the dashboard? Perhaps in the helm chart?

@jetersen
Copy link
Author

jetersen commented Nov 3, 2023

The question becomes does this even need to be a command flag option. Since most tooling uses Mi and I wonder if we should simply replace the different units like M with Mi to avoid the Quantity math 🤔
Perhaps there is another go api or library to do rounding using BinarySI units?

@sudermanjr
Copy link
Member

Thanks for the PR! We will likely need some extra time to review this - it's an issue that has plagued us for a while :-D

I do like making this a flagged feature to start, even if we plan to default differently later.

@github-actions github-actions bot added the stale Marked as stale by stalebot label Feb 21, 2024
@github-actions github-actions bot closed this Feb 28, 2024
@jetersen
Copy link
Author

@sudermanjr @transient1 This definitely not stale 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Marked as stale by stalebot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use mebibytes (Mi) instead of megabites (M) in memory recommendation
3 participants