Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rego: Parse store modules iff modules set on the Rego object #6081

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions rego/rego.go
Original file line number Diff line number Diff line change
Expand Up @@ -1736,22 +1736,20 @@ func (r *Rego) prepare(ctx context.Context, qType queryType, extras []extraStage
}

func (r *Rego) parseModules(ctx context.Context, txn storage.Transaction, m metrics.Metrics) error {
if len(r.modules) == 0 {
return nil
}

ids, err := r.store.ListPolicies(ctx, txn)
if err != nil {
return err
}

// if there are no raw modules, nor modules in the store, then there
// is nothing to do.
if len(r.modules) == 0 && len(ids) == 0 {
return nil
}

m.Timer(metrics.RegoModuleParse).Start()
defer m.Timer(metrics.RegoModuleParse).Stop()
var errs Errors

// Parse any modules in the are saved to the store, but only if
// Parse any modules that are saved to the store, but only if
// another compile step is going to occur (ie. we have parsed modules
// that need to be compiled).
for _, id := range ids {
Expand Down
8 changes: 4 additions & 4 deletions sdk/opa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ main = true
t.Fatal("expected true but got:", decision, ok)
}

if exp, act := 5, len(m.All()); exp != act {
if exp, act := 4, len(m.All()); exp != act {
t.Fatalf("expected %d metrics, got %d", exp, act)
}

Expand Down Expand Up @@ -576,7 +576,7 @@ main = true
t.Fatal("expected true but got:", decision, ok)
}

if exp, act := 26, len(m.All()); exp != act {
if exp, act := 25, len(m.All()); exp != act {
t.Fatalf("expected %d metrics, got %d", exp, act)
}

Expand Down Expand Up @@ -1024,7 +1024,7 @@ allow {
t.Fatal("expected &{[2 = data.junk.x] []} true but got:", decision, ok)
}

if exp, act := 6, len(m.All()); exp != act {
if exp, act := 5, len(m.All()); exp != act {
t.Fatalf("expected %d metrics, got %d", exp, act)
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ allow {
t.Fatal("expected &{[2 = data.junk.x] []} true but got:", decision, ok)
}

if exp, act := 33, len(m.All()); exp != act {
if exp, act := 32, len(m.All()); exp != act {
t.Fatalf("expected %d metrics, got %d", exp, act)
}

Expand Down
1 change: 0 additions & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ func TestCompileV1Observability(t *testing.T) {
"timer_rego_partial_eval_ns",
"timer_rego_query_compile_ns",
"timer_rego_query_parse_ns",
"timer_rego_module_parse_ns",
"timer_server_handler_ns",
"counter_disk_read_keys",
"timer_disk_read_ns",
Expand Down