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: 60 stored on GitLab.com

Changes:

  • ApplicationSetting: delete_merged_branches_limit in the rate_limits JSONB column, default 0, exposed through the settings API.
  • SupportedRateLimits: the delete_merged_branches rule 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

How to set up and validate locally

  1. 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
  2. With the default, repeated calls to DELETE /api/v4/projects/:id/repository/merged_branches always return 202, even with Feature.enable(:delete_merged_branches_rate_limit).

  3. Set a low limit and wait about a minute for the settings cache:

    Gitlab::CurrentSettings.update!(delete_merged_branches_limit: 2)
  4. The third call in a minute returns 429 with RateLimit-Name: delete_merged_branches. The UI button redirects back with an alert.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Gavin Hinfey

Merge request reports

Loading
Loading