Add author filter and dimension to MergeRequests aggregation engine
What does this MR do and why?
The DAP Impact Dashboard needs to let leaders filter and group dashboard data by an arbitrary team (a set of people), not only by GitLab group or project. Issue https://gitlab.com/gitlab-org/gitlab/-/issues/611201 is being delivered as four merge requests, one per ClickHouse aggregation engine that was missing by-user support. This MR covers the MergeRequests engine.
The merge_requests table stores author_id as Nullable(Int64), and the engine had no way to filter or group by it. Without this, a team-scoped view of merge requests silently fell back to unfiltered data.
Changes:
- Adds
column :author_id, :integer, description: 'Merge request author', association: { model: ::User }andexact_match :author_id, :string, description: 'Filter by one or many author Global IDs', formatter: gid_formattertoee/app/models/analytics/aggregation_engines/merge_requests.rb. - The dimension name drives model inference in the GraphQL layer: the
_idsuffix is stripped and the remainder is constantized. Plainassociation: truewould try to resolve a non-existentAuthorconstant, so this dimension passes an explicitassociation: { model: ::User }instead. - This adds a new
authorIdargument onAnalytics.mergeRequestsand a newauthorfield of typeUserCoreonMergeRequestsAggregationResponseDimensions, both generated from the engine declaration. author_idis not part of the table's sort key, so the aggregation framework wraps it inargMaxfor deduplication, matching how the other non-key columns on thisReplacingMergeTreetable are already handled.- Nullable column: merge requests with no recorded author group under a null key and the
authorfield resolves to null. Specs cover that case. - Also updates the shared spec helper
spec/support/helpers/click_house_helpers.rbsoinsert_merge_requests_to_click_housecarriesauthor_id. That helper builds a fixed column set for every row, so this is a single added key. - No migration, schema change, or feature flag: the column already existed in ClickHouse.
- Regenerates
doc/api/graphql/reference/_index.mdandpublic/-/graphql/introspection_result.json. - Spec coverage: dimension examples for
:author_idand the:authorassociation alias (including a row with no author), a filter block for a single Global ID and an array of Global IDs, and a GraphQL request context that filters by an author Global ID and groups by the resolved association.
Out of scope
- Only
author_idis covered here. Theassignee_id,merge_user_id, andmetric_merged_by_idcolumns can follow in later work if the dashboard needs them. - The
user_usernamefilter work, tracked in #599750. - The
DuoWorkflowsengine, tracked in https://gitlab.com/gitlab-org/gitlab/-/issues/605529, which will ship with by-user filtering and grouping from day one. - The other three engines needing the same treatment (
Contributions,Deployments,Pipelines), each covered by its own MR against https://gitlab.com/gitlab-org/gitlab/-/issues/611201.
How to set up and validate locally
-
Query the new argument and dimension in GraphiQL:
query { group(fullPath: "gitlab-org") { analytics { mergeRequests(authorId: ["gid://gitlab/User/1"]) { aggregated { nodes { dimensions { author { id username } } totalCount } } } } } } -
Run the specs for this engine:
bundle exec rspec ee/spec/models/analytics/aggregation_engines/merge_requests_spec.rb ee/spec/requests/api/graphql/analytics/merge_requests_spec.rb -
Confirm the GraphQL docs are up to date:
bundle exec rake gitlab:graphql:check_docs -
Confirm the introspection JSON is up to date:
bundle exec rake gitlab:graphql:check_introspection_sync
References
- Part of https://gitlab.com/gitlab-org/gitlab/-/issues/611201
- Epic https://gitlab.com/groups/gitlab-org/-/work_items/23225
- Related: #599750
- Related: https://gitlab.com/gitlab-org/gitlab/-/issues/605529
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.