Add rate limit logging to the user credits usage field
What does this MR do and why?
Adds rate limit logging to CurrentUser.creditsUsage.
Each call is counted per user in 3 windows (minute, hour, day). The log line also records the root namespace.
A call over a threshold is logged as Credits usage rate limit exceeded with throttled: false in additional_details, and still succeeds. The call is only rejected when the enforce_credits_usage_rate_limits feature flag (gitlab_com_derisk, actor: root namespace) is enabled. The flag is off by default.
The check runs after authorization, so unauthorized calls are not counted.
The resolver uses the rate limit concern from !267552 (merged), with its own keys and enforce flag. It uses the concern, not staged_rule, to stay consistent with !267552 (merged) and !267593 (merged). A follow-up can move all three to staged_rule together. Administrators can change the thresholds with the credits_usage_per_minute_limit, credits_usage_per_hour_limit, and credits_usage_per_day_limit application settings, the same as in !268308 (merged).
Thresholds
| Window | Threshold |
|---|---|
| minute | 60 |
| hour | 300 |
| day | 3,000 |
Rollout
- Merge with the flag off. Calls over a threshold are logged.
- Review the logs for 1 week.
- Adjust any threshold that a legitimate caller would exceed, with the application settings.
- Decide on enforcement in the rollout issue. Rollback: disable the flag.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/636782
- Rollout issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/638617
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.