Skip to content

Fix searches for Upgrade Status to act on runner manager versions

What does this MR do and why?

This MR Fixes Ci::Runner.with_upgrade_status scope to act on ci_runner_machines.version values. The context is that we recently introduced the Ci::RunnerManager model to track individual runner machines. Previously we were only storing the version of the runner manager that last contacted GitLab. Now we have the versions of all the runner managers that contacted GitLab, so this MR updates the scope to look at the correct table through a join.

It also updates some Ci::Runner scopes that could result in ambiguous column references if joined with Ci::RunnerManager. These cases are covered by tests already. I've checked that the resulting SQL is still the same.

Changelog: fixed

Part of #421188 (closed)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Notice that as a side effect, runners that have no runner managers registered against them, no longer show up in this branch (since there is no version to compare against - the version in the runner is ignored):

Before After
image image

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Start the GDK console: gdk console

  2. Evaluate the following expression:

    > Ci::Runner.with_upgrade_status(:recommended)
      Ci::Runner Load (1.4ms)  SELECT "ci_runners".* FROM "ci_runners" INNER JOIN "ci_runner_machines" ON "ci_runner_machines"."runner_id" = "ci_runners"."id" INNER JOIN ci_runner_versions runner_version ON runner_version.version = ci_runner_machines.version WHERE "runner_version"."status" = 3 /*application:console,db_config_name:ci,console_hostname:gitlab-macbookpro.work.pombei.ro,console_username:pedropombeiro,line:bin/rails:4:in `<main>'*/
    => []
  3. Switch to master branch and run reload!

  4. Evaluate the expression again:

    > Ci::Runner.with_upgrade_status(:recommended)
      Ci::Runner Load (11.0ms)  SELECT "ci_runners".* FROM "ci_runners" INNER JOIN "ci_runner_versions" "runner_version" ON "runner_version"."version" = "ci_runners"."version" WHERE "runner_version"."status" = 3 /*application:console,db_config_name:ci,console_hostname:gitlab-macbookpro.work.pombei.ro,console_username:pedropombeiro,line:bin/rails:4:in `<main>'*/

Database query

Ci::Runner.with_upgrade_status(:recommended).limit(100)

https://postgres.ai/console/gitlab/gitlab-production-ci/sessions/21139/commands/68982

SELECT "ci_runners".*
FROM "ci_runners"
  INNER JOIN "ci_runner_versions" "runner_version" ON "runner_version"."version" = "ci_runners"."version"
WHERE "runner_version"."status" = 3
LIMIT 100
 Limit  (cost=1.14..14.82 rows=100 width=276) (actual time=6.112..143.238 rows=100 loops=1)
   Buffers: shared hit=10 read=64 dirtied=6
   I/O Timings: read=141.169 write=0.000
   ->  Merge Join  (cost=1.14..351380.95 rows=2568343 width=276) (actual time=6.110..143.183 rows=100 loops=1)
         Merge Cond: ((ci_runners.version)::text = runner_version.version)
         Buffers: shared hit=10 read=64 dirtied=6
         I/O Timings: read=141.169 write=0.000
         ->  Index Scan using index_ci_runners_on_version on public.ci_runners  (cost=0.43..322163.37 rows=2622668 width=276) (actual time=4.417..141.180 rows=102 loops=1)
               Buffers: shared hit=6 read=62 dirtied=6
               I/O Timings: read=139.595 write=0.000
         ->  Index Only Scan using index_ci_runner_versions_on_unique_status_and_version on public.ci_runner_versions runner_version  (cost=0.28..133.66 rows=1588 width=21) (actual time=1.679..1.714 rows=14 loops=1)
               Index Cond: (runner_version.status = 3)
               Heap Fetches: 0
               Buffers: shared hit=4 read=2
               I/O Timings: read=1.574 write=0.000

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Pedro Pombeiro

Merge request reports