-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccf8965
commit a91c417
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Feature Flags | ||
|
||
## Intro | ||
|
||
The Rootstrap Rails API Base allows developers to define feature flags, which are essentially boolean variables representing whether a particular feature or piece of code should be enabled or disabled. These flags can be easily controlled without requiring code changes or redeployment. | ||
Feature flags can be set at different levels of granularity, such as for individual users, user groups, or percentage-based rollouts. This allows for controlled feature releases and gradual rollouts. | ||
Our feature flag engine is built upon Flipper. To learn more about Flipper, please visit the following website: [Flipper Documentation](https://www.flippercloud.io/docs/introduction) | ||
|
||
## Flipper Configuration | ||
|
||
We have taken care of all aspects of the Flipper configuration, and the Feature Flags system is ready to use. However, we understand that some users might have different needs. Flipper configuration can be find in the following files: | ||
|
||
- config/routes.rb => This config file mounts the Flipper UI and restricts access to admin_user. | ||
- config/initializers/active_admin.rb => This config file adds a link in `active_admin` to the Flipper UI. | ||
- config/initializers/flipper.rb => This configuration file enables the inclusion of a description for every feature flag. | ||
- config/feature-flags.yml => This YAML file lists all registered feature flags in the system. | ||
- spec/rails_helper.rb => In this file, we configure the Memory adapter for use in the testing environment | ||
|
||
|
||
## Set Up Feature Flags | ||
|
||
1. [DEV ENVIRONMENT] Register your feature flag in config/feature-flags.yml, adhering to the format specified in that file. | ||
2. [DEV ENVIRONMENT] Restart your server | ||
|
||
## Use Feature Flags in Your Application | ||
|
||
``` | ||
Flipper.enabled?(:feature_flag) Checks if the feature flag is globally enabled. | ||
Flipper.enabled?(:feature_flag, user) Checks if the feature is enabled at the user level. | ||
``` | ||
For more examples, please visit [Flipper documentation](https://www.flippercloud.io/docs/features). | ||
|
||
## Deploy | ||
|
||
The Rootstrap Rails API base utilizes the `bin/release.sh` script to execute `lib/tasks/feature_flags.rake`. This rake task registers non-existing feature flags based on the list in config/feature-flags.yml. This approach eliminates the need for developers to manually register feature flags in the production environment, as registering them in the local environment is sufficient. | ||
|
||
## Testing | ||
|
||
Testing new code behind a feature flag is straightforward; developers only need to enable the feature flag before running the test. | ||
Here's an example: | ||
|
||
``` | ||
context 'when test_feature_flag is on' do | ||
before { Flipper.enable(:test_feature_flag) } | ||
it do | ||
expect(feature).to match_behavior_behind_the_feature_flag | ||
expect(Flipper).to be_enabled(:test_feature_flag) | ||
end | ||
end | ||
``` | ||
|
||
No need to reset the feature flag state; our system already resets the Flipper instance before each test. This ensures that all tests start in a fresh state. | ||
|
||
## Monitoring and Managing Feature Flags | ||
|
||
To monitor and manage feature flags, we recommend using the Flipper UI, which can be accessed through `active_admin` or at this path: `/admin/feature-flags/` |