Commit d007e3ff authored by Shinya Maeda's avatar Shinya Maeda

Selective merge train concurrency

This commits allow to select merge train concurrency via
feature flag. The new parallel factor is disabled by default.
parent c392490a
...@@ -4,8 +4,10 @@ module MergeTrains ...@@ -4,8 +4,10 @@ module MergeTrains
include ::Gitlab::ExclusiveLeaseHelpers include ::Gitlab::ExclusiveLeaseHelpers
include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Utils::StrongMemoize
DEFAULT_MAX_CONCURRENCY = 4 HIGH_CONCURRENCY = 20
ONE_AT_A_TIME_STRATEGY = 1 MEDIUM_CONCURRENCY = 10
LOW_CONCURRENCY = 4
NO_CONCURRENCY = 1
## ##
# merge_request ... A merge request pointer in a merge train. # merge_request ... A merge request pointer in a merge train.
...@@ -68,9 +70,15 @@ module MergeTrains ...@@ -68,9 +70,15 @@ module MergeTrains
def max_concurrency def max_concurrency
strong_memoize(:max_concurrency) do strong_memoize(:max_concurrency) do
if Feature.enabled?(:merge_trains_parallel_pipelines, project, default_enabled: true) if Feature.enabled?(:merge_trains_parallel_pipelines, project, default_enabled: true)
DEFAULT_MAX_CONCURRENCY if Feature.enabled?(:merge_trains_high_concurrency, project)
HIGH_CONCURRENCY
elsif Feature.enabled?(:merge_trains_medium_concurrency, project)
MEDIUM_CONCURRENCY
else
LOW_CONCURRENCY
end
else else
ONE_AT_A_TIME_STRATEGY NO_CONCURRENCY
end end
end end
end end
......
...@@ -180,4 +180,60 @@ describe MergeTrains::RefreshMergeRequestsService do ...@@ -180,4 +180,60 @@ describe MergeTrains::RefreshMergeRequestsService do
end end
end end
end end
describe '#max_concurrency' do
subject { service.send(:max_concurrency) }
context 'when `merge_trains_parallel_pipelines` feature flag is enabled' do
before do
stub_feature_flags(merge_trains_parallel_pipelines: true)
end
context 'when `merge_trains_high_concurrency` feature flag is enabled' do
before do
stub_feature_flags(merge_trains_high_concurrency: true)
end
it 'returns high concurrency' do
is_expected.to eq(described_class::HIGH_CONCURRENCY)
end
end
context 'when `merge_trains_high_concurrency` feature flag is disabled' do
before do
stub_feature_flags(merge_trains_high_concurrency: false)
end
context 'when `merge_trains_medium_concurrency` feature flag is enabled' do
before do
stub_feature_flags(merge_trains_medium_concurrency: true)
end
it 'returns medium concurrency' do
is_expected.to eq(described_class::MEDIUM_CONCURRENCY)
end
end
context 'when `merge_trains_medium_concurrency` feature flag is disabled' do
before do
stub_feature_flags(merge_trains_medium_concurrency: false)
end
it 'returns low concurrency' do
is_expected.to eq(described_class::LOW_CONCURRENCY)
end
end
end
end
context 'when `merge_trains_parallel_pipelines` feature flag is disabled' do
before do
stub_feature_flags(merge_trains_parallel_pipelines: false)
end
it 'returns no concurrency' do
is_expected.to eq(described_class::NO_CONCURRENCY)
end
end
end
end end
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