Partial evaluation response simplification #121
-
Hello We have a use case where we create some policies those contain somehow complex operators as
To visualise the situation, let's say we have multiple complex operations package pkg
custom_business_condition1(collection1) {
lhs := { x |
x := collection1[_].value
x.important
}
count(lhs) == 0
}
custom_business_condition2(collection1, collection2) {
lhs := { x |
x := collection1[_].value
x.important
}
rhs := { x | x := collection2[_].value}
count(lhs) == count(lhs & rhs)
}
allow {
custom_business_condition1(input.col1)
custom_business_condition2(input.col1, input.col2)
} And then this policy (among other similar policies) bundled and the policies need to be called by different services via As it is now, with an example input {
"col2": [
{
"value": "a"
}
]
} Partial evaluation result will be as below # Query 1
__local2__2 = {__local1__2 | __local1__2 = input.col1[_].value; __local1__2.important}
count(__local2__2, 0)
__local6__3 = {__local5__3 |
__local5__3 = input.col1[_].value
__local5__3.important
}
count(__local6__3 & {"a"}, count(__local6__3)) The resulting We are looking into a way that OPA sends directly the function name in the partial evaluation response as Therefore, instead of having to deal with the low level rego conditions, the expected partial evaluation response in Rego format could be simplified to this: # Query 1
custom_business_condition1(input.col1)
custom_business_condition2(input.col1, [{"value": "a"}]) The services that call OPA will then be able to create and optimize the condition (eg. One possible solution we have looked into is creating these complex operations as built-in functions and compile our own dialect of OPA. This seems to work fine but also comes with a con that we would need to build our own instance of OPA executable. I was wondering if there's a way to achieve this without extending OPA or a feature in the road-map? Maybe some kind of annotation for the functions to hint OPA for this behavior? # @compile_api_unwrap(false)
custom_business_condition1(collection1) {
...
} Looking forward to hear your ideas and suggestions |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There are more comprehensive inlining controls available when using the golang library. Would those do the trick for you? Perhaps exposing some more of those via the compile API would be a way forward 🤔 |
Beta Was this translation helpful? Give feedback.
There are more comprehensive inlining controls available when using the golang library. Would those do the trick for you? Perhaps exposing some more of those via the compile API would be a way forward 🤔