Make the delete merged branches rate limit an application setting
What does this MR do and why?
The rate limit on deleting merged branches (DELETE /projects/:id/repository/merged_branches and the Delete merged branches button) was hard-coded at 60 requests per minute per user in !269510 (merged). This adds the delete_merged_branches_limit application setting so the value can be changed without a deploy, and sets its default to 0 (disabled) so GitLab Self-Managed and GitLab Dedicated do not enforce the limit on upgrade. Setting it to 0 turns the limit off.
Enforcement stays behind the delete_merged_branches_rate_limit feature flag (#639311). This follows the pattern from !271030 (merged) and !271345 (merged): the setting is the switch, the flag is GitLab.com de-risking.
GitLab.com reads the code default for any setting it has not stored, so its value must be set through the application settings API before the flag is enabled:
-
delete_merged_branches_limit: 60stored on GitLab.com
Changes:
ApplicationSetting:delete_merged_branches_limitin therate_limitsJSONB column, default0, exposed through the settings API.SupportedRateLimits: thedelete_merged_branchesrule reads its limit from the setting.- Specs for the setting, the API round-trip, and the rule.
- Regenerated OpenAPI definition, and docs: the limit moves from the non-configurable list to the Projects API rate limits page, with the setting added to the settings API reference.
References
- Rollout issue: #639311
- !269510 (merged) (the limit), !271030 (merged) (pattern)
How to set up and validate locally
-
In a Rails console, check the default and that the rule reads it:
ApplicationSetting.current.delete_merged_branches_limit # => 0 Gitlab::ApplicationRateLimiter::LabkitAdapter::SupportedRateLimits.limit_for(:delete_merged_branches) # => 0 -
With the default, repeated calls to
DELETE /api/v4/projects/:id/repository/merged_branchesalways return202, even withFeature.enable(:delete_merged_branches_rate_limit). -
Set a low limit and wait about a minute for the settings cache:
Gitlab::CurrentSettings.update!(delete_merged_branches_limit: 2) -
The third call in a minute returns
429withRateLimit-Name: delete_merged_branches. The UI button redirects back with an alert.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.