Loading
Add rate limit to GraphQL pagesDeployments field
What does this MR do and why?
Adds a feature-flagged application rate limit to the GraphQL pagesDeployments field. Both Project.pagesDeployments and Namespace.pagesDeployments use the same resolver, so both are covered. This MR covers the query only. The Pages mutations are not changed.
- New application setting
pages_deployments_api_limit(integer, resolutions per minute,0disables the limit). It is stored in therate_limitsJSONB column, so no migration is needed. The default is1000. - Two Labkit rules read that setting:
pages_deployments_api, per user, for authenticated requests.pages_deployments_api_unauthenticated, per IP address, for unauthenticated requests.
- Both rules return
0(no limit) unless thepages_deployments_api_rate_limitfeature flag (gitlab_com_derisk, disabled by default) is enabled. Resolvers::PagesDeploymentsResolver#resolvecallsverify_rate_limit!. There is no service to hook into, so the check lives in the resolver, as inResolvers::BlameResolver.- Each resolution of the field counts once, as in
BlameResolver. A namespace query (for example, the Usage Quotas Pages query) resolves the field once for each project, so a page of 100 projects counts as 100. Aliases and multiplexed queries count separately. This caps the work done, not the number of queries. - The default of
1000covers every Usage Quotas user from the last 30 days (the heaviest user-minute returned about 400 rows) and throttles scripted crawlers after about 10 namespace pages per minute.
Follows the pattern of !266323 (merged): rule, setting, feature flag, docs, and rate limited endpoint shared examples.
References
- Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/635660
- Pattern: !266323 (merged)
Screenshots or screen recordings
Not applicable. There are no UI changes.
How to set up and validate locally
- Enable the flag:
Feature.enable(:pages_deployments_api_rate_limit). - Lower the limit:
ApplicationSetting.current.update!(pages_deployments_api_limit: 2). - Run a
project(fullPath: "...") { pagesDeployments { nodes { id } } }query three times in GraphiQL. The third call returns the errorThis endpoint has been requested too many times. Try again later. - Reset the limit window, then run a
namespace(fullPath: "...") { projects { nodes { pagesDeployments { nodes { id } } } } }query on a group with three or more projects. The first two projects return deployments, and the rest return the rate limit error.
Rollout issue: #638280
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Naman Jagdish Gala