Skip to content

Fix Merge Request analytics query optimization

Adam Hegyi requested to merge match-exact-mr-analytics-query into master

What does this MR do?

Note: the change is behind a feature flag, so there are no user facing changes.

Given the following query:

project(fullPath: "gitlab-org/gitlab") {
  mergeRequests(mergedBefore: "2020-09-01", mergedAfter: "2020-08-01", first: 0) { 
    count
  }
}

If the optimized_merge_request_count_with_merged_at_filter feature flag is turned on, the backend will execute special DB queries for the count. The optimization works when specific fields are requested (count, totalTimeToMerge). The field check logic on the backend did not anticipate null arguments, so the optimized code path was never reached when loading the MR analytics page.

Example:

project(fullPath: "gitlab-org/gitlab") {
  mergeRequests(mergedBefore: "2020-09-01", mergedAfter: "2020-08-01", first: 0, labels: null) { 
    count
    __typename
  }
}

Fix:

  • .compact the argument names to ignore empty (null) arguments
  • Ignore the __typename field. It seems like this is always requested by the FE.

How to test it:

  1. Make sure you're on ultimate
  2. Enable the FF: Feature.enable(:optimized_merge_request_count_with_merged_at_filter)
  3. Go to any project: Analytics / Merge Request
  4. Inspect the graphql request with many COUNT queries. You should see that the COUNT queries are querying the merge_request_metrics table. FROM "merge_request_metrics"

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Resolves #276386 (closed)

Edited by Dan Jensen

Merge request reports