-
-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of findings retrieval #3869
Conversation
The `/v1/finding/{projectUuid}` endpoint has historically been slow to respond (DependencyTrack#3811). While the "main" query behind it is somewhat optimized SQL already, it still suffered from various performance killers: * Filtering of suppressed findings was done in-memory, and required fetching of individual `Analysis` records *for every single finding*. * `Clob` fields were not mapped directly from the SQL query result, but instead by re-fetching `Component` and `Vulnerability` records *for every single finding*, such that the ORM would provide properly `String`-ified field values. * Aliases were fetched *for every single finding* individually. * Latest component versions were fetched *for every single finding* individually. Performance was improved via the following changes: 1. Filtering of suppressed findings is moved to the main SQL query, voiding the need to fetch individual `Analysis` records later. This also reduces the overall result set that needs to be transferred and mapped. 2. Mapping of `Clob` fields is done within the `Finding` constructor, voiding the need to re-fetch `Vulnerability` records in order to retrieve `String` values for them. 3. Aliases are loaded in bulk, and in a way that avoids redundant queries if the same `Vulnerability` appears multiple times within a list of `Finding`s. 4. Latest component versions are loaded in bulk, and in a way that avoids redundant queries if the same `Component` appears multiple times within a list of `Finding`s. Because the modified functionality is re-used across the code base, multiple features benefit from this enhancement: * `/v1/finding/{projectUuid}` endpoint * Corresponds to the *Audit Vulnerabilities* tab in the UI * `/v1/project/{projectUuid}/export` endpoint * CycloneDX exports for *Inventory with Vulnerabilities*, *VDR*, and *VEX* * Fortify, Kenna, and DefectDojo integrations Signed-off-by: nscuro <nscuro@protonmail.com>
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences🚀 Don’t miss a bit, follow what’s new on Codacy. Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
Ports DependencyTrack/dependency-track#3869 from Dependency-Track v4.12.0-SNAPSHOT. Signed-off-by: nscuro <nscuro@protonmail.com>
Ports DependencyTrack/dependency-track#3869 from Dependency-Track v4.12.0-SNAPSHOT. Signed-off-by: nscuro <nscuro@protonmail.com>
Ports DependencyTrack/dependency-track#3869 from Dependency-Track v4.12.0-SNAPSHOT. Signed-off-by: nscuro <nscuro@protonmail.com>
Description
The
/v1/finding/{projectUuid}
endpoint has historically been slow to respond (#3811). While the "main" query behind it is somewhat optimized SQL already, it still suffered from various performance killers:Analysis
records for every single finding.Clob
fields were not mapped directly from the SQL query result, but instead by re-fetchingComponent
andVulnerability
records for every single finding, such that the ORM would provide properlyString
-ified field values.Performance was improved via the following changes:
Analysis
records later. This also reduces the overall result set that needs to be transferred and mapped.Clob
fields is done within theFinding
constructor, voiding the need to re-fetchVulnerability
records in order to retrieveString
values for them.Vulnerability
appears multiple times within a list ofFinding
s.Component
appears multiple times within a list ofFinding
s.Because the modified functionality is re-used across the code base, multiple features benefit from this enhancement:
/v1/finding/{projectUuid}
endpoint/v1/project/{projectUuid}/export
endpointNote
Tested with H2, MSSQL, and PostgreSQL.
Addressed Issue
Relates to #3811
Additional Details
Performance comparison with local Docker Compose setup:
cd dev docker compose -f docker-compose.yml -f docker-compose.postgres.yml up -d
Details about the setup:
bom-bloated.json
(9056 unique components)API server images compared:
snapshot@sha256:42b94f37ad5d4c9965fc89d48524bddb84c6142ee574a0c01c72ab3b667d321f
local
(local build of this PR)Load tested the
/api/v1/finding/${projectUuid}
endpoint usinghey
:hey -H "X-Api-Key: $APIKEY" \ http://localhost:8080/api/v1/finding/project/d7b6156e-c58b-4b85-b3ef-db61e9667cd4
Results for
snapshot
Results for
local
Summary
4.8
->54.7
11.2s
->1.4s
10.5s
->1s
10.3s
->0.9s
Coming out to a fairly consistent 10x improvement.
Checklist
This PR fixes a defect, and I have provided tests to verify that the fix is effectiveThis PR introduces changes to the database model, and I have added corresponding update logicThis PR introduces new or alters existing behavior, and I have updated the documentation accordingly