Skip to content

Instantly share code, notes, and snippets.

@ixti
Created January 24, 2023 01:40
Show Gist options
  • Save ixti/c02a1dea6b9c38126158b84fb8a44846 to your computer and use it in GitHub Desktop.
Save ixti/c02a1dea6b9c38126158b84fb8a44846 to your computer and use it in GitHub Desktop.
class CarExperiment < ApplicationExperiment
class CappedRollout < Gitlab::Experiment::Rollout
def execute_assignment
assignments = Users::ExperimentAssignment.where(experiment_name: @experiment.name).group(:variant_name).count
variants = %i[polo golf touran].select { |variant_name| assignments[variant_name.to_s].to_i < 5000 }
return if variants.blank?
variants[Digest::MD5.hexdigest(id).to_i(16) % variants.size]
end
end
default_rollout CappedRollout
control { nil }
variant(:polo) { update_car_size "XS" }
variant(:golf) { update_car_size "S" }
variant(:touran) { update_car_size "M" }
def enabled?
return false unless Feature.enabled?("#{name}_experiment", user)
!user.experiment_assignments.where(experiment_name: name).exists?
end
def should_track?
super && enabled? && "control" != assigned.name
end
private
def update_car_size(size)
# do something
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment