Check runner manager job status from the runners' running jobs
What does this MR do and why?
Context
REST GET /runners/:id/managers and the GraphQL CiRunnerManager.jobExecutionStatus field find which managers run a job with a statement that probes the runner's running jobs once per manager. Its cost grows with the number of managers listed, so a runner with many managers makes each call expensive on the CI database. The figures and the agreed approach are in https://gitlab.com/gitlab-org/gitlab/-/work_items/638238#note_4185424743 (part 1 of 3).
This MR
Ci::RunnerManager.ids_with_running_builds_for_runner_managersreads the running builds of the batch's runners once, joins them to their managers, and keeps the listed managers. It returns the same statuses as today.- The runner IDs come from the loaded managers, so the REST helper and the GraphQL field now batch on manager records instead of IDs.
Ci::Runner's job status is unchanged. - The manager filter runs on a materialized CTE rather than on the partitioned
p_ci_runner_machine_buildstable, so query planning doesn't repeat it per partition. - With
ci_runner_manager_job_status_by_runneroff, both surfaces run today's statement.
Planning time still grows with the number of managers in one call, but it stays well below today's execution cost. Runners with very large manager counts are left to the per-user limit in part 3.
No Changelog: the change is behind a disabled flag, and the statuses don't change.
Feature Flag: ci_runner_manager_job_status_by_runner
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/638238+
- https://gitlab.com/gitlab-org/gitlab/-/work_items/639064+
Screenshots or screen recordings
Not applicable: no UI change.
How to set up and validate locally
- Register a runner and run a job on it so it has at least one manager with a running job (or use a runner from your GDK seed data).
- List the managers with a personal access token (
read_apiscope), with the flag off, and note each manager'sjob_execution_status:curl --header "PRIVATE-TOKEN: <your_access_token>" "http://gdk.test:3000/api/v4/runners/<runner_id>/managers" - In a Rails console, run
Feature.enable(:ci_runner_manager_job_status_by_runner), list the managers again, and check the statuses match.log/development.logshows therunning_buildsandrunning_managersCTEs. - Query the same managers in GraphiQL and check
jobExecutionStatusmatches:{ runner(id: "gid://gitlab/Ci::Runner/<runner_id>") { managers { nodes { id jobExecutionStatus } } } } - Clean up:
Feature.remove(:ci_runner_manager_job_status_by_runner).
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.