ROX-33939: virtual machine v2 reconciliation improvements#19904
ROX-33939: virtual machine v2 reconciliation improvements#19904dashrews78 wants to merge 2 commits intomasterfrom
Conversation
…ciliation Reconciliation only needs IDs, not full VM objects. Use Search() + ResultsToIDSet() — the same pattern all other pipelines use — to avoid deserializing full rows and the manual ID-extraction loop. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Skipping CI for Draft Pull Request. |
🚀 Build Images ReadyImages are ready for commit 1fd38ea. To use with deploy scripts: export MAIN_IMAGE_TAG=4.11.x-603-g1fd38ea3eb |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19904 +/- ##
==========================================
- Coverage 49.60% 49.60% -0.01%
==========================================
Files 2766 2766
Lines 208567 208562 -5
==========================================
- Hits 103454 103448 -6
- Misses 97436 97437 +1
Partials 7677 7677
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:
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe reconciliation logic in the VM pipeline is refactored to use the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@central/sensor/service/pipeline/virtualmachines/pipeline.go`:
- Around line 89-90: reconcileV2 is calling p.virtualMachineV2Store.Search with
a query built by search.NewQueryBuilder().AddExactMatches(...).ProtoQuery()
which relies on the default 100-result page size and thus misses VMs past the
first page; modify reconcileV2 to set explicit pagination on the query (either a
sufficiently large PageSize or, preferably, implement paging by setting/reading
PageToken and looping calls to p.virtualMachineV2Store.Search until no more
results) so you collect the complete set of VMs for the cluster before
reconciling/cleaning up.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: e7c9e062-aafa-4d2d-8080-83bc2c387d41
📒 Files selected for processing (2)
central/sensor/service/pipeline/virtualmachines/pipeline.gocentral/sensor/service/pipeline/virtualmachines/pipeline_test.go
| query := search.NewQueryBuilder().AddExactMatches(search.ClusterID, clusterID).ProtoQuery() | ||
| query.Pagination = &v1.QueryPagination{Limit: math.MaxInt32} | ||
| virtualMachines, err := p.virtualMachineV2Store.SearchRawVirtualMachines(ctx, query) | ||
| results, err := p.virtualMachineV2Store.Search(ctx, query) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate v2 datastore interface/impl Search signatures.
rg -nP --type=go '\btype\s+DataStore\s+interface\b|\bSearch\s*\(\s*ctx\s+context\.Context,\s*q\s+\*v1\.Query\s*\)\s*\(\s*\[\]search\.Result,\s*error\s*\)' -C3
rg -nP --type=go '\bfunc\s+\(.*\)\s+Search\s*\(\s*ctx\s+context\.Context,\s*q\s+\*v1\.Query\s*\)\s*\(\s*\[\]search\.Result,\s*error\s*\)' -C8
# Find pagination normalization/defaulting logic in search/datastore layers.
rg -nP --type=go '\bQueryPagination\b|\bPagination\b|default.*limit|fill.*pagination|normalize.*pagination|MaxInt32' -C3
# Compare other reconciliation code paths using Search + ResultsToIDSet.
rg -nP --type=go '\bResultsToIDSet\s*\(' -C3Repository: stackrox/stackrox
Length of output: 50374
🏁 Script executed:
# Find the applyQueryDefaults implementation to understand pagination defaults
rg -nA 15 'func.*applyQueryDefaults' --type=go
# Check if there's a default pagination limit applied anywhere
rg -n 'QueryPagination|DefaultLimit|default.*limit' --type=go central/virtualmachine/v2/datastore/store/postgres/store.go
# Check the VM v2 store Search implementation in detail
rg -nA 20 'func (s \*storeImpl) Search\(ctx context.Context, q \*v1.Query\)' central/virtualmachine/v2/datastore/store/postgres/store.goRepository: stackrox/stackrox
Length of output: 883
🏁 Script executed:
# Search for pagination handling in the query execution layer
rg -n 'FillDefaultSortOption|RunQueryRequest|GetQueryPagination|default.*pagination|Limit.*0|Limit.*-1' --type=go pkg/search/postgres/ | head -40
# Check the Search implementation in VM store more carefully
cat central/virtualmachine/v2/datastore/store/postgres/store.go | sed -n '669,720p'
# Search for where Pagination limits might be applied by default
rg -n 'NewQueryRequestWithPagination|pagination.*limit|limit.*pagination' --type=go pkg/search/ -A 3 | head -50Repository: stackrox/stackrox
Length of output: 4415
🏁 Script executed:
# Check the reconcileV1 implementation to see the explicit pagination pattern
rg -nB 5 -A 10 'func.*reconcileV1' central/sensor/service/pipeline/virtualmachines/pipeline.go
# Check what reconcileV2 currently looks like around line 89-90
rg -nB 3 -A 10 'func.*reconcileV2' central/sensor/service/pipeline/virtualmachines/pipeline.goRepository: stackrox/stackrox
Length of output: 1438
Set explicit pagination for Search in reconciliation.
reconcileV2 needs a complete cluster VM ID snapshot for accurate reconciliation. Without explicit pagination, Search defaults to a 100-result limit, causing VMs beyond the first page to be missed and never reconciled or cleaned up.
Proposed fix
func (p *pipelineImpl) reconcileV2(ctx context.Context, clusterID string, storeMap *reconciliation.StoreMap) error {
query := search.NewQueryBuilder().AddExactMatches(search.ClusterID, clusterID).ProtoQuery()
+ query.Pagination = &v1.QueryPagination{Limit: math.MaxInt32}
results, err := p.virtualMachineV2Store.Search(ctx, query)
if err != nil {
return errors.Wrap(err, "retrieving v2 virtual machines for reconciliation")
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| query := search.NewQueryBuilder().AddExactMatches(search.ClusterID, clusterID).ProtoQuery() | |
| query.Pagination = &v1.QueryPagination{Limit: math.MaxInt32} | |
| virtualMachines, err := p.virtualMachineV2Store.SearchRawVirtualMachines(ctx, query) | |
| results, err := p.virtualMachineV2Store.Search(ctx, query) | |
| query := search.NewQueryBuilder().AddExactMatches(search.ClusterID, clusterID).ProtoQuery() | |
| query.Pagination = &v1.QueryPagination{Limit: math.MaxInt32} | |
| results, err := p.virtualMachineV2Store.Search(ctx, query) |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@central/sensor/service/pipeline/virtualmachines/pipeline.go` around lines 89
- 90, reconcileV2 is calling p.virtualMachineV2Store.Search with a query built
by search.NewQueryBuilder().AddExactMatches(...).ProtoQuery() which relies on
the default 100-result page size and thus misses VMs past the first page; modify
reconcileV2 to set explicit pagination on the query (either a sufficiently large
PageSize or, preferably, implement paging by setting/reading PageToken and
looping calls to p.virtualMachineV2Store.Search until no more results) so you
collect the complete set of VMs for the cluster before reconciling/cleaning up.
Description
Reconciliation only needs IDs, not full VM objects. Use Search() +
ResultsToIDSet() — the same pattern all other pipelines use — to
avoid deserializing full rows and the manual ID-extraction loop.
Partially generated by AI.
User-facing documentation
Testing and quality
Automated testing
How I validated my change
change me!