Rate limit GraphQL value stream stage metrics per user

What does this MR do and why?

The value stream stage metrics field runs one data collector query per stage, and the VSA page asks for every active stage at once (one request per stage). A client calling it in a loop can put a lot of aggregate queries on the replicas. !266129 (merged) and !268644 (merged) bound the size of one request; this adds a rate limit as the backstop for many requests.

  • New application rate limit value_stream_stage_metrics: 150 stage metrics resolutions per minute, keyed by user, or by IP for anonymous callers on public projects.
  • It counts once per stage, so a query pays for every stage it asks metrics for. A full VSA page load with 15 stages uses 15.
  • It's a staged rule behind the gitlab_com_derisk flag vsa_stage_metrics_rate_limit (actor: user). While the flag is off for a caller the limit only logs, so we can see who would be limited before enforcing it. Anonymous callers are enforced only when the flag is fully on.
  • The check runs after the 180-day timeframe validation, so a rejected query doesn't count.
  • A new key instead of reusing project_value_stream_analytics (row 3 of the Code Red issue): that one is per project with a per-project flag and 60/min, has no group, and one VSA page load would use 15 of it.
  • Over the limit, the field returns the standard "This endpoint has been requested too many times. Try again later." error.

References

Screenshots or screen recordings

Not applicable, backend only. The VSA UI is unchanged unless a user goes over the limit.

How to set up and validate locally

  1. In the Rails console, lower the limit and enable the flag for your user:
    Feature.enable(:vsa_stage_metrics_rate_limit, User.find_by_username('root'))
    Then temporarily change limit: 150 to limit: 3 for value_stream_stage_metrics in lib/gitlab/application_rate_limiter/labkit_adapter/supported_rate_limits.rb and restart Rails.
  2. In GraphiQL (http://gdk.test:3000/-/graphql-explorer), run this a few times for a project with value streams:
    query {
      project(fullPath: "<project>") {
        valueStreams {
          nodes {
            stages {
              metrics(timeframe: { start: "2026-09-01", end: "2026-11-01" }) { count { value } }
            }
          }
        }
      }
    }
    Once more than 3 stage metrics are resolved within a minute, the field returns "This endpoint has been requested too many times. Try again later."
  3. Disable the flag and repeat: no error, the limit only logs.

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 Jatin Parihar

Merge request reports

Loading
Loading