The space camp project provides guidance on how to easily get started with feature flags on launchdarkly and turning on features for a specific group of users.
Pre-req: Please make sure you have at least Python 3.8 installed
- Clone this project back to your local dev environment by running:
git clone https://github.com/kleeadrian/space-camp.git
- Navigate to space-camp folder
cd space-camp
- Install the necessary python dependencies by running
pip3 install -r requirements
Note: You can also run this within GitHub Codespaces. No need to perform step 1 or 2.
DO NOT COMMIT YOUR CODE WITH THE SDK KEY. THIS IS MEANT FOR A LOCAL ENVIRONMENT
Note: This section requires access to Launchdarkly. Please sign up for a trial at https://launchdarkly.com/start-trial/
- Login to your launchdarkly account by going to app.launchdarkly.com
- Navigate to Account Settings
DO NOT COMMIT YOUR CODE WITH THE SDK KEY. THIS IS MEANT FOR A LOCAL ENVIRONMENT
-
-
Open up server.py in the space-camp folder and replace os.getenv('LD_SD_KEY') on line 12 with the key you copied. Example end result:
ldclient.set_sdk_key('XXXX-XXXXX-XXXXX-XXXXX-XXXXX')
-
Type in the following command in terminal and navigate to http://127.0.0.1:5000 to see the following page
python3 server.py
DO NOT COMMIT YOUR CODE WITH THE SDK KEY. THIS IS MEANT FOR A LOCAL ENVIRONMENT
- Head back to app.launchdarkly.com
- Click on Top Left yellow button to ensure that you're navigated to the correct project and environment. Make sure its the same project as the SDK key you copied earlier (incase you have multiple projects)
- Click on Feature Flags
- Call this feature flag pricing-tier-3 (This has to match the Feature_FLAG_KEY in the codebase. Look at Line 32 in server.js
- Check the SDKs using Client-ID box
- Save
- Change the targeting to On and press on Save Changes and the website should have an extra tier
It should look like
- Navigate back to your feature flag
- You can perform a percentage based rollout by only rolling out to a subset of users by configuring the feature flag rule
- Navigate to your feature flag
- You can also target users based on a specific attribute. E.g. Target users with letters starting with A, B and it matches a regex
Note: Find a meaningful rollout. Maybe roll it out to users on MAC first, then Android.
You can also view the insights of people who have accessed your web app by navigating to the Insights Tab
- Integrate it back to your APM to monitor any errors that may show up. A list of integrations have been created
- Define a workflow and several approvers of each feature flag toggling.
- Determine what scenarios would require a rollback
- Define a rollout process by targetting users with specific OS, devices or geographies.
- Keep track of all work items and stories by integrating it back to your work management system
- Use a secret store to store all secrets
- Rotate the keys often. A Guide is available here
- As you add more and more feature flags. It may not become scalable as management of many feature flags may be tough. One idea would be to leverage the terraform provider to create feature flags via a terraform template. Have a look
- Archive unused flags!