diff --git a/cmd/promtool/backfill.go b/cmd/promtool/backfill.go index c0fc627ee..95c14c4f8 100644 --- a/cmd/promtool/backfill.go +++ b/cmd/promtool/backfill.go @@ -65,7 +65,7 @@ func getMinAndMaxTimestamps(p textparse.Parser) (int64, int64, error) { return maxt, mint, nil } -func createBlocks(input []byte, mint, maxt int64, maxSamplesInAppender int, outputDir string, humanReadable bool) (returnErr error) { +func createBlocks(input []byte, mint, maxt int64, maxSamplesInAppender int, outputDir string, humanReadable, quiet bool) (returnErr error) { blockDuration := tsdb.DefaultBlockDuration mint = blockDuration * (mint / blockDuration) @@ -169,6 +169,9 @@ func createBlocks(input []byte, mint, maxt int64, maxSamplesInAppender int, outp block, err := w.Flush(ctx) switch err { case nil: + if quiet { + break + } blocks, err := db.Blocks() if err != nil { return errors.Wrap(err, "get blocks") @@ -196,11 +199,11 @@ func createBlocks(input []byte, mint, maxt int64, maxSamplesInAppender int, outp } -func backfill(maxSamplesInAppender int, input []byte, outputDir string, humanReadable bool) (err error) { +func backfill(maxSamplesInAppender int, input []byte, outputDir string, humanReadable, quiet bool) (err error) { p := textparse.NewOpenMetricsParser(input) maxt, mint, err := getMinAndMaxTimestamps(p) if err != nil { return errors.Wrap(err, "getting min and max timestamp") } - return errors.Wrap(createBlocks(input, mint, maxt, maxSamplesInAppender, outputDir, humanReadable), "block creation") + return errors.Wrap(createBlocks(input, mint, maxt, maxSamplesInAppender, outputDir, humanReadable, quiet), "block creation") } diff --git a/cmd/promtool/backfill_test.go b/cmd/promtool/backfill_test.go index ce1573637..bd0109da1 100644 --- a/cmd/promtool/backfill_test.go +++ b/cmd/promtool/backfill_test.go @@ -540,7 +540,7 @@ after_eof 1 2 require.NoError(t, os.RemoveAll(outputDir)) }() - err = backfill(test.MaxSamplesInAppender, []byte(test.ToParse), outputDir, false) + err = backfill(test.MaxSamplesInAppender, []byte(test.ToParse), outputDir, false, false) if !test.IsOk { require.Error(t, err, test.Description) diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index 01a7181e2..867404f24 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -144,6 +144,7 @@ func main() { importCmd := tsdbCmd.Command("create-blocks-from", "[Experimental] Import samples from input and produce TSDB blocks. Please refer to the storage docs for more details.") importHumanReadable := importCmd.Flag("human-readable", "Print human readable values.").Short('r').Bool() + importQuiet := importCmd.Flag("quiet", "Do not print created blocks.").Short('q').Bool() openMetricsImportCmd := importCmd.Command("openmetrics", "Import samples from OpenMetrics input and produce TSDB blocks. Please refer to the storage docs for more details.") // TODO(aSquare14): add flag to set default block duration importFilePath := openMetricsImportCmd.Arg("input file", "OpenMetrics file to read samples from.").Required().String() @@ -221,7 +222,7 @@ func main() { os.Exit(checkErr(dumpSamples(*dumpPath, *dumpMinTime, *dumpMaxTime))) //TODO(aSquare14): Work on adding support for custom block size. case openMetricsImportCmd.FullCommand(): - os.Exit(backfillOpenMetrics(*importFilePath, *importDBPath, *importHumanReadable)) + os.Exit(backfillOpenMetrics(*importFilePath, *importDBPath, *importHumanReadable, *importQuiet)) case importRulesCmd.FullCommand(): os.Exit(checkErr(importRules(*importRulesURL, *importRulesStart, *importRulesEnd, *importRulesOutputDir, *importRulesEvalInterval, *importRulesFiles...))) diff --git a/cmd/promtool/tsdb.go b/cmd/promtool/tsdb.go index 871437795..68e84beb6 100644 --- a/cmd/promtool/tsdb.go +++ b/cmd/promtool/tsdb.go @@ -611,7 +611,7 @@ func checkErr(err error) int { return 0 } -func backfillOpenMetrics(path string, outputDir string, humanReadable bool) int { +func backfillOpenMetrics(path string, outputDir string, humanReadable, quiet bool) int { inputFile, err := fileutil.OpenMmapFile(path) if err != nil { return checkErr(err) @@ -622,5 +622,5 @@ func backfillOpenMetrics(path string, outputDir string, humanReadable bool) int return checkErr(errors.Wrap(err, "create output dir")) } - return checkErr(backfill(5000, inputFile.Bytes(), outputDir, humanReadable)) + return checkErr(backfill(5000, inputFile.Bytes(), outputDir, humanReadable, quiet)) }