Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit b4c782f

Browse files
GabeVillalobosmarkstory
andauthoredMay 31, 2024··
feat(flagpole): Adds core flagpole documentation (#1297)
Co-authored-by: Mark Story <[email protected]>
1 parent a205f25 commit b4c782f

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
 

‎src/docs/feature-flags/flagpole.mdx

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Flagpole
2+
Flagpole is Sentry's internal, options-backed feature flagging library.
3+
4+
Features are defined in the [`sentry-options-automator`](https://github.com/getsentry/sentry-options-automator) repository as yaml objects within the [`options/defaults/flagpole.yml`](https://github.com/getsentry/sentry-options-automator/blob/main/options/default/flagpole.yml) file.
5+
These yaml options are pushed to each of our deployments and stored in a database table, where they are later queried and parsed during feature flag evaluation.
6+
7+
Here's the example configuration for a feature named `organizations:is_sentry`, which is enabled for an organization with the slug `sentry`.
8+
```yaml
9+
options:
10+
'feature.organizations:is_sentry':
11+
created_at: '2024-06-01T00:00:00.000000'
12+
enabled: false
13+
owner: hybrid-cloud
14+
segments:
15+
- conditions:
16+
- operator: in
17+
value:
18+
- sentry
19+
property: organization_slug
20+
name: is_sentry
21+
rollout: 100
22+
```
23+
24+
## Flagpole Feature Yaml Structure
25+
26+
`created_at`
27+
28+
: The ISO 8601 datetime of when the feature was added to the config yaml.
29+
30+
`owner`
31+
32+
: The team name or email of the user that owns this feature flag
33+
34+
`enabled` [optional]
35+
36+
: The global toggle for the feature flag. Defaults to `True`. Setting this to `False` can be a break-glass safety valve to disable a feature without having to modify existing segments or conditions.
37+
38+
`segments`
39+
40+
: A wrapper around a list of conditions, acting as a logical grouping of customers/entities to enable the feature flag for. If no segments are defined, the feature will evaluate to `True`. Segments allow you to create `OR` operations with other segments. At least one segment must evaluate to `True` for a feature to be granted.
41+
42+
### Segments
43+
`conditions`
44+
45+
: A list of predicates to evaluate for the feature flag to be enabled for this segment. All conditions in a segment must be evaluate to `True` in order for the segment to be enabled. If no conditions are defined, the segment will evaluate to `False`.
46+
47+
`name`
48+
49+
: A brief description of the segment identifying its intended purpose.
50+
51+
`rollout` [optional]
52+
53+
: A percentage of entities to enable the feature for, defined as an integer between `0` - `100`. Defaults to `100`.
54+
55+
56+
### Conditions
57+
`property`
58+
59+
: The property name of the evaluation context entry to match against.
60+
61+
`value`
62+
63+
: The expected value to compare against the evaluation context's property value, using the provided operator.
64+
65+
`operator`
66+
67+
: The comparison strategy to apply between the evaluation context's property value and the provided condition value.
68+
69+
70+
### Operators
71+
Flagpole currently supports the following `operator` types:
72+
73+
`in`
74+
75+
: Given a list of values, evaluates to `True` if the context property value exists in the list.
76+
77+
`not_in`
78+
79+
: The inverse of `in`, evaluates to `True` if the context property value does not exist in the provided list.
80+
81+
`contains`
82+
83+
: Given a single int, string, float, or boolean value, evalutes to `True` if the context property value is a list containing the provided value.
84+
85+
`not_contains`
86+
87+
: The inverse of `contains`, evalutes to `True` if the context property value is a list which does not contain the provided value.
88+
89+
`equals`
90+
91+
: Given a single int, string, float, or boolean value, evaluates to `True` if the context property value exactly matches the provided value.
92+
93+
`not_equals`
94+
95+
: The inverse of `equals`, evaluates to `True` if the context property value does not match the provided value.
96+
97+
## Evaluation Contexts
98+
When a feature flag is checked, the caller must provide one or more entity objects for the feature handler to match against. These objects are used to construct an `EvaluationContext`, which is essentially a flat dictionary of keys and primitive values. This context is passed to each feature, which provides this context to each segment and condition to enforce whether the feature should be enabled.
99+
100+
### Context Builders
101+
Each evaluation context is built up in stages via a [`ContextBuilder`](https://github.com/getsentry/sentry/blob/3cbf73a389a4ea006cbad9d8c4b8073effe09393/src/flagpole/evaluation_context.py#L54) object.
102+
103+
Each context builder consists of a list of context transformers, which are responsible for creating individual slices of the larger evaluation context.
104+
105+
## Rolling out a new Flagpole feature
106+
107+
Creating a new Flagpole Feature is currently a 3 step process:
108+
1. Register a new feature in GetSentry's `features.py` file with the Flagpole strategy:
109+
```python
110+
features.add(
111+
"<feature_scope>:<feature_name>",
112+
OrganizationFeature,
113+
FeatureHandlerStrategy.FLAGPOLE
114+
)
115+
```
116+
117+
2. Add a new feature object entry to sentry-options-automator's `flagpole.yml` file. The feature's option name must follow the following format in order to be picked up by Flagpole:
118+
119+
`feature.<feature_scope>:<feature_name>`.
120+
121+
3. Add the feature name to the `flagpole.flagpole_only_features` list in sentry-options-automator's default [`app.yaml`](https://github.com/getsentry/sentry-options-automator/blob/483737d45dbc68253e926c3f860b5ae33111697b/options/default/app.yaml#L219) file, omitting the `feature.` prefix.
122+
123+
Once the option change is deployed, the feature checks will immediately be active in all environments and regions.
124+
125+
126+
## Testing a Flagpole feature locally
127+
You can test a flagpole feature flag locally using the GetSentry devserver. Because the feature handler for Flagpole only exists in GetSentry, it's not currently possible to test Sentry-only flagpole features.
128+
129+
Start by creating a new yaml file containing your feature config.
130+
131+
You can push your feature option to your local devserver using the following `getsentry` CLI command:
132+
133+
```bash
134+
getsentry configoptions -f <path>/<to>/<your>/<config>.yml -l DEBUG patch
135+
```
136+
137+
If this command runs successfully, your flagpole feature should now be active in your local devserver instance and will persist across runs until you remove the feature option.

0 commit comments

Comments
 (0)
This repository has been archived.