diff --git a/pkg/ebpf/uprobes/attacher.go b/pkg/ebpf/uprobes/attacher.go index 903b69b59f620..f413462bea633 100644 --- a/pkg/ebpf/uprobes/attacher.go +++ b/pkg/ebpf/uprobes/attacher.go @@ -295,6 +295,9 @@ type FileRegistry interface { // GetRegisteredProcesses returns a map of all the processes that are currently registered in the registry GetRegisteredProcesses() map[uint32]struct{} + + // Log is a function that gets called periodically to log the state of the registry + Log() } // AttachCallback is a callback that is called whenever a probe is attached successfully @@ -489,6 +492,9 @@ func (ua *UprobeAttacher) Start() error { case <-processSync.C: // We always track process deletions in the scan, to avoid memory leaks. _ = ua.Sync(ua.config.EnablePeriodicScanNewProcesses, true) + + // Periodically log the state of the registry + ua.fileRegistry.Log() } } }() diff --git a/pkg/ebpf/uprobes/attacher_test.go b/pkg/ebpf/uprobes/attacher_test.go index 6003decb2ca42..55172da64b1bb 100644 --- a/pkg/ebpf/uprobes/attacher_test.go +++ b/pkg/ebpf/uprobes/attacher_test.go @@ -326,6 +326,7 @@ func TestMonitor(t *testing.T) { // Tell mockRegistry to return on any calls, we will check the values later mockRegistry.On("Clear").Return() + mockRegistry.On("Log").Return() mockRegistry.On("Unregister", mock.Anything).Return(nil) mockRegistry.On("Register", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) lib := getLibSSLPath(t) @@ -872,6 +873,7 @@ func (s *SharedLibrarySuite) TestSingleFile() { // Tell mockRegistry to return on any calls, we will check the values later mockRegistry.On("Clear").Return() + mockRegistry.On("Log").Return() mockRegistry.On("Unregister", mock.Anything).Return(nil) mockRegistry.On("Register", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) @@ -950,6 +952,7 @@ func (s *SharedLibrarySuite) TestDetectionWithPIDAndRootNamespace() { // Tell mockRegistry to return on any calls, we will check the values later mockRegistry.On("Clear").Return() + mockRegistry.On("Log").Return() mockRegistry.On("Unregister", mock.Anything).Return(nil) mockRegistry.On("Register", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) diff --git a/pkg/ebpf/uprobes/testutil.go b/pkg/ebpf/uprobes/testutil.go index d5d27d4e5b2aa..dcda53b56d155 100644 --- a/pkg/ebpf/uprobes/testutil.go +++ b/pkg/ebpf/uprobes/testutil.go @@ -78,6 +78,11 @@ func (m *MockFileRegistry) GetRegisteredProcesses() map[uint32]struct{} { return args.Get(0).(map[uint32]struct{}) } +// Log is a mock implementation of the FileRegistry.Log method. +func (m *MockFileRegistry) Log() { + m.Called() +} + // MockBinaryInspector is a mock implementation of the BinaryInspector interface. type MockBinaryInspector struct { mock.Mock