Skip to content

[CEP] Supporting domains without privilege while GAing feature-flags to paid privileges #32482

@sravfeyn

Description

@sravfeyn

Abstract

This proposes a solution on how to migrate feature-flags/toggles (when GA-ing) into paid privileges for domains that may not have a paid plan or are below the plan that the toggle is being upgraded into.

The solution proposes to migrate the StaticToggle document into a new FrozenToggle document (thereby disabling its Edits in the Edit Toggle UI for further edits) and patch domain_has_privilege with a decorator that checks the FrozenToggle for enablement for a given domain.

Motivation

Currently, we are in the process of GA-ing all the feature flags and deleting them after GA. It is often the case that some of the flags need to be converted into a new privilege under one of the paid subscription plans. The domains that have these flags enabled may not be subscribed to these plans and we might want to still enable the functionality provided via the new privilege to these domains.

There is an existing strategy that has been used to do one of migrations such as ERM migration. This involves creating custom software plans and roles to grandfather the domains under the new privilege. While this works well for one-off cases, it has few below drawbacks.

  1. Extra custom subscription (role, plan) model objects will need to be created for each of the domains and privilege to be migrated (potentially around the order of Number of Domains X Number of toggles). This could get more complicated as the toggles will be migrated one after another, hence creating custom plans/roles on top of each other to capture various combinations of the feature flags on various domains.
  2. The process involves multi stage migration.

Given that we want to migrate a large number of toggles, this becomes specially challenging, so a simpler method is desired.

Specification

  1. A new FrozenToggle class will be added with pretty much the same spec as Toggle class except that the 'enabled_users' attribute on FrozenToggle class (which holds enabled domains also) will be frozen for further modifications.
  2. The FrozenToggle document will have an additional attribute to hold the new privilege which the flag will be migrated to.
  3. domain_has_privilege function will be updated to check FrozenToggle document to lookup domains that have the toggle enabled historically.

The migration process involves

  1. removing the StaticToggle for the feature flag,
  2. creating a new FrozenToggle object with the new privilege and
  3. writing a Django migration that converts the Toggle document into FrozenToggle document

The migration can be run as part of the migration inside the deploy. After the deploy the toggle will not be available for editing in the UI. So this solution can be deployed in one go without a manual maintenance.

Impact on users

For the purpose of this CEP, this doesn't impact the users directly.

Impact on hosting

There is no manual migrations to be run, so this will be a simpler process.

Release Timeline

This will be implemented as soon as the it is deemed good enough and other the feedback is integrated.

Open questions and issues

  1. One of the goals of GAing features is to be able to delete all the toggle related code (?). While this solution still requires various Toggle related code in place for now, when we do want to remove the code it will still be possible by converting all the FrozenToggle documents to a simple static JSON documents to lookup the privilege for old domains with historical privilege for a toggle. (Think of FrozenToggle as a place to keep track of a new privilege and enabled-domains, it can exist without any of the toggle related code when/if we want to)
  2. This doesn't/can't address the user only feature-flags. As there are only 7 such feature-flags it will need to be dealt in a different way at a different time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CEPCommCare Enhancement Proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions