Skip to content

Add job and project count to Runner GraphQL object

Pedro Pombeiro requested to merge pedropombeiro/332345/graphql-add-counts into master

What does this MR do?

This MR adds a presenter for the Ci::Runner class so that we can extend the GraphQL entity with the job_count (limited to 1000) and project_count properties to be used in the UI.

Testing

query getRunners {
  runners {
    edges {
      node {
        # ... RunnerType
        id
        description
        projectCount
        jobCount
        # ... RunnerType
      }
    }
  }
}

returns:

{
  "data": {
    "runners": {
      "edges": [
        {
          "node": {
            "id": "gid://gitlab/Ci::Runner/24",
            "description": "test runner",
            "projectCount": 0,
            "jobCount": 0
          }
        },
        {
          "node": {
            "id": "gid://gitlab/Ci::Runner/2",
            "description": "docker-runner - updated",
            "projectCount": 1,
            "jobCount": 30
          }
        }
      ]
    }
  }
}

Screenshots (strongly suggested)

image

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Database query plans

The new properties execute the following queries:

projectCount

SQL

SELECT
    "ci_runner_projects"."runner_id",
    COUNT(*) AS count
FROM
    "ci_runner_projects"
WHERE
    "ci_runner_projects"."runner_id" IN (38, 37, 24, 2)
GROUP BY
    "ci_runner_projects"."runner_id"

Query plan

Link: https://gitlab.slack.com/archives/CLJMDRD8C/p1624520835221100

 Aggregate  (cost=0.43..9.39 rows=6 width=12) (actual time=11.360..11.361 rows=0 loops=1)
   Group Key: ci_runner_projects.runner_id
   Buffers: shared hit=12 read=3
   I/O Timings: read=11.230 write=0.000
   ->  Index Only Scan using index_ci_runner_projects_on_runner_id on public.ci_runner_projects  (cost=0.43..9.30 rows=6 width=4) (actual time=11.316..11.317 rows=0 loops=1)
         Index Cond: (ci_runner_projects.runner_id = ANY ('{38,37,24,2}'::integer[]))
         Heap Fetches: 0
         Buffers: shared hit=12 read=3
         I/O Timings: read=11.230 write=0.000
jobCount

SQL

SELECT
    COUNT(*)
FROM (
    SELECT
        1 AS one
    FROM
        "ci_builds"
    WHERE
        "ci_builds"."type" = 'Ci::Build'
        AND "ci_builds"."runner_id" = 2
    LIMIT 1000) subquery_for_count

Query plan

Link: https://gitlab.slack.com/archives/CLJMDRD8C/p1623950536048600

 Aggregate  (cost=1513.22..1513.23 rows=1 width=8) (actual time=1309.647..1309.656 rows=1 loops=1)
   Buffers: shared hit=8 read=970
   I/O Timings: read=1299.004 write=0.000
   ->  Limit  (cost=0.58..1500.72 rows=1000 width=4) (actual time=7.051..1308.816 rows=1000 loops=1)
         Buffers: shared hit=8 read=970
         I/O Timings: read=1299.004 write=0.000
         ->  Index Scan using index_ci_builds_on_runner_id_and_id_desc on public.ci_builds  (cost=0.58..9017.91 rows=6011 width=4) (actual time=7.048..1308.105 rows=1000 loops=1)
               Index Cond: (ci_builds.runner_id = 2)
               Filter: ((ci_builds.type)::text = 'Ci::Build'::text)
               Rows Removed by Filter: 0
               Buffers: shared hit=8 read=970
               I/O Timings: read=1299.004 write=0.000

Part of #332345 (closed)

Edited by Pedro Pombeiro

Merge request reports