diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /app/experiments | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'app/experiments')
-rw-r--r-- | app/experiments/application_experiment.rb | 8 | ||||
-rw-r--r-- | app/experiments/force_company_trial_experiment.rb | 11 | ||||
-rw-r--r-- | app/experiments/members/invite_email_experiment.rb | 93 | ||||
-rw-r--r-- | app/experiments/new_project_readme_content_experiment.rb | 2 | ||||
-rw-r--r-- | app/experiments/new_project_readme_experiment.rb | 38 |
5 files changed, 18 insertions, 134 deletions
diff --git a/app/experiments/application_experiment.rb b/app/experiments/application_experiment.rb index 4ebf4a80498..37d87baf30b 100644 --- a/app/experiments/application_experiment.rb +++ b/app/experiments/application_experiment.rb @@ -12,17 +12,21 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp def publish(_result = nil) super - 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 + publish_to_client + publish_to_database if @record end def publish_to_client + return unless should_track? + 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 + return unless should_track? + # 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] diff --git a/app/experiments/force_company_trial_experiment.rb b/app/experiments/force_company_trial_experiment.rb new file mode 100644 index 00000000000..00bdd5d693d --- /dev/null +++ b/app/experiments/force_company_trial_experiment.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class ForceCompanyTrialExperiment < ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass + exclude :setup_for_personal + + private + + def setup_for_personal + !context.user.setup_for_company + end +end diff --git a/app/experiments/members/invite_email_experiment.rb b/app/experiments/members/invite_email_experiment.rb deleted file mode 100644 index 893061e34f3..00000000000 --- a/app/experiments/members/invite_email_experiment.rb +++ /dev/null @@ -1,93 +0,0 @@ -# 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' - - def self.initial_invite_email?(invite_type) - invite_type == INVITE_TYPE - end - - def resolve_variant_name - RoundRobin.new(feature_flag_name, %i[activity control]).execute - end - end - - class RoundRobin - CacheError = Class.new(StandardError) - - COUNTER_EXPIRE_TIME = 86400 # one day - - def initialize(key, variants) - @key = key - @variants = variants - end - - def execute - increment_counter - resolve_variant_name - end - - # When the counter would expire - # - # @api private Used internally by SRE and debugging purpose - # @return [Integer] Number in seconds until expiration or false if never - def counter_expires_in - Gitlab::Redis::SharedState.with do |redis| - redis.ttl(key) - end - end - - # Return the actual counter value - # - # @return [Integer] value - def counter_value - Gitlab::Redis::SharedState.with do |redis| - (redis.get(key) || 0).to_i - end - end - - # Reset the counter - # - # @private Used internally by SRE and debugging purpose - # @return [Boolean] whether reset was a success - def reset! - redis_cmd do |redis| - redis.del(key) - end - end - - private - - attr_reader :key, :variants - - # Increase the counter - # - # @return [Boolean] whether operation was a success - def increment_counter - redis_cmd do |redis| - redis.incr(key) - redis.expire(key, COUNTER_EXPIRE_TIME) - end - end - - def resolve_variant_name - remainder = counter_value % variants.size - - variants[remainder] - end - - def redis_cmd - Gitlab::Redis::SharedState.with { |redis| yield(redis) } - - true - rescue CacheError => e - Gitlab::AppLogger.warn("GitLab: An unexpected error occurred in writing to Redis: #{e}") - - false - end - end -end diff --git a/app/experiments/new_project_readme_content_experiment.rb b/app/experiments/new_project_readme_content_experiment.rb index f86803db093..d9f0fb3b93e 100644 --- a/app/experiments/new_project_readme_content_experiment.rb +++ b/app/experiments/new_project_readme_content_experiment.rb @@ -19,7 +19,7 @@ class NewProjectReadmeContentExperiment < ApplicationExperiment # rubocop:disabl end def redirect(to_url) - experiment_redirect_url(self, to_url) + experiment_redirect_url(self, url: to_url) end private diff --git a/app/experiments/new_project_readme_experiment.rb b/app/experiments/new_project_readme_experiment.rb deleted file mode 100644 index c5c41330949..00000000000 --- a/app/experiments/new_project_readme_experiment.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -class NewProjectReadmeExperiment < ApplicationExperiment # rubocop:disable Gitlab/NamespacedClass - include ProjectCommitCount - - INITIAL_WRITE_LIMIT = 3 - EXPERIMENT_START_DATE = DateTime.parse('2021/1/20') - MAX_ACCOUNT_AGE = 7.days - - exclude { context.value[:actor].nil? } - exclude { context.actor.created_at < MAX_ACCOUNT_AGE.ago } - - def control_behavior - false # we don't want the checkbox to be checked - end - - def candidate_behavior - true # check the checkbox by default - end - - def track_initial_writes(project) - return unless should_track? # early return if we don't need to ask for commit counts - return unless project.created_at > EXPERIMENT_START_DATE # early return for older projects - return unless (count = commit_count(project)) < INITIAL_WRITE_LIMIT - - track(:write, property: project.created_at.to_s, value: count) - end - - private - - def commit_count(project) - commit_count_for(project, - default_count: INITIAL_WRITE_LIMIT, - max_count: INITIAL_WRITE_LIMIT, - experiment: name - ) - end -end |