Commit dafe999c authored by Dallas Reedy's avatar Dallas Reedy

Fix for broken master due to unpersisted feature flags

Works around the currently broken CI job by calling
Feature.enabled?(...) inside Gitlab::Experimentation::Experiment#active?
even though we're not actually making full use of it (yet).

Also adds yaml definition files for a few more experiments that have
been added to master since the original MR was reverted.
parent ef60eaae
---
name: ci_syntax_templates_experiment_percentage
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/48141
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/281057
milestone: '13.8'
type: experiment
group: group::activation
default_enabled: false
---
name: pipelines_empty_state_experiment_percentage
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47952
rollout_issue_url: https://gitlab.com/gitlab-org/growth/team-tasks/-/issues/289
milestone: '13.8'
type: experiment
group: group::activation
default_enabled: false
---
name: trial_during_signup_experiment_percentage
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/45147/
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/251231
milestone: '13.8'
type: experiment
group: group::conversion
default_enabled: false
......@@ -20,6 +20,8 @@ RSpec.describe API::Experiments do
end
before do
skip_feature_flags_yaml_validation
skip_default_enabled_yaml_check
stub_const('Gitlab::Experimentation::EXPERIMENTS', experiments)
Feature.enable_percentage_of_time('experiment_1_experiment_percentage', 10)
Feature.disable('experiment_2_experiment_percentage')
......
......@@ -11,11 +11,13 @@ module Gitlab
@key = key
@tracking_category = params[:tracking_category]
@use_backwards_compatible_subject_index = params[:use_backwards_compatible_subject_index]
@experiment_percentage = Feature.get(:"#{key}#{FEATURE_FLAG_SUFFIX}").percentage_of_time_value # rubocop:disable Gitlab/AvoidFeatureGet
end
def active?
# TODO: just touch a feature flag
# Temporary change, we will change `experiment_percentage` in future to `Feature.enabled?
Feature.enabled?(feature_flag_name, type: :experiment, default_enabled: :yaml)
::Gitlab.dev_env_or_com? && experiment_percentage > 0
end
......@@ -27,7 +29,17 @@ module Gitlab
private
attr_reader :experiment_percentage
def experiment_percentage
feature_flag.percentage_of_time_value
end
def feature_flag
Feature.get(feature_flag_name) # rubocop:disable Gitlab/AvoidFeatureGet
end
def feature_flag_name
:"#{key}#{FEATURE_FLAG_SUFFIX}"
end
end
end
end
......@@ -14,8 +14,10 @@ RSpec.describe Gitlab::Experimentation::Experiment do
end
before do
feature = double('FeatureFlag', percentage_of_time_value: percentage )
expect(Feature).to receive(:get).with(:experiment_key_experiment_percentage).and_return(feature)
skip_feature_flags_yaml_validation
skip_default_enabled_yaml_check
feature = double('FeatureFlag', percentage_of_time_value: percentage, enabled?: true)
allow(Feature).to receive(:get).with(:experiment_key_experiment_percentage).and_return(feature)
end
subject(:experiment) { described_class.new(:experiment_key, **params) }
......
......@@ -38,6 +38,8 @@ RSpec.describe Gitlab::Experimentation do
}
})
skip_feature_flags_yaml_validation
skip_default_enabled_yaml_check
Feature.enable_percentage_of_time(:backwards_compatible_test_experiment_experiment_percentage, enabled_percentage)
Feature.enable_percentage_of_time(:test_experiment_experiment_percentage, enabled_percentage)
allow(Gitlab).to receive(:com?).and_return(true)
......
# frozen_string_literal: true
module StubExperiments
SUFFIX = Gitlab::Experimentation::Experiment::FEATURE_FLAG_SUFFIX
# Stub Experiment with `key: true/false`
#
# @param [Hash] experiment where key is feature name and value is boolean whether active or not.
......@@ -13,7 +11,7 @@ module StubExperiments
allow(Gitlab::Experimentation).to receive(:active?).and_call_original
experiments.each do |experiment_key, enabled|
Feature.persist_used!("#{experiment_key}#{SUFFIX}")
Feature.persist_used!("#{experiment_key}#{feature_flag_suffix}")
allow(Gitlab::Experimentation).to receive(:active?).with(experiment_key) { enabled }
end
end
......@@ -28,8 +26,14 @@ module StubExperiments
allow(Gitlab::Experimentation).to receive(:in_experiment_group?).and_call_original
experiments.each do |experiment_key, enabled|
Feature.persist_used!("#{experiment_key}#{SUFFIX}")
Feature.persist_used!("#{experiment_key}#{feature_flag_suffix}")
allow(Gitlab::Experimentation).to receive(:in_experiment_group?).with(experiment_key, anything) { enabled }
end
end
private
def feature_flag_suffix
Gitlab::Experimentation::Experiment::FEATURE_FLAG_SUFFIX
end
end
......@@ -66,4 +66,8 @@ module StubFeatureFlags
def skip_feature_flags_yaml_validation
allow(Feature::Definition).to receive(:valid_usage!)
end
def skip_default_enabled_yaml_check
allow(Feature::Definition).to receive(:default_enabled?).and_return(false)
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