Skip to content

Commit

Permalink
simplify histograms, make it based on the server return (minio#4935)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored May 13, 2024
1 parent 900235c commit b46cf3c
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions cmd/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,33 +384,6 @@ func (v bucketInfoMessage) JSON() string {
return buf.String()
}

type histogramDef struct {
start, end uint64
text string
}

var histogramTagsDesc = map[string]histogramDef{
"LESS_THAN_1024_B": {0, 1024, "less than 1024 bytes"},
"BETWEEN_1024_B_AND_1_MB": {1024, 1024 * 1024, "between 1024 bytes and 1 MB"},
"BETWEEN_1_MB_AND_10_MB": {1024 * 1024, 10 * 1024 * 1024, "between 1 MB and 10 MB"},
"BETWEEN_10_MB_AND_64_MB": {10 * 1024 * 1024, 64 * 1024 * 1024, "between 10 MB and 64 MB"},
"BETWEEN_64_MB_AND_128_MB": {64 * 1024 * 1024, 128 * 1024 * 1024, "between 64 MB and 128 MB"},
"BETWEEN_128_MB_AND_512_MB": {128 * 1024 * 1024, 512 * 1024 * 1024, "between 128 MB and 512 MB"},
"GREATER_THAN_512_MB": {512 * 1024 * 1024, 0, "greater than 512 MB"},
}

// Return a sorted list of histograms
func sortHistogramTags() (orderedTags []string) {
orderedTags = make([]string, 0, len(histogramTagsDesc))
for tag := range histogramTagsDesc {
orderedTags = append(orderedTags, tag)
}
sort.Slice(orderedTags, func(i, j int) bool {
return histogramTagsDesc[orderedTags[i]].start < histogramTagsDesc[orderedTags[j]].start
})
return
}

func countDigits(num uint64) (count uint) {
for num > 0 {
num /= 10
Expand Down Expand Up @@ -466,11 +439,15 @@ func (v bucketInfoMessage) String() string {
}
}

sortedTags := sortHistogramTags()
var sortedTags []string
for k := range v.Usage.ObjectSizesHistogram {
sortedTags = append(sortedTags, k)
}
sort.Strings(sortedTags)
for _, tagName := range sortedTags {
val, ok := v.Usage.ObjectSizesHistogram[tagName]
if ok {
fmt.Fprintf(&b, " %*d object(s) %s\n", maxDigits, val, histogramTagsDesc[tagName].text)
fmt.Fprintf(&b, " %*d object(s) %s\n", maxDigits, val, tagName)
}
}
}
Expand Down

0 comments on commit b46cf3c

Please sign in to comment.