Skip to content

Draft: GraphQL: Add `CiRunnerManager.jobs` field

What does this MR do and why?

This MR adds adds the CiRunnerManager.jobs field, to bring the GraphQL API in line with the REST version being introduced in !140667 (merged). This query only allows returning jobs for a single runner manager at a time, due to https://gitlab.com/gitlab-org/gitlab/-/blob/ce5e581b0a42b934be53ff75a57d7f73c08f3af1/app/graphql/resolvers/ci/runner_jobs_resolver.rb#L12-12.

Changelog: added

Part of #438005

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.

image

How to set up and validate locally

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

  1. Create a runner if haven't one already, by going to http://gdk.test:3000/admin/runners and clicking New instance runner.

  2. Follow the workflow to create the runner, set the accepted tags to gdk, shell.

  3. Register the runner with gitlab-runner register

  4. Run the runner with gitlab-runner run

  5. Create a project with a .gitlab-ci.yml as follows:

    job1:
      script: echo Hi
      tags: 
        - gdk
        - shell

The runner should pick up the job.

  1. Run the following query at http://gdk.test:3000/-/graphql-explorer (adapting the runner ID):

    {
      runner(id: "gid://gitlab/Ci::Runner/9620") {
        id
        description
        version
        managers {
          nodes {
            id
            systemId
            jobs {
              nodes {
                id
                status
              }
            }
          }
        }
      }
    }

Database query plan

Runner manager jobs

https://console.postgres.ai/gitlab/gitlab-production-ci/sessions/25170/commands/79921

SELECT "p_ci_builds"."status", "p_ci_builds"."finished_at", "p_ci_builds"."created_at", "p_ci_builds"."updated_at",
  "p_ci_builds"."started_at", "p_ci_builds"."runner_id", "p_ci_builds"."coverage", "p_ci_builds"."commit_id",
  "p_ci_builds"."name", "p_ci_builds"."options", "p_ci_builds"."allow_failure", "p_ci_builds"."stage",
  "p_ci_builds"."trigger_request_id", "p_ci_builds"."stage_idx", "p_ci_builds"."tag", "p_ci_builds"."ref",
  "p_ci_builds"."user_id", "p_ci_builds"."type", "p_ci_builds"."target_url", "p_ci_builds"."description",
  "p_ci_builds"."project_id", "p_ci_builds"."erased_by_id", "p_ci_builds"."erased_at", "p_ci_builds"."artifacts_expire_at",
  "p_ci_builds"."environment", "p_ci_builds"."when", "p_ci_builds"."yaml_variables", "p_ci_builds"."queued_at",
  "p_ci_builds"."lock_version", "p_ci_builds"."coverage_regex", "p_ci_builds"."auto_canceled_by_id", "p_ci_builds"."retried",
  "p_ci_builds"."protected", "p_ci_builds"."failure_reason", "p_ci_builds"."scheduled_at", "p_ci_builds"."token_encrypted",
  "p_ci_builds"."upstream_pipeline_id", "p_ci_builds"."resource_group_id", "p_ci_builds"."waiting_for_resource_at",
    "p_ci_builds"."processed",
  "p_ci_builds"."scheduling_type", "p_ci_builds"."id", "p_ci_builds"."stage_id", "p_ci_builds"."partition_id",
  "p_ci_builds"."auto_canceled_by_partition_id"
FROM "p_ci_builds"
  INNER JOIN "p_ci_runner_machine_builds" ON "p_ci_builds"."id" = "p_ci_runner_machine_builds"."build_id"
WHERE "p_ci_builds"."type" = 'Ci::Build'
  AND "p_ci_runner_machine_builds"."runner_machine_id" = 216
  AND ("p_ci_builds"."status" NOT IN ('created'))
  AND ("p_ci_builds"."status" IN ('success', 'failed'))
ORDER BY "p_ci_builds"."id" DESC
LIMIT 101
 Limit  (cost=1.86..5646.86 rows=101 width=1229) (actual time=761.858..3657.793 rows=101 loops=1)
   Buffers: shared hit=8931 read=1878 dirtied=1672
   I/O Timings: read=3553.856 write=0.000
   ->  Nested Loop  (cost=1.86..356881049.61 rows=6385294 width=1229) (actual time=761.856..3657.614 rows=101 loops=1)
         Buffers: shared hit=8931 read=1878 dirtied=1672
         I/O Timings: read=3553.856 write=0.000
         ->  Merge Append  (cost=1.15..312758059.00 rows=6385294 width=8) (actual time=204.721..369.274 rows=297 loops=1)
               Sort Key: p_ci_runner_machine_builds.build_id DESC
               Buffers: shared hit=6070 read=216 dirtied=181
               I/O Timings: read=335.306 write=0.000
               ->  Index Scan Backward using ci_runner_machine_builds_100_pkey on gitlab_partitions_dynamic.ci_runner_machine_builds_100 p_ci_runner_machine_builds_1  (cost=0.57..256574613.58 rows=3310522 width=8) (actual time=202.195..202.195 rows=1 loops=1)
                     Filter: (p_ci_runner_machine_builds_1.runner_machine_id = 11814776)
                     Rows Removed by Filter: 46
                     Buffers: shared hit=8 read=42 dirtied=38
                     I/O Timings: read=186.691 write=0.000
               ->  Index Scan Backward using ci_runner_machine_builds_101_pkey on gitlab_partitions_dynamic.ci_runner_machine_builds_101 p_ci_runner_machine_builds_2  (cost=0.57..56119592.48 rows=3074772 width=8) (actual time=2.520..166.453 rows=297 loops=1)
                     Filter: (p_ci_runner_machine_builds_2.runner_machine_id = 11814776)
                     Rows Removed by Filter: 5996
                     Buffers: shared hit=6062 read=174 dirtied=143
                     I/O Timings: read=148.614 write=0.000
         ->  Append  (cost=0.71..6.89 rows=2 width=1229) (actual time=10.885..11.065 rows=0 loops=297)
               Buffers: shared hit=2861 read=1662 dirtied=1491
               I/O Timings: read=3218.550 write=0.000
               ->  Index Scan using ci_builds_pkey on public.ci_builds p_ci_builds_1  (cost=0.71..3.62 rows=1 width=1250) (actual time=0.249..0.249 rows=0 loops=297)
                     Index Cond: (p_ci_builds_1.id = p_ci_runner_machine_builds.build_id)
                     Filter: (((p_ci_builds_1.status)::text <> 'created'::text) AND ((p_ci_builds_1.status)::text = ANY ('{success,failed}'::text[])) AND ((p_ci_builds_1.type)::text = 'Ci::Build'::text))
                     Rows Removed by Filter: 0
                     Buffers: shared hit=1480 read=5
                     I/O Timings: read=68.995 write=0.000
               ->  Index Scan using ci_builds_101_pkey on gitlab_partitions_dynamic.ci_builds_101 p_ci_builds_2  (cost=0.57..3.26 rows=1 width=540) (actual time=10.630..10.810 rows=0 loops=297)
                     Index Cond: (p_ci_builds_2.id = p_ci_runner_machine_builds.build_id)
                     Filter: (((p_ci_builds_2.status)::text <> 'created'::text) AND ((p_ci_builds_2.status)::text = ANY ('{success,failed}'::text[])) AND ((p_ci_builds_2.type)::text = 'Ci::Build'::text))
                     Rows Removed by Filter: 1
                     Buffers: shared hit=1381 read=1657 dirtied=1491
                     I/O Timings: read=3149.555 write=0.000
Edited by Pedro Pombeiro

Merge request reports

Loading