debian-mirror-gitlab/lib/gitlab/experimentation/experiment.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module Gitlab
module Experimentation
class Experiment
2021-03-08 18:12:59 +05:30
FEATURE_FLAG_SUFFIX = "_experiment_percentage"
2021-11-11 11:23:49 +05:30
attr_reader :key, :tracking_category, :rollout_strategy
2021-02-22 17:27:13 +05:30
def initialize(key, **params)
@key = key
@tracking_category = params[:tracking_category]
2021-03-11 19:13:27 +05:30
@rollout_strategy = params[:rollout_strategy] || :cookie
2021-02-22 17:27:13 +05:30
end
def active?
2021-03-08 18:12:59 +05:30
# 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)
2022-05-07 20:08:51 +05:30
::Gitlab.com? && experiment_percentage > 0
2021-02-22 17:27:13 +05:30
end
def enabled_for_index?(index)
return false if index.blank?
index <= experiment_percentage
end
private
2021-03-08 18:12:59 +05:30
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
2021-02-22 17:27:13 +05:30
end
end
end