Skip to content

Commit

Permalink
feat(logql-compliance-tester): count unsuccessful results
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Apr 27, 2024
1 parent d7fb867 commit d6da84e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cmd/logql-compliance-tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func run(ctx context.Context) error {
)
// Progress bar messes up Github Actions logs, so keep it static.
if os.Getenv("GITHUB_ACTIONS") == "true" {
progressBar.Set(pb.Static, true)
progressBar.SetTemplate(pb.Default + `{{ "\n" }}`)
}

grp, grpCtx := errgroup.WithContext(ctx)
Expand All @@ -68,7 +68,7 @@ func run(ctx context.Context) error {
if err := grp.Wait(); err != nil {
return errors.Wrap(err, "run queries")
}
progressBar.Finish().Write()
progressBar.Finish()

return printOutput(results, cfg.Output)
}
Expand Down
24 changes: 18 additions & 6 deletions cmd/logql-compliance-tester/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,34 @@ func outp(output io.Writer, results []*lokicompliance.Result, cfg OutputConfig)
}

func verifyTargetCompliance(results []*lokicompliance.Result, target float64) error {
var successes, unsupported int
var successes, differ, unsupported int
for _, res := range results {
if res.Success() {
switch {
case res.Success() && !res.Unsupported:
successes++
}
if res.Unsupported {
case res.Unsupported:
unsupported++
default:
differ++
}
}

fmt.Println(strings.Repeat("=", 80))
successPercentage := 100 * float64(successes) / float64(len(results))

fmt.Printf("Total: %d / %d (%.2f%%) passed, %d unsupported\n",
successes, len(results), successPercentage, unsupported,
fmt.Printf("Total: %d / %d (%.2f%%) passed",
successes, len(results), successPercentage,
)
if differ > 0 {
fmt.Print(", ")
fmt.Print(color.RedString("%d differ", differ))
}
if unsupported > 0 {
fmt.Print(", ")
fmt.Print(color.YellowString("%d unsupported", unsupported))
}
fmt.Println()

if math.IsNaN(target) {
return nil
}
Expand Down

0 comments on commit d6da84e

Please sign in to comment.