Skip to content

ROX-33251: use SQL aggregate query for FailingPolicyCounter resolvers#19136

Open
dashrews78 wants to merge 3 commits intomasterfrom
dashrews/resolvers-alert-policy-counts-33251
Open

ROX-33251: use SQL aggregate query for FailingPolicyCounter resolvers#19136
dashrews78 wants to merge 3 commits intomasterfrom
dashrews/resolvers-alert-policy-counts-33251

Conversation

@dashrews78
Copy link
Contributor

@dashrews78 dashrews78 commented Feb 23, 2026

Description

Another internal caller of SearchListAlerts that 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

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

CI, added a test, and some manual testing on a live cluster.

@dashrews78
Copy link
Contributor Author

dashrews78 commented Feb 23, 2026

@openshift-ci
Copy link

openshift-ci bot commented Feb 23, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

//////////////////

func mapListAlertsToPolicySeverityCount(alerts []*storage.ListAlert) *PolicyCounterResolver {
func mapListAlertPoliciesToPolicySeverityCount(policies []*storage.ListAlertPolicy) *PolicyCounterResolver {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff here is weird. Essentially mapListAlertsToPolicySeverityCount was removed and this method mapListAlertPoliciesToPolicySeverityCount was not changed.

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Feb 23, 2026

Images are ready for the commit at 9753b99.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-169-g9753b99d82.

@codecov
Copy link

codecov bot commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 20.00000% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.52%. Comparing base (06385ec) to head (9753b99).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
central/alert/datastore/datastore_impl.go 0.00% 20 Missing ⚠️
central/graphql/resolvers/clusters.go 0.00% 2 Missing ⚠️
central/graphql/resolvers/deployments.go 0.00% 2 Missing ⚠️
central/graphql/resolvers/namespaces.go 0.00% 2 Missing ⚠️
central/graphql/resolvers/policy_counter.go 77.77% 2 Missing ⚠️
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     
Flag Coverage Δ
go-unit-tests 49.52% <20.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Base automatically changed from dashrews/update-violations-multiplier-33252 to master February 24, 2026 16:56
dashrews78 and others added 3 commits February 24, 2026 11:56
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>
@dashrews78 dashrews78 force-pushed the dashrews/resolvers-alert-policy-counts-33251 branch from 9bb4292 to 9753b99 Compare February 24, 2026 16:57
@dashrews78 dashrews78 marked this pull request as ready for review February 24, 2026 19:25
@dashrews78 dashrews78 requested review from a team, AlexVulaj, ajheflin, c-du, charmik-redhat, clickboo and ksurabhi91 and removed request for clickboo February 26, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants