Manually update vulnerability_reads with upsert service
What does this MR do and why?
This MR continues the work from !208297 (merged) by manually updating vulnerability_reads records now that the SQL database trigger has been turned off.
With the database trigger feature flag being disabled, vulnerability_reads records need to be manually updated at the application level. This MR:
- Creates a new upsert utility service for vulnerability reads (
Vulnerabilities::Reads::UpsertService) - Makes the upsert service capable of handling bulk upserts
- Refactors and modifies files to use the common
Vulnerabilities::Reads::UpsertService - Changes manual updates throughout the codebase to use this utility service
Background
The original MR !208297 (merged) was merged but had to be reverted (see !212452 (merged)) due to a master:foss-broken issue. The problem was that a scope (pluck_distinct_project_ids) was used in the Community Edition (CE) of GitLab but was only present in the Enterprise Edition (EE), causing FOSS builds to break.
This MR addresses that issue by ensuring all necessary code is available in both CE and EE contexts, while maintaining the same functionality for manual vulnerability reads updates.
How?
This MR builds upon the infrastructure established in !208297 (merged) and refined in !212568 (closed):
Infrastructure
- Utilizes feature flag transaction helper methods from
SecApplicationRecord:-
feature_flagged_transaction_for(projects)- wraps transactions with feature flag passing -
db_trigger_flag_not_set?- checks if feature flag is set -
pass_feature_flag_to_vuln_reads_db_trigger(projects)- passes flag to DB trigger
-
- Leverages the
EnforceVulnerabilityReadDbTriggerFfconcern to enforce feature flag usage in transactions - Ensures CE/EE compatibility by properly scoping EE-only features
Model Extensions
- Extended
Vulnerability,Vulnerabilities::Finding,Vulnerabilities::MergeRequestLink, andVulnerabilities::Readmodels with enforcement concern - Added necessary scopes (like
pluck_distinct_project_ids) in appropriate CE/EE contexts
Service Updates
Updates vulnerability services to use the new upsert service for manual vulnerability_reads updates, ensuring consistency across:
Vulnerabilities::Archival::Restoration::RestoreBatchServiceVulnerabilities::Archival::ArchiveBatchServiceVulnerabilities::BaseServiceVulnerabilities::BaseStateTransitionServiceVulnerabilities::BulkDismissServiceVulnerabilities::BulkSeverityOverrideServiceVulnerabilities::CreateServiceVulnerabilities::FindOrCreateFromSecurityFindingServiceVulnerabilities::ManuallyCreateServiceVulnerabilities::AutoResolveServiceVulnerabilities::Removal::RemoveFromProjectServiceVulnerabilities::Findings::FindOrCreateFromSecurityFindingServiceVulnerabilities::Reads::UpsertService-
Import::DirectReassignService(with special handling for Vulnerability models)
This ensures that we're safely managing vulnerability reads at the application level while maintaining the ability to track that all necessary updates are being performed, and that the implementation works correctly in both CE and EE environments.
References
Related to:
- !208297 (merged) (Original enforcement MR - merged)
- !212452 (merged) (Revert MR due to FOSS breakage)
- !212568 (closed) (Additional implementation details)
- #580521 (Reinstate issue)
How to set up and validate locally
- Ensure the database trigger feature flag is disabled
- Perform operations that create or update vulnerabilities
- Verify that
vulnerability_readsrecords are correctly created/updated via the upsert service - Run the test suite to ensure all vulnerability read updates are properly handled
- Verify FOSS compatibility by running tests in CE context
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.