-
Notifications
You must be signed in to change notification settings - Fork 57
5. Development
The idea behind feature flags is that new features can be enabled/disabled per environment with a simple configuration change.
Some of the FEC projects are using feature flags which work similarly. In general, they work with an environment variable or user provided credential (on Cloud Foundry). This is parsed and made available as a FEATURES
dictionary with boolean fields describing whether the feature is active or not.
settings.py includes a set of FEATURES
which can be enabled using environment flags or via settings.local
.
# settings/local.py
FEATURES['legal'] = 1
or at runtime
FEC_FEATURE_LEGAL=1 python manage.py runserver
The feature flags are provided by the credential service. cf
will update the service wholesale, so you must include all existing values. Anything not included will be removed.
First copy the existing parameters so you don't blow them away.
cf env fec-creds-dev
...
"user-provided": [
{
"credentials": {
"FEC_FEATURE_LEGAL": "true",
"FEC_FEATURE_FOO": "true"
},
"label": "user-provided",
"name": "fec-creds-dev",
"syslog_drain_url": "",
"tags": [],
"volume_mounts": []
},
...
Find the credentials for the right service you're modifying, e.g. fec-creds-dev
.
"name": "fec-creds-dev",
Copy the JSON keys to file e.g fec-creds-dev.json
, then add or update the key you want to change. To disable a feature, be sure it set it to the empty string or remove it from the credential service entirely. "0"
will actually evaluate to True
.
cf update-user-provided-service fec-creds-dev -p fec-creds-dev.json
You can restage
the app or re-deploy without downtime via cf zero-downtime-push app -f manifest.yml
.
Feature flags introduce complexity to your app because there is additional code that runs conditionally when the feature is enabled. This can make code difficult to read, as you may have to check the environment configuration to determine if certain code paths are executing or not.
- Don't combine feature flags
- Avoid checking the feature flag in multiple places, the fewer the better.
- The code that runs under the feature flag should be as simple as possible e.g. adding a CSS class or hiding/showing a link to a new page or functionality
- Remove and clean up the feature flag ASAP
- Consider writing tests for both when the feature is enabled and when it is disabled.