GraphQL: Add support for counting running builds for the busiest instance runners
In #377324 (closed), we'll need to display a list of the 5 busiest runners, along with the count of running builds and a link to the runner details page.
Implementation plan
As mentioned in the exploration in the parent issue, we can use the existing ci_running_builds
table to compute the required metrics. Initially, this will only be available for jobs executed by instance runners due to the fact that ci_running_builds
is only populated for that type of runners. Once we prove the concept, we can look into expanding the implementation so that ci_running_builds
is populated for all runner types.
The query would look something like:
SELECT *
FROM (
SELECT runner_id, COUNT(runner_id) AS job_count
FROM ci_running_builds
GROUP BY runner_id
ORDER BY job_count DESC
LIMIT 5) runners_by_jobs
INNER JOIN ci_runners ON runners_by_jobs.runner_id = ci_runners.id;
GraphQL
We could add a new filter to the Resolvers::Ci::RunnersResolver
class (filterByMetrics
below), which would be an enum representing possible predefined queries that could be used for different metrics:
{
runners(type: INSTANCE_TYPE, filterByMetrics: MOST_ACTIVE) {
count
edges {
webUrl
node {
id
jobCount(statuses: [RUNNING])
}
}
}
}
The Ci::RunnersFinder
class could raise an error if we try to use filterByMetrics: MOST_ACTIVE
without type: INSTANCE_TYPE
(this limitation should also be documented in the MOST_ACTIVE
enum value). Adding filterByMetrics: MOST_ACTIVE
would also automatically limit the number of records returned, in order to reduce load on the database.