Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the targeted vulnerability-lookup changes.
No open issues 🎉
What changed in this PR
This PR reduces memory use and database work during scan-report conversion by fetching only vulnerability records matching the report, addressing the scan-all resource pressure described in #22008 and #22059.
Changes:
- Adds scanner-scoped lookups by CVE, package, and version, querying 500 keys per batch and loading only required columns.
- Reuses the parsed report instead of decoding its JSON twice.
- Adds tests for exact matching, scanner isolation, empty input, limited field loading, and batching.
| File | Description |
|---|---|
src/pkg/scan/postprocessors/report_converters.go |
Builds deduplicated lookup keys and reuses the parsed report. |
src/pkg/scan/dao/scan/vulnerability.go |
Adds batched exact-key queries with a limited column selection. |
src/pkg/scan/dao/scan/vulnerability_test.go |
Tests lookup filtering, field selection, empty input, and batching. |
src/pkg/scan/dao/scan/model.go |
Defines the vulnerability-record lookup key type. |
Review effort: Balanced
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24509 +/- ##
==========================================
- Coverage 74.27% 74.26% -0.01%
==========================================
Files 1096 1096
Lines 103611 103630 +19
Branches 3079 3079
==========================================
+ Hits 76953 76964 +11
- Misses 26290 26297 +7
- Partials 368 369 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
After a scan, the report converter listed the existing vulnerability records with cve_id IN (all CVEs of the report). That returns the records of every package and version that has one of those CVEs, with all columns, and only the exact cve_id/package/version matches were used. On a large registry this loads hundreds of thousands of rows per scan job into jobservice and makes PostgreSQL scan the whole vulnerability_record table. Look the records up by cve_id, package and package_version instead, which uses the unique index on these columns, and only load the columns needed to update severity and status. The report JSON is now parsed once in ToRelationalSchema and passed to toSchema. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mathijs Möhlmann <mathijs.mohlmann@ns.nl>
secmff
force-pushed
the
fix-job-service-memory
branch
from
December 1, 2026 16:26
83d84aa to
ef2976a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: load only the vulnerability records of a scan report
Related: #22008, #22059 (earlier attempts #22009 and #22127 were closed as stale)
Problem
After every vulnerability scan, jobservice stores the report in the relational schema (
toSchemainsrc/pkg/scan/postprocessors/report_converters.go). To find the records that already exist, it runs:This returns every record of every CVE in the report, for all packages and versions that were ever scanned, with all columns, including
description,urlsandvendor_attributes. Only the records that match the report oncve_id,packageandpackage_versionare used; the rest is thrown away.Common CVEs (glibc, openssl, zlib, ...) have thousands of records, so on a large registry a single report pulls in hundreds of thousands of rows. With an IN list that long, PostgreSQL also gives up on the
cve_idindex and scans the whole table.What we see in production:
vulnerability_record: about 1.2M rows, 21,444 sequential scans that read 25.5 billion rows in total, so the whole table on every scan.Change
ListByKeys(ctx, registrationUUID, keys): looks records up by(cve_id, package, package_version)for one scanner, which matches the existing unique constraint onvulnerability_record. It queries in batches of 500 keys and only loadsid, the key columns,severityandstatus, which is alltoSchemaneeds to update severity and status.toSchemabuilds the keys from the de-duplicated vulnerabilities of the report and usesListByKeys. The update, create and link logic is unchanged.ToRelationalSchemaand passed totoSchema, instead of being parsed again there.The memory a job needs now grows with the size of the report, not with the vulnerability history of the whole registry.
Query plan on the production database, with 500 keys:
Tests
TestListVulnerabilityRecordByKeys:TestListVulnerabilityRecordByKeysBatches: more keys than fit in one batch.pkg/scan/dao/scan,pkg/scan/postprocessors,pkg/scan/report,pkg/scan/vulnerabilityandpkg/scan/exportpass.