diff --git a/app/services/concerns/measurable.rb b/app/services/concerns/measurable.rb index b099a58a9ae6b1088cadf95ab243830fe72a7357..fcb3022a1dc83f5343d41f9389e3a3db92d9de1b 100644 --- a/app/services/concerns/measurable.rb +++ b/app/services/concerns/measurable.rb @@ -45,7 +45,7 @@ def extra_attributes_for_measurement private def measuring? - Feature.enabled?("gitlab_service_measuring_#{service_class}") + Feature.enabled?("gitlab_service_measuring_#{service_class}", type: :ops) end # These attributes are always present in log. diff --git a/doc/development/feature_flags/development.md b/doc/development/feature_flags/development.md index bdce0c29eeaeecbe80af59e48f809e9cf02cc298..bf7fee90600bd5e9e3b24133d05731bd3a98d750 100644 --- a/doc/development/feature_flags/development.md +++ b/doc/development/feature_flags/development.md @@ -25,9 +25,7 @@ This document is the subject of continued work as part of an epic to [improve in ## Types of feature flags -Currently, only a single type of feature flag is available. -Additional feature flag types will be provided in the future, -with descriptions for their usage. +Choose a feature flag type that matches the expected usage. ### `development` type @@ -40,6 +38,29 @@ ideally created using the [Feature Flag Roll Out template](https://gitlab.com/gi NOTE: **Note:** This is the default type used when calling `Feature.enabled?`. +### `ops` type + +`ops` feature flags are long-lived feature flags that control operational aspects +of GitLab's behavior. For example, feature flags that disable features that might +have a performance impact, like special Sidekiq worker behavior. + +`ops` feature flags likely do not have rollout issues, as it is hard to +predict when they will be enabled or disabled. + +To use `ops` feature flags, you must append `type: :ops` to `Feature.enabled?` +invocations: + +```ruby +# Check if feature flag is enabled +Feature.enabled?(:my_ops_flag, project, type: ops) + +# Check if feature flag is disabled +Feature.disabled?(:my_ops_flag, project, type: ops) + +# Push feature flag to Frontend +push_frontend_feature_flag(:my_ops_flag, project, type: :ops) +``` + ## Feature flag definition and validation > [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/229161) in GitLab 13.3. @@ -147,6 +168,21 @@ if Feature.disabled?(:my_feature_flag, project, default_enabled: true) end ``` +If not specified, the default feature flag type for `Feature.enabled?` and `Feature.disabled?` +is `type: development`. For all other feature flag types, you must specify the `type:`: + +```ruby +if Feature.enabled?(:feature_flag, project, type: :ops) + # execute code if ops feature flag is enabled +else + # execute code if ops feature flag is disabled +end + +if Feature.disabled?(:my_feature_flag, project, type: :ops) + # execute code if feature flag is disabled +end +``` + ### Frontend Use the `push_frontend_feature_flag` method for frontend code, which is @@ -192,6 +228,15 @@ before_action do end ``` +If not specified, the default feature flag type for `push_frontend_feature_flag` +is `type: development`. For all other feature flag types, you must specify the `type:`: + +```ruby +before_action do + push_frontend_feature_flag(:vim_bindings, project, type: :ops) +end +``` + ### Feature actors **It is strongly advised to use actors with feature flags.** Actors provide a simple diff --git a/lib/feature/shared.rb b/lib/feature/shared.rb index 14efbb07100b2c195df132ff749b087a33ad3cea..53f027e3893d4e7734b9aa65c37e671557aaf55d 100644 --- a/lib/feature/shared.rb +++ b/lib/feature/shared.rb @@ -15,8 +15,18 @@ module Shared optional: true, rollout_issue: true, example: <<-EOS - Feature.enabled?(:my_feature_flag) - Feature.enabled?(:my_feature_flag, type: :development) + Feature.enabled?(:my_feature_flag, project) + Feature.enabled?(:my_feature_flag, project, type: :development) + push_frontend_feature_flag?(:my_feature_flag, project) + EOS + }, + ops: { + description: "Long-lived feature flags that control operational aspects of GitLab's behavior", + optional: true, + rollout_issue: false, + example: <<-EOS + Feature.enabled?(:my_ops_flag, type: ops) + push_frontend_feature_flag?(:my_ops_flag, project, type: :ops) EOS } }.freeze diff --git a/lib/gitlab/metrics/methods.rb b/lib/gitlab/metrics/methods.rb index 2b5d1c710f6c1e0ecdfb8c19871d5aa79bbea4cb..3100450bc00b77c09cfa5535e17ae3fcd941f7bc 100644 --- a/lib/gitlab/metrics/methods.rb +++ b/lib/gitlab/metrics/methods.rb @@ -52,7 +52,7 @@ def synchronized_cache_fill(key) end def disabled_by_feature(options) - options.with_feature && !::Feature.enabled?(options.with_feature) + options.with_feature && !::Feature.enabled?(options.with_feature, type: :ops) end def build_metric!(type, name, options) diff --git a/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb b/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb index 0dc53c61e8461e4390afa0bbd24b4ddaa2bcae73..5efd1b34d3250c725296a72e38262ff61c4119de 100644 --- a/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb +++ b/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb @@ -71,7 +71,7 @@ def duplicate? end def droppable? - idempotent? && ::Feature.disabled?("disable_#{queue_name}_deduplication") + idempotent? && ::Feature.disabled?("disable_#{queue_name}_deduplication", type: :ops) end def scheduled_at