Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/queue/metrics.rb')
-rw-r--r--lib/gitlab/ci/queue/metrics.rb37
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/gitlab/ci/queue/metrics.rb b/lib/gitlab/ci/queue/metrics.rb
index 7f45d626922..54fb1d19ea8 100644
--- a/lib/gitlab/ci/queue/metrics.rb
+++ b/lib/gitlab/ci/queue/metrics.rb
@@ -69,17 +69,6 @@ module Gitlab
self.class.attempt_counter.increment
end
- # rubocop: disable CodeReuse/ActiveRecord
- def jobs_running_for_project(job)
- return '+Inf' unless runner.instance_type?
-
- # excluding currently started job
- running_jobs_count = job.project.builds.running.where(runner: ::Ci::Runner.instance_type)
- .limit(JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET + 1).count - 1
- running_jobs_count < JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET ? running_jobs_count : "#{JOBS_RUNNING_FOR_PROJECT_MAX_BUCKET}+"
- end
- # rubocop: enable CodeReuse/ActiveRecord
-
def increment_queue_operation(operation)
self.class.increment_queue_operation(operation)
end
@@ -242,6 +231,32 @@ module Gitlab
Gitlab::Metrics.histogram(name, comment, labels, buckets)
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)
+ .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.instance_type.where(project_id: job.project_id)
+ else
+ job.project.builds.running.where(runner: ::Ci::Runner.instance_type)
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
end
end
end