Rate limit the security policy resync mutation

What does this MR do and why?

resyncSecurityPolicies force-syncs every project that the policy configuration covers. For a large group that means one sync job per project and policy, and each one also re-syncs the open merge requests of that project. Nothing stops the same group from calling the mutation again before the previous sync drains, so repeated calls (scripts, scheduled jobs) stack full syncs on top of each other.

This MR limits the mutation to one call per hour for each project or group, reusing the Labkit rate-limit pattern from mergeRequestResyncSecurityPolicies. A throttled call returns an error in errors and enqueues nothing. Only direct resyncs of a container that has a security policy project count against the limit: inherited resyncs only touch the given project, and a call that fails because no policy project exists doesn't use up the hour. Assigning or reassigning a security policy project is not limited.

How to set up and validate locally

  1. Pick a project that has a security policy project.

  2. Run the mutation twice in GraphiQL:

    mutation { resyncSecurityPolicies(input: { fullPath: "<project full path>" }) { errors } }
  3. The first call returns errors: []. The second returns Policies were resynchronized recently. Try again in an hour.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist.

Edited by Alan (Maciej) Paruszewski

Merge request reports

Loading
Loading