diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 15:09:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-03 15:09:24 +0000 |
commit | 6cbb93596d65dff377372f4b50da932dcf6dc514 (patch) | |
tree | c381ee98bd0fb444665f11c452b8e8f0e8e7731a /app/experiments | |
parent | ce9b8ee20d039da5f93e37d0ab3905813f3dd7bc (diff) | |
download | gitlab-ce-6cbb93596d65dff377372f4b50da932dcf6dc514.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/experiments')
-rw-r--r-- | app/experiments/application_experiment.rb | 14 | ||||
-rw-r--r-- | app/experiments/members/invite_email_experiment.rb | 22 |
2 files changed, 31 insertions, 5 deletions
diff --git a/app/experiments/application_experiment.rb b/app/experiments/application_experiment.rb index 92bd8d5783b..1c9a3c5f37f 100644 --- a/app/experiments/application_experiment.rb +++ b/app/experiments/application_experiment.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -class ApplicationExperiment < Gitlab::Experiment +class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/NamespacedClass def enabled? - return false if Feature::Definition.get(name).nil? # there has to be a feature flag yaml file + return false if Feature::Definition.get(feature_flag_name).nil? # there has to be a feature flag yaml file return false unless Gitlab.dev_env_or_com? # we're in an environment that allows experiments - Feature.get(name).state != :off # rubocop:disable Gitlab/AvoidFeatureGet + Feature.get(feature_flag_name).state != :off # rubocop:disable Gitlab/AvoidFeatureGet end def publish(_result) @@ -26,11 +26,15 @@ class ApplicationExperiment < Gitlab::Experiment private def resolve_variant_name - return variant_names.first if Feature.enabled?(name, self, type: :experiment, default_enabled: :yaml) + 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 + def feature_flag_name + name.tr('/', '_') + end + # Cache is an implementation on top of Gitlab::Redis::SharedState that also # adheres to the ActiveSupport::Cache::Store interface and uses the redis # hash data type. @@ -48,7 +52,7 @@ class ApplicationExperiment < Gitlab::Experiment # default cache key strategy. So running `cache.fetch("foo:bar", "value")` # would create/update a hash with the key of "foo", with a field named # "bar" that has "value" assigned to it. - class Cache < ActiveSupport::Cache::Store + class Cache < ActiveSupport::Cache::Store # rubocop:disable Gitlab/NamespacedClass # Clears the entire cache for a given experiment. Be careful with this # since it would reset all resolved variants for the entire experiment. def clear(key:) diff --git a/app/experiments/members/invite_email_experiment.rb b/app/experiments/members/invite_email_experiment.rb new file mode 100644 index 00000000000..58703fd505d --- /dev/null +++ b/app/experiments/members/invite_email_experiment.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Members + class InviteEmailExperiment < ApplicationExperiment + exclude { context.actor.created_by.blank? } + exclude { context.actor.created_by.avatar_url.nil? } + + INVITE_TYPE = 'initial_email' + + private + + def resolve_variant_name + # we are overriding here so that when we add another experiment + # we can merely add that variant and check of feature flag here + if Feature.enabled?(feature_flag_name, self, type: :experiment, default_enabled: :yaml) + :avatar + else + nil # :control + end + end + end +end |