Skip to content

ROX-33939: virtual machine v2 reconciliation improvements#19904

Open
dashrews78 wants to merge 2 commits intomasterfrom
dashrews/virt-reconciliation-33939
Open

ROX-33939: virtual machine v2 reconciliation improvements#19904
dashrews78 wants to merge 2 commits intomasterfrom
dashrews/virt-reconciliation-33939

Conversation

@dashrews78
Copy link
Copy Markdown
Contributor

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

  • 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

change me!

dashrews78 and others added 2 commits April 8, 2026 15:06
…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>
@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Apr 8, 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🚀 Build Images Ready

Images are ready for commit 1fd38ea. To use with deploy scripts:

export MAIN_IMAGE_TAG=4.11.x-603-g1fd38ea3eb

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.60%. Comparing base (39d15cc) to head (1fd38ea).
⚠️ Report is 8 commits behind head on master.

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              
Flag Coverage Δ
go-unit-tests 49.60% <100.00%> (-0.01%) ⬇️

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.

@dashrews78 dashrews78 marked this pull request as ready for review April 9, 2026 14:37
@dashrews78 dashrews78 requested a review from ajheflin April 9, 2026 14:38
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Improved internal virtual machine reconciliation implementation for better code consistency and maintainability.

Walkthrough

The reconciliation logic in the VM pipeline is refactored to use the Search API instead of SearchRawVirtualMachines, with results converted to an ID set via search.ResultsToIDSet() for deletion operations. Corresponding test mocks are updated to match the new API signature.

Changes

Cohort / File(s) Summary
VM Pipeline Search API Migration
central/sensor/service/pipeline/virtualmachines/pipeline.go, central/sensor/service/pipeline/virtualmachines/pipeline_test.go
Refactored reconcileV2 to call Search(ctx, query) instead of SearchRawVirtualMachines with explicit QueryPagination, and convert results to ID set via search.ResultsToIDSet(). Updated test mocks to return []search.Result instead of []*storage.VirtualMachineV2, and added github.com/stackrox/rox/pkg/search import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description explains the technical rationale but leaves critical validation sections incomplete, with 'change me!' placeholder remaining in the 'How I validated my change' section. Complete the 'How I validated my change' section explaining the testing approach or why validation was deferred to CI; clarify which testing checkboxes apply.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: a refactoring of the virtual machine v2 reconciliation pipeline to use a more efficient search pattern.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dashrews/virt-reconciliation-33939

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39d15cc and 1fd38ea.

📒 Files selected for processing (2)
  • central/sensor/service/pipeline/virtualmachines/pipeline.go
  • central/sensor/service/pipeline/virtualmachines/pipeline_test.go

Comment on lines 89 to +90
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 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*\(' -C3

Repository: 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.go

Repository: 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 -50

Repository: 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.go

Repository: 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.

Suggested change
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.

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