Module: Gitlab::Experimentation
- Defined in:
- lib/gitlab/experimentation.rb,
lib/gitlab/experimentation/experiment.rb,
lib/gitlab/experimentation/group_types.rb,
lib/gitlab/experimentation/controller_concern.rb
Defined Under Namespace
Modules: ControllerConcern, GroupTypes
Classes: Experiment
Constant Summary
collapse
- EXPERIMENTS =
{
}.freeze
Class Method Summary
collapse
Class Method Details
.active?(experiment_key) ⇒ Boolean
42
43
44
45
46
47
|
# File 'lib/gitlab/experimentation.rb', line 42
def active?(experiment_key)
experiment = get_experiment(experiment_key)
return false unless experiment
experiment.active?
end
|
.get_experiment(experiment_key) ⇒ Object
.in_experiment_group?(experiment_key, subject:) ⇒ Boolean
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/gitlab/experimentation.rb', line 49
def in_experiment_group?(experiment_key, subject:)
return false if subject.blank?
return false unless active?(experiment_key)
log_invalid_rollout(experiment_key, subject)
experiment = get_experiment(experiment_key)
return false unless experiment
experiment.enabled_for_index?(index_for_subject(experiment, subject))
end
|
.log_invalid_rollout(experiment_key, subject) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/gitlab/experimentation.rb', line 68
def log_invalid_rollout(experiment_key, subject)
return if valid_subject_for_rollout_strategy?(experiment_key, subject)
logger = Gitlab::ExperimentationLogger.build
logger.warn message: 'Subject must conform to the rollout strategy',
experiment_key: experiment_key,
subject: subject.class.to_s,
rollout_strategy: rollout_strategy(experiment_key)
end
|
.rollout_strategy(experiment_key) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/gitlab/experimentation.rb', line 61
def rollout_strategy(experiment_key)
experiment = get_experiment(experiment_key)
return unless experiment
experiment.rollout_strategy
end
|
.valid_subject_for_rollout_strategy?(experiment_key, subject) ⇒ Boolean
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/gitlab/experimentation.rb', line 78
def valid_subject_for_rollout_strategy?(experiment_key, subject)
case rollout_strategy(experiment_key)
when :user
subject.is_a?(User)
when :group
subject.is_a?(Group)
when :cookie
subject.nil? || subject.is_a?(String)
else
false
end
end
|