File: random.rb

package info (click to toggle)
ruby-gitlab-experiment 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: ruby: 1,202; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

# The random rollout strategy will randomly assign a variant when the context is determined to be within the experiment
# group.
#
# If caching is enabled this is a predicable and consistent assignment that will eventually assign a variant (since
# control isn't cached) but if caching isn't enabled, assignment will be random each time.
#
# Example configuration usage:
#
# config.default_rollout = Gitlab::Experiment::Rollout::Random.new
#
# Example class usage:
#
# class PillColorExperiment < ApplicationExperiment
#   control { }
#   variant(:red) { }
#   variant(:blue) { }
#
#   # Randomize between all behaviors, with a mostly even distribution).
#   default_rollout :random
# end
#
module Gitlab
  class Experiment
    module Rollout
      class Random < Base
        protected

        def execute_assignment
          behavior_names.sample # pick a random variant
        end
      end
    end
  end
end