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, 0 disables the limit). It is stored in the rate_limits JSONB column, so no migration is needed. The default is 1000.
  • 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 the pages_deployments_api_rate_limit feature flag (gitlab_com_derisk, disabled by default) is enabled.
  • Resolvers::PagesDeploymentsResolver#resolve calls verify_rate_limit!. There is no service to hook into, so the check lives in the resolver, as in Resolvers::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 1000 covers 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

Screenshots or screen recordings

Not applicable. There are no UI changes.

How to set up and validate locally

  1. Enable the flag: Feature.enable(:pages_deployments_api_rate_limit).
  2. Lower the limit: ApplicationSetting.current.update!(pages_deployments_api_limit: 2).
  3. Run a project(fullPath: "...") { pagesDeployments { nodes { id } } } query three times in GraphiQL. The third call returns the error This endpoint has been requested too many times. Try again later.
  4. 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

Merge request reports

Loading
Loading