mozilla-mobile / focus-android

⚠️ Firefox Focus (Android) moved to a new repository. It is now developed and maintained as part of: https://github.com/mozilla-mobile/firefox-android
https://github.com/mozilla-mobile/firefox-android
Mozilla Public License 2.0
2.11k stars 710 forks source link

[breakdown]Add feature flags #1548

Closed jenn-chaulk closed 6 years ago

jenn-chaulk commented 6 years ago

From focus-android created by liuche : mozilla-mobile/focus-android#1515

We want to add the ability to turn on/off features based on feature flags so that we can 1) incrementally land features that may not be complete 2) allow predictable feature releases

liuche commented 6 years ago

@pocmo I started the breakdown in the description of #1515, but I need to look into if we need to have a preprocessed "constants" file of feature flags that can be built from a config file, or if there's some gradle-flavor-y way to do it (for different builds, like dev, QA, l10n, dot-release, release, etc) so those can be automated.

I'll probably think on this some more but feel free to pick it up if you want! I'll unassign myself for now and pass it to you.

pocmo commented 6 years ago

Some interesting articles about feature flags:

Requirements

Options

From a high-level point of view we can choose between two types of feature flags:

(* Technically we could also mix both: Flags are decided at build time but there's an option to override them at runtime).

Possible solutions / Brainstorming

Simple static feature flags

We have some flags for “is this a beta build?” or “is this Klar?” in BuildConfig and AppConstants already. We could use those to build simple feature flag constants:

public class Features {
   private static final boolean BOOKMARKS = AppConstants.IsBetaBuild()
}

Switchboard only

We are going to enable/disable features via Switchboard for experiments. We could decide to not have separate feature flags but instead move every new feature (at least the ones we want to hold back) behind switchboard flags. Via Switchboard we have fine-grained controls to specify who is able to use a feature.

Gradle based flags

Gradle allows us to add additional static fields to the BuildConfig class (That's how we create a constant for the Adjust token for example). We could use this to create build time feature flags that can be enabled/disabled via various means:

Third-party libraries

There are some libraries that provide such functionality:


For now we do not have very complex requirements. I think I would start with a very simple implementation first: static flags. We can cover most of our use cases for now by limiting features to the debug version. This version is only used by developers and for screenshots and ui tests. If we want to distribute them internally we can limit it to the beta builds only (-> The beta build is only distributed internally via buddybuild. The beta on Google Play is a release version!). Right now I do not see the need for complex configuration files where we will have various permutations of features enabled for different developers/users.

If we need more complex rules soon then using Switchboard for feature flags would make sense - as we are going to add it anyways. Using a specific configuration in automation without needing to talk to our servers for downloading the experiment configuration will need some more thought though.

pocmo commented 6 years ago

@liuche What do you think? Are there things I missed?

mcomella commented 6 years ago

To add some of my intuition (which I mentioned in the Android meeting):

pocmo commented 6 years ago

In the engineering meeting we decided to use simple static flags for now. Later we might want to use Switchboard or mix both behind a nice interface. At this time no work is needed - so we decided to close this issue.