-
Notifications
You must be signed in to change notification settings - Fork 177
ROX-33555: Refactor UMH to per-resource tracking, wire node ACK flow #19319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ac9ef79
ROX-32316: Refactor UMH to per-resource tracking and wire node ACK flow
vikin91 4f87762
Avoid TODO(ROX-) comment to not self-block this PR
vikin91 2178326
Self-review
vikin91 3b9a9b3
ROX-33555: address UMH review feedback and fix compliance ACK tests
vikin91 950ed7c
Refactor tests
vikin91 90233ba
Address AI reviews
vikin91 1f291af
Fix style
vikin91 c400789
fix(compliance): prevent stale retry dispatch after ACK
vikin91 38d0dae
Address review
vikin91 09b1884
Rename test func, change int32->int
vikin91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package compliance | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stackrox/rox/generated/internalapi/sensor" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| func TestCompliance(t *testing.T) { | ||
| suite.Run(t, new(ComplianceTestSuite)) | ||
| } | ||
|
|
||
| type ComplianceTestSuite struct { | ||
| suite.Suite | ||
| } | ||
|
|
||
| func (s *ComplianceTestSuite) TestHandleComplianceACK() { | ||
| cases := map[string]struct { | ||
| ack *sensor.MsgToCompliance_ComplianceACK | ||
| expectedInventoryACKs int | ||
| expectedInventoryNACKs int | ||
| expectedIndexACKs int | ||
| expectedIndexNACKs int | ||
| }{ | ||
| "should handle NODE_INVENTORY ACK": { | ||
| ack: &sensor.MsgToCompliance_ComplianceACK{ | ||
| Action: sensor.MsgToCompliance_ComplianceACK_ACK, | ||
| MessageType: sensor.MsgToCompliance_ComplianceACK_NODE_INVENTORY, | ||
| ResourceId: "node-1", | ||
| }, | ||
| expectedInventoryACKs: 1, | ||
| }, | ||
| "should handle NODE_INVENTORY NACK": { | ||
| ack: &sensor.MsgToCompliance_ComplianceACK{ | ||
| Action: sensor.MsgToCompliance_ComplianceACK_NACK, | ||
| MessageType: sensor.MsgToCompliance_ComplianceACK_NODE_INVENTORY, | ||
| ResourceId: "node-1", | ||
| Reason: "rate limit exceeded", | ||
| }, | ||
| expectedInventoryNACKs: 1, | ||
| }, | ||
| "should handle NODE_INDEX_REPORT ACK": { | ||
| ack: &sensor.MsgToCompliance_ComplianceACK{ | ||
| Action: sensor.MsgToCompliance_ComplianceACK_ACK, | ||
| MessageType: sensor.MsgToCompliance_ComplianceACK_NODE_INDEX_REPORT, | ||
| ResourceId: "node-2", | ||
| }, | ||
| expectedIndexACKs: 1, | ||
| }, | ||
| "should handle NODE_INDEX_REPORT NACK": { | ||
| ack: &sensor.MsgToCompliance_ComplianceACK{ | ||
| Action: sensor.MsgToCompliance_ComplianceACK_NACK, | ||
| MessageType: sensor.MsgToCompliance_ComplianceACK_NODE_INDEX_REPORT, | ||
| ResourceId: "node-2", | ||
| Reason: "central unreachable", | ||
| }, | ||
| expectedIndexNACKs: 1, | ||
| }, | ||
| } | ||
|
|
||
| for name, tc := range cases { | ||
| s.Run(name, func() { | ||
| mockInventory := &fakeUMH{retryC: make(chan string)} | ||
| mockIndex := &fakeUMH{retryC: make(chan string)} | ||
|
|
||
| c := &Compliance{ | ||
| umhNodeInventory: mockInventory, | ||
| umhNodeIndex: mockIndex, | ||
| } | ||
|
|
||
| c.handleComplianceACK(tc.ack) | ||
|
|
||
| s.Equal(tc.expectedInventoryACKs, mockInventory.ackCount, "inventory ACK count") | ||
| s.Equal(tc.expectedInventoryNACKs, mockInventory.nackCount, "inventory NACK count") | ||
| s.Equal(tc.expectedIndexACKs, mockIndex.ackCount, "index ACK count") | ||
| s.Equal(tc.expectedIndexNACKs, mockIndex.nackCount, "index NACK count") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func (s *ComplianceTestSuite) TestHandleComplianceACK_NilACK() { | ||
| mockInventory := &fakeUMH{retryC: make(chan string)} | ||
| mockIndex := &fakeUMH{retryC: make(chan string)} | ||
|
|
||
| c := &Compliance{ | ||
| umhNodeInventory: mockInventory, | ||
| umhNodeIndex: mockIndex, | ||
| } | ||
|
|
||
| // Should not panic and should not call any handlers | ||
| c.handleComplianceACK(nil) | ||
|
|
||
| s.Equal(0, mockInventory.ackCount) | ||
| s.Equal(0, mockInventory.nackCount) | ||
| s.Equal(0, mockIndex.ackCount) | ||
| s.Equal(0, mockIndex.nackCount) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.