Add job and project count to Runner GraphQL object
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)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
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