Skip to content

Add fflag groups enabled#1737

Merged
thomasiles merged 6 commits intomainfrom
add-fflag-groups-enabled
Jan 30, 2025
Merged

Add fflag groups enabled#1737
thomasiles merged 6 commits intomainfrom
add-fflag-groups-enabled

Conversation

@thomasiles
Copy link
Copy Markdown
Contributor

@thomasiles thomasiles commented Jan 29, 2025

Add a feature flag for enabling advanced branching for specified groups

Trello card: https://trello.com/c/GgbE96M1/2083-enable-branch-routing-feature-in-production-for-an-internal-test-group

To begin with, we want to release the advanced branching features to a small number of users.

To do this, we are enabling some Groups to have the feature flag enabled, instead of enabling it for the whole environment. We still want the flag to be enabled in dev for all users and groups.

This PR adds a new way to specify that a feature flag value should be taken per group rather than set for the whole environment. See the commits for details.

This PR is heavily based off the changes @stephencdaly and feature team one did for file upload.

It's more complicated because the branching feature flag is used in more places, mainly views.

This PR replaces #1729

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

@thomasiles thomasiles force-pushed the add-fflag-groups-enabled branch from 4186309 to 2ebda9a Compare January 29, 2025 20:25
@thomasiles thomasiles marked this pull request as ready for review January 29, 2025 20:32
@lfdebrux
Copy link
Copy Markdown
Contributor

Nice, thanks for making it work with the FeatureService.

I've tested this locally and it works for me 👍

The FeatureService class can be initialized with single positional
argument to hold the user.

The user argument is optional and most features don't use it.

Adding other arguments in the future would require callers to provide
nil as a placeholder.

Instead the initializer has been changed to take a keyword argument for
user.

All the callers have been updated to use this new format.

This should make it easier to add new keywords in the future.
Add a new way to specify that feature flags should be per group
instead of set by environment variable.

To allow individual groups to have a feature flag, you need to do two
things.

Add the feature flag to the settings.yml file. For example, to add a
feature flag called branch_routing, follow these steps:

Add method to Group, called `branch_routing_enabled?`. You probably want
to add a new column to Group called `branch_routing_enabled` and rely on
the rails helper to add the `?` at the end. It should probably have a
default value of false.

Add a rake task to set/clear this value.

Add the following to the settings yaml config.

```yaml
features:
  branch_routing:
    enabled_by_group: true
```

Use FeatureService.new(group:
current_form.group).enabled?(:branch_routing) whenever you need to test
the feature flag.

The setting can be enabled for a whole environment, for example dev, in
the usual way:

```yaml
features:
  branch_routing: true
```

This commit uses:

```
return group.send(:"#{feature_name}_enabled?")
```

in FeatureService#enabled? to check if the group has the feature. It
will raise an exception if this method is not defined, so the changes to
group should be made before adding the feature to the settings file.

Raising an exception rather than returning false was chosen to expose
issues earlier in development.
Add a new boolean column for enabling the branch_routing feature flag.
Add two tasks to enable and disable the branch feature for a specific
group.

Heavily inspired by

#1645

Like the above PR, there are no tests.
Every call to check if the branch_routing feature is enabled now
includes the current form's group.

This change will allow us to set the feature flag to be enabled per
group rather than for every environment.
Change the value of the feature setting for branch_routing to be
enabled_by_group instead.

This will allow the flag to be set per group in environments which have
not overridden it.
@thomasiles thomasiles force-pushed the add-fflag-groups-enabled branch from 2ebda9a to 1e57741 Compare January 30, 2025 07:56
@sonarqubecloud
Copy link
Copy Markdown

@thomasiles thomasiles merged commit d7dd719 into main Jan 30, 2025
4 checks passed
@thomasiles thomasiles deleted the add-fflag-groups-enabled branch January 30, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants