Skip to content
Snippets Groups Projects
Commit dfbbda75 authored by Laura Montemayor's avatar Laura Montemayor :zero:
Browse files

Increase number of includes from 100 to 250

Changelog: changed
parent 2ad75fe5
No related branches found
No related tags found
1 merge request!89656Increase number of includes from 100 to 250
---
name: ci_increase_includes_to_250
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64934
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/344449
milestone: '15.2'
type: development
group: group::pipeline authoring
default_enabled: false
......@@ -9,14 +9,20 @@ class Context
TimeoutError = Class.new(StandardError)
MAX_INCLUDES = 100
TRIAL_MAX_INCLUDES = 250
include ::Gitlab::Utils::StrongMemoize
attr_reader :project, :sha, :user, :parent_pipeline, :variables
attr_reader :expandset, :execution_deadline, :logger
attr_reader :expandset, :execution_deadline, :logger, :max_includes
delegate :instrument, to: :logger
def initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil, logger: nil)
def initialize(
project: nil, sha: nil, user: nil, parent_pipeline: nil, variables: nil,
logger: nil
)
@project = project
@sha = sha
@user = user
......@@ -25,7 +31,7 @@ def initialize(project: nil, sha: nil, user: nil, parent_pipeline: nil, variable
@expandset = Set.new
@execution_deadline = 0
@logger = logger || Gitlab::Ci::Pipeline::Logger.new(project: project)
@max_includes = Feature.enabled?(:ci_increase_includes_to_250, project) ? TRIAL_MAX_INCLUDES : MAX_INCLUDES
yield self if block_given?
end
......@@ -52,6 +58,7 @@ def mutate(attrs = {})
ctx.expandset = expandset
ctx.execution_deadline = execution_deadline
ctx.logger = logger
ctx.max_includes = max_includes
end
end
......@@ -86,7 +93,7 @@ def includes
protected
attr_writer :expandset, :execution_deadline, :logger
attr_writer :expandset, :execution_deadline, :logger, :max_includes
private
......
......@@ -7,8 +7,6 @@ module External
class Mapper
include Gitlab::Utils::StrongMemoize
MAX_INCLUDES = 100
FILE_CLASSES = [
External::File::Remote,
External::File::Template,
......@@ -134,8 +132,8 @@ def verify!(location_object)
end
def verify_max_includes!
if expandset.count >= MAX_INCLUDES
raise TooManyIncludesError, "Maximum of #{MAX_INCLUDES} nested includes are allowed!"
if expandset.count >= context.max_includes
raise TooManyIncludesError, "Maximum of #{context.max_includes} nested includes are allowed!"
end
end
......
# frozen_string_literal: true
require 'fast_spec_helper'
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::External::Context do
let(:project) { double('Project') }
let(:project) { build(:project) }
let(:user) { double('User') }
let(:sha) { '12345' }
let(:variables) { Gitlab::Ci::Variables::Collection.new([{ 'key' => 'a', 'value' => 'b' }]) }
......@@ -126,7 +126,7 @@
end
context 'with attributes' do
let(:new_attributes) { { project: double, user: double, sha: '56789' } }
let(:new_attributes) { { project: build(:project), user: double, sha: '56789' } }
it_behaves_like 'a mutated context'
end
......
......@@ -232,11 +232,9 @@
image: 'image:1.0' }
end
before do
stub_const("#{described_class}::MAX_INCLUDES", 2)
end
it 'does not raise an exception' do
allow(context).to receive(:max_includes).and_return(2)
expect { subject }.not_to raise_error
end
end
......@@ -250,11 +248,9 @@
image: 'image:1.0' }
end
before do
stub_const("#{described_class}::MAX_INCLUDES", 1)
end
it 'raises an exception' do
allow(context).to receive(:max_includes).and_return(1)
expect { subject }.to raise_error(described_class::TooManyIncludesError)
end
......@@ -264,6 +260,8 @@
end
it 'raises an exception' do
allow(context).to receive(:max_includes).and_return(1)
expect { subject }.to raise_error(described_class::TooManyIncludesError)
end
end
......
......@@ -323,11 +323,9 @@
end
context 'when too many includes is included' do
before do
stub_const('Gitlab::Ci::Config::External::Mapper::MAX_INCLUDES', 1)
end
it 'raises an error' do
allow(context).to receive(:max_includes).and_return(1)
expect { subject }.to raise_error(Gitlab::Ci::Config::External::Processor::IncludeError, /Maximum of 1 nested/)
end
end
......
......@@ -126,5 +126,51 @@
it_behaves_like 'not including the file'
end
end
context 'with ci_increase_includes_to_250 enabled on root project' do
let_it_be(:included_project) do
create(:project, :repository).tap { |p| p.add_developer(user) }
end
before do
stub_const('::Gitlab::Ci::Config::External::Context::MAX_INCLUDES', 0)
stub_const('::Gitlab::Ci::Config::External::Context::TRIAL_MAX_INCLUDES', 3)
stub_feature_flags(ci_increase_includes_to_250: false)
stub_feature_flags(ci_increase_includes_to_250: project)
allow(Project)
.to receive(:find_by_full_path)
.with(included_project.full_path)
.and_return(included_project)
allow(included_project.repository)
.to receive(:blob_data_at).with(included_project.commit.id, '.gitlab-ci.yml')
.and_return(local_config)
allow(included_project.repository)
.to receive(:blob_data_at).with(included_project.commit.id, file_location)
.and_return(File.read(Rails.root.join(file_location)))
end
let(:config) do
<<~EOY
include:
- project: #{included_project.full_path}
file: .gitlab-ci.yml
EOY
end
let(:local_config) do
<<~EOY
include: #{file_location}
job:
script: exit 0
EOY
end
it_behaves_like 'including the file'
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment