Apply dedicated rate limit to create snippet APIs

What does this MR do and why?

Apply dedicated rate limit to create snippet APIs

  • POST api/v4/snippets
  • POST api/v4/projects/:id/snippets
  • CreateSnippet GraphQL mutation

Changelog: added

Usage analysis: https://gitlab.com/gitlab-org/gitlab/-/work_items/617372#note_3734857083

References

Resolves https://gitlab.com/gitlab-org/gitlab/-/work_items/617372

Screenshots or screen recordings

Before After

How to set up and validate locally

  • Modify the limit_snippets_created_by_user in lib/gitlab/application_rate_limiter/labkit_adapter/supported_rate_limits.rb limit to 1
  • gdk restart
  • The following request succeeds and creates a snippet:
curl --request POST "http://localhost:3000/api/v4/snippets" \
  --header "PRIVATE-TOKEN: $TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"title":"t","file_name":"a.txt","content":"x","visibility":"private"}'
  • Repeat and get a 429 with {"message":{"error":"This endpoint has been requested too many times. Try again later."}}% response
  • The project snippets endpoint returns the same response.
curl --request POST "http://localhost:3000/api/v4/projects/<PROJECT_ID>/snippets" \
  --header "PRIVATE-TOKEN: $TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"title":"t","file_name":"a.txt","content":"x","visibility":"private"}'
  • A GraphQL request returns a 200 with "This endpoint has been requested too many times. Try again later." message.
curl --request POST "http://localhost:3000/api/graphql" \
  --header "Authorization: Bearer $TOKEN" \
  --header 'Content-Type: application/json' \
  --data '{"query":"mutation { createSnippet(input: {title: \"t\", visibility_level: private, blobActions: [{action: create, filePath: \"a.txt\", content: \"x\"}]}) { snippet { id } errors } }"}'

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 Fred Reinink

Merge request reports

Loading
Loading