Count commit issue closes against the work item update limit
What does this MR do and why?
When a commit pushed to the default branch closes issues, ProcessCommitWorker queues one Issues::CloseWorker job for each issue. These closes did not count against any rate limit. Closing an issue through the issue update paths in the UI, the REST API or GraphQL already counts against the per-user work_item_update limit, because those paths go through Issues::UpdateService.
With the rate_limit_issue_closing_from_commits feature flag enabled for the pushing user, ProcessCommitWorker:
- Skips issues that are already closed.
Issues::CloseServicealready does nothing for them, so this only avoids queueing jobs that have no effect. The one difference: an issue reopened between the push and the close job is no longer closed again. - Counts the remaining issues against
work_item_update, one update for each issue, the same wayWorkItems::BulkUpdateRateLimitercounts a bulk edit. When the user is over the limit, the commit closes no issues and the worker logsclosing_issues_skipped_count. A commit that closes more issues than the enforced limit is skipped without counting, like an oversized bulk edit.
The limit itself is enforced by the existing work_item_update_rate_limit flag (#638508). While that flag is disabled, the closes are counted and logged but not blocked. On GitLab.com that flag is enabled, so enabling rate_limit_issue_closing_from_commits there enforces the limit right away.
This MR reuses the existing key, so it adds no application setting. The flag is checked at the call site, as described in the application limits guide for an existing key.
Trade-offs:
- When a commit is over the limit, its issues stay open with no "closed via commit" or "mentioned in commit" note, and the pusher sees no error. The skipped count is logged.
- If
ProcessCommitWorkerfails after counting and Sidekiq retries it, the retry counts again for the issues that are still open.
Closing issues by merging a merge request goes through MergeRequests::CloseIssueWorker and is handled separately in https://gitlab.com/gitlab-org/gitlab/-/work_items/637023.
References
- Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/635840, rollout #640300
- Update limit: !268180 (merged), rollout #638508
How to set up and validate locally
-
In the Rails console, set a small limit and enable both flags:
ApplicationSetting.current.update!(work_item_update_limit: 5) Feature.enable(:work_item_update_rate_limit) Feature.enable(:rate_limit_issue_closing_from_commits) -
In a new project with a repository, create 11 issues (
#1to#11) and close#11. -
Push an empty commit to the default branch that closes two open issues and the closed one:
git commit --allow-empty -m "Closes #1, #2, #11" && git push#1and#2close.log/sidekiq.loghasIssues::CloseWorkerjobs for#1and#2only. -
Push a commit that closes the other open issues:
git commit --allow-empty -m "Closes #3, #4, #5, #6, #7, #8, #9, #10" && git pushNone of them close: 8 issues are more than the limit of 5. The
ProcessCommitWorkerline inlog/sidekiq.loghas"extra.process_commit_worker.closing_issues_skipped_count":8. -
Disable
rate_limit_issue_closing_from_commitsand push the same message again in a new commit.#3to#10close. -
Reset the setting:
ApplicationSetting.current.update!(work_item_update_limit: 1000).
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.