Add fast timeout to group sidebar MR and epic counts

What does this MR do and why?

The group sidebar loads its open counts through the NamespaceSidebar GraphQL type. The issue and work item counts already run under ApplicationRecord.with_fast_read_statement_timeout (4.5 seconds) and return null when it fires. The merge request and epic counts ran under the normal statement timeout, and a timeout failed the whole sidebar query, so no counts were shown.

This MR:

  • Adds a fast_timeout: option (default false) to Groups::MergeRequestsCountService and Groups::EpicsCountService, matching Groups::OpenIssuesCountService and Groups::OpenWorkItemsCountService. Other callers, such as Group#open_merge_requests_count, are unchanged.
  • Passes fast_timeout: from NamespaceSidebar.openMergeRequestsCount (groups only) and NamespaceSidebar.openEpicsCount, behind the group_sidebar_mr_and_epic_counts_fast_timeout flag (gitlab_com_derisk, disabled by default).
  • Rescues ActiveRecord::QueryCanceled for both counts, logs it with query: 'group_sidebar_merge_requests_count' or query: 'group_sidebar_epics_count', and returns null, like the issue and work item counts.
Decisions
  • The rescue is not behind the flag. With the flag disabled, a count that reaches the normal statement timeout now returns null instead of failing the request. Turning the flag off during rollout therefore still keeps the other sidebar counts working.
  • No changelog entry. The new timeout is behind a default-off flag. The rescue only changes what happens after a query has already timed out.
  • Flag actor is the group's root ancestor, so enabling the flag for a top-level group also covers its subgroups. root_ancestor is memoized, and both counts share the same actor in a request.
  • The option is copied into each service to match the two existing services, rather than moved into Groups::CountService, to keep this change small.
  • No frontend change. The super sidebar already hides the count pill when a count is null.
  • Project namespaces are unchanged. Their merge request count uses Projects::OpenMergeRequestsCountService, and they have no epic count.

References

Screenshots or screen recordings

Not applicable: backend only. The sidebar looks the same, and it already hides a count that is null.

How to set up and validate locally

  1. In the Rails console, enable the feature flag:

    Feature.enable(:group_sidebar_mr_and_epic_counts_fast_timeout)
  2. Visit a group with open merge requests, such as http://127.0.0.1:3000/flightjs. With a Premium or Ultimate license, the group also shows an epic count.

  3. In log/development.log, find the NamespaceSidebar GraphQL request. SET LOCAL statement_timeout = 4500 now runs before the merge request and epic count queries. Groups with 1,000 or fewer open items are not cached, so the counts run on every page load.

  4. Disable the flag with Feature.disable(:group_sidebar_mr_and_epic_counts_fast_timeout) and reload the page. SET LOCAL statement_timeout now runs only before the issue and work item counts.

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.

Edited by Konstantin Greif

Merge request reports

Loading
Loading