Add soft rate limit to SBOM vulnerability scans
What does this MR do and why?
Background
With Add an API for on-demand Dependency Scanning us... (#542831 - closed) we added the capability to scan an SBOM document for vulnerabilities in the GitLab rails backend (not released yet, it's behind a Feature flag, disabled by default). Since this process uses Sidekiq background jobs rather than CI jobs, it requires additional considerations to handle scalability and limits.
The initial implementation included some basic application rate limits as a temporary measure, but it was clear that a more thorough approach was required before launching the feature.
dependency_scanning_sbom_scan_api feature flag that is disabled by default.
What
This MRs introduces a soft rate limit mechanism to the SBOM vulnerability scans API, scoped by project.
Normal usage (under threshold):
- Scans processed on high-priority worker (
ProcessSbomScanWorker) - Fast processing with
:highurgency - Standard API responses
Heavy usage (over threshold):
- Scans routed to throttled worker (
ProcessSbomScanThrottledWorker) - Lower urgency (
:low) with higher concurrency limits - API returns additional properties in response body to inform client
- Client displays a warning about increased processing time
Why
- Maintains availability: Heavy users can still use the feature beyond the soft limit
- Preserves service quality: Prevents resource contention affecting other users
- Transparent communication: Clients are informed about throttling via properties n response body
- Gradual degradation: Performance degrades gracefully rather than failing
Implementation changes:
- Add a
ProcessSbomScanThrottledWorkerthat does the same job asProcessSbomScanWorkerbut using a lower urgency and higher concurrency - Add a
dependency_scanning_sbom_scan_api_throttlingapplication limit and use it in SBOM upload API endpoint - Route scans requests above threshold to the newly introduced throttled worker
- Update the SBOM Scan API response to return additional properrties when scan are throttled
- Maintain hard application limits on the API endpoints with higher values, to prevent runaway usage
Performance analysis
See private note: !204070 (comment 2736964026)
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- Follow the steps to enable the API on your GDK: !195062 (merged)
- Manually adjust
:dependency_scanning_sbom_scan_api_throttlingthreshold in theApplicationRateLimiterto use a lower value for testing purposes - Trigger multiple CI jobs to reach the limit and verify that:
- the throttled worker is used
gdk tail rails-background-jobs | grep SbomScan - the response provide the
throttledandproject_throttling_resets_inproperties
- the throttled worker is used
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.