Remove unused ai_events_counts aggregation and aiMetricsBasic GraphQL field in two phases
The Why
Expand to read The Why
In GitLab 18.5 we built a PostgreSQL-based data source for a GitLab Duo usage dashboard, aimed at self-managed customers without ClickHouse. It aggregated AI usage events into daily counts every 5 minutes and exposed code suggestion shown/accepted counts through an experimental GraphQL field on groups and projects. See issue https://gitlab.com/gitlab-org/gitlab/-/issues/558280, and merge requests !205716 (merged) and !207721 (merged).
The parent epic &19630 (closed) was closed on 2026-02-12. The product manager's closing note states the team will not pursue a PostgreSQL-based Duo dashboard, and will instead focus on the ClickHouse dashboard and APIs, with ClickHouse expected to become generally available across all deployment tiers. PostgreSQL-only installs will get raw data via API instead. The planned frontend consumer, #578196 (closed), was closed with no merge request.
Today nothing consumes this field: no frontend code and no other internal project queries it. Keeping it costs us a cron job running every 5 minutes on every instance, writing data nobody reads; a growing partitioned table that keeps getting pruned; dead code that reviewers and the Optimize group must keep maintaining; and an experimental public API surface that could be mistaken for something supported. The field is marked experimental, so it can be removed at any time without a deprecation cycle.
Proposal
Remove the background aggregation job, the experimental GraphQL field, and the underlying storage table. There is no user-facing feature change: the ClickHouse-backed AI metrics that customers actually use today remain untouched. The removal happens in two phases across consecutive milestones, because the table can only be dropped once no running code references it, and the worker class must outlive its purged jobs by one release. It should save us some CPU cycles, roughly 1.5Gb in DB space and reduce codebase size.
Technical Proposal
Today a Sidekiq cron worker aggregates AI usage events into a dedicated table every 5 minutes, and an experimental GraphQL field reads that table to serve code suggestion metrics on groups and projects. This work removes the worker's behavior and all the application code first, then drops the table and the worker class itself one milestone later. One GraphQL type in the ClickHouse-backed metrics path currently inherits two fields from the type being removed, so those two fields need to be inlined rather than deleted.
Implementation details
Phase 1 (milestone M): remove the model and application code, neutralize and unschedule the worker, purge queued jobs.
Phase 2 (milestone M+1): drop the table and finish worker removal.
Acceptance criteria
- After phase 1, there is no cron entry and no scheduled Sidekiq jobs for the aggregation worker on GitLab.com.
- After phase 1,
aiMetricsBasicis absent from the GraphQL schema and from the generated GraphQL reference docs. - After phase 1,
codeSuggestionMetricsstill returnsacceptedCountandshownCountfrom the ClickHouse-backed path. - After phase 2, the
ai_events_countstable is absent fromdb/structure.sqland its dictionary entry is present underdb/docs/deleted_tables. - After phase 2, no references to the removed worker, services, resolvers, types, model, or table remain anywhere in the repository.
Out of scope
- The raw
ai_usage_eventstable and theAi::UsageEventmodel, which are still used by other features such as per-user AI metrics. - The ClickHouse-backed
aiMetricsfield and its dashboards. - Any change to how PostgreSQL-only instances obtain Duo usage data going forward.