Skip to content

Commit

Permalink
tempo-cli analyse blocks skips compacted blocks and updates block list (
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer authored Nov 28, 2023
1 parent c00e7ef commit 7a6e77b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## main / unreleased

+ [BUGFIX] Change exit code if config is successfully verified [#3174](https://github.com/grafana/tempo/pull/3174) (@am3o @agrib-01)
* [BUGFIX] Change exit code if config is successfully verified [#3174](https://github.com/grafana/tempo/pull/3174) (@am3o @agrib-01)
* [BUGFIX] The tempo-cli analyse blocks command no longer fails on compacted blocks [#3183](https://github.com/grafana/tempo/pull/3183) (@stoewer)
* [ENHANCEMENT] Introduced `AttributePolicyMatch` & `IntrinsicPolicyMatch` structures to match span attributes based on strongly typed values & precompiled regexp [#3025](https://github.com/grafana/tempo/pull/3025) (@andriusluk)
* [CHANGE] TraceQL/Structural operators performance improvement. [#3088](https://github.com/grafana/tempo/pull/3088) (@joe-elliott)
* [CHANGE] Merge the processors overrides set through runtime overrides and user-configurable overrides [#3125](https://github.com/grafana/tempo/pull/3125) (@kvrhdn)
Expand Down
13 changes: 5 additions & 8 deletions cmd/tempo-cli/cmd-analyse-block.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (cmd *analyseBlockCmd) Run(ctx *globalOptions) error {

blockSum, err := processBlock(r, c, cmd.TenantID, cmd.BlockID, time.Hour, 0)
if err != nil {
if errors.Is(err, backend.ErrDoesNotExist) {
return fmt.Errorf("unable to analyze block: block has no block.meta because it was compacted")
}
return err
}

Expand All @@ -118,15 +121,9 @@ func processBlock(r backend.Reader, _ backend.Compactor, tenantID, blockID strin
id := uuid.MustParse(blockID)

meta, err := r.BlockMeta(context.TODO(), id, tenantID)
if err != nil && !errors.Is(err, backend.ErrDoesNotExist) {
if err != nil {
return nil, err
}

if meta == nil {
fmt.Println("Unable to load any meta for block", blockID)
return nil, nil
}

if meta.CompactionLevel < minCompactionLvl {
return nil, nil
}
Expand Down Expand Up @@ -344,7 +341,7 @@ func printSummary(scope string, max int, summary genericAttrSummary) error {
return w.Flush()
}

func printDedicatedColumnOverridesJsonnet(spanSummary genericAttrSummary, resourceSummary genericAttrSummary) {
func printDedicatedColumnOverridesJsonnet(spanSummary, resourceSummary genericAttrSummary) {
fmt.Println("")
fmt.Printf("parquet_dedicated_columns: [\n")

Expand Down
31 changes: 25 additions & 6 deletions cmd/tempo-cli/cmd-analyse-blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package main

import (
"context"
"errors"
"time"

"github.com/google/uuid"

"github.com/grafana/tempo/tempodb/backend"
)

type analyseBlocksCmd struct {
Expand All @@ -26,17 +31,30 @@ func (cmd *analyseBlocksCmd) Run(ctx *globalOptions) error {
return err
}

processedBlocks := 0
processedBlocks := map[uuid.UUID]struct{}{}
topSpanAttrs, topResourceAttrs := make(map[string]uint64), make(map[string]uint64)
totalSpanBytes, totalResourceBytes := uint64(0), uint64(0)
for _, block := range blocks {
if processedBlocks >= cmd.MaxBlocks {
break

for i := 0; i < len(blocks) && len(processedBlocks) < cmd.MaxBlocks; i++ {
block := blocks[i]
if _, ok := processedBlocks[block]; ok {
continue
}

blockSum, err := processBlock(r, c, cmd.TenantID, block.String(), time.Hour, uint8(cmd.MinCompactionLevel))
if err != nil {
return err
if !errors.Is(err, backend.ErrDoesNotExist) {
return err
}

// the block was already compacted and blocks might be outdated: refreshing blocks
blocks, _, err = r.Blocks(context.Background(), cmd.TenantID)
if err != nil {
return err
}
i = -1

continue
}

if blockSum == nil {
Expand All @@ -53,8 +71,9 @@ func (cmd *analyseBlocksCmd) Run(ctx *globalOptions) error {
}
totalResourceBytes += blockSum.resourceSummary.totalBytes

processedBlocks++
processedBlocks[block] = struct{}{}
}

// Get top N attributes from map
return (&blockSummary{
spanSummary: genericAttrSummary{
Expand Down

0 comments on commit 7a6e77b

Please sign in to comment.