Add stale scope to ci_runner_machines
What does this MR do and why?
Describe in detail what your merge request does and why.
This MR adds a stale
scope to Ci::RunnerMachine
that allows finding out which machines haven't contacted in the last 7 days. This is similar to what is already being done in Ci::Runner#stale
. It also adds a couple of indices to the table to support the queries.
Part of #387398 (closed)
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Database query plans
Ci::RunnerMachine.stale
SQL query
SELECT "ci_runner_machines".*
FROM ((
SELECT "ci_runner_machines".*
FROM "ci_runner_machines"
WHERE "ci_runner_machines"."contacted_at" IS NULL)
UNION ALL (
SELECT "ci_runner_machines".*
FROM "ci_runner_machines"
WHERE "ci_runner_machines"."contacted_at" <= '2023-01-04 14:12:54.932635')) ci_runner_machines
WHERE "ci_runner_machines"."created_at" <= '2023-01-04 14:12:54.932507'
Query plan
https://postgres.ai/console/gitlab/gitlab-production-ci/sessions/14406/commands/50678
Append (cost=0.15..22.08 rows=31 width=266) (actual time=0.014..0.014 rows=0 loops=1)
Buffers: shared hit=3
I/O Timings: read=0.000 write=0.000
-> Index Scan using index_ci_runner_machines_on_contacted_at_desc_and_id_desc on public.ci_runner_machines (cost=0.15..3.17 rows=1 width=266) (actual time=0.007..0.007 rows=0 loops=1)
Index Cond: (ci_runner_machines.contacted_at IS NULL)
Filter: (ci_runner_machines.created_at <= '2023-01-04 14:12:54.932507+00'::timestamp with time zone)
Rows Removed by Filter: 0
Buffers: shared hit=2
I/O Timings: read=0.000 write=0.000
-> Index Scan using index_ci_runner_machines_on_created_at_and_id_desc on public.ci_runner_machines ci_runner_machines_1 (cost=0.15..18.45 rows=30 width=266) (actual time=0.005..0.005 rows=0 loops=1)
Index Cond: (ci_runner_machines_1.created_at <= '2023-01-04 14:12:54.932507+00'::timestamp with time zone)
Filter: (ci_runner_machines_1.contacted_at <= '2023-01-04 14:12:54.932635+00'::timestamp with time zone)
Rows Removed by Filter: 0
Buffers: shared hit=1
I/O Timings: read=0.000 write=0.000
Edited by Pedro Pombeiro