ROX-33251: use SQL aggregate query for FailingPolicyCounter resolvers#19136
ROX-33251: use SQL aggregate query for FailingPolicyCounter resolvers#19136dashrews78 wants to merge 3 commits intomasterfrom
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
|
Skipping CI for Draft Pull Request. |
| ////////////////// | ||
|
|
||
| func mapListAlertsToPolicySeverityCount(alerts []*storage.ListAlert) *PolicyCounterResolver { | ||
| func mapListAlertPoliciesToPolicySeverityCount(policies []*storage.ListAlertPolicy) *PolicyCounterResolver { |
There was a problem hiding this comment.
The diff here is weird. Essentially mapListAlertsToPolicySeverityCount was removed and this method mapListAlertPoliciesToPolicySeverityCount was not changed.
|
Images are ready for the commit at 9753b99. To use with deploy scripts, first |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #19136 +/- ##
==========================================
- Coverage 49.54% 49.52% -0.02%
==========================================
Files 2674 2674
Lines 201754 201771 +17
==========================================
- Hits 99954 99933 -21
- Misses 94341 94376 +35
- Partials 7459 7462 +3
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:
|
The 3 FailingPolicyCounter GraphQL resolvers (deployment, cluster, namespace) were fetching all matching alerts via SearchListAlerts, deserializing every protobuf blob, then counting distinct policies by severity in Go. Replace with a SQL COUNT(DISTINCT policy_id) FILTER (WHERE severity = ...) query that returns 4 integers directly, avoiding all protobuf deserialization and intermediate allocations. Follows the filtered count pattern from central/views/common/queries.go. AI-assisted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
AI-assisted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
No callers remain after switching to SQL aggregate query. AI-assisted. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9bb4292 to
9753b99
Compare
Description
Another internal caller of
SearchListAlertsthat could easily be done with just a query. This will save significantly on the memory used within central and the time spent marshalling/unmarshalling alert objects.The 3 FailingPolicyCounter GraphQL resolvers (deployment, cluster, namespace) were fetching all matching alerts via SearchListAlerts, deserializing every protobuf blob, then counting distinct policies by severity in Go. Replace with a SQL COUNT(DISTINCT policy_id) FILTER (WHERE severity = ...) query that returns 4 integers directly, avoiding all protobuf deserialization and intermediate allocations.
Follows the filtered count pattern from central/views/common/queries.go.
AI-assisted.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
User-facing documentation
Testing and quality
Automated testing
How I validated my change
CI, added a test, and some manual testing on a live cluster.