Skip to content

Concepts: Rules Engine Filter

Pratik Bhattacharya edited this page Dec 17, 2021 · 4 revisions

Rules Engine Filter

Using the custom filter and operators, you can only configure simple expressions (like In, Equals, Greater than, etc.). Another drawback is joining expressions. If you configure multiple filters for a feature flag, the flag will be evaluated to true even if 1 of the filter conditions is evaluated to true. Hence you evaluate the final result by combining results from multiple filters.

For such complex scenarios you can use RulesEngine filter. RulesEngine is an open-source library that can create JSON-based workflows to evaluate rules and complex conditions. You can check the details of Rules Engine in its GitHub repository.

Integration

For utilizing Rules Engine, you will need to create a filter of type RulesEngine, and configure the name of the Workflow/JSON file which contains the rule. The JSON file is kept in an Azure Storage Blob. Tenants who are interested in using Rules Engine filter must provide the Storage Connection String (with Read permission) and the name of the Container where the JSON files will be kept.

Each workflow in a rule engine can have multiple Rules, the feature flag will be evaluated to true only if all the rules passes.

Flight Context Input

The flight context object (header x-flightcontext) is passed an input to the Rule Engine workflow. Hence, if the Rule engine as an expression Country == \"UK\" then the property Country should be present in the flight context object

Check this scenario to evaluate a Simple Rule Engine in a feature flag.

Additional Operators

Rules Engine supports writing dynamic Linq Lambda operations, so you can use simple operators (=, !=, '>', etc.) and relational operators like (||, &&). However, this restricts usage of Graph operators like checking if an User belongs to a Security Group. We leverage ReSettings in Rules Engine to allow custom Operators. that cannot be written in Lamda expressions. All the additional operators are exposed as part of the Operator static class. As of now the following Customer Operators are allowed

Operator Description Example Usage
IsMember Checks if the UPN is part of a Security Group. The UPN and the Group ID are needed as parameters. Operator.IsMember(UserPrincipalName, \"HERO_GROUP_OBJECT_ID\")
IsNotMember Checks if the UPN is not part of a Security Group. The UPN and the Group ID are needed as parameters. Operator.IsNotMember(UserPrincipalName, \"NON_HERO_GROUP_OBJECT_ID\")
In Checks if a given value belongs to a list of values. The list of values are given in comma-separated string. Operator.In(EmpType, \"1,2,3,4\")
NotIn Checks if a given value doesn't belongs to a list of values. The list of values are given in comma-separated string. Operator.NotIn(EmpType, \"5,6,7,8\")

Check this scenario to evaluate a a Rule Engine with custom operators and multiple rules.

Clone this wiki locally