Add author dimension to Contributions 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, since team boundaries do not always map cleanly to a 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 Contributions engine.

The contributions_new table already stores author_id (Int64, not nullable, and part of the table sort key), and the engine already had an author_id exact match filter. Only the dimension was missing, so contributions could be narrowed to a team but never broken down per person. This is the smallest of the four MRs, adding a single dimension declaration.

Changes:

  • Adds column :author_id, :integer, description: 'Contribution author', association: { model: ::User } to ee/app/models/analytics/aggregation_engines/contributions.rb.
  • Because the response field and batch loader are generated from the dimension declaration, this adds a new author field of type UserCore on ContributionsAggregationResponseDimensions. No new argument is needed, since Analytics.contributions(authorId:) already existed.
  • The dimension name drives model inference in the GraphQL layer: the _id suffix is stripped and the remainder is constantized. Plain association: true would try to resolve a non-existent Author constant, so this dimension passes an explicit association: { model: ::User } instead.
  • author_id is part of the sort key, so it does not need the argMax wrapping that the aggregation framework applies to non-key columns for deduplication.
  • No migration, schema change, or feature flag: the column already existed in ClickHouse, this only closes a gap in the engine declaration.
  • Regenerates doc/api/graphql/reference/_index.md and public/-/graphql/introspection_result.json.
  • Spec coverage: adds dimension examples for :author_id and the :author association alias, plus a GraphQL request context that filters by an author Global ID and groups by the resolved association.

Out of scope

How to set up and validate locally

  1. Query the new dimension in GraphiQL:

    query {
      group(fullPath: "gitlab-org") {
        analytics {
          contributions(authorId: ["gid://gitlab/User/1"]) {
            aggregated { nodes { dimensions { author { id username } } totalCount } }
          }
        }
      }
    }
  2. Run the specs for this engine:

    bundle exec rspec ee/spec/models/analytics/aggregation_engines/contributions_spec.rb ee/spec/requests/api/graphql/analytics/contributions_spec.rb
  3. Confirm the GraphQL docs are up to date:

    bundle exec rake gitlab:graphql:check_docs
  4. Confirm the introspection JSON is up to date:

    bundle exec rake gitlab:graphql:check_introspection_sync

References

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.

Merge request reports

Loading
Loading