- What do we use to manage Feature Flags?
- Who can manage feature flags?
- How do I manage feature flags?
- What feature flags are available and how do I create new ones?
- How are feature flags used in the app?
- How are feature flags tied to users?
- How do I enabled a feature flag for a percentage of users?
- How do I turn a feature flag off for a user if it is enabled for everyone?
The NPQ app uses Flipper along with Flipper-UI for managing feature flags.
This allows us to enable/disable features in production without having to deploy new code. This also brings us the ability to enable features for specific users, groups of users, or percentage of users. This allows us to manage slowly ramp up new features over time.
This has been used in the past for running a pilot of the Get an Identity service.
User's with the superadmin
role can manage feature flags, see Admins and Superadmins for more information on these users.
To manage feature flags, you need to be logged in as a superadmin
user. You can then visit the /admin/feature_flags/features
path in the app. This is accessible within the admin interface by clicking on the Feature Flags
link in the navigation.
Feature flags can then be fully enabled, disabled, or enabled for a percentage of users.
Feature flags supported by the app are defined in Feature, upon deployment any new feature flags will be created in the database and will be available to be managed. By default they will be turned off.
This is handled by the feature_flags:initialize
rake task that is run as part of the deployment process.
Feature flags can be checked using the standard Flipper syntax, for example:
Flipper.enabled?(:my_feature_flag)
Flipper.enabled?(:my_feature_flag, current_user)
This will return true or false depending on whether the feature flag is enabled for the current user.
On User creation (when they returned from the Get an Identity service) they will have their feature flag ID that was set in their cookies tied to their User record, from then on this will be used for determining their feature flag status. This is typically only important for feature flags set on a percentage of users.
When creating a new feature flag, you can set the percentage of users that the feature flag should be enabled for. This is done by setting the percentage_of_users
field to a value between 0 and 100.
When checking the feature flag you should use the Flipper.enabled?(:my_feature_flag, current_user)
syntax when checking if the flag is enabled. This will check if the feature flag is enabled for the current user, if it is not it will then check if the feature flag is enabled for a percentage of users and if the current user is within that percentage.
This will persist for the user as the percentage changes.
By default, you cannot do this. Flipper does not provide the ability to turn a flag off for a user if it is enabled for a group they are within, and everyone counts as a group.
To handle this you need two feature flags, one that enables it, and a second override feature flag that turns it back off.
For example:
def user_in_pilot?(current_user)
Flipper.enabled?(:feature_pilot, current_user) &&
!Flipper.enabled?(:removed_from_feature_pilot, current_user)
end
This would allow you to turn a feature off for a user if the feature has otherwise been turned on for everyone.