Commit a97a6441 authored by jejacks0n's avatar jejacks0n

Update gitlab-experiment to version 0.4.8

- This introduces a new concept to define enabled/disabled states for
experiments, an improved exclusion interface, and new rspec tooling.
parent 2a03d152
...@@ -477,7 +477,7 @@ gem 'flipper', '~> 0.17.1' ...@@ -477,7 +477,7 @@ gem 'flipper', '~> 0.17.1'
gem 'flipper-active_record', '~> 0.17.1' gem 'flipper-active_record', '~> 0.17.1'
gem 'flipper-active_support_cache_store', '~> 0.17.1' gem 'flipper-active_support_cache_store', '~> 0.17.1'
gem 'unleash', '~> 0.1.5' gem 'unleash', '~> 0.1.5'
gem 'gitlab-experiment', '~> 0.4.5' gem 'gitlab-experiment', '~> 0.4.8'
# Structured logging # Structured logging
gem 'lograge', '~> 0.5' gem 'lograge', '~> 0.5'
......
...@@ -424,7 +424,7 @@ GEM ...@@ -424,7 +424,7 @@ GEM
github-markup (1.7.0) github-markup (1.7.0)
gitlab-chronic (0.10.5) gitlab-chronic (0.10.5)
numerizer (~> 0.2) numerizer (~> 0.2)
gitlab-experiment (0.4.5) gitlab-experiment (0.4.8)
activesupport (>= 3.0) activesupport (>= 3.0)
scientist (~> 1.5, >= 1.5.0) scientist (~> 1.5, >= 1.5.0)
gitlab-fog-azure-rm (1.0.0) gitlab-fog-azure-rm (1.0.0)
...@@ -1364,7 +1364,7 @@ DEPENDENCIES ...@@ -1364,7 +1364,7 @@ DEPENDENCIES
gitaly (~> 13.8.0.pre.rc3) gitaly (~> 13.8.0.pre.rc3)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5) gitlab-chronic (~> 0.10.5)
gitlab-experiment (~> 0.4.5) gitlab-experiment (~> 0.4.8)
gitlab-fog-azure-rm (~> 1.0) gitlab-fog-azure-rm (~> 1.0)
gitlab-labkit (= 0.14.0) gitlab-labkit (= 0.14.0)
gitlab-license (~> 1.0) gitlab-license (~> 1.0)
......
...@@ -59,8 +59,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -59,8 +59,7 @@ class Projects::IssuesController < Projects::ApplicationController
around_action :allow_gitaly_ref_name_caching, only: [:discussions] around_action :allow_gitaly_ref_name_caching, only: [:discussions]
before_action :run_null_hypothesis_experiment, before_action :run_null_hypothesis_experiment,
only: [:index, :new, :create], only: [:index, :new, :create]
if: -> { Feature.enabled?(:gitlab_experiments) }
respond_to :html respond_to :html
......
# frozen_string_literal: true # frozen_string_literal: true
class ApplicationExperiment < Gitlab::Experiment class ApplicationExperiment < Gitlab::Experiment
def enabled?
return false if Feature::Definition.get(name).nil? # there has to be a feature flag yaml file
return false unless Gitlab.dev_env_or_com? # we're in an environment that allows experiments
Feature.get(name).state != :off # rubocop:disable Gitlab/AvoidFeatureGet
end
def publish(_result) def publish(_result)
track(:assignment) # track that we've assigned a variant for this context track(:assignment) # track that we've assigned a variant for this context
Gon.global.push({ experiment: { name => signature } }, true) # push to client Gon.global.push({ experiment: { name => signature } }, true) # push to client
end end
def track(action, **event_args) def track(action, **event_args)
return if excluded? # no events for opted out actors or excluded subjects return unless should_track? # no events for opted out actors or excluded subjects
Gitlab::Tracking.event(name, action.to_s, **event_args.merge( Gitlab::Tracking.event(name, action.to_s, **event_args.merge(
context: (event_args[:context] || []) << SnowplowTracker::SelfDescribingJson.new( context: (event_args[:context] || []) << SnowplowTracker::SelfDescribingJson.new(
......
---
name: gitlab_experiments
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/45840
rollout_issue_url:
milestone: '13.7'
type: development
group: group::adoption
default_enabled: false
...@@ -63,56 +63,23 @@ RSpec.describe Projects::IssuesController do ...@@ -63,56 +63,23 @@ RSpec.describe Projects::IssuesController do
end end
end end
describe 'the null hypothesis experiment', :snowplow do describe 'the null hypothesis experiment', :experiment do
it 'defines the expected before actions' do
expect(controller).to use_before_action(:run_null_hypothesis_experiment)
end
context 'when rolled out to 100%' do
it 'assigns the candidate experience and tracks the event' do
get :index, params: { namespace_id: project.namespace, project_id: project }
expect_snowplow_event(
category: 'null_hypothesis',
action: 'index',
context: [{
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0',
data: { variant: 'candidate', experiment: 'null_hypothesis', key: anything }
}]
)
end
end
context 'when not rolled out' do
before do before do
stub_feature_flags(null_hypothesis: false) stub_experiments(null_hypothesis: :candidate)
end end
it 'assigns the control experience and tracks the event' do it 'defines the expected before actions' do
get :index, params: { namespace_id: project.namespace, project_id: project } expect(controller).to use_before_action(:run_null_hypothesis_experiment)
expect_snowplow_event(
category: 'null_hypothesis',
action: 'index',
context: [{
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0',
data: { variant: 'control', experiment: 'null_hypothesis', key: anything }
}]
)
end
end end
context 'when gitlab_experiments is disabled' do it 'assigns the candidate experience and tracks the event' do
it 'does not run the experiment at all' do expect(experiment(:null_hypothesis)).to track('index').on_any_instance.for(:candidate)
stub_feature_flags(gitlab_experiments: false) .with_context(project: project)
expect(controller).not_to receive(:run_null_hypothesis_experiment)
get :index, params: { namespace_id: project.namespace, project_id: project } get :index, params: { namespace_id: project.namespace, project_id: project }
end end
end end
end end
end
context 'internal issue tracker' do context 'internal issue tracker' do
before do before do
......
...@@ -2,9 +2,45 @@ ...@@ -2,9 +2,45 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ApplicationExperiment do RSpec.describe ApplicationExperiment, :experiment do
subject { described_class.new(:stub) } subject { described_class.new(:stub) }
before do
allow(subject).to receive(:enabled?).and_return(true)
end
describe "enabled" do
before do
allow(subject).to receive(:enabled?).and_call_original
allow(Feature::Definition).to receive(:get).and_return('_instance_')
allow(Gitlab).to receive(:dev_env_or_com?).and_return(true)
allow(Feature).to receive(:get).and_return(double(state: :on))
end
it "is enabled when all criteria are met" do
expect(subject).to be_enabled
end
it "isn't enabled if the feature definition doesn't exist" do
expect(Feature::Definition).to receive(:get).with('stub').and_return(nil)
expect(subject).not_to be_enabled
end
it "isn't enabled if we're not in dev or dotcom environments" do
expect(Gitlab).to receive(:dev_env_or_com?).and_return(false)
expect(subject).not_to be_enabled
end
it "isn't enabled if the feature flag state is :off" do
expect(Feature).to receive(:get).with('stub').and_return(double(state: :off))
expect(subject).not_to be_enabled
end
end
describe "publishing results" do describe "publishing results" do
it "tracks the assignment" do it "tracks the assignment" do
expect(subject).to receive(:track).with(:assignment) expect(subject).to receive(:track).with(:assignment)
...@@ -31,8 +67,8 @@ RSpec.describe ApplicationExperiment do ...@@ -31,8 +67,8 @@ RSpec.describe ApplicationExperiment do
end end
describe "tracking events", :snowplow do describe "tracking events", :snowplow do
it "doesn't track if excluded" do it "doesn't track if we shouldn't track" do
subject.exclude { true } allow(subject).to receive(:should_track?).and_return(false)
subject.track(:action) subject.track(:action)
......
# frozen_string_literal: true # frozen_string_literal: true
# Require the provided spec helper and matchers.
require 'gitlab/experiment/rspec'
# Disable all caching for experiments in tests. # Disable all caching for experiments in tests.
Gitlab::Experiment::Configuration.cache = nil Gitlab::Experiment::Configuration.cache = nil
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment