-
Notifications
You must be signed in to change notification settings - Fork 136
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
Use mebibytes (Mi) instead of megabites (M) in memory recommendation #522
Comments
Thanks for the request. We would be happy to accept a community contribution for this change. I think being able to change the units would be super cool. |
I've ended up using following to get recommendations in Mi: kubectl get vpa -o json | jq -r '.items[] | .metadata.name, (.status.recommendation.containerRecommendations[] | ["", .containerName, .target.cpu, (.target.memory | tonumber / 1048576 | round | tostring) + "Mi"] | @tsv)' |
Thanks @tbondarchuk this is the route I've also gone down for now |
I have a working solution for the dashboard. The whole issue is that resource quantity uses DecimalSI which I am not quite sure where it is coming from 🤔 My only concern is at what level do we want this feature? I have two approaches for formatting to Mebibytes. One where 5G would be converted to 4769Mi or one where 5G gets converted to 5Gi but This is the approach that simply deals with Mi units so 5G gets converted to 4769Mi const (
Mebibyte = 1024 * 1024
)
func formatToMebibyte(actual resource.Quantity) resource.Quantity {
value := actual.Value() / Mebibyte
if actual.Value()%Mebibyte != 0 {
value++
}
return *resource.NewQuantity(value*Mebibyte, resource.BinarySI)
} This is the generic approach that can be expanded to more units. Although the approach could have rules like anything below 2 Gibibyte is considered Mebibyte const (
Mebibyte = 1024 * 1024
Gibibyte = Mebibyte * 1024
)
func formatToBinarySi(actual resource.Quantity) resource.Quantity {
var unit int64
if actual.Value() >= 2*Gibibyte {
unit = Gibibyte
} else {
unit = Mebibyte
}
value := actual.Value() / unit
if actual.Value()%unit != 0 {
value++
}
return *resource.NewQuantity(value*unit, resource.BinarySI)
} this code above could quickly expand to support Ti and Pi (although for pods that is debatable) but at the same time at what point do you start using Gibibyte? At the same time I am not sure if the code is the best approach to get the value converted correctly to BinarySI. I tried to use RoundUp and ScaledValue but I never got the expected output in the ToString method 🤔 |
Oh after some digging I found the culprit 👏 |
Created #667 |
Goldilocks dashboard shows memory recommendation in megabytes units (M), which is 10^6 of bytes.
Mebibytes (Mi) instead use as base powers of 2.
Usually Kubernetes memory requests are specified in Mi and also different tools, like default Prometheus Operator Grafana dashboard show in MiB units.
As a feature option to switch between different types of measurements can be added.
From Kubernetes docs:
The text was updated successfully, but these errors were encountered: