Skip to content

Commit

Permalink
[cli] add jsonnet support to analyse blocks (#4012)
Browse files Browse the repository at this point in the history
* [cli] add jsonnet support to analyse blocks

* Spell
  • Loading branch information
zalegrala authored Aug 27, 2024
1 parent 88f09a6 commit aa68a61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions cmd/tempo-cli/cmd-analyse-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func processBlock(r backend.Reader, tenantID, blockID string, maxStartTime, minS
// merge dedicated with span attributes
for k, v := range spanDedicatedSummary.attributes {
spanAttrsSummary.attributes[k] = v
spanAttrsSummary.dedicated[k] = struct{}{}
}
spanAttrsSummary.totalBytes += spanDedicatedSummary.totalBytes

Expand Down Expand Up @@ -215,6 +216,7 @@ func (s *blockSummary) print(maxAttr int, generateJsonnet bool) error {
type genericAttrSummary struct {
totalBytes uint64
attributes map[string]uint64 // key: attribute name, value: total bytes
dedicated map[string]struct{}
}

type attribute struct {
Expand Down Expand Up @@ -262,6 +264,7 @@ func aggregateAttributes(pf *parquet.File, keyPath string, valuePaths []string)
return genericAttrSummary{
totalBytes: totalBytes,
attributes: attrMap,
dedicated: make(map[string]struct{}),
}, nil
}

Expand All @@ -282,7 +285,7 @@ func aggregateDedicatedColumns(pf *parquet.File, scope backend.DedicatedColumnSc
}
i++

attrMap["dedicated: "+dedColumn.Name] = sz
attrMap[dedColumn.Name] = sz
totalBytes += sz
}

Expand Down Expand Up @@ -331,8 +334,14 @@ func printSummary(scope string, max int, summary genericAttrSummary) error {
fmt.Printf("Top %d %s attributes by size\n", max, scope)
attrList := topN(max, summary.attributes)
for _, a := range attrList {

name := a.name
if _, ok := summary.dedicated[a.name]; !ok {
name = a.name + " (dedicated)"
}

percentage := float64(a.bytes) / float64(summary.totalBytes) * 100
_, err := fmt.Fprintf(w, "name: %s\t size: %s\t (%s%%)\n", a.name, humanize.Bytes(a.bytes), strconv.FormatFloat(percentage, 'f', 2, 64))
_, err := fmt.Fprintf(w, "name: %s\t size: %s\t (%s%%)\n", name, humanize.Bytes(a.bytes), strconv.FormatFloat(percentage, 'f', 2, 64))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/tempo-cli/cmd-analyse-blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type analyseBlocksCmd struct {
backendOptions

Jsonnet bool `help:"output Jsonnet necessary for overrides"`
TenantID string `arg:"" help:"tenant-id within the bucket"`
MinCompactionLevel int `help:"Min compaction level to analyse" default:"3"`
MaxBlocks int `help:"Max number of blocks to analyse" default:"10"`
Expand Down Expand Up @@ -100,5 +101,5 @@ func (cmd *analyseBlocksCmd) Run(ctx *globalOptions) error {
totalBytes: totalResourceBytes,
attributes: topResourceAttrs,
},
}).print(cmd.NumAttr, false)
}).print(cmd.NumAttr, cmd.Jsonnet)
}

0 comments on commit aa68a61

Please sign in to comment.