Re-index SBOM occurrence refs on policy dismissal change

What does this MR do and why?

The indexed policy_violations value goes stale because nothing re-indexes an occurrence once a preserved dismissal covers it. Re-track from ingestion when a preserved dismissal gains uuids, and from the preserved event for uuids added while it was still open.

The subscription is behind a feature flag because canary has no Sidekiq fleet of its own and the docs recommend creating a new subscriber under an FF - https://docs.gitlab.com/development/sidekiq/compatibility_across_updates/#adding-new-workers

Database

New read query introduced by Sbom::TrackPolicyDismissalOccurrenceRefsService#execute. It runs once per slice of 100 license_occurrence_uuids when a policy dismissal is preserved, so at most 10 times for a dismissal at the 1,000-uuid limit.

1. Occurrence refs for a slice of dismissed occurrence uuids

SELECT "sbom_occurrence_refs".* FROM "sbom_occurrence_refs"
WHERE "sbom_occurrence_refs"."sbom_occurrence_id" IN (
  SELECT "sbom_occurrences"."id" FROM "sbom_occurrences"
  WHERE "sbom_occurrences"."uuid" IN (<uuid_1>, ..., <uuid_100>)
)

Plan: https://console.postgres.ai/gitlab/projects/gitlab-production-sec/sessions/84938/commands/191917

(Nested Loop: Index Scan on index_sbom_occurrences_on_uuid (100 rows) → Index Scan on idx_sbom_occurrence_refs_on_sbom_occ_id_and_tracked_context_id (3 refs per occurrence), 300 rows, 377 ms cold, buffers: 832 hit / 369 read)

Notes on the plan
  • Run on gitlab-production-sec with 100 occurrence uuids from gitlab-org/gitlab (one full slice).
  • The uuids were passed as an array from a scratch table on the clone (uuid = ANY(...)), because the clone does not return row values to paste as literals. Postgres turns the Rails IN (...) list into = ANY(array), so the plan has the same shape. The planner's row estimate is lower (10 versus 100) because it cannot see the array's length.
  • The cold time comes from 369 disk reads on a cold thin clone. Buffers are bounded per slice, and the query runs in a low-urgency background worker.

References

Related to #628673

How to set up and validate locally

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 Rushik Subba

Merge request reports

Loading
Loading