From 7a6e77b3e998d8a71c313bfa9f0d1e34b7bd8186 Mon Sep 17 00:00:00 2001 From: "A. Stoewer" Date: Wed, 29 Nov 2023 07:06:58 +1000 Subject: [PATCH] tempo-cli analyse blocks skips compacted blocks and updates block list (#3183) --- CHANGELOG.md | 3 ++- cmd/tempo-cli/cmd-analyse-block.go | 13 +++++------- cmd/tempo-cli/cmd-analyse-blocks.go | 31 +++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c64facebec8..9d6945ee7df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cmd/tempo-cli/cmd-analyse-block.go b/cmd/tempo-cli/cmd-analyse-block.go index 49ef29d7c4c..2c9394c6d47 100644 --- a/cmd/tempo-cli/cmd-analyse-block.go +++ b/cmd/tempo-cli/cmd-analyse-block.go @@ -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 } @@ -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 } @@ -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") diff --git a/cmd/tempo-cli/cmd-analyse-blocks.go b/cmd/tempo-cli/cmd-analyse-blocks.go index 0823917d41d..65f6ddcdb2f 100644 --- a/cmd/tempo-cli/cmd-analyse-blocks.go +++ b/cmd/tempo-cli/cmd-analyse-blocks.go @@ -2,7 +2,12 @@ package main import ( "context" + "errors" "time" + + "github.com/google/uuid" + + "github.com/grafana/tempo/tempodb/backend" ) type analyseBlocksCmd struct { @@ -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 { @@ -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{