Commit 19017d5f authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'include-actual-limit-in-pipeline-errors' into 'master'

Include actual limit in pipeline errors

See merge request gitlab-org/gitlab!48710
parents 26da9d21 4b5e4b8e
---
title: Include actual limit in pipeline limit errors
merge_request: 48710
author:
type: changed
...@@ -21,24 +21,23 @@ module EE ...@@ -21,24 +21,23 @@ 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
@project.ci_pipelines.alive.count strong_memoize(:alive_pipelines_limit) do
@project.ci_pipelines.alive.count
end
end end
def ci_active_pipelines_limit def ci_active_pipelines_limit
......
...@@ -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,7 +40,9 @@ module EE ...@@ -39,7 +40,9 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def jobs_in_alive_pipelines_count 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 end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -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