Skip to content

WIP: Support for simple feature flags

yorickpeterse-staging requested to merge feature-flags into master

What does this MR do?

This MR adds support for defining/checking feature flags to disable or enable certain parts of GitLab. This MR also uses this system to allow enabling/disabling of creating, updating, and removing notes as well as toggling award emojis.

Feature flags re-use the ApplicationSetting model and thus don't require a restart. This also allows re-use of the ApplicationSetting cache as well as expiring it automatically whenever changing any of the flags.

Checking if a feature is enabled is as simple as:

if Gitlab::Feature.some_feature_enabled?

end

There is also a Rails controller helper called require_feature! which automatically responds with an error should a feature not be enabled:

require_feature!(:some_feature) do
  ... code to run when the feature is enabled ...
end

The settings page is updated automatically based on the registered features, thus one only needs to perform two steps to register a new feature:

  1. Add it to the Gitlab::Feature::FEATURES array
  2. Add a migration to add the column to application_settings

By default a feature is marked as enabled, even when the column doesn't exist. This ensures that when GitLab is operating without a database (and thus using a mock settings object) things still work and you're not suddenly unable to perform certain operations.

Are there points in the code the reviewer needs to double check?

@jschatz1 and the UI gang are kindly asked to review the UI changes I made (see screenshots below).

Why was this MR needed?

For 8.9 there was a migration migrating notes to a separate award emojis table. Between completing these migrations and deploying the new code a user might try to create a note which would end up triggering an error (due to a column the old code relies on no longer being there). Had there been a feature flag for disabling the creation of new comments this could have been avoided.

What are the relevant issue numbers?

#15031 (closed)

Screenshots (if relevant)

An issue (with a comment) where creating/updating notes as well as toggling award emoji is disabled:

features_disabled

The settings page:

feature_settings

Does this MR meet the acceptance criteria?

Merge request reports