diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-13 00:09:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-13 00:09:01 +0300 |
commit | eef0c69d45082b370f1e41e50f12488a216944f2 (patch) | |
tree | 5c4a5c0e4db3fff89b9b4146b799e5de9dca57b9 /app/experiments/application_experiment.rb | |
parent | 6d533fe8b44007d82b8de29a4b706da69e5f5936 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/experiments/application_experiment.rb')
-rw-r--r-- | app/experiments/application_experiment.rb | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/app/experiments/application_experiment.rb b/app/experiments/application_experiment.rb index 1c9a3c5f37f..663c58ceda6 100644 --- a/app/experiments/application_experiment.rb +++ b/app/experiments/application_experiment.rb @@ -23,16 +23,41 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp )) end + def rollout_strategy + # no-op override in inherited class as desired + end + + def variants + # override as desired in inherited class with all variants + control + # %i[variant1 variant2 control] + # + # this will make sure we supply variants as these go together - rollout_strategy of :round_robin must have variants + raise NotImplementedError, "Inheriting class must supply variants as an array if :round_robin strategy is used" if rollout_strategy == :round_robin + end + private + def feature_flag_name + name.tr('/', '_') + end + def resolve_variant_name - return variant_names.first if Feature.enabled?(feature_flag_name, self, type: :experiment, default_enabled: :yaml) + case rollout_strategy + when :round_robin + round_robin_rollout + else + percentage_rollout + end + end - nil # Returning nil vs. :control is important for not caching and rollouts. + def round_robin_rollout + Strategy::RoundRobin.new(feature_flag_name, variants).execute end - def feature_flag_name - name.tr('/', '_') + def percentage_rollout + return variant_names.first if Feature.enabled?(feature_flag_name, self, type: :experiment, default_enabled: :yaml) + + nil # Returning nil vs. :control is important for not caching and rollouts. end # Cache is an implementation on top of Gitlab::Redis::SharedState that also |