GraphQL: Add jobs field to CiRunner
What does this MR do and why?
Describe in detail what your merge request does and why.
This MR adds a jobs
property to the CiRunner
GraphQL type. This will be used to display the jobs of a single runner in the new read-only view. For performance reasons, only a single runner is allowed to return jobs.
The jobs
property is only available to administrators for the time being, as that is the target audience of the instance runners page. This will change when we start showing jobs
in group and project-level runners page. The :read_builds
policy rule was added as a way to perform a quick check for basic permissions, but is not meant as a full permission check: in the case of project-level runners for instance, we'll might need to check the permissions for each returned job, if we decide to only show jobs for the project in the current context.
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
Scenario | Screenshot |
---|---|
single runner |
|
multiple runners - |
- Make sure you have some runners registered on your local GDK (ideally some of them with jobs)
- Open http://gdk.test:3000/-/graphql-explorer
- Use the query listed in the sub-sections below
- Check that the response contains the jobs as seen in the respective JSON responses below
Single runner scenario
GraphQL query
query getRunnerJobs {
runner(id: "gid://gitlab/Ci::Runner/110") {
jobCount
jobs(statuses:[SUCCESS]) {
count
nodes {
id
status
}
}
}
}
JSON response
{
"data": {
"runner": {
"jobCount": 1,
"jobs": {
"count": 1,
"nodes": [
{
"id": "gid://gitlab/Ci::Build/812",
"status": "SUCCESS"
}
]
}
}
}
}
Multiple runners scenario
GraphQL query
query getRunnersJobs {
runners(first:2) {
nodes {
id
runnerType
jobCount
jobs(statuses: [SUCCESS]) {
count
nodes {
id
status
}
}
}
}
}
JSON response
{
"data": {
"runners": {
"nodes": [
{
"id": "gid://gitlab/Ci::Runner/110",
"runnerType": "PROJECT_TYPE",
"jobCount": 1,
"jobs": {
"count": 1,
"nodes": [
{
"id": "gid://gitlab/Ci::Build/812",
"status": "SUCCESS"
}
]
}
},
{
"id": "gid://gitlab/Ci::Runner/109",
"runnerType": "PROJECT_TYPE",
"jobCount": 0,
"jobs": null
}
]
}
},
"errors": [
{
"message": "Jobs can only be requested for one runner at a time",
"locations": [
{
"line": 7,
"column": 7
}
],
"path": [
"runners",
"nodes",
1,
"jobs"
]
}
]
}
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.
Part of #349896 (closed)