From f29231ddeb09bea1d27ee41bdf4b1994ea299349 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Sun, 28 Apr 2024 08:17:40 +0300 Subject: [PATCH] feat(logql-compliance-tester): add a flag to print diffs to stdout --- cmd/logql-compliance-tester/config.go | 4 ++++ cmd/logql-compliance-tester/output.go | 8 +++++--- dev/local/ch-logql-compliance/run.sh | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/logql-compliance-tester/config.go b/cmd/logql-compliance-tester/config.go index c983576c..e0ea6f95 100644 --- a/cmd/logql-compliance-tester/config.go +++ b/cmd/logql-compliance-tester/config.go @@ -29,6 +29,7 @@ type OutputConfig struct { OutputFormat string OutputPassing bool OutputUnsupported bool + PrintFailed bool MinimumPercentage float64 } @@ -43,6 +44,7 @@ type Flags struct { OutputFormat string OutputPassing bool OutputUnsupported bool + PrintFailed bool MinimumPercentage float64 } @@ -67,6 +69,7 @@ func (f *Flags) Register(set *flag.FlagSet) { set.StringVar(&f.OutputFormat, "output-format", "json", "The comparison output format. Valid values: [json]") set.BoolVar(&f.OutputPassing, "output-passing", false, "Whether to also include passing test cases in the output.") set.BoolVar(&f.OutputUnsupported, "output-unsupported", false, "Whether to also include unsupported test cases in the output.") + set.BoolVar(&f.PrintFailed, "print-failed", false, "Whether to print diff to stdout.") set.Float64Var(&f.MinimumPercentage, "target", math.NaN(), "Minimum compliance percentage") } @@ -99,6 +102,7 @@ func parseConfig() (c Config, _ error) { OutputFormat: flags.OutputFormat, OutputPassing: flags.OutputPassing, OutputUnsupported: flags.OutputUnsupported, + PrintFailed: flags.PrintFailed, MinimumPercentage: flags.MinimumPercentage, } diff --git a/cmd/logql-compliance-tester/output.go b/cmd/logql-compliance-tester/output.go index 03858566..8f1c41d7 100644 --- a/cmd/logql-compliance-tester/output.go +++ b/cmd/logql-compliance-tester/output.go @@ -36,9 +36,11 @@ func printOutput(results []*lokicompliance.Result, cfg OutputConfig) error { } func outp(output io.Writer, results []*lokicompliance.Result, cfg OutputConfig) error { - for _, r := range results { - if d := r.Diff; d != "" && !r.Unsupported { - fmt.Printf("%q:\n%s\n", r.TestCase.Query, d) + if cfg.PrintFailed { + for _, r := range results { + if d := r.Diff; d != "" && !r.Unsupported { + fmt.Printf("%q:\n%s\n", r.TestCase.Query, d) + } } } diff --git a/dev/local/ch-logql-compliance/run.sh b/dev/local/ch-logql-compliance/run.sh index 91d82ca5..55ae468b 100755 --- a/dev/local/ch-logql-compliance/run.sh +++ b/dev/local/ch-logql-compliance/run.sh @@ -18,4 +18,5 @@ END="5s" go run github.com/go-faster/oteldb/cmd/logql-compliance-tester \ -end "${END}" -range "${RANGE}" \ -config-file logql-test-queries.yml -config-file test-oteldb.yml \ - -output-format json -output-file result.oteldb.json || true + -output-format json -output-file result.oteldb.json \ + -print-failed || true