From 449f874679fde9df62f9750a0525c3278cbb5fdd Mon Sep 17 00:00:00 2001 From: fpetkovski Date: Wed, 8 Sep 2021 10:49:00 +0200 Subject: [PATCH] promtool: add extended flag for tsdb analysis The compaction analysis which runs under promtool tsdb analyze can be an intensive process which slows down the entire command. This commit adds an --extended flag to tsdb analyze which can be toggled for running long running tasks, such as compaction analysis. Signed-off-by: fpetkovski --- cmd/promtool/main.go | 3 ++- cmd/promtool/tsdb.go | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index 39cf1b80f..ae46d84e5 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -137,6 +137,7 @@ func main() { analyzePath := tsdbAnalyzeCmd.Arg("db path", "Database path (default is "+defaultDBPath+").").Default(defaultDBPath).String() analyzeBlockID := tsdbAnalyzeCmd.Arg("block id", "Block to analyze (default is the last block).").String() analyzeLimit := tsdbAnalyzeCmd.Flag("limit", "How many items to show in each list.").Default("20").Int() + analyzeRunExtended := tsdbAnalyzeCmd.Flag("extended", "Run extended analysis.").Bool() tsdbListCmd := tsdbCmd.Command("list", "List tsdb blocks.") listHumanReadable := tsdbListCmd.Flag("human-readable", "Print human readable values.").Short('r').Bool() @@ -237,7 +238,7 @@ func main() { os.Exit(checkErr(benchmarkWrite(*benchWriteOutPath, *benchSamplesFile, *benchWriteNumMetrics, *benchWriteNumScrapes))) case tsdbAnalyzeCmd.FullCommand(): - os.Exit(checkErr(analyzeBlock(*analyzePath, *analyzeBlockID, *analyzeLimit))) + os.Exit(checkErr(analyzeBlock(*analyzePath, *analyzeBlockID, *analyzeLimit, *analyzeRunExtended))) case tsdbListCmd.FullCommand(): os.Exit(checkErr(listBlocks(*listPath, *listHumanReadable))) diff --git a/cmd/promtool/tsdb.go b/cmd/promtool/tsdb.go index 782ea7d54..45cde87cf 100644 --- a/cmd/promtool/tsdb.go +++ b/cmd/promtool/tsdb.go @@ -418,7 +418,7 @@ func openBlock(path, blockID string) (*tsdb.DBReadOnly, tsdb.BlockReader, error) return db, block, nil } -func analyzeBlock(path, blockID string, limit int) error { +func analyzeBlock(path, blockID string, limit int, runExtended bool) error { db, block, err := openBlock(path, blockID) if err != nil { return err @@ -564,7 +564,11 @@ func analyzeBlock(path, blockID string, limit int) error { fmt.Printf("\nHighest cardinality metric names:\n") printInfo(postingInfos) - return analyzeCompaction(block, ir) + if runExtended { + return analyzeCompaction(block, ir) + } + + return nil } func analyzeCompaction(block tsdb.BlockReader, indexr tsdb.IndexReader) (err error) {