Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import data.regal.result

report contains violation if {
# foo = "bar"
# default foo = "bar
# default foo = "bar"
# foo(bar) = "baz"
# default foo(_) = "bar
# default foo(_) = "bar"
some rule in input.rules
not rule.head.assign
not rule.head.key
Expand Down
48 changes: 48 additions & 0 deletions pkg/linter/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/open-policy-agent/opa/v1/ast"
"github.com/open-policy-agent/opa/v1/topdown"

"github.com/styrainc/regal/bundle"
"github.com/styrainc/regal/internal/cache"
"github.com/styrainc/regal/internal/parse"
"github.com/styrainc/regal/internal/test"
Expand Down Expand Up @@ -784,3 +785,50 @@ func BenchmarkRegalNoEnabledRules(b *testing.B) {
_ = rep.Violations
}
}

// Runs a separate benchmark for each rule in the bundle. Note that this will take *several* minutes to run,
// meaning you do NOT want to do this more than occasionally. You may however find it helpful to use this with
// a single, or handful of rules to get a better idea of how long they take to run, and relative to each other.
// The reason why this is currently so slow is that we parse + compile everything for each rule, which is really
// something we should fix: https://github.com/StyraInc/regal/issues/1394
func BenchmarkEachRule(b *testing.B) {
conf, err := config.LoadConfigWithDefaultsFromBundle(&bundle.LoadedBundle, nil)
if err != nil {
b.Fatal(err)
}

for _, category := range conf.Rules {
for ruleName := range category {
// Uncomment / modify this to benchmark specific rule(s) only
//
// if ruleName != "metasyntactic-variable" {
// continue
// }
b.Run(ruleName, func(b *testing.B) {
linter := NewLinter().
WithInputPaths([]string{"../../bundle"}).
WithBaseCache(cache.NewBaseCache()).
WithDisableAll(true).
WithEnabledRules(ruleName)

b.ResetTimer()
b.ReportAllocs()

var err error

var rep report.Report

for range b.N {
rep, err = linter.Lint(context.Background())
if err != nil {
b.Fatal(err)
}
}

if len(rep.Violations) != 0 {
_ = rep.Violations
}
})
}
}
}
Loading