Merged
Conversation
NerdyShawn
reviewed
Oct 17, 2025
There was a problem hiding this comment.
Nice I think displaying some unit is better than no unit for sure. The only other thing I was thinking was making it a bit dynamic something like a df -h where its relative to the size consumed. I haven't tried this below but the 🤖 vibes was suggesting something like that to get dynamic, without needing an additional dependency. If this is a bad idea, feel free to say its too much. 😃
// humanSize returns a human‑readable string for a value in bytes
// using powers of 1024: B, KB, MB, GB, TB, PB.
func humanSize(bytes int64) string {
const (
_ = iota
KB float64 = 1 << (10 * iota)
MB
GB
TB
PB
)
// use float64 so we can keep two decimal places
value := float64(bytes)
switch {
case value >= PB:
return fmt.Sprintf("%.2f PB", value/PB)
case value >= TB:
return fmt.Sprintf("%.2f TB", value/TB)
case value >= GB:
return fmt.Sprintf("%.2f GB", value/GB)
case value >= MB:
return fmt.Sprintf("%.2f MB", value/MB)
case value >= KB:
return fmt.Sprintf("%.2f KB", value/KB)
default:
return fmt.Sprintf("%d B", bytes)
}
}then update the variable reference if we think this is a good idea
// sizeUsedMB := float64(stats.SizeKBUtilised) / 1024.0
// ow.AppendDataWithLabel("stats", fmt.Sprintf("Objects: %d, Size: %d MB, Size Used: %.2f MB", stats.NumObjects, objectStore.MaxSize, sizeUsedMB), "Stats")
// ---- NEW ----
sizeUsedBytes := int64(stats.SizeKBUtilised) * 1024
humanSizeUsed := humanSize(sizeUsedBytes)
ow.AppendDataWithLabel(
"stats",
fmt.Sprintf("Objects: %d, Size: %d MB, Size Used: %s", stats.NumObjects, objectStore.MaxSize, humanSizeUsed),
"Stats",
)
Contributor
Author
|
Sure thing @NerdyShawn, I agree with the suggestions, I will update the code soon |
|
Sounds good thanks! Also left a comment on the issue but the unit on the 500 is also wrong, that should be a static 500GB I believe. |
giornetta
reviewed
Nov 26, 2025
b1440a8 to
174c584
Compare
giornetta
reviewed
Nov 26, 2025
giornetta
approved these changes
Nov 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Disambiguating value adding "KB" to the output of civoobjectstore show command #563