Skip to content

Commit

Permalink
docs(schema): update rules to include JSON values; update image
Browse files Browse the repository at this point in the history
  • Loading branch information
heitorlessa committed Dec 31, 2021
1 parent c34b7ff commit 801c6b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/feature_flags/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SchemaValidator(BaseValidator):
A dictionary containing default value and rules for matching.
The value MUST be an object and MIGHT contain the following members:
* **default**: Union[`bool`, `JSONType`]. Defines default feature value. This MUST be present
* **default**: `Union[bool, JSONType]`. Defines default feature value. This MUST be present
* **boolean_type**: bool. Defines whether feature has non-boolean value (`JSONType`). This MIGHT be present
* **rules**: `Dict[str, Dict]`. Rules object. This MIGHT be present
Expand All @@ -74,7 +74,7 @@ class SchemaValidator(BaseValidator):
A dictionary with each rule and their conditions that a feature might have.
The value MIGHT be present, and when defined it MUST contain the following members:
* **when_match**: Union[`bool`, `JSONType`]. Defines value to return when context matches conditions
* **when_match**: `Union[bool, JSONType]`. Defines value to return when context matches conditions
* **conditions**: `List[Dict]`. Conditions object. This MUST be present
```python
Expand Down
Binary file removed docs/media/feat_flags_evaluation_workflow.png
Binary file not shown.
31 changes: 25 additions & 6 deletions docs/utilities/feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,15 @@ A feature can simply have its name and a `default` value. This is either on or o

=== "minimal_schema.json"

```json hl_lines="2-3"
```json hl_lines="2-3 6-7"
{
"global_feature": {
"default": true
}
},
"non_boolean_global_feature": {
"default": {"group": "read-only"},
"boolean_type": False
},
}
```

Expand All @@ -404,12 +408,12 @@ If you need more control and want to provide context such as user group, permiss
When adding `rules` to a feature, they must contain:

1. A rule name as a key
2. `when_match` boolean value that should be used when conditions match
2. `when_match` boolean or JSON value that should be used when conditions match
3. A list of `conditions` for evaluation

=== "feature_with_rules.json"

```json hl_lines="4-11"
```json hl_lines="4-11 19-26"
{
"premium_feature": {
"default": false,
Expand All @@ -425,6 +429,21 @@ When adding `rules` to a feature, they must contain:
]
}
}
},
"non_boolean_premium_feature": {
"default": [],
"rules": {
"customer tier equals premium": {
"when_match": ["remove_limits", "remove_ads"],
"conditions": [
{
"action": "EQUALS",
"key": "tier",
"value": "premium"
}
]
}
}
}
}
```
Expand Down Expand Up @@ -474,9 +493,9 @@ Action | Equivalent expression

#### Rule engine flowchart

Now that you've seen all properties of a feature flag schema, this flowchart describes how the rule engines makes a decision on when to return `True` or `False`.
Now that you've seen all properties of a feature flag schema, this flowchart describes how the rule engine decides what value to return.

![Rule engine ](../media/feat_flags_evaluation_workflow.png)
![Rule engine ](../media/feature_flags_diagram.png)

### Adjusting in-memory cache

Expand Down

0 comments on commit 801c6b9

Please sign in to comment.