ROX-33252: optimize ViolationsMultiplier to query what it needs#19115
ROX-33252: optimize ViolationsMultiplier to query what it needs#19115dashrews78 merged 8 commits intomasterfrom
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
|
Skipping CI for Draft Pull Request. |
|
Images are ready for the commit at 2994031. To use with deploy scripts, first |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19115 +/- ##
=======================================
Coverage 49.52% 49.52%
=======================================
Files 2672 2672
Lines 201665 201686 +21
=======================================
+ Hits 99870 99895 +25
+ Misses 94337 94334 -3
+ Partials 7458 7457 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
40dde73 to
46e7d88
Compare
|
I did ask Claude to evaluate the impact of this change with the assumption of 10K deployments that have on average 6 active violations. This is the quantification that Claude provided which is likely reasonable. Before this change this was a very expensive operation. Summary
Call Frequency
Query ChangeOld: SELECT alerts.serialized FROM alerts WHERE deployment_id=$1 AND state=$2
New: SELECT alerts.policy_name, alerts.policy_severity FROM alerts WHERE deployment_id=$1 AND state=$2
Assumptions
Scenario: 10,000 Deployments, 3 Violations Each (30,000 alerts)Per Score() Call (1 deployment, 3 alerts)
Per Full Reprocessing Cycle (10,000 deployments)
Scenario: 10,000 Deployments, 6 Violations Each (60,000 alerts)Per Score() Call (1 deployment, 6 alerts)
Per Full Reprocessing Cycle (10,000 deployments)
What This Doesn't Change
|
ViolationsMultiplier.Score() only needs policy_name and policy_severity from alerts but was deserializing full Alert protobuf blobs via SearchListAlerts. Add SearchAlertPolicyNamesAndSeverities which uses RunSelectRequestForSchema to query only the two needed columns directly, avoiding protobuf deserialization entirely. Follows the same pattern as central/secret/datastore for DB access (ROX-31142). Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the lightweight projection type to a dedicated views package under central/alert/ so future projection types can be co-located. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add GetPolicyName() and GetSeverity() methods so callers use accessors instead of direct field access. GetSeverity() returns storage.Severity directly, removing the need for manual casts. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sort imports alphabetically and pass DB pool to New() in datastore_impl_test.go. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace deprecated RunSelectRequestForSchema with the callback-based RunSelectRequestForSchemaFn. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add integration tests in datastore_impl_test.go covering basic behavior, excludeResolved filtering, deployment ID filtering, and multiple alerts with different severities. Add SAC tests in datastore_sac_test.go covering scoped and unrestricted access patterns. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46e7d88 to
2994031
Compare
clickboo
left a comment
There was a problem hiding this comment.
Code looks good, curious to see the improvements (because they will be significant for the risk reprocessing path on a scaled cluster). Left a few thoughts as comments.
ViolationsMultiplier.Score() only needs policy_name and policy_severity from alerts but was deserializing full Alert protobuf blobs via SearchListAlerts. This is grossly unnecessary because we only need 2 fields both of which are populated column. Getting the entire serialized object and unmarshalling it is a very expensive and unnecessary.
Added SearchAlertPolicyNamesAndSeverities which uses RunSelectRequestForSchemaFn to query only the two needed columns directly
Follows the same pattern as central/secret/datastore for DB access
(ROX-31142).
Partially generated by AI.
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
Description
change me!
User-facing documentation
Testing and quality
Automated testing
How I validated my change
Added unit tests. Existing tests. CI. long running cluster.