Commit b48d81a1 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Make running jobs metric for queuing a private method

parent 7f669ae8
...@@ -69,31 +69,6 @@ module Gitlab ...@@ -69,31 +69,6 @@ module Gitlab
self.class.attempt_counter.increment self.class.attempt_counter.increment
end end
# rubocop: disable CodeReuse/ActiveRecord
def jobs_running_for_project(job)
return '+Inf' unless runner.instance_type?
# excluding currently started job
running_jobs_count = running_jobs_relation(job)
.where(runner: ::Ci::Runner.instance_type)
.limit(JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET + 1).count - 1
if running_jobs_count < JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET
running_jobs_count
else
"#{JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET}+"
end
end
# rubocop: enable CodeReuse/ActiveRecord
def running_jobs_relation(job)
if ::Feature.enabled?(:ci_pending_builds_maintain_denormalized_data, default_enabled: :yaml)
::Ci::RunningBuild.where(project_id: job.project.id)
else
job.project.builds.running
end
end
def increment_queue_operation(operation) def increment_queue_operation(operation)
self.class.increment_queue_operation(operation) self.class.increment_queue_operation(operation)
end end
...@@ -256,6 +231,33 @@ module Gitlab ...@@ -256,6 +231,33 @@ module Gitlab
Gitlab::Metrics.histogram(name, comment, labels, buckets) Gitlab::Metrics.histogram(name, comment, labels, buckets)
end end
end end
private
# rubocop: disable CodeReuse/ActiveRecord
def jobs_running_for_project(job)
return '+Inf' unless runner.instance_type?
# excluding currently started job
running_jobs_count = running_jobs_relation(job)
.where(runner: ::Ci::Runner.instance_type)
.limit(JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET + 1).count - 1
if running_jobs_count < JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET
running_jobs_count
else
"#{JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET}+"
end
end
def running_jobs_relation(job)
if ::Feature.enabled?(:ci_pending_builds_maintain_denormalized_data, default_enabled: :yaml)
::Ci::RunningBuild.where(project_id: job.project.id)
else
job.project.builds.running
end
end
# rubocop: enable CodeReuse/ActiveRecord
end end
end 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