Loading
Skip merge request sweeps for unaffected policies on events
What does this MR do and why?
Per-project policy sync on policy events (SyncPolicyEventService) swept every open merge request of the project even when it had no merge request rules to update. That is wasted work on projects with many open MRs and holds a SyncProjectPolicyWorker slot longer than needed.
- After converging a policy on a compliance framework event (the only converge event that reaches scan execution and pipeline execution policies),
sync_approval_policy_rules(and its MR sweep) runs only for approval policies. - The unlink on scope or disable events (including resync and security attribute events) is skipped for approval policies that are not linked to the project and have nothing left over. This reuses the guard
SyncProjectServicealready has;approval_rules_remain_in_project?moves toBaseProjectPolicyService. - The guard now also checks the policy's
scan_result_policy_reads. Anany_merge_requestrule withoutrequire_approvalcreates a read but no approval rule, so an interrupted unlink could leave only the read behind. The retry now still cleans up the read, its violations and the bot comments.SyncProjectServicegets the same check.
This ships without a feature flag because it fails closed. Approval policies are unchanged: linked policies still unlink and sweep, and leftover project rules, open-MR rules or reads still trigger the cleanup, so no merge request loses a required approval rule. The worst case of a missed skip is stricter, stale state, never a bypass.
References
- References: tracking issue to be created
How to set up and validate locally
bundle exec rspec ee/spec/services/security/security_orchestration_policies/sync_policy_event_service_spec.rb ee/spec/services/security/security_orchestration_policies/sync_project_service_spec.rb- In a console, with a project that has open MRs: trigger a
Projects::ComplianceFrameworkChangedEvent(added) sync for a scan execution policy in scope and countSyncMergeRequestsService.newcalls. Expect 0. - Repeat with an approval policy. Expect 2 sweeps, as before.
Rollback
Revert this MR.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
Edited by Alan (Maciej) Paruszewski