Conversation
|
Skipping CI for Draft Pull Request. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
This change is part of the following stack: Change managed by git-spice. |
|
Images are ready for the commit at 3a951ff. To use with deploy scripts, first |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #16452 +/- ##
=======================================
Coverage 49.09% 49.09%
=======================================
Files 2649 2650 +1
Lines 196680 196706 +26
=======================================
+ Hits 96551 96564 +13
- Misses 92572 92588 +16
+ Partials 7557 7554 -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:
|
|
/test all |
942c125 to
f65318b
Compare
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider making the UpdateComputer implementation injectable via NewManager options rather than hardcoding NewLegacy, to improve configurability and facilitate future implementations.
- Since updateComputer is always initialized in NewManager, you can remove the redundant nil checks around m.updateComputer to simplify the code.
- Add an integration test in networkFlowManager to ensure it correctly delegates to the UpdateComputer and maintains equivalent state transitions across ticks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider making the UpdateComputer implementation injectable via NewManager options rather than hardcoding NewLegacy, to improve configurability and facilitate future implementations.
- Since updateComputer is always initialized in NewManager, you can remove the redundant nil checks around m.updateComputer to simplify the code.
- Add an integration test in networkFlowManager to ensure it correctly delegates to the UpdateComputer and maintains equivalent state transitions across ticks.
## Individual Comments
### Comment 1
<location> `sensor/common/networkflow/updatecomputer/update_computer_test.go:154` </location>
<code_context>
+ }
+}
+
+func TestComputeUpdatedEndpoints(t *testing.T) {
+ entity1 := networkgraph.Entity{Type: storage.NetworkEntityInfo_DEPLOYMENT, ID: "deployment-1"}
+
</code_context>
<issue_to_address>
Endpoint update tests lack coverage for state transitions and removals.
Please add tests for endpoints transitioning from open to closed, and for endpoints that are removed from the state, to match the coverage of connection tests and address possible edge cases.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
func TestComputeUpdatedEndpoints(t *testing.T) {
entity1 := networkgraph.Entity{Type: storage.NetworkEntityInfo_DEPLOYMENT, ID: "deployment-1"}
=======
func TestComputeUpdatedEndpoints(t *testing.T) {
entity1 := networkgraph.Entity{Type: storage.NetworkEntityInfo_DEPLOYMENT, ID: "deployment-1"}
// Endpoint transitions from open to closed
t.Run("endpoint transitions from open to closed", func(t *testing.T) {
openEndpoint := indicator.Endpoint{
Entity: entity1,
Port: 8080,
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
State: indicator.EndpointStateOpen,
FirstSeen: timestamp.Now(),
}
closedEndpoint := openEndpoint
closedEndpoint.State = indicator.EndpointStateClosed
initialState := []*indicator.Endpoint{&openEndpoint}
currentState := []*indicator.Endpoint{&closedEndpoint}
computer := NewUpdateComputer()
computer.UpdateState(nil, initialState, nil)
updates := computer.ComputeUpdatedEndpoints(currentState)
assert.Len(t, updates, 1)
assert.Equal(t, indicator.EndpointStateClosed, updates[0].State)
})
// Endpoint removed from state
t.Run("endpoint removed from state", func(t *testing.T) {
endpoint := indicator.Endpoint{
Entity: entity1,
Port: 8081,
Protocol: storage.L4Protocol_L4_PROTOCOL_TCP,
State: indicator.EndpointStateOpen,
FirstSeen: timestamp.Now(),
}
initialState := []*indicator.Endpoint{&endpoint}
currentState := []*indicator.Endpoint{}
computer := NewUpdateComputer()
computer.UpdateState(nil, initialState, nil)
updates := computer.ComputeUpdatedEndpoints(currentState)
// Expect an update indicating removal (implementation may vary)
assert.True(t, len(updates) == 1 || len(updates) == 0, "Should handle endpoint removal gracefully")
})
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `sensor/common/networkflow/updatecomputer/update_computer_test.go:205` </location>
<code_context>
+
+// TestComputeUpdatedProcesses relies on exactly the same method as for endpoints.
+// Adding this test despite that to ensure test coverage.
+func TestComputeUpdatedProcesses(t *testing.T) {
+ process1 := indicator.ProcessListening{
+ Process: indicator.ProcessInfo{
</code_context>
<issue_to_address>
Process update tests do not verify feature flag behavior.
Please add a test case with ProcessesListeningOnPort set to false to confirm that no updates are produced when the flag is disabled.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
I did the first one in 40a11cd, so that the second one does not apply.
This feels huge as I would need to: (1) build a mock for update computer, (2) execute tests for |
40a11cd to
3a951ff
Compare
|
Images are ready for the commit at 6cd5354. To use with deploy scripts, first |
lvalerom
left a comment
There was a problem hiding this comment.
Looks good! I left a few comments but 99% of them are nitpicks. The only one that concerns me is the one regarding updating the state before we know if the update was sent.
Also (I couldn't comment in the file because the line was not changed in the PR) the loggingRateLimiter in the manager_impl.go file can be deleted.
sensor/common/networkflow/updatecomputer/update_computer_test.go
Outdated
Show resolved
Hide resolved
|
/retest |
lvalerom
left a comment
There was a problem hiding this comment.
LGTM. Feel free to ignore the last nit if you think it's overkill 🙂
|
Images are ready for the commit at 9f663c4. To use with deploy scripts, first |
b136877 to
9f663c4
Compare
🐑 Shepherd of this stack is @lvalerom and @rhybrillou (when back)
Description
This PR extracts the calculation logic for sending updates to Central. A new
updateComputerpackage is introduced that is responsible for determining what should be sent to central and what skipped. In this PR, there is only one implementation of theupdateComputercalledLegacy. TheLegacyimplements the update calculation behavior without any changes to the logic.Some metrics and dedicated tests are added for the new
updateComputerpackage.User-facing documentation
Testing and quality
Automated testing
How I validated my change