Hi,
TL;DR: Is there a way to map the variables used in a rule condition to an ID on the EvalState (returned as part of the EvalDetails)?
Context:
I'm evaluating the use of cel-go as the rules engine for a new service. In my use case, I need to know the reason that triggered a specific rule.
Let's say the rule is written as follows:
features.value1 > 100 &&
features.value2 < 500
And my input data has "value1 = 90". I want to know that the rule evaluated to false because of value1.
One way I found to do that was to write the rule as
features.value1 < 100 ? "value1" :
features.value2 > 500 ? "value2" :
""
and then consider it evaluated to true if the returned value is empty. However, I think that harms readability as I need to chain multiple ternary operations.
So I saw that I can use the eval option OptPartialEval and an EvalDetails object will be returned. When I print the values I can see it holds the evaluations in a map with the keys as integers and the value for each operator. However, I don't know how to map variables to those IDs so I can check if the value for the condition was true or false.
Is it possible to do? I appreciate any suggestions (even for other ways of writing the condition).