Make GitLab Credits usage rate limits configurable

What does this MR do and why?

Makes the GitLab Credits usage rate limits from !267552 (merged) and !267593 (merged) configurable, as per application limits development guide.

The thresholds move into application settings in the rate_limits JSONB column, so administrators can raise, lower, or disable them through the application settings API without a code change. No migration is needed. The defaults keep the current values, so behavior does not change.

Setting Default Applies to
subscription_usage_per_minute_limit 300 subscriptionUsage and trialUsage
subscription_usage_per_hour_limit 10,000 subscriptionUsage and trialUsage
subscription_usage_per_day_limit 40,000 subscriptionUsage and trialUsage
budget_cap_update_per_minute_limit 150 upsertUserBudgetCapOverrides and upsertFlatUserCap
budget_cap_update_per_hour_limit 1,000 upsertUserBudgetCapOverrides and upsertFlatUserCap
budget_cap_update_per_day_limit 20,000 upsertUserBudgetCapOverrides and upsertFlatUserCap

Setting a limit to 0 disables that window, as for the other Gitlab::ApplicationRateLimiter settings.

Enforcement is still behind the enforce_subscription_usage_rate_limits and enforce_budget_cap_rate_limits flags, which are off by default.

References

How to set up and validate locally

  1. As an administrator, set a limit through the API:

    curl --request PUT --header "PRIVATE-TOKEN: <admin token>" \
      "http://gdk.test:3000/api/v4/application/settings?subscription_usage_per_minute_limit=2"
  2. In the Rails console, check that the rule reads it:

    Gitlab::ApplicationRateLimiter::LabkitAdapter::SupportedRateLimits.limit_for(:subscription_usage_per_minute)
    # => 2
  3. Run the subscriptionUsage query from !267552 (merged) 3 times. The third call logs Subscription usage rate limit exceeded.

  4. Set subscription_usage_per_minute_limit=0 and repeat. Nothing is logged.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Roy Zwambag

Merge request reports

Loading
Loading