Skip to content

Commit

Permalink
feat(logql-compliance-tester): add a flag to print diffs to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Apr 28, 2024
1 parent 09724e8 commit f29231d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cmd/logql-compliance-tester/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type OutputConfig struct {
OutputFormat string
OutputPassing bool
OutputUnsupported bool
PrintFailed bool
MinimumPercentage float64
}

Expand All @@ -43,6 +44,7 @@ type Flags struct {
OutputFormat string
OutputPassing bool
OutputUnsupported bool
PrintFailed bool
MinimumPercentage float64
}

Expand All @@ -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")
}

Expand Down Expand Up @@ -99,6 +102,7 @@ func parseConfig() (c Config, _ error) {
OutputFormat: flags.OutputFormat,
OutputPassing: flags.OutputPassing,
OutputUnsupported: flags.OutputUnsupported,
PrintFailed: flags.PrintFailed,
MinimumPercentage: flags.MinimumPercentage,
}

Expand Down
8 changes: 5 additions & 3 deletions cmd/logql-compliance-tester/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion dev/local/ch-logql-compliance/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f29231d

Please sign in to comment.