Add RateLimit-* headers to RackAttack responses
What does this MR do?
Closes gitlab-com/gl-infra/scalability#731 (closed), #296680 (closed), and #20482 (closed).
Recently, HAProxy returns a list of RateLimit-* headers when a request is throttled. These headers are specific to GitLab.com only. Some clients are using these headers for calculation. This creates some problems:
- The behaviors are different between GitLab.com and self-managed instances.
- In future, when the rate limiting function is moved out of HAProxy to the application completely, we still need to maintain those headers for backward compatibility.
The list of returned headers include:
{
'RateLimit-Name' => 'throttle_unauthenticated',
'RateLimit-Limit' => '60',
'RateLimit-Observed' => '3700',
'RateLimit-Remaining' => '0',
'RateLimit-Reset' => '1800',
'RateLimit-ResetTime' => 'Wed, 06 Jan 2021 00:00:00 GMT', # Next day
'Retry-After' => '1800'
}
Besides, this MR adds validation to throttle_* application setting. This saves us from crashing and weird behavior when an admin sets the period to 0.
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Quang-Minh Nguyen