Commit 4b5e4b8e authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason

Include actual limit in pipeline errors

Previously, we would only show the excess, which is not very helpful.

See https://gitlab.com/gitlab-org/gitlab/-/issues/284594
parent 8662326a
---
title: Include actual limit in pipeline limit errors
merge_request: 48710
author:
type: changed
......@@ -21,24 +21,23 @@ module EE
def exceeded?
return false unless enabled?
excessive_pipelines_count > 0
alive_pipelines_count > ci_active_pipelines_limit
end
def message
return unless exceeded?
'Active pipelines limit exceeded by ' \
"#{pluralize(excessive_pipelines_count, 'pipeline')}!"
'Project has too many active pipelines! ' \
"There are #{pluralize(alive_pipelines_count, 'active pipeline')}, "\
"but the limit is #{ci_active_pipelines_limit}."
end
private
def excessive_pipelines_count
@excessive ||= alive_pipelines_count - ci_active_pipelines_limit
end
def alive_pipelines_count
@project.ci_pipelines.alive.count
strong_memoize(:alive_pipelines_limit) do
@project.ci_pipelines.alive.count
end
end
def ci_active_pipelines_limit
......
......@@ -21,14 +21,15 @@ module EE
def exceeded?
return false unless enabled?
excessive_jobs_count > 0
jobs_in_alive_pipelines_count > ci_active_jobs_limit
end
def message
return unless exceeded?
'Active jobs limit exceeded by ' \
"#{pluralize(excessive_jobs_count, 'job')} in the past 24 hours!"
'Project has too many active jobs created in the last 24 hours! ' \
"There are #{pluralize(jobs_in_alive_pipelines_count, 'active job')}, " \
"but the limit is #{ci_active_jobs_limit}."
end
private
......@@ -39,7 +40,9 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord
def jobs_in_alive_pipelines_count
@project.all_pipelines.created_after(24.hours.ago).alive.joins(:builds).count
strong_memoize(:jobs_in_alive_pipelines_count) do
@project.all_pipelines.created_after(24.hours.ago).alive.joins(:builds).count
end
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -22,22 +22,17 @@ module EE
def exceeded?
return false unless enabled?
excessive_seeds_count > 0
seeds_size > ci_pipeline_size_limit
end
def message
return unless exceeded?
'Pipeline size limit exceeded by ' \
"#{pluralize(excessive_seeds_count, 'job')}!"
"Pipeline has too many jobs! Requested #{seeds_size}, but the limit is #{ci_pipeline_size_limit}."
end
private
def excessive_seeds_count
@excessive ||= seeds_size - ci_pipeline_size_limit
end
def ci_pipeline_size_limit
strong_memoize(:ci_pipeline_size_limit) do
@namespace.actual_limits.ci_pipeline_size
......
......@@ -83,7 +83,7 @@ RSpec.describe EE::Gitlab::Ci::Pipeline::Quota::Activity do
it 'returns info about pipeline activity limit exceeded' do
expect(subject.message)
.to eq "Active pipelines limit exceeded by 2 pipelines!"
.to eq "Project has too many active pipelines! There are 3 active pipelines, but the limit is 1."
end
end
end
......
......@@ -119,7 +119,7 @@ RSpec.describe EE::Gitlab::Ci::Pipeline::Quota::JobActivity do
it 'returns info about pipeline activity limit exceeded' do
expect(subject.message)
.to eq "Active jobs limit exceeded by 2 jobs in the past 24 hours!"
.to eq "Project has too many active jobs created in the last 24 hours! There are 3 active jobs, but the limit is 1."
end
end
end
......
......@@ -86,7 +86,7 @@ RSpec.describe EE::Gitlab::Ci::Pipeline::Quota::Size do
it 'returns infor about pipeline size limit exceeded' do
expect(subject.message)
.to eq "Pipeline size limit exceeded by 1 job!"
.to eq "Pipeline has too many jobs! Requested 2, but the limit is 1."
end
end
end
......
......@@ -64,7 +64,7 @@ RSpec.describe ::Gitlab::Ci::Pipeline::Chain::Limit::Size do
subject
expect(pipeline.errors.to_a)
.to include 'Pipeline size limit exceeded by 1 job!'
.to include 'Pipeline has too many jobs! Requested 2, but the limit is 1.'
end
it 'logs the error' do
......
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