Class: Gitlab::Experiment::Rollout::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/experiment/rollout.rb

Direct Known Subclasses

Percent, Random, RoundRobin

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(experiment, options = {}) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/experiment/rollout.rb', line 29

def initialize(experiment, options = {})
  raise ArgumentError, 'you must provide an experiment instance' unless experiment.class <= Gitlab::Experiment

  @experiment = experiment
  @options = options

  return if !options.key?(:cache_control) || options[:cache_control] == true

  Configuration.deprecated(
    :cache_control,
    "setting `cache_control` to a non-true value on a rollout is deprecated and " \
      "will be removed in version 2.0. Control variants will always be cached.",
    version: '1.4'
  )
end

Instance Attribute Details

#experimentObject (readonly)

Returns the value of attribute experiment.



25
26
27
# File 'lib/gitlab/experiment/rollout.rb', line 25

def experiment
  @experiment
end

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/gitlab/experiment/rollout.rb', line 25

def options
  @options
end

Instance Method Details

#cache_control_enabled?Boolean

Returns true when this rollout caches ‘:control` assignments. Per-rollout `cache_control:` option takes precedence over the global default.

Returns:

  • (Boolean)


62
63
64
# File 'lib/gitlab/experiment/rollout.rb', line 62

def cache_control_enabled?
  options.fetch(:cache_control, Configuration.cache_control)
end

#enabled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gitlab/experiment/rollout.rb', line 45

def enabled?
  true
end

#resolveObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/gitlab/experiment/rollout.rb', line 49

def resolve
  validate! # allow the rollout strategy to validate itself

  assignment = execute_assignment
  # Cache control assignments unless explicitly opted out. The per-rollout `cache_control:`
  # option takes precedence over the global `Configuration.cache_control` default.
  return assignment if cache_control_enabled?

  assignment == :control ? nil : assignment
end