Commit 9db81275 authored by Fabio Pitino's avatar Fabio Pitino Committed by Kamil Trzciński

Log when a pipeline limit is hit

Use existing Sentry exception logging for all
existing limits
parent 8bc9939f
......@@ -7,6 +7,8 @@ module EE
# Abstract base class for CI/CD Quotas
#
class Limit
LimitExceededError = Class.new(StandardError)
def initialize(_context, _resource)
end
......@@ -21,6 +23,13 @@ module EE
def message
raise NotImplementedError
end
def log_error!(extra_context = {})
error = LimitExceededError.new(message)
# TODO: change this to Gitlab::Sentry.log_exception(error, extra_context)
# https://gitlab.com/gitlab-org/gitlab/issues/32906
::Gitlab::Sentry.track_acceptable_exception(error, extra: extra_context)
end
end
end
end
......
......@@ -27,6 +27,7 @@ module EE
retry_optimistic_lock(pipeline) do
pipeline.drop!(:activity_limit_exceeded)
limit.log_error!(project_id: project.id, plan: project.namespace.actual_plan_name)
end
end
......
......@@ -27,6 +27,7 @@ module EE
retry_optimistic_lock(pipeline) do
pipeline.drop!(:job_activity_limit_exceeded)
limit.log_error!(project_id: project.id, plan: project.namespace.actual_plan_name)
end
end
......
......@@ -28,6 +28,7 @@ module EE
pipeline.drop!(:size_limit_exceeded)
end
limit.log_error!(project_id: project.id, plan: project.namespace.actual_plan_name)
error(limit.message)
end
......
......@@ -17,6 +17,8 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Activity do
let(:step) { described_class.new(pipeline, command) }
subject { step.perform! }
context 'when active pipelines limit is exceeded' do
before do
gold_plan = create(:gold_plan, active_pipelines_limit: 1)
......@@ -24,38 +26,59 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Activity do
create(:ci_pipeline, project: project, status: 'pending')
create(:ci_pipeline, project: project, status: 'running')
step.perform!
end
it 'drops the pipeline' do
subject
expect(pipeline.reload).to be_failed
end
it 'persists the pipeline' do
subject
expect(pipeline).to be_persisted
end
it 'breaks the chain' do
subject
expect(step.break?).to be true
end
it 'sets a valid failure reason' do
subject
expect(pipeline.activity_limit_exceeded?).to be true
end
end
context 'when pipeline activity limit is not exceeded' do
before do
step.perform!
it 'logs the error' do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
instance_of(EE::Gitlab::Ci::Limit::LimitExceededError),
extra: { project_id: project.id, plan: namespace.actual_plan_name }
)
subject
end
end
context 'when pipeline activity limit is not exceeded' do
it 'does not break the chain' do
subject
expect(step.break?).to be false
end
it 'does not invalidate the pipeline' do
subject
expect(pipeline.errors).to be_empty
end
it 'does not log any error' do
expect(Gitlab::Sentry).not_to receive(:track_acceptable_exception)
subject
end
end
end
......@@ -17,6 +17,8 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::JobActivity do
let(:step) { described_class.new(pipeline, command) }
subject { step.perform! }
context 'when active jobs limit is exceeded' do
before do
gold_plan = create(:gold_plan, active_jobs_limit: 2)
......@@ -26,38 +28,59 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::JobActivity do
create(:ci_build, pipeline: pipeline)
create(:ci_build, pipeline: pipeline)
create(:ci_build, pipeline: pipeline)
step.perform!
end
it 'drops the pipeline' do
subject
expect(pipeline.reload).to be_failed
end
it 'persists the pipeline' do
subject
expect(pipeline).to be_persisted
end
it 'breaks the chain' do
subject
expect(step.break?).to be true
end
it 'sets a valid failure reason' do
subject
expect(pipeline.job_activity_limit_exceeded?).to be true
end
end
context 'when job activity limit is not exceeded' do
before do
step.perform!
it 'logs the error' do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
instance_of(EE::Gitlab::Ci::Limit::LimitExceededError),
extra: { project_id: project.id, plan: namespace.actual_plan_name }
)
subject
end
end
context 'when job activity limit is not exceeded' do
it 'does not break the chain' do
subject
expect(step.break?).to be false
end
it 'does not invalidate the pipeline' do
subject
expect(pipeline.errors).to be_empty
end
it 'does not log any error' do
expect(Gitlab::Sentry).not_to receive(:track_acceptable_exception)
subject
end
end
end
......@@ -19,12 +19,12 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
let(:step) { described_class.new(pipeline, command) }
subject { step.perform! }
context 'when pipeline size limit is exceeded' do
before do
gold_plan = create(:gold_plan, pipeline_size_limit: 1)
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan)
step.perform!
end
let(:pipeline) do
......@@ -42,25 +42,44 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
end
it 'drops the pipeline' do
subject
expect(pipeline.reload).to be_failed
end
it 'persists the pipeline' do
subject
expect(pipeline).to be_persisted
end
it 'breaks the chain' do
subject
expect(step.break?).to be true
end
it 'sets a valid failure reason' do
subject
expect(pipeline.size_limit_exceeded?).to be true
end
it 'appends validation error' do
subject
expect(pipeline.errors.to_a)
.to include 'Pipeline size limit exceeded by 1 job!'
end
it 'logs the error' do
expect(Gitlab::Sentry).to receive(:track_acceptable_exception).with(
instance_of(EE::Gitlab::Ci::Limit::LimitExceededError),
extra: { project_id: project.id, plan: namespace.actual_plan_name }
)
subject
end
end
context 'when not saving incomplete pipelines' do
......@@ -71,26 +90,36 @@ describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
end
it 'does not drop the pipeline' do
subject
expect(pipeline).not_to be_failed
end
it 'breaks the chain' do
subject
expect(step.break?).to be true
end
end
end
context 'when pipeline size limit is not exceeded' do
before do
step.perform!
end
it 'does not break the chain' do
subject
expect(step.break?).to be false
end
it 'does not persist the pipeline' do
subject
expect(pipeline).not_to be_persisted
end
it 'does not log any error' do
expect(Gitlab::Sentry).not_to receive(:track_acceptable_exception)
subject
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