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