13 Feature Toggle Settings Scenarios
Pratik Bhattacharya редактировал(а) эту страницу 2021-12-18 01:51:39 +05:30

Feature Toggle Settings Scenarios

In this section we will discuss the various scenarios that you may encounter while creating/evaluating a feature toggle, and how the feature flag will be configured in those scenarios.

Scenario 1 - Feature flag with condition that user's UPN must belong to a list of UPN

Feature Flag

{
    "name": "Scenario-1-Single-Filter",
    "description": "UPN must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "UserUPN",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com",
                    "isActive": "true",
                    "stageId": "0",
                    "stageName": "Ring 1",
                    "flightContextKey": "UserUPN"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "UserUPN": "jarvis@gmail.com" } true UPN part of the list
{ "UserUPN": "bruce.wayne@gmail.com" } false UPN not part of the list

Scenario 2 - Feature flag with condition that user's UPN must belong to a list of UPNs or the user must be from USA

Feature Flag

{
    "name": "Scenario-2-Multi-Filter",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "UserUPN",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com",
                    "isActive": "true",
                    "stageId": "0",
                    "stageName": "Ring 1",
                    "flightContextKey": "UserUPN"
                }
            },
            {
                "name": "Country",
                "parameters": {
                    "operator": "Equals",
                    "value": "USA",
                    "isActive": "true",
                    "stageId": "0",
                    "stageName": "Ring 1",
                    "flightContextKey": "Country"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "UserUPN": "jarvis@gmail.com", "Country": "USA" } true Both UPN and country matches
{ "UserUPN": "bruce.wayne@gmail.com", "Country": "USA" } true UPN not part of the list but country passes
{ "UserUPN": "bruce.wayne@gmail.com", "Country": "UK" } false Nor UPN neither country passes

Scenario 3 - Feature flag with condition that user's UPN must belong to a list of UPNs (but flight context key is different)

Feature Flag

{
    "name": "Scenario-3-Context-Key",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "UserUPN",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com",
                    "isActive": "true",
                    "stageId": "0",
                    "stageName": "Ring 1",
                    "flightContextKey": "Id"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "Id": "jarvis@gmail.com" } true UPN part of the list
{ "UserUPN": "jarvis@gmail.com" } false The required key Id is not present in the context
{ "Id": "jarvis@gmail.com" } false UPN not part of the list

Scenario 4 - Draft/disabled feature flag

Feature Flag

{
    "name": "Scenario-4-Disabled",
    "description": "Mail must belong to any of the configured value",
    "enabled": false,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "Generic",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com",
                    "isActive": "true",
                    "stageId": "0",
                    "stageName": "Ring 1",
                    "flightContextKey": "UserMail"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "UserMail": "jarvis@gmail.com" } false Email part of the list but feature flag is disabled
{ "UserMail": "bruce.wayne@gmail.com" } false Condition won't be evaluated since feature flag is disabled

Scenario 5 - Feature flag with 2 stages/rings, with second Ring being disabled

{
    "name": "Scenario-5-Multi-Ring",
    "description": "Mail must belong to any of the configured value",
    "enabled": false,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "Generic",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "Ring 1",
                    "flightContextKey": "UserMail"
                }
            },
            {
                "name": "Generic",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com,wanda@vision.com,pepper.potts@gmail.com,thor@asgard.com",
                    "isActive": "false",
                    "stageId": "2",
                    "stageName": "Ring 2",
                    "flightContextKey": "UserMail"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "UserMail": "jarvis@gmail.com" } true Email part of the Ring1's list
{ "UserMail": "thor@asgard.com" } false Email part of Ring 2, but Ring 2 is disabled

Scenario 6 - Feature flag with 2 stages/rings, with second Ring being disabled and each Ring having 2 filters

{
    "name": "Scenario-6-Rings",
    "description": "Mail must belong to any of the configured value",
    "enabled": false,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "Generic",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "Ring 1",
                    "flightContextKey": "UserMail"
                }
            },
            {
                "name": "Country",
                "parameters": {
                    "operator": "Equal",
                    "value": "USA",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "Ring 1",
                    "flightContextKey": "Country"
                }
            },
            {
                "name": "Generic",
                "parameters": {
                    "operator": "In",
                    "value": "tonystark@gmail.com,jarvis@gmail.com,peter.parker@outlook.com,wanda@vision.com,pepper.potts@gmail.com,thor@asgard.com",
                    "isActive": "false",
                    "stageId": "2",
                    "stageName": "Ring 2",
                    "flightContextKey": "UserMail"
                }
            },
            {
                "name": "Country",
                "parameters": {
                    "operator": "In",
                    "value": "USA,India,UK",
                    "isActive": "false",
                    "stageId": "2",
                    "stageName": "Ring 2",
                    "flightContextKey": "Country"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "UserMail": "jarvis@gmail.com", "Country": "USA" } true Email and Country part of the Ring 1's list
{ "UserMail": "thor@asgard.com", "Country": "USA" } true Email part of Ring 2, but Ring 2 is disabled however Country part of Ring 1
{ "UserMail": "thor@asgard.com", "Country": "UK" } false Email and Country part of disabled Ring 2

Scenario 7 - Feature flag with UPN part of a Security Group/Office 365 Group

{
    "name": "Scenario-1",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "UserUpn",
                "parameters": {
                    "operator": "MemberOfSecurityGroup",
                    "value": "[{\"Name\":\"HERO_GROUP\",\"ObjectId\":\"HERO_GROUP_OIBJECT_ID_GUID\"}]",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "Ring 1",
                    "flightContextKey": "UPN"
                }
            },
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "UPN": "jarvis@gmail.com" } true Assuming jarvis@gmail.com is part of HERO_GROUP
{ "UPN": "mikefury@shield.com" } false Assuming mikefury@shield.com is not part of HERO_GROUP

Scenario 8: Always ON feature flag (after global rollout)

{
    "name": "Scenario-8-Always-On",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "Generic",
                "parameters": {
                    "operator": "Equals",
                    "value": "1",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "Ring 1",
                    "flightContextKey": "Enabled"
                }
            },
        ]
    }
}

X-FlightContext Samples

Will work for any combination of flight context

Scenario 9 - Feature flag with Simple Rule Engine

Feature Flag

{
    "name": "Scenario-9-Simple-Rule-Engine",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "RulesEngine",
                "parameters": {
                    "operator": "Evaluates",
                    "value": "TestFeatureRule",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "stg1",
                    "flightContextKey": "RulesEngine"
                }
            }
        ]
    }
}

Rule Engine (TestFeatureRule)

{
    "WorkflowName": "TestFeatureRule",
    "Rules": [
      {
        "RuleName": "Country_India_UK",
        "SuccessEvent": "Success_Country",
        "ErrorMessage": "Country must be UK or India",
        "ErrorType": "Error",
        "RuleExpressionType": "LambdaExpression",
        "Expression": "Country == \"UK\" OR Country == \"India\""
      }
    ]
  }

X-FlightContext Samples

Value Result Comments
{ "Country": "UK" } true Country_India_UK rule passes
{ "Country": "USA" } false Country_India_UK rule fails
{ "UPN": "jarvis@gmail.com" } true Country input is not present

Scenario 10 - Feature flag with Rule Engine with multiple rules and additional operators

Feature Flag

{
    "name": "Scenario-10-Rule-Engine-Multiple-Rules",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "RulesEngine",
                "parameters": {
                    "operator": "Evaluates",
                    "value": "TestFeatureRule",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "stg1",
                    "flightContextKey": "RulesEngine"
                }
            }
        ]
    }
}

Rule Engine (TestFeatureRule)

{
    "WorkflowName": "TestFeatureRule",
    "Rules": [
      {
        "RuleName": "Country_India_UK",
        "SuccessEvent": "Success_Country",
        "ErrorMessage": "Country must be UK or India",
        "ErrorType": "Error",
        "RuleExpressionType": "LambdaExpression",
        "Expression": "Country == \"UK\" OR Country == \"India\""
      },
      {
        "RuleName": "UPN_HERO_GROUP",
        "SuccessEvent": "Success_UPN_Group",
        "ErrorMessage": "UPN must be in HERO GROUP",
        "ErrorType": "Error",
        "RuleExpressionType": "LambdaExpression",
        "Expression": "Operator.IsMember(UserPrincipalName, \"HERO_GROUP_OBJECT_ID\")"
      },
      {
        "RuleName": "EmployeeType",
        "SuccessEvent": "Success_EMP_IN",
        "ErrorMessage": "Emp Type must be 1,2,3,4",
        "ErrorType": "Error",
        "RuleExpressionType": "LambdaExpression",
        "Expression": "Operator.In(EmpType, \"1,2,3,4\")"
      }
    ]
  }

X-FlightContext Samples

Value Result Comments
{ "Country": "UK", "UserPrincipalName": "tonystark@gmail.com", "EmpType": 3 } true All rule passes
{ "Country": "UK", "UserPrincipalName": "tonystark@gmail.com", "EmpType": 7 } false EmpType fails
{ "Country": "UK", "EmpType": 7 } false UserPrincipalName is missing

Scenario 11 - Feature flag with Complex Rule Engine with multiple local params

Feature Flag

{
    "name": "Scenario-11-Rule-Engine-Multiple-Local-Params",
    "description": "Mail must belong to any of the configured value",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "RulesEngine",
                "parameters": {
                    "operator": "Evaluates",
                    "value": "Complex_Rule",
                    "isActive": "true",
                    "stageId": "1",
                    "stageName": "stg1",
                    "flightContextKey": "RulesEngine"
                }
            }
        ]
    }
}

Rule Engine (Complex_Rule)

{
    "WorkflowName": "Complex_Rule",
    "Rules": [
      {
        "RuleName": "Allow onsite architects or offsite engineers",
        "SuccessEvent": "Show_Architect_Dashboard",
        "ErrorMessage": "Eval failed",
        "ErrorType": "Error",
        "LocalParams": [
          {
            "Name": "Onsite_Architects",
            "Expression": "Country == \"USA\" OR Region == \"Europe\" AND JobTitle == \"Architect\""
          },
          {
            "Name": "Offsite_Engineers",
            "Expression": "Country == \"India\" AND JobTitle == \"Engineer\""
          }
        ],
        "Expression": "Onsite_Architects == true || Offsite_Engineers == true"
      }
    ]
  }

X-FlightContext Samples

Value Result Comments
{ "Country": "USA", "Region": "America", "JobTitle": "Architect" } true Matches first local param
{ "Country": "India", "Region": "Asia", "JobTitle": "Engineer" } true Matches second local param
{ "Country": "India", "Region": "Asia", "JobTitle": "Architect" } false Matches neither param

Scenario 12 - Feature flag with Generic filter (IP Address)

Feature Flag

{
    "name": "Scenario-12-Generic-IP-Address",
    "description": "IP Address must be in the list",
    "enabled": true,
    "environment": "dev",
    "conditions": {
        "client_filters": [
            {
                "name": "Generic",
                "parameters": {
                    "operator": "In",
                    "value": "192.89.10.32,194.67.91.01,251.87.15.42,199.65.98.03",
                    "isActive": "true",
                    "stageId": "0",
                    "stageName": "Ring 1",
                    "flightContextKey": "IPAddress"
                }
            }
        ]
    }
}

X-FlightContext Samples

Value Result Comments
{ "IPAddress": "199.65.98.03" } true IP Address part of the list
{ "IPAddress": "180.30.45.62" } false IP Address not part of the list
{ "IP": "199.65.98.03" } false The key IPAddress is not present in the flight context