From 8adc915888240c56ee10a7f0cad74de39f30d4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Julia=CC=81n?= Date: Fri, 22 Nov 2024 17:43:22 +0100 Subject: [PATCH] Add registry.Log --- pkg/ebpf/uprobes/attacher.go | 6 ++++++ pkg/ebpf/uprobes/attacher_test.go | 3 +++ pkg/ebpf/uprobes/testutil.go | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/pkg/ebpf/uprobes/attacher.go b/pkg/ebpf/uprobes/attacher.go index 6b027c9bf36d0..735333bbcc99b 100644 --- a/pkg/ebpf/uprobes/attacher.go +++ b/pkg/ebpf/uprobes/attacher.go @@ -268,6 +268,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 @@ -464,6 +467,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() case event, ok := <-sharedLibDataChan: if !ok { return diff --git a/pkg/ebpf/uprobes/attacher_test.go b/pkg/ebpf/uprobes/attacher_test.go index dc06c6e193552..f6db89937792b 100644 --- a/pkg/ebpf/uprobes/attacher_test.go +++ b/pkg/ebpf/uprobes/attacher_test.go @@ -297,6 +297,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) @@ -822,6 +823,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) @@ -899,6 +901,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