Feature requests for more filter on runner status query
Problem to solve
I am using the graphql API to pull metrics for custom GitLab runner autoscaling. Currently, it is working but it could be much better if there were a few additional queries that were supported.
The current query:
query {
group(fullPath: "my_group_name") {
runners(status:ONLINE) {
nodes {
id
managers {
count
edges {
node {
id
systemId
status
contactedAt
}
}
}
}
}
}
}
Returns all the runners assigned to runner configuration token. However, with autoscaling and instance termination, there could a lot of linger runners that are offline or inactive and never coming back.
In python, I must filter this manually to get the actual online runner count or information
online_nodes = [node for node in result['runner']['managers']['nodes'] if node['status'] == 'ONLINE']
Proposal
Add in a filter query on the node or status to support filtering based on status:
query {
group(fullPath: "my_group_name") {
runners(status:ONLINE) {
nodes {
id
managers(status: ONLINE) {
count
edges {
node {
id
systemId
status
contactedAt
}
}
}
}
}
}
}
Implementation guide
Since this represents a relatively big chunk of work, we should split the work into a couple of MRs:
-
MR 1
- Create a
Ci::RunnerManagersFinder
that will implement the finding of the runner managers, similar toCi::RunnersFinder
. - Add tests for the new finder.
- Create a
-
MR 2
- Implement a
Resolvers::Ci::RunnerManagersResolver
, similar toResolvers::Ci::RunnersResolver
- Implement a
status
field in the resolver, similar to the one in https://gitlab.com/gitlab-org/gitlab/-/blob/ab7808ac997a2b1d9bbc7a5d9d3ac2bc7ac3fccb/app/graphql/resolvers/ci/runners_resolver.rb#L20-22. - Use the new resolver in the
Types::Ci::RunnerType#managers
field - Add specs for the resolver in https://gitlab.com/gitlab-org/gitlab/-/blob/376a2d845f773c757875fb8258b78bb0dabb04cb/spec/requests/api/graphql/ci/runners_spec.rb#L37-46.
- Implement a