Skip to content

Concepts: Filter and Operators

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

Filters

A feature flag consists of one or more filters. The Filters represents the conditions for evaluating the Feature Flag. For example, if a feature flag needs be true if either the user belongs to USA (location) or if the user's UPN belongs to a list of users, then the flag will have 2 filters - Country and UPN. A filter mainly consists of the below attributes

  • Filter Name - The name of the filter, like Country, UPN, Region, etc.
  • Value - The value against which the condition will be evaluated.
  • Operator - The type of operator that needs to be used while evaluating the filter.
  • FlightContextKey - Attribute name in the Flight Context whose value will be used to operator with the configured value in the Filter.
  • IsActive - Represents if the filter is active. Only active filters are used for evaluation (used for determining Rings).

Joining Filters

If there are n number of filters in a flag, then at least 1 filter must be true for the Feature Flag to be true. Currently there is no way to create a complex expression by joining filters using Relational Operators (like AND). Check Rules Engine filter for authoring complex conditions.

Preset Filters

Based on the common scenarios that are used for feature flighting in Enterprise application we have provided some of the common type of Filter

  • UserUPN - For creating filters based on a user's User Principal Name. The UPN is an unique identifier for a user. The term is used commonly in MS Active Directory. Check this scenario.
  • Country - Country of a user. Check this scenario.
  • Region - Similar to country but represents a wide area like Central America, LATAM, Western Europe, etc.
  • RoleGroup - A numerical value which represents a user's role (for e.g. Manager, Architect, Consultant. etc.). The Role is represented as a number
  • Date - For creating date based filters. For e.g. you might want to light up a feature only for users who has joined in the last 6 months.
  • Alias - An alternate User ID. Generally the Alias is the first portion of a user's UPN, before the domain name. So if a user's UPN is jarvis@gmail.com, then 'jarvis' will be the Alias.
  • RulesEngine - A special filter for evaluating conditions based on JSON Rules Engine. Read more here.

FlightContextKey

The flight context represents the contextual information for evaluating the feature flag. There can be multiple keys in the flight context object. When a filter is getting evaluated, we check the flight context object and select that attribute which has the same name as that of the filter. The value from that attribute is operated against the configured value for the filter.

Flight context key is a special attribute in every filter which allows you to choose the attribute from the Flight Context, i.e., the attribute name in the Flight Context object and the Filter name may not match. For e.g., let's say you have created a Filter of type UserUPN, however, in the flight context your application needs to pass Id instead of UserUPN. In such scenarios, when creating the UserUPN filter you can set the FlightContextKey to Id. Check this scenario for an example.

FlightContextKey is very important for Generic filters.

Generic Filter

If none of the Present Filters match your requirement you can create a Generic filter. For example you might want to create a filter based on User's IP address. Since there is no preset of IP Address, you will need to create a Generic filter for IP Address. The flight context key must be set for a generic filter, for selecting the required attribute from Flight Context. Check this scenario for an example.

Operator

Specifies the kind of operation that will be performed to evaluate a filter condition. For e.g., if you want to equate a value you will use the Equal filter, if you need to check if a value is part of the list then you will use the In operator.

Here are the common operators

Operator Description
Equals Equates the flight context value and configured value
NotEquals Opposite of Equals
In Value from flight context matches any of the configured value in the comma-separated string
NotIn Opposite of In
GreaterThan Flight context value must be greater than the configured value (can be used for strings, numbers and dates)
LesserThan Flight context value must be smaller than the configured value (can be used for strings, numbers and dates)

The common operators can be used in all the filters.

Special Operators

Apart from the above common operators there are some special operators only allowed for some of the filters

Operator Description Supported Filter Comments
MemberOfSecurityGroup Checks if the UserUPN is part of any of the configured Groups UserUPN, Alias See more
NotMemberOfSecurityGroup Checks if the UserUPN is not part of any of the configured UserUPN, Alias See more
Evaluates Returns true if the configured Rules Engine returns true RulesEngine See more
NotEvaluates Returns true if the configured Rules Engine returns false RulesEngine See more