Skip to content

Commit

Permalink
[EBPF] attacher: Add Log() call to registry (DataDog#31390)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjulianm authored Nov 27, 2024
1 parent 06deb63 commit b49aa34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/ebpf/uprobes/attacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
}()
Expand Down
3 changes: 3 additions & 0 deletions pkg/ebpf/uprobes/attacher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions pkg/ebpf/uprobes/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b49aa34

Please sign in to comment.