Skip to content

Feature Flag Setup

Johanna edited this page Apr 4, 2023 · 6 revisions

The feature flag setup allows developers to deploy new functionality in dark and later launch the feature live by turning the flag on. The current setup also allows the frontend and the backend to share the same source of truth hence being always in sync.

Using this setup will launch the feature at the application/org/facility level. If you need to launch a feature at the user level another method using okta groups has been used in the past.

Overview

The setup consists of 3 main pieces:

  1. FeatureFlagsConfig object.
  2. GET /feature-flags REST endpoint.
  3. WithFeatureFlags react context.

featureFlagDiagram

FeatureFlagsConfig object

When the server starts this object loads the flag values that have been setup in the application yaml under the features property. To have access to the feature flags on the Java code import this object as part of the Java class that needs access (example of integration with Java class).

When creating a new flag, besides adding the flag and its value as a property to the yaml file, you also need to add it as a new property of this object.

As an optional capability this configuration object can be set up to retrieve the flag value from the database every minute allowing the possibility of turning on a feature without the need of a redeployment or a server restart (both things are needed when relying on setting the flag through the yaml only). This extra setup is done by adding a new entry to the feature_flag table in our DB and adding the logic to map that entry value to the config object.

GET /feature-flags REST endpoint

The backend exposes a GET /feature-flags endpoint (through the FeatureFlagsController.java) which returns a JSON with all the flags and their values to the UI. No change is needed in this service when adding a new flag as it will automatically reflect the new additions in the response.

WithFeatureFlags context

In the UI side the application uses the flagged library to implement a react context called WithFeatureFlags.tsx that takes care of calling the /feature-flags endpoint on load and injecting the flag values in the application's root component. Through the use of the useFeature hook any component in SimpleReport can access any flag value (example of integration with react component).

Additional: DB models and feature_flag table

As mentioned in the FeatureFlagsConfig section. This setup also has the capability to set the flag value in the database to allow the launch of a feature without the need of code changes (updates to the yaml) and redeployments.

To support this load of values the backend also counts with a FeatureFlag.java which is the model to represent an entry from the feature_flag table, and the FeatureFlagRepository.Java with is the object used to connect and retrieve the values to the database.

Local development

Setup

How to

Development process and standards

Oncall

Technical resources

How-to guides

Environments/Azure

Misc

?

Clone this wiki locally