Commit bea3b85e authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'add-feature-flag-type-ops' into 'master'

Add feature flag type Ops (RUN AS-IF-FOSS)

Closes #221054

See merge request gitlab-org/gitlab!34274
parents 2f94378e ca598d39
...@@ -45,7 +45,7 @@ module Measurable ...@@ -45,7 +45,7 @@ module Measurable
private private
def measuring? def measuring?
Feature.enabled?("gitlab_service_measuring_#{service_class}") Feature.enabled?("gitlab_service_measuring_#{service_class}", type: :ops)
end end
# These attributes are always present in log. # These attributes are always present in log.
......
...@@ -25,9 +25,7 @@ This document is the subject of continued work as part of an epic to [improve in ...@@ -25,9 +25,7 @@ This document is the subject of continued work as part of an epic to [improve in
## Types of feature flags ## Types of feature flags
Currently, only a single type of feature flag is available. Choose a feature flag type that matches the expected usage.
Additional feature flag types will be provided in the future,
with descriptions for their usage.
### `development` type ### `development` type
...@@ -40,6 +38,29 @@ ideally created using the [Feature Flag Roll Out template](https://gitlab.com/gi ...@@ -40,6 +38,29 @@ ideally created using the [Feature Flag Roll Out template](https://gitlab.com/gi
NOTE: **Note:** NOTE: **Note:**
This is the default type used when calling `Feature.enabled?`. 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 ## Feature flag definition and validation
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/229161) in GitLab 13.3. > [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) ...@@ -147,6 +168,21 @@ if Feature.disabled?(:my_feature_flag, project, default_enabled: true)
end 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 ### Frontend
Use the `push_frontend_feature_flag` method for frontend code, which is Use the `push_frontend_feature_flag` method for frontend code, which is
...@@ -192,6 +228,15 @@ before_action do ...@@ -192,6 +228,15 @@ before_action do
end 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 ### Feature actors
**It is strongly advised to use actors with feature flags.** Actors provide a simple **It is strongly advised to use actors with feature flags.** Actors provide a simple
......
...@@ -15,8 +15,18 @@ class Feature ...@@ -15,8 +15,18 @@ class Feature
optional: true, optional: true,
rollout_issue: true, rollout_issue: true,
example: <<-EOS example: <<-EOS
Feature.enabled?(:my_feature_flag) Feature.enabled?(:my_feature_flag, project)
Feature.enabled?(:my_feature_flag, type: :development) 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 EOS
} }
}.freeze }.freeze
......
...@@ -52,7 +52,7 @@ module Gitlab ...@@ -52,7 +52,7 @@ module Gitlab
end end
def disabled_by_feature(options) def disabled_by_feature(options)
options.with_feature && !::Feature.enabled?(options.with_feature) options.with_feature && !::Feature.enabled?(options.with_feature, type: :ops)
end end
def build_metric!(type, name, options) def build_metric!(type, name, options)
......
...@@ -71,7 +71,7 @@ module Gitlab ...@@ -71,7 +71,7 @@ module Gitlab
end end
def droppable? def droppable?
idempotent? && ::Feature.disabled?("disable_#{queue_name}_deduplication") idempotent? && ::Feature.disabled?("disable_#{queue_name}_deduplication", type: :ops)
end end
def scheduled_at def scheduled_at
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment