Rate limit removing merge requests from merge trains
What does this MR do and why?
Removing a merge request from a merge train restarts the pipelines of the merge
requests queued behind it. This MR makes every user-initiated removal count
against the per-user merge_train_removal rate limit added in
!271196 (merged).
The check is the first statement of AutoMerge::MergeTrainService#cancel, so
all four ways a user can remove a car share one allowance:
| Caller | When throttled |
|---|---|
mergeTrainsDeleteCar mutation (merge trains page) |
Message in errors. The page already shows errors[0] |
POST .../merge_requests/:iid/cancel_auto_merge |
429 with Retry-After |
Projects::MergeRequestsController#cancel_auto_merge (MR widget) |
429, and the widget shows its existing "Something went wrong. Please try again." alert |
POST .../cancel_merge_when_pipeline_succeeds (deprecated) |
201 with status: error in the body. This deprecated endpoint already reports every failure that way, so it keeps its documented contract rather than gaining a new status code |
The merge request stays on the train when throttled. System removals, for
example after a failed train pipeline or a merge conflict, go through #abort
and are not counted.
The rule is staged: while rate_limit_merge_train_removal is disabled, removals
over the limit are only logged (rate_limit_state on the request log line), so
nothing is blocked until the flag is enabled. That log line also replaces the
explicit AppJsonLogger call the pipeline schedule and trigger limits use.
The documentation adds a Merge train removal rate limits section to the
CI/CD limits page, a GitLab.com settings row, and the 429 response for
cancel_auto_merge.
No changelog: the behavior is behind a default-off flag.
References
Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636911
Rollout issue: #640280
Screenshots or screen recordings
Not applicable, no new UI.
How to set up and validate locally
-
Set the limit to
1and enable the flag:ApplicationSetting.current.update!(merge_train_removal_limit_per_user: 1) Feature.enable(:rate_limit_merge_train_removal) -
In a project with merge trains enabled, add two merge requests to the train.
-
Open Code > Merge requests > Merge trains and remove one merge request. It succeeds.
-
Within a minute, remove the other one. The page shows
This endpoint has been requested too many times. Try again later.and the merge request stays on the train. -
Disable the flag and repeat: both removals succeed.
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.