Add rate limit logging to the compute usage projects field

What does this MR do and why?

Adds rate limit logging to the projects field of Query.ciMinutesUsage.

Each request that selects projects is counted per user in 2 windows (minute and hour). Requests that do not select projects are not counted. The Usage Quotas page does not select projects.

The check runs in the projects field of CiMinutesNamespaceMonthlyUsage, after the read_usage authorization of the type. It runs once for each request and root namespace, also when the response has several months. A namespace without usage data is not counted, because the projects field does not resolve.

A request over a threshold is logged as Compute usage projects rate limit exceeded with throttled: false in additional_details, and still succeeds. When the enforce_ci_minutes_usage_rate_limits feature flag (gitlab_com_derisk, actor: root namespace) is enabled, the projects field returns the throttled error for each month. The monthly usage still returns. The flag is off by default.

The rate limit applies on GitLab.com only. On GitLab Self-Managed and GitLab Dedicated, requests are not counted or logged.

Aliases of ciMinutesUsage for the same root namespace count once for each request. The GraphQL query complexity limit caps the number of aliases.

The ciMinutesUsage field, its arguments, and its query complexity do not change.

Window Threshold Setting
minute 60 ci_minutes_usage_projects_per_minute_limit
hour 600 ci_minutes_usage_projects_per_hour_limit

Set a setting to 0 to disable that window.

Rollout issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/639396

How to set up and validate locally

  1. Set a low threshold in the Rails console:

    ApplicationSetting.current.update!(ci_minutes_usage_projects_per_minute_limit: 1)
  2. Run this query twice in GraphiQL as a user with compute usage:

    { ciMinutesUsage { nodes { minutes projects { nodes { minutes } } } } }
  3. Check log/application_json.log for Compute usage projects rate limit exceeded with throttled: false. The second request still returns data.

  4. Enable the flag: Feature.enable(:enforce_ci_minutes_usage_rate_limits). Run the query again. The months return, and projects is null with the throttled error.

  5. Run { ciMinutesUsage { nodes { minutes } } }. It is not counted and returns data.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Roy Zwambag

Merge request reports

Loading
Loading