Commit d83e71ae authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '285093-measure-num-jobs-in-pipelines' into 'master'

Log data for determining global pipeline size limit

See merge request gitlab-org/gitlab!66382
parents 453dccb8 ae2b035e
......@@ -22,16 +22,29 @@ module EE
override :perform!
def perform!
return unless limit.exceeded?
limit.log_error!(project_id: project.id, plan: project.actual_plan_name)
error(limit.message, drop_reason: :size_limit_exceeded)
if limit.exceeded?
limit.log_error!(log_attrs)
error(limit.message, drop_reason: :size_limit_exceeded)
elsif limit.log_exceeded_limit?
limit.log_error!(log_attrs)
end
end
override :break?
def break?
limit.exceeded?
end
private
def log_attrs
{
pipeline_source: pipeline.source,
plan: project.actual_plan_name,
project_id: project.id,
project_full_path: project.full_path
}
end
end
end
end
......
......@@ -9,6 +9,8 @@ module EE
include ::Gitlab::Utils::StrongMemoize
include ActionView::Helpers::TextHelper
LOGGABLE_JOBS_COUNT = 2000 # log large pipelines to determine a future global pipeline size limit
def initialize(namespace, pipeline, command)
@namespace = namespace
@pipeline = pipeline
......@@ -25,9 +27,11 @@ module EE
seeds_size > ci_pipeline_size_limit
end
def message
return unless exceeded?
def log_exceeded_limit?
seeds_size > LOGGABLE_JOBS_COUNT
end
def message
"Pipeline has too many jobs! Requested #{seeds_size}, but the limit is #{ci_pipeline_size_limit}."
end
......
......@@ -84,10 +84,32 @@ RSpec.describe EE::Gitlab::Ci::Pipeline::Quota::Size do
context 'when limit is exceeded' do
include_context 'pipeline size limit exceeded'
it 'returns infor about pipeline size limit exceeded' do
it 'returns info about pipeline size limit exceeded' do
expect(subject.message)
.to eq "Pipeline has too many jobs! Requested 2, but the limit is 1."
end
end
end
describe '#log_exceeded_limit?' do
context 'when there are more than 2000 jobs in the pipeline' do
let(:command) do
double(:command, pipeline_seed: double(:pipeline_seed, size: 2001))
end
it 'returns true' do
expect(subject.log_exceeded_limit?).to be_truthy
end
end
context 'when there are 2000 or less jobs in the pipeline' do
let(:command) do
double(:command, pipeline_seed: double(:pipeline_seed, size: 2000))
end
it 'returns false' do
expect(subject.log_exceeded_limit?).to be_falsey
end
end
end
end
......@@ -54,7 +54,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Activity do
end
it 'logs the error' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name
)
......
......@@ -56,7 +56,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::JobActivity do
end
it 'logs the error' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name
)
......
......@@ -68,9 +68,10 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
end
it 'logs the error' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name
project_id: project.id, plan: namespace.actual_plan_name,
project_full_path: project.full_path, pipeline_source: pipeline.source
)
subject
......@@ -132,4 +133,31 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
subject
end
end
context 'when pipeline size limit is disabled' do
before do
ultimate_plan = create(:ultimate_plan)
create(:plan_limits, plan: ultimate_plan, ci_pipeline_size: 0)
create(:gitlab_subscription, namespace: namespace, hosted_plan: ultimate_plan)
end
context 'when global pipeline size limit is exceeded' do
let(:command) do
double(:command,
project: project,
current_user: user,
pipeline_seed: double(:seed, size: 2001))
end
it 'logs the pipeline' do
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name,
project_full_path: project.full_path, pipeline_source: pipeline.source
)
subject
end
end
end
end
......@@ -24,10 +24,13 @@ module Gitlab
end
def log_error!(extra_context = {})
error = LimitExceededError.new(message)
# TODO: change this to Gitlab::ErrorTracking.log_exception(error, extra_context)
# https://gitlab.com/gitlab-org/gitlab/issues/32906
::Gitlab::ErrorTracking.track_exception(error, extra_context)
::Gitlab::ErrorTracking.log_exception(limit_exceeded_error, extra_context)
end
protected
def limit_exceeded_error
LimitExceededError.new(message)
end
end
end
......
......@@ -24,7 +24,7 @@ module Gitlab
name = :gitlab_ci_pipeline_size_builds
comment = 'Pipeline size'
labels = { source: nil }
buckets = [0, 1, 5, 10, 20, 50, 100, 200, 500, 1000]
buckets = [0, 1, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 3000]
::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end
......
......@@ -85,7 +85,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Deployments do
end
it 'logs the error' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name
)
......
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