Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2021-03-11 03:09:29 +00:00
parent c8795e6bd0
commit e610587418
3 changed files with 85 additions and 5 deletions

View file

@ -7,7 +7,7 @@ type: reference
<!-- markdownlint-disable MD044 -->
<!-- vale gitlab.Spelling = NO -->
# Keyword reference for the .gitlab-ci.yml file
# Keyword reference for the .gitlab-ci.yml file **(FREE)**
<!-- vale gitlab.Spelling = YES -->
<!-- markdownlint-enable MD044 -->
@ -312,9 +312,7 @@ does not block triggered pipelines.
### `include`
> - Introduced in [GitLab Premium](https://about.gitlab.com/pricing/) 10.5.
> - Available for Starter, Premium, and Ultimate in GitLab 10.6 and later.
> - [Moved](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/42861) to GitLab Free in 11.4.
> [Moved](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/42861) to GitLab Free in 11.4.
Use `include` to include external YAML files in your CI/CD configuration.
You can break down one long `gitlab-ci.yml` file into multiple files to increase readability,

View file

@ -15,7 +15,7 @@ module Gitlab
included do
before_action :set_experimentation_subject_id_cookie, unless: :dnt_enabled?
helper_method :experiment_enabled?, :experiment_tracking_category_and_group, :tracking_label
helper_method :experiment_enabled?, :experiment_tracking_category_and_group, :record_experiment_group, :tracking_label
end
def set_experimentation_subject_id_cookie
@ -72,6 +72,16 @@ module Gitlab
::Experiment.add_user(experiment_key, tracking_group(experiment_key, nil, subject: subject), current_user, context)
end
def record_experiment_group(experiment_key, group)
return if dnt_enabled?
return unless Experimentation.active?(experiment_key) && group
variant_subject = Experimentation.rollout_strategy(experiment_key) == :cookie ? nil : group
variant = tracking_group(experiment_key, nil, subject: variant_subject)
::Experiment.add_group(experiment_key, group: group, variant: variant)
end
def record_experiment_conversion_event(experiment_key, context = {})
return if dnt_enabled?
return unless current_user

View file

@ -520,6 +520,78 @@ RSpec.describe Gitlab::Experimentation::ControllerConcern, type: :controller do
end
end
describe '#record_experiment_group' do
let(:group) { 'a group object' }
let(:experiment_key) { :some_experiment_key }
let(:dnt_enabled) { false }
let(:experiment_active) { true }
let(:rollout_strategy) { :whatever }
let(:variant) { 'variant' }
before do
allow(controller).to receive(:dnt_enabled?).and_return(dnt_enabled)
allow(::Gitlab::Experimentation).to receive(:active?).and_return(experiment_active)
allow(::Gitlab::Experimentation).to receive(:rollout_strategy).and_return(rollout_strategy)
allow(controller).to receive(:tracking_group).and_return(variant)
allow(::Experiment).to receive(:add_group)
end
subject(:record_experiment_group) { controller.record_experiment_group(experiment_key, group) }
shared_examples 'exits early without recording' do
it 'returns early without recording the group as an ExperimentSubject' do
expect(::Experiment).not_to receive(:add_group)
record_experiment_group
end
end
shared_examples 'calls tracking_group' do |using_cookie_rollout|
it "calls tracking_group with #{using_cookie_rollout ? 'a nil' : 'the group as the'} subject" do
expect(controller).to receive(:tracking_group).with(experiment_key, nil, subject: using_cookie_rollout ? nil : group).and_return(variant)
record_experiment_group
end
end
shared_examples 'records the group' do
it 'records the group' do
expect(::Experiment).to receive(:add_group).with(experiment_key, group: group, variant: variant)
record_experiment_group
end
end
context 'when DNT is enabled' do
let(:dnt_enabled) { true }
include_examples 'exits early without recording'
end
context 'when the experiment is not active' do
let(:experiment_active) { false }
include_examples 'exits early without recording'
end
context 'when a nil group is given' do
let(:group) { nil }
include_examples 'exits early without recording'
end
context 'when the experiment uses a cookie-based rollout strategy' do
let(:rollout_strategy) { :cookie }
include_examples 'calls tracking_group', true
include_examples 'records the group'
end
context 'when the experiment uses a non-cookie-based rollout strategy' do
let(:rollout_strategy) { :group }
include_examples 'calls tracking_group', false
include_examples 'records the group'
end
end
describe '#record_experiment_conversion_event' do
let(:user) { build(:user) }