Add a setting for the merge train removal rate limit
What does this MR do and why?
Removing a merge request from a merge train restarts the pipelines of every merge request queued behind it, and nothing limits how often a user can do that. This MR adds the setting and the rate limit key, so the MR that makes the removal paths count against it can focus on the enforcement:
| Setting | Default |
|---|---|
merge_train_removal_limit_per_user |
30 per minute, 0 disables |
The default matches merge_requests_rebase_limit, the closest existing limit:
it is also per user and per minute, and each rebase also starts a pipeline.
Merge trains are Premium and Ultimate, so the setting is an EE setting in the
existing rate_limits JSONB column (no migration). Like the other EE rate
limit settings, it is set through the application settings API only, with no
admin form field.
The LabKit rule merge_train_removal (per user, per minute) is defined with
staged_rule, as doc/development/application_limits.md recommends for a new
key. Once the removal paths check the key, removals over the limit are only
logged while the rate_limit_merge_train_removal feature flag (gitlab_com_derisk,
default off) is disabled, in rate_limit_state as
applimiter_merge_train_removal:limit_merge_train_removals_by_user_log:log.
Enabling the flag makes the rule block them.
Nothing calls this rule yet. AutoMerge::MergeTrainService#cancel starts
checking it in !271199,
which is stacked on this one.
References
Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/636911
Rollout issue: #640280
Screenshots or screen recordings
Not applicable, no UI change.
How to set up and validate locally
-
Set the limit through the API:
curl --request PUT --header "PRIVATE-TOKEN: <admin token>" \ "http://gdk.test:3000/api/v4/application/settings?merge_train_removal_limit_per_user=1" -
In the Rails console, the key allows one call a minute once the flag is enabled:
user = User.first Feature.enable(:rate_limit_merge_train_removal) 2.times.map { Gitlab::ApplicationRateLimiter.throttled?(:merge_train_removal, scope: { user: user }) } # => [false, true] -
With the flag disabled, the same calls return
[false, false](log mode).
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.