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 ...@@ -22,16 +22,29 @@ module EE
override :perform! override :perform!
def perform! def perform!
return unless limit.exceeded? if limit.exceeded?
limit.log_error!(log_attrs)
limit.log_error!(project_id: project.id, plan: project.actual_plan_name) error(limit.message, drop_reason: :size_limit_exceeded)
error(limit.message, drop_reason: :size_limit_exceeded) elsif limit.log_exceeded_limit?
limit.log_error!(log_attrs)
end
end end
override :break? override :break?
def break? def break?
limit.exceeded? limit.exceeded?
end 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 end
end end
......
...@@ -9,6 +9,8 @@ module EE ...@@ -9,6 +9,8 @@ module EE
include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Utils::StrongMemoize
include ActionView::Helpers::TextHelper include ActionView::Helpers::TextHelper
LOGGABLE_JOBS_COUNT = 2000 # log large pipelines to determine a future global pipeline size limit
def initialize(namespace, pipeline, command) def initialize(namespace, pipeline, command)
@namespace = namespace @namespace = namespace
@pipeline = pipeline @pipeline = pipeline
...@@ -25,9 +27,11 @@ module EE ...@@ -25,9 +27,11 @@ module EE
seeds_size > ci_pipeline_size_limit seeds_size > ci_pipeline_size_limit
end end
def message def log_exceeded_limit?
return unless exceeded? seeds_size > LOGGABLE_JOBS_COUNT
end
def message
"Pipeline has too many jobs! Requested #{seeds_size}, but the limit is #{ci_pipeline_size_limit}." "Pipeline has too many jobs! Requested #{seeds_size}, but the limit is #{ci_pipeline_size_limit}."
end end
......
...@@ -84,10 +84,32 @@ RSpec.describe EE::Gitlab::Ci::Pipeline::Quota::Size do ...@@ -84,10 +84,32 @@ RSpec.describe EE::Gitlab::Ci::Pipeline::Quota::Size do
context 'when limit is exceeded' do context 'when limit is exceeded' do
include_context 'pipeline size limit exceeded' 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) expect(subject.message)
.to eq "Pipeline has too many jobs! Requested 2, but the limit is 1." .to eq "Pipeline has too many jobs! Requested 2, but the limit is 1."
end end
end 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 end
...@@ -54,7 +54,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Activity do ...@@ -54,7 +54,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Activity do
end end
it 'logs the error' do 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), instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name project_id: project.id, plan: namespace.actual_plan_name
) )
......
...@@ -56,7 +56,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::JobActivity do ...@@ -56,7 +56,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::JobActivity do
end end
it 'logs the error' do 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), instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name project_id: project.id, plan: namespace.actual_plan_name
) )
......
...@@ -68,9 +68,10 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do ...@@ -68,9 +68,10 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
end end
it 'logs the error' do 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), 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 subject
...@@ -132,4 +133,31 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do ...@@ -132,4 +133,31 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
subject subject
end end
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 end
...@@ -24,10 +24,13 @@ module Gitlab ...@@ -24,10 +24,13 @@ module Gitlab
end end
def log_error!(extra_context = {}) def log_error!(extra_context = {})
error = LimitExceededError.new(message) ::Gitlab::ErrorTracking.log_exception(limit_exceeded_error, extra_context)
# TODO: change this to Gitlab::ErrorTracking.log_exception(error, extra_context) end
# https://gitlab.com/gitlab-org/gitlab/issues/32906
::Gitlab::ErrorTracking.track_exception(error, extra_context) protected
def limit_exceeded_error
LimitExceededError.new(message)
end end
end end
end end
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
name = :gitlab_ci_pipeline_size_builds name = :gitlab_ci_pipeline_size_builds
comment = 'Pipeline size' comment = 'Pipeline size'
labels = { source: nil } 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) ::Gitlab::Metrics.histogram(name, comment, labels, buckets)
end end
......
...@@ -85,7 +85,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Deployments do ...@@ -85,7 +85,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Deployments do
end end
it 'logs the error' do 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), instance_of(Gitlab::Ci::Limit::LimitExceededError),
project_id: project.id, plan: namespace.actual_plan_name 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