Add Graphql API for runner usage by project
What does this MR do and why?
Add Graphql API for runner usage by project API for CI compute minute breakdown by project (#437658 - closed)
See the example usage below.
It's deliberately put into its own "endpoint", not into runners
or ci_queueing_history
. ci_queueing_history
has a different input: time
instead of date
. runners
return runners, and not the generic stats, and have too many filters which we don't plan to support here.
I also don't want to unify that with the "top runners" from the API for CI compute minute breakdown by project (#437658 - closed).
For now, I want to keep those things separate, and we can unify them later if needed.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- Follow https://docs.gitlab.com/ee/development/database/clickhouse/clickhouse_within_gitlab.html#gdk-setup up to and including running migrations
- Run the following in the rails console:
::Ci::Build.where.not(finished_at: nil).find_each{|build| ::Ci::FinishedBuildChSyncEvent.upsert({ build_id: build.id, build_finished_at: build.finished_at }, unique_by: [:build_id, :partition]) }
ClickHouse::DataIngestion::CiFinishedBuildsSyncService.new.execute
- Login as admin and go to
/-/graphql-explorer
- Execute the following query:
{ runnerUsageByProject(runnerType: INSTANCE_TYPE, fromDate: "2023-01-01", toDate: "2023-12-31", projectsLimit: 3) {
project {
name
fullPath
}
ciBuildCount
ciMinutesUsed
}}
It should return something similar to:
{
"data": {
"runnerUsageByProject": [
{
"project": {
"name": "Gitlab Test",
"fullPath": "gitlab-org/gitlab-test"
},
"ciBuildCount": 52,
"ciMinutesUsed": 6001
},
{
"project": {
"name": "Lab Coat",
"fullPath": "Commit451/lab-coat"
},
"ciBuildCount": 52,
"ciMinutesUsed": 6001
},
{
"project": {
"name": "Flight",
"fullPath": "flightjs/Flight"
},
"ciBuildCount": 52,
"ciMinutesUsed": 6000
},
{
"project": null,
"ciBuildCount": 104,
"ciMinutesUsed": 12000
}
]
}
}