GraphQL: Add PipelineAnalyticsPeriod type
What does this MR do and why?
This MR adds a PipelineAnalyticsPeriod
type and an accompanying CiAnalyticsJobStatus
enum type, marked as alpha (experiment). It allows performing the same work as weekPipelinesTotals
, weekPipelinesLabels
, weekPipelinesSuccessful
, and its monthly and yearly variants, while keeping a smaller API surface by reusing the PipelineAnalyticsPeriod
type, and allowing more flexibility in the results returned by adding the status
argument to the totals
field.
Changelog: added
Part of #454313 (closed)
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.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
-
Go to the shell in your GDK
gitlab
directory and runbundle exec rake "gitlab:seed:runner_fleet"
. This will seed your GDK with some pipelines and jobs required for testing this MR. -
Execute the following query:
{ project(fullPath: "rf-top-level-group-1/rf-group-1.1/rf-group-1.1.1/rf-project-1-1-1-1") { pipelineAnalytics { yearPipelines { labels all: totals success: totals(status: SUCCESS) failed: totals(status: FAILED) other: totals(status: OTHER) } } } }
You should see a JSON result outlining the monthly totals per status.
Database query plans
The plans below are based on a worst-case scenario (yearly pipelines on a large project - gitlab-org/gitlab
)
↳ lib/gitlab/ci/charts.rb:46:in `collect'
https://console.postgres.ai/gitlab/gitlab-production-ci/sessions/29545/commands/91764
SELECT COUNT("ci_pipelines"."created_at") AS "count_created_at", date_trunc('month', ci_pipelines.created_at) AS "date_trunc_month_ci_pipelines_created_at"
FROM "ci_pipelines"
WHERE "ci_pipelines"."project_id" = 278964
AND "ci_pipelines"."created_at" >= '2023-06-01 00:00:00'
AND "ci_pipelines"."created_at" <= '2024-06-30 23:59:59.999999'
GROUP BY date_trunc('month', ci_pipelines.created_at)
HashAggregate (cost=71559.72..82119.42 rows=844776 width=16) (actual time=888.709..892.633 rows=13 loops=1)
Group Key: date_trunc('month'::text, ci_pipelines.created_at)
Buffers: shared hit=516219
I/O Timings: read=0.000 write=0.000
-> Index Only Scan using index_ci_pipelines_on_project_id_and_status_and_created_at on public.ci_pipelines (cost=0.70..67335.43 rows=844859 width=16) (actual time=5.823..692.626 rows=1282742 loops=1)
Index Cond: ((ci_pipelines.project_id = 278964) AND (ci_pipelines.created_at >= '2023-06-01 00:00:00'::timestamp without time zone) AND (ci_pipelines.created_at <= '2024-06-30 23:59:59.999999'::timestamp without time zone))
Heap Fetches: 105755
Buffers: shared hit=516219
I/O Timings: read=0.000 write=0.000
↳ lib/gitlab/ci/charts.rb:74:in `totals_by_status'
https://console.postgres.ai/gitlab/gitlab-production-ci/sessions/29545/commands/91767
SELECT COUNT("ci_pipelines"."created_at") AS "count_created_at", date_trunc('month', ci_pipelines.created_at) AS
"date_trunc_month_ci_pipelines_created_at", "ci_pipelines"."status" AS "ci_pipelines_status"
FROM "ci_pipelines"
WHERE "ci_pipelines"."project_id" = 278964
AND "ci_pipelines"."created_at" >= '2023-06-01 00:00:00'
AND "ci_pipelines"."created_at" <= '2024-06-30 23:59:59.999999'
GROUP BY date_trunc('month', ci_pipelines.created_at), "ci_pipelines"."status"
HashAggregate (cost=73671.87..84231.57 rows=844776 width=23) (actual time=811.519..814.737 rows=91 loops=1)
Group Key: date_trunc('month'::text, ci_pipelines.created_at), ci_pipelines.status
Buffers: shared hit=516219
I/O Timings: read=0.000 write=0.000
-> Index Only Scan using index_ci_pipelines_on_project_id_and_status_and_created_at on public.ci_pipelines (cost=0.70..67335.43 rows=844859 width=23) (actual time=5.000..586.773 rows=1282742 loops=1)
Index Cond: ((ci_pipelines.project_id = 278964) AND (ci_pipelines.created_at >= '2023-06-01 00:00:00'::timestamp without time zone) AND (ci_pipelines.created_at <= '2024-06-30 23:59:59.999999'::timestamp without time zone))
Heap Fetches: 105755
Buffers: shared hit=516219
I/O Timings: read=0.000 write=0.000