Skip to content

Add ability to define variant behavior methods

Jeremy Jackson requested to merge jj-add-behavior-methods into master

They're required to be named [variant]_behavior, which is to ensure arbitrary code can’t be (easily) executed, even if passing in a query param for the experiment variant that should be used (though I don't see this as being particularly likely.)

This is related to https://gitlab.com/gitlab-org/gitlab-experiment/-/merge_requests/18, as the generator actually accepts these variants as arguments and generates the experiment class with those methods defined for you.

class MyExperiment < ApplicationExperiment
  def control_behavior
    #...
  end
end

We should document that passing in a query param or other user provided value for the experiment name should generally not be done, or maybe provide a way to specify that a method is registered as a behavior (e.g. route_behavior :control, to: :control_behavior), but I'm not convinced this has a lot of value just yet. Curious what others think first.

Edited by Jeremy Jackson

Merge request reports

Loading