From b1ac4a45e61f3162c44e6c6c87641d0ac9aa5700 Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Tue, 9 Mar 2021 11:14:17 +0100 Subject: [PATCH] Add num scrapes as tsdb write benchmark command flag By default same value that was hardcoded is used, but with the new flag added the number of scrapes can be increased to any value. Signed-off-by: Pau Freixes --- cmd/promtool/main.go | 3 ++- cmd/promtool/tsdb.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index 505fecb59..461a2b57a 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -124,6 +124,7 @@ func main() { tsdbBenchWriteCmd := tsdbBenchCmd.Command("write", "Run a write performance benchmark.") benchWriteOutPath := tsdbBenchWriteCmd.Flag("out", "Set the output path.").Default("benchout").String() benchWriteNumMetrics := tsdbBenchWriteCmd.Flag("metrics", "Number of metrics to read.").Default("10000").Int() + benchWriteNumScrapes := tsdbBenchWriteCmd.Flag("scrapes", "Number of scrapes to simulate.").Default("3000").Int() benchSamplesFile := tsdbBenchWriteCmd.Arg("file", "Input file with samples data, default is ("+filepath.Join("..", "..", "tsdb", "testdata", "20kseries.json")+").").Default(filepath.Join("..", "..", "tsdb", "testdata", "20kseries.json")).String() tsdbAnalyzeCmd := tsdbCmd.Command("analyze", "Analyze churn, label pair cardinality.") @@ -195,7 +196,7 @@ func main() { os.Exit(RulesUnitTest(*testRulesFiles...)) case tsdbBenchWriteCmd.FullCommand(): - os.Exit(checkErr(benchmarkWrite(*benchWriteOutPath, *benchSamplesFile, *benchWriteNumMetrics))) + os.Exit(checkErr(benchmarkWrite(*benchWriteOutPath, *benchSamplesFile, *benchWriteNumMetrics, *benchWriteNumScrapes))) case tsdbAnalyzeCmd.FullCommand(): os.Exit(checkErr(analyzeBlock(*analyzePath, *analyzeBlockID, *analyzeLimit))) diff --git a/cmd/promtool/tsdb.go b/cmd/promtool/tsdb.go index c22e12d4b..9fb59cb9d 100644 --- a/cmd/promtool/tsdb.go +++ b/cmd/promtool/tsdb.go @@ -58,7 +58,7 @@ type writeBenchmark struct { logger log.Logger } -func benchmarkWrite(outPath, samplesFile string, numMetrics int) error { +func benchmarkWrite(outPath, samplesFile string, numMetrics, numScrapes int) error { b := &writeBenchmark{ outPath: outPath, samplesFile: samplesFile, @@ -118,7 +118,7 @@ func benchmarkWrite(outPath, samplesFile string, numMetrics int) error { if err := b.startProfiling(); err != nil { return err } - total, err = b.ingestScrapes(lbs, 3000) + total, err = b.ingestScrapes(lbs, numScrapes) if err != nil { return err }