-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add initial support for print() function #3868
Conversation
999a778
to
e856927
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far! 👀
As for "breaking" I was probably into my second year of working with OPA before I really started using I suspect the special treatment of If an OPA admin wants to forbid |
844bd45
to
d89c79e
Compare
@anderseknert @srenatus I've fixed the outstanding issue and added e2e tests for the server and addressed the comments. I've added a small section to the language reference for the function. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Doc update is great 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 🥳 Let's make sure we get a proper announcement for this when it comes wrapped in a release.
💭 How will this break now? package p
x {
print("hello")
}
print(x) = trace(sprintf("trace: %v", [x])) |
@srenatus your example shouldn't break; the
This applies to all built-ins... even ones with infix operators 😅 ...
|
3fd7313
to
1d71393
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
GK users would appreciate this, too, I think. Have we reached out already? Would be nice if it made it into a GK release not too long after OPA... |
@ashutosh-narkar right |
87d42ae
87d42ae
to
5c79586
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm changes look good to me ✔️
x := NewTerm(gen.Generate()).SetLocation(args[j].Loc()) | ||
capture := Equality.Expr(x, args[j]).SetLocation(args[j].Loc()) | ||
arr = arr.Append(SetComprehensionTerm(x, NewBody(capture)).SetLocation(args[j].Loc())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use some sort of helper, walking a term and calling SetLocation on anything that accepts it.
Something's still funky with the wasm pieces:
|
So, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'll deal with value_dump and empty sets in another PR.
☝️ With that commit cherry-picked, we get:
|
5c79586
to
af5adcc
Compare
This commit prevents the rewriting step from attempting to capture the result of void function calls. This avoids generating invalid queries that will fail to type check. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit fixes the output var analysis for nested calls. Previously, statements like `x = split("abc", "")[y]` would not mark `x` or `y` as outputs. The reason was that the output var analysis was never invoked at an early enough stage in the compiler where these nested calls still existed. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
The print built-in function has special-case handling in two ways: 1. Print arguments are wrapped in comprehensions at compile-time to ensure that undefined values do not short-circuit evaluation. The evaluator is aware of this rewriting and extracts the actual values during evaluation. 2. Print arguments cannot contain unsafe/undeclared variables, i.e., vars appearing in refs inside of print args _must_ be assigned in a previous expression in the body. This ensures that print statements do not affect the semantics of the rule. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit does not change any functionality except it provides callers with a way to provide a logger when instantiating the runtime. Previously, the runtime had hardcoded dependencies on the global logrus logger which made it problematic to test logging behaviour. With this change, the logger can be supplied as a parameter (which allows the caller to mock out the logger in tests...) As part of this change, the dependencies on logrus have been moved out of the runtime package entirely. This commit includes a breaking change to the runtime.NewLoggingHandler function: the function now requires a logger to be supplied. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit enables print() calls inside of the server for INFO and DEBUG log levels. The print hook is plumbed through to the server via the manager so that other server implementations (e.g., the Envoy plugin) can be updated similarly. The server will compile print() calls for the /v1/query API but not others since (i) print() calls inside the policies will already have been compiled and (ii) the queries are limited to fetching `data` paths and therefore cannot contain print() calls themselves. The bundle plugin has been updated to compile print() calls as well--this way the bundle plugin/server will respect incoming bundles and not attempt to override them. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit plumbs the print hook through to the wasm runtime so that print calls are enabled when the wasm target is on. This commit also updates the planner and compiler to support calls to void functions--previously, the planner and wasm backend assumed that functions returned values so they would perform checks for defined values, however, with void functions, those checks must be suppressed. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This is still WIP but the core implementation is there. Remaining work:
opa test
opa eval
🐛 I've found an issue during manual testing with nested calls, e.g.,x = split("A,B,C", ",")[_]; print(x)
generates an error right now because the output var analysis doesn't take into account nested calls. Will fix this tomorrow.