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

Support CelOptions.enableComprehension(boolean) for feature parity with CEL-Cpp #484

Open
2 of 3 tasks
sergiitk opened this issue Oct 24, 2024 · 0 comments
Open
2 of 3 tasks

Comments

@sergiitk
Copy link
Member

sergiitk commented Oct 24, 2024

Feature request checklist

  • There are no issues that match the desired change
  • The change is large enough it can't be addressed with a simple Pull Request
  • If this is a bug, please file a Bug Report.

Change
To make CEL environment setup consistent across CEL implementations, I propose to add a runtime option equivalent to CEL-cpp InterpreterOptions.enable_comprehension to CEL-Java and CEL-Go (corresponding ticket google/cel-go#1050).

CelOptions.enableComprehension is true by default. Setting it to false will disable comprehension expressions (e.g. exists(), all() -- except has()). Under-the-hood it may simply call comprehensionMaxIterations(0) to disable comprehension expressions, and reset it to the default value to enable them.

Example

private static final CelRuntime CEL_RUNTIME = CelRuntimeFactory
    .standardCelRuntimeBuilder()
    .setOptions(CelOptions.current().enableComprehension(false).build())
    .build();
@Test
public void macros_comprehensionsDisabled() throws Exception {
  CelCompiler CEL_COMPILER = CelCompilerFactory.standardCelCompilerBuilder()
    .addVar("request", SimpleType.ANY)
    .setResultType(SimpleType.BOOL)
    .setStandardMacros(CelStandardMacro.STANDARD_MACROS)
    .build();

  String expr = "size(['foo', 'bar'].map(x, request[x])) == 2";
  CelRuntime.Program program = CEL_RUNTIME.createProgram(CEL_COMPILER.compile(expr).getAst());

  Map<String, ?> input = ImmutableMap.of("request", ImmutableMap.of("foo", "f", "bar", "b"));
  CelEvaluationException celErr = assertThrows(CelEvaluationException.class, () -> program.eval(input));

  assertThat(celErr.getErrorCode()).isEqualTo(CelErrorCode.ITERATION_BUDGET_EXCEEDED);
}

Related
Internal ref: go/grpc-cel-integration

@sergiitk sergiitk changed the title SupportCelOptions.enableComprehension(boolean) for feature parity with CEL-Cpp Support CelOptions.enableComprehension(boolean) for feature parity with CEL-Cpp Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant