Rate limit CSV imports of issues, work items and requirements

What does this MR do and why?

CSV imports of issues, work items and requirements had no rate limit of their own. Each import runs a background job whose cost grows with the number of rows in the file, so repeated imports could keep many Sidekiq workers busy.

All imports go through Import::PrepareService: the issues and work items import_csv actions, the workItemsCsvImport GraphQL mutation and the requirements import_csv action. The service uses the rate_limit DSL from RateLimitedService to check a new issuable_csv_import rule there, before the file is uploaded, keyed on the user. The existing RateLimitedError handlers in ApplicationController and GraphqlController return the 429 responses, the same way as the CSV export limit.

The limit comes from the new issuable_csv_import_limit application setting, 20 imports per hour by default. Admins can change it in the Rails console, and 0 disables it. The setting lives in the rate_limits JSONB column, so no migration is needed. It is not exposed in the application settings API for now, so it can change later without a breaking change, see !266323 (comment 4151027115).

The limit is behind the issuable_csv_import_rate_limit feature flag, disabled by default. The flag is checked in the rule's limit, which returns 0 when the flag is off, so it applies to the whole instance and not per user.

References

None.

Screenshots or screen recordings

Not applicable, no UI changes. Over the limit, the existing 429 response is shown.

How to set up and validate locally

  1. Enable the feature flag in the Rails console:

    Feature.enable(:issuable_csv_import_rate_limit)
  2. Optional. Change the limit with ApplicationSetting.current.update!(issuable_csv_import_limit: 2).

  3. Go to a project's work items or issues list and import a CSV file 21 times within one hour (or one more time than the limit you set), or run the workItemsCsvImport mutation in GraphiQL.

  4. The request over the limit returns This endpoint has been requested too many times. Try again later.

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 Stefanos Xanthopoulos

Merge request reports

Loading
Loading