diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-29 00:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-29 00:10:13 +0300 |
commit | 8f016fe5fb42704dd949e77859888fcd898fd985 (patch) | |
tree | 32c3c311c5fb330769601b2cf684aebe6f102196 /app/experiments/application_experiment.rb | |
parent | e4632f4c63eae7ec36243d11b23d69b4fd880830 (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 | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/app/experiments/application_experiment.rb b/app/experiments/application_experiment.rb index 53ea8ea2d3a..c777fdc63a1 100644 --- a/app/experiments/application_experiment.rb +++ b/app/experiments/application_experiment.rb @@ -10,22 +10,28 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp end def publish(_result = nil) - return unless should_track? # don't track events for excluded contexts - - record_experiment if @record # record the subject in the database if the context contains a namespace, group, project, actor or user - - track(:assignment) # track that we've assigned a variant for this context + super - push_to_client + publish_to_client if should_track? # publish the experiment data to the client + publish_to_database if @record # publish the experiment context to the database end - # push the experiment data to the client - def push_to_client + def publish_to_client Gon.push({ experiment: { name => signature } }, true) rescue NoMethodError # means we're not in the request cycle, and can't add to Gon. Log a warning maybe? end + def publish_to_database + # if the context contains a namespace, group, project, user, or actor + value = context.value + subject = value[:namespace] || value[:group] || value[:project] || value[:user] || value[:actor] + return unless ExperimentSubject.valid_subject?(subject) + + variant = :experimental if @variant_name != :control + Experiment.add_subject(name, variant: variant || :control, subject: subject) + end + def track(action, **event_args) return unless should_track? # don't track events for excluded contexts @@ -41,14 +47,23 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp @record = true end - def exclude! - @excluded = true - end - def control_behavior # define a default nil control behavior so we can omit it when not needed end + # TODO: remove + # This is deprecated logic as of v0.6.0 and should eventually be removed, but + # needs to stay intact for actively running experiments. The new strategy + # utilizes Digest::SHA2, a secret seed, and generates a 64-byte string. + def key_for(source, seed = name) + source = source.keys + source.values if source.is_a?(Hash) + + ingredients = Array(source).map { |v| identify(v) } + ingredients.unshift(seed) + + Digest::MD5.hexdigest(ingredients.join('|')) + end + private def feature_flag_name @@ -58,13 +73,4 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp def experiment_group? Feature.enabled?(feature_flag_name, self, type: :experiment, default_enabled: :yaml) end - - def record_experiment - subject = context.value[:namespace] || context.value[:group] || context.value[:project] || context.value[:user] || context.value[:actor] - return unless ExperimentSubject.valid_subject?(subject) - - variant = :experimental if @variant_name != :control - - Experiment.add_subject(name, variant: variant || :control, subject: subject) - end end |