Class: ApplicationExperiment

Inherits:
Gitlab::Experiment show all
Defined in:
app/experiments/application_experiment.rb

Instance Method Summary collapse

Instance Method Details

#control_behaviorObject


25
26
27
# File 'app/experiments/application_experiment.rb', line 25

def control_behavior
  # define a default nil control behavior so we can omit it when not needed
end

#key_for(source, seed = name) ⇒ Object

Deprecated.

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.

gitlab.com/gitlab-org/gitlab/-/issues/334590


36
37
38
39
40
41
42
43
# File 'app/experiments/application_experiment.rb', line 36

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

#nest_experiment(other) ⇒ Object


45
46
47
# File 'app/experiments/application_experiment.rb', line 45

def nest_experiment(other)
  instance_exec(:nested, { label: other.name }, &Configuration.tracking_behavior)
end

#publish_to_databaseObject


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/experiments/application_experiment.rb', line 11

def publish_to_database
  ActiveSupport::Deprecation.warn('publish_to_database is deprecated and should not be used for reporting anymore')

  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]
  return unless ExperimentSubject.valid_subject?(subject)

  variant_name = :experimental if variant&.name != 'control'
  Experiment.add_subject(name, variant: variant_name || :control, subject: subject)
end