DEV Community

Cover image for 🦊 GitLab - Feature flags : a practical guide to control your features
Jean-Phi Baconnais for Zenika

Posted on

🦊 GitLab - Feature flags : a practical guide to control your features

✨ Feature flag, also known as Feature toggle is a technique allowing teams to activate or deactivate features in applications without redeploying or editing code.

πŸ’‘ A Feature Flag ?

Feature flag is a concept essential in modern infrastructures, particularly for projects implementing continuous deployment. They allow code to be deployed to production without being visible or enabled for users. This requires some pertinent tests to ensure that existing features are not affected.

A/B testing is another concept often associated with feature flags. It involves deploying different versions of the same component or application, allowing a group of users defined by a random percentage, a geographic region, a group of users, .... access to a specific version.

πŸ“ Some Feature Flag tools

Choosing the right feature flag management tool can be not easy and depends on several factors: the licence, the cost, the usage of an open source project, …
Here’s a list of tools very interesting:

🦊 Feature flag on GitLab

GitLab has simplified feature flag management with a integration based on Unleash. This makes it easier to control feature flags and A/B testing in your application.

The menu Deploy > Feature flag allows you to create and configure feature flags. Each of them has to be defined with a name, a description and a list of strategies that determine when and for whom the feature is enabled. Strategies can be based on user IDs, percentages of users or other criteria, enabling A/B testing.

Create a feature flag

Feature flag strategies

✨ Implementation

Unleash provides a consequent list of SDKs (cf https://docs.getunleash.io/reference/sdks/) for backend and frontend development like Go, Java, Node, React, Vue, Flutter, PHP.

This is an example of Go implementation :

// Configure your Unleash instance
err = unleash.Initialize(
    unleash.WithUrl("https://gitlab.com/api/v4/feature_flags/unleash/<unleash id>"),
    unleash.WithInstanceId("<instance id>"),
    unleash.WithAppName("production"), // the dedicated environment defined during the creation of the feature flag, * for all environments.
    unleash.WithListener(&metricsInterface{}),
)
Enter fullscreen mode Exit fullscreen mode

This code checks the state of a feature flag called my-first-ff.

if unleash.IsEnabled("my-first-ff") {
    io.WriteString(w, "βœ… Feature flag enabled\n")
} else {
    io.WriteString(w, "❌ Feature flag disabled\n")
}
Enter fullscreen mode Exit fullscreen mode

In Java, the same example can be:

UnleashConfig config = UnleashConfig.builder()
    .appName(env.getProperty("unleash.appName"))
    .instanceId(env.getProperty("unleash.instanceId"))
    .unleashAPI(env.getProperty("unleash.unleashAPI"))
    .build();


return new DefaultUnleash(config);
Enter fullscreen mode Exit fullscreen mode
 if (unleashConfiguration.isEnabled(env.getProperty("unleash.ffs.my-first-ff"))) {
    return "βœ… Feature flag enabled\n";
} else {
    return "❌ Feature flag disabled\";
}
Enter fullscreen mode Exit fullscreen mode

πŸš€ Integrating Feature Flags into your application

Using GitLab’s Feature Flag in production is possible but it’s important to be aware of the connection created between your application infrastructure and your development platform. In the case where your GitLab instance endures an incident, your application in production should be affected by this incident. The inverse is also true, your production is in difficulty, your development platform will be too.

I have never been able to quantify this objectively. It’s a feeling based on my experiences with self-hosting GitLab instances.

Centralizing all feature flags in a GitLab project is, for me, a good approach. However, user roles must be clearly defined, as these feature flags impact production environments, be careful 😁.

GitLab’s feature flag management simplified the implementation in your application. Compared with other tools, the mainly used case to activate or deactivate a feature is respected. Others tools such as Izanami offers more features to go further in this implementation with a dedicated UI, an historic of feature flag actions, protect feature flags with an account management.

You can find my experimentation on this project: https://gitlab.com/jeanphi-baconnais-experiments/test-feature-flags

Top comments (0)