Draft: Add support for ordering group runners by most active
What does this MR do and why?
- Changelog: added
This MR adds support for checking for the most active group runners. It does so by changing ee/app/finders/ee/ci/runners_finder.rb
and the Ci::Runner
model to allow sorting by most_active_desc
for group runners when a group is specified.
Part of #452185 (closed), #437849 (closed)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Scenario | Screenshot |
---|---|
Using DIRECT membership |
|
Not specifying membership | |
Using DESCENDANTS membership |
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
-
Create a group runner with the following tags:
shell
,gdk
,mac
, for instance on http://gdk.test:3000/groups/gitlab-org/-/runners -
Create a simple pipeline on a project inside that group:
default: tags: - shell - gdk - mac before_script: - echo "Before script section" - echo "For example you might run an update here or install a build dependency" - echo "Or perhaps you might print out some debugging details" after_script: - echo "After script section" - echo "For example you might do some cleanup here" build1: stage: build script: - echo "Do your build here" - sleep 30 test1: stage: test script: - echo "Do a test here" - echo "For example run a test suite" - sleep 30 test2: stage: test script: - echo "Do another parallel test here" - echo "For example run a lint test" - sleep 60 deploy1: stage: deploy script: - echo "Do your deploy here" environment: production
-
Run the following query:
{ group(fullPath: "gitlab-org") { runners(first: 5, type: GROUP_TYPE, membership: DIRECT, sort: MOST_ACTIVE_DESC) { nodes { id jobs(statuses: RUNNING) { count } } } } }
Database query plans
Query most active group runners on group ID 9970 (gitlab-org)
SELECT "ci_runners".*
FROM "ci_runners"
INNER JOIN "ci_runner_namespaces" ON "ci_runner_namespaces"."runner_id" = "ci_runners"."id"
INNER JOIN (
SELECT "ci_running_builds"."runner_id", ROW_NUMBER() OVER (PARTITION BY runner_id ORDER BY runner_id) AS rn
FROM "ci_running_builds"
WHERE "ci_running_builds"."runner_type" = 2
AND "ci_running_builds"."runner_owner_namespace_xid" = 9970) AS "limited_builds" ON "limited_builds"."runner_id" = "ci_runners"."id"
AND "limited_builds".rn <= 1000
WHERE "ci_runner_namespaces"."namespace_id" = 9970
AND "ci_runners"."runner_type" = 2
GROUP BY "ci_runners"."id"
ORDER BY COUNT(limited_builds.runner_id) DESC NULLS LAST, "ci_runners"."id" DESC
LIMIT 5 OFFSET 0