Commit 4b0e82b7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '353921-gitlab-experiment-variant-caching-has-errors' into 'master'

Add experimentation circuit breaker

See merge request gitlab-org/gitlab!81834
parents e5f32c63 54056a31
---
name: gitlab_experiment
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81834
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/353921
milestone: '14.9'
type: ops
group: group::conversion
default_enabled: true
...@@ -12,10 +12,11 @@ module Gitlab ...@@ -12,10 +12,11 @@ module Gitlab
# - not have rolled out the feature flag at all (no percent of actors, # - not have rolled out the feature flag at all (no percent of actors,
# no inclusions, etc.) # no inclusions, etc.)
def enabled? def enabled?
return false if ::Feature::Definition.get(feature_flag_name).nil? return false unless feature_flag_defined?
return false unless Gitlab.dev_env_or_com? return false unless Gitlab.dev_env_or_com?
return false unless ::Feature.enabled?(:gitlab_experiment, type: :ops, default_enabled: :yaml)
::Feature.get(feature_flag_name).state != :off # rubocop:disable Gitlab/AvoidFeatureGet feature_flag_instance.state != :off
end end
# For assignment we first check to see if our feature flag is enabled # For assignment we first check to see if our feature flag is enabled
...@@ -58,6 +59,14 @@ module Gitlab ...@@ -58,6 +59,14 @@ module Gitlab
private private
def feature_flag_instance
::Feature.get(feature_flag_name) # rubocop:disable Gitlab/AvoidFeatureGet
end
def feature_flag_defined?
::Feature::Definition.get(feature_flag_name).present?
end
def feature_flag_name def feature_flag_name
experiment.name.tr('/', '_') experiment.name.tr('/', '_')
end end
......
...@@ -9,9 +9,10 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do ...@@ -9,9 +9,10 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do
describe "#enabled?" do describe "#enabled?" do
before do before do
allow(Feature::Definition).to receive(:get).and_return('_instance_') stub_feature_flags(gitlab_experiment: true)
allow(subject).to receive(:feature_flag_defined?).and_return(true)
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true) allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Feature).to receive(:get).and_return(double(state: :on)) allow(subject).to receive(:feature_flag_instance).and_return(double(state: :on))
end end
it "is enabled when all criteria are met" do it "is enabled when all criteria are met" do
...@@ -19,7 +20,7 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do ...@@ -19,7 +20,7 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do
end end
it "isn't enabled if the feature definition doesn't exist" do it "isn't enabled if the feature definition doesn't exist" do
expect(Feature::Definition).to receive(:get).with('namespaced_stub').and_return(nil) expect(subject).to receive(:feature_flag_defined?).and_return(false)
expect(subject).not_to be_enabled expect(subject).not_to be_enabled
end end
...@@ -31,7 +32,13 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do ...@@ -31,7 +32,13 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment do
end end
it "isn't enabled if the feature flag state is :off" do it "isn't enabled if the feature flag state is :off" do
expect(Feature).to receive(:get).with('namespaced_stub').and_return(double(state: :off)) expect(subject).to receive(:feature_flag_instance).and_return(double(state: :off))
expect(subject).not_to be_enabled
end
it "isn't enabled if the gitlab_experiment feature flag is false" do
stub_feature_flags(gitlab_experiment: false)
expect(subject).not_to be_enabled expect(subject).not_to be_enabled
end end
......
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