Closed dwertent closed 7 months ago
PR Description updated to latest commit (https://github.com/kubescape/node-agent/commit/cc745367a6efa9a1032d621849577fdae1fdb28d)
⏱️ Estimated effort to review [1-5] | 4, because the PR introduces significant changes across multiple components, including new functionality for handling container max time events, modifications to existing interfaces, and the addition of new methods in several managers and mock classes. The complexity and breadth of these changes require a thorough review to ensure compatibility and correctness across the system. |
🧪 Relevant tests | No |
🔍 Possible issues | Synchronization Concerns: The implementation of `ContainerReachedMaxTime` across different managers involves sending signals through channels. It's crucial to ensure that these signals are correctly synchronized and do not lead to race conditions or deadlocks. |
Error Handling: The new error `ContainerReachedMaxTime` is introduced and used in various places. It's important to verify that all possible error paths are correctly handled and that appropriate actions are taken when this error occurs. | |
Integration Testing: Given the changes impact multiple components (e.g., `ApplicationProfileManager`, `NetworkManager`, `RelevancyManager`), it's essential to perform integration testing to ensure these components work harmoniously and the new functionality behaves as expected in real-world scenarios. | |
🔒 Security concerns | No |
Category | Suggestions |
Maintainability |
Refactor repetitive calls to a loop or method for notifying managers about
___
**Consider using a loop or a dedicated method to notify all managers about |
Possible issue |
Prevent potential blocking on channel send in
___
**Ensure that sending to the channel does not block indefinitely by selecting on a context |
Enhancement |
Add safety checks and non-blocking send to prevent panic when sending to a channel.___ **Consider handling the case where the channel is closed before sending to prevent panic.** [pkg/applicationprofilemanager/v1/applicationprofile_manager.go [145]](https://github.com/kubescape/node-agent/pull/250/files#diff-fc815317651e17975c117749e7661127dbcde82fd9d4d36ebc76cb5b09b3c54eR145-R145) ```diff -channel <- utils.ContainerReachedMaxTime +if channel, ok := am.watchedContainerChannels.Get(containerID); ok && channel != nil { + select { + case channel <- utils.ContainerReachedMaxTime: + default: + // Log error or handle the case where the channel is blocked or closed + } +} ``` |
Add error handling for missing channels in
___
**Add error handling or logging when the channel is not found or is nil to aid in debugging | |
Best practice |
Merge switch cases with identical outcomes for cleaner code.___ **To improve code readability and reduce redundancy, consider merging cases inmonitorContainer that have identical bodies.**
[pkg/relevancymanager/v1/relevancy_manager.go [260-262]](https://github.com/kubescape/node-agent/pull/250/files#diff-f665b80e0e8d6552b56e677f5579b3b90cb7cd78999a4bec61d41522469393a3R260-R262)
```diff
-case errors.Is(err, utils.ContainerReachedMaxTime):
+case errors.Is(err, utils.ContainerReachedMaxTime), errors.Is(err, utils.IncompleteSBOMError):
rm.handleRelevancy(ctx, watchedContainer, container.Runtime.ContainerID)
return nil
```
|
Summary:
User description
Overview
Create an event when we reach max sniffing time so the managers will stop caching the events. This will save a lot of memory and CPU.
Type
enhancement
Description
ApplicationProfileManager
,NetworkManager
,RelevancyManager
).ContainerReachedMaxTime
in utils to signal the max time event.ContainerReachedMaxTime
methods in mock classes for testing.Changes walkthrough
11 files
applicationprofile_manager_interface.go
Add Max Time Handler to ApplicationProfileManager Interface
pkg/applicationprofilemanager/applicationprofile_manager_interface.go
ContainerReachedMaxTime
method to theApplicationProfileManagerClient
interface.applicationprofile_manager_mock.go
Implement Max Time Handler in ApplicationProfileManager Mock
pkg/applicationprofilemanager/applicationprofile_manager_mock.go
ContainerReachedMaxTime
method as a no-operation in themock.
applicationprofile_manager.go
Implement Container Max Time Handling in ApplicationProfileManager
pkg/applicationprofilemanager/v1/applicationprofile_manager.go
ContainerReachedMaxTime
method to trigger a max time event for acontainer.
container_watcher_private.go
Propagate Container Max Time Event in ContainerWatcher
pkg/containerwatcher/v1/container_watcher_private.go
ContainerReachedMaxTime
across multiple managers when acontainer reaches max time.
network_manager_interface.go
Add Max Time Handler to NetworkManager Interface
pkg/networkmanager/network_manager_interface.go
ContainerReachedMaxTime
method to theNetworkManagerClient
interface.
network_manager_mock.go
Implement Max Time Handler in NetworkManager Mock
pkg/networkmanager/network_manager_mock.go
ContainerReachedMaxTime
method as a no-operation in themock.
network_manager.go
Implement Container Max Time Handling in NetworkManager
pkg/networkmanager/v1/network_manager.go
ContainerReachedMaxTime
method to handle max time event for acontainer.
relevancy_manager_interface.go
Add Max Time Handler to RelevancyManager Interface
pkg/relevancymanager/relevancy_manager_interface.go
ContainerReachedMaxTime
method to theRelevancyManagerClient
interface.
relevancy_manager_mock.go
Implement Max Time Handler in RelevancyManager Mock
pkg/relevancymanager/relevancy_manager_mock.go
ContainerReachedMaxTime
method as a no-operation in themock.
relevancy_manager.go
Implement Container Max Time Handling in RelevancyManager
pkg/relevancymanager/v1/relevancy_manager.go
ContainerReachedMaxTime
method to trigger relevancy handlingupon reaching max time.
utils.go
Add Container Max Time Error in Utils
pkg/utils/utils.go
ContainerReachedMaxTime
error to signal when a containerreaches its maximum allowed time.