diff --git a/.mockery.yaml b/.mockery.yaml index 9135bad6ef9c3..50c2336b1f844 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -29,6 +29,8 @@ packages: github.com/DataDog/datadog-agent/pkg/process/net: interfaces: SysProbeUtil: + config: + with-expecter: true github.com/DataDog/datadog-agent/pkg/process/procutil: interfaces: Probe: @@ -40,5 +42,5 @@ packages: config: mock-build-tags: test replace-type: - # https://github.com/vektra/mockery/issues/331 - - github.com/DataDog/datadog-agent/pkg/serializer/types.stubMessageBody=github.com/DataDog/datadog-agent/pkg/serializer/types.ProcessMessageBody + # https://github.com/vektra/mockery/issues/331 + - github.com/DataDog/datadog-agent/pkg/serializer/types.stubMessageBody=github.com/DataDog/datadog-agent/pkg/serializer/types.ProcessMessageBody diff --git a/pkg/collector/corechecks/ebpf/ebpf.go b/pkg/collector/corechecks/ebpf/ebpf.go index 4e9e6fe65a3cf..c7c2eb17d80a4 100644 --- a/pkg/collector/corechecks/ebpf/ebpf.go +++ b/pkg/collector/corechecks/ebpf/ebpf.go @@ -39,7 +39,7 @@ type EBPFCheckConfig struct { // EBPFCheck grabs eBPF map/program/perf buffer metrics type EBPFCheck struct { config *EBPFCheckConfig - sysProbeUtil *processnet.RemoteSysProbeUtil + sysProbeUtil processnet.SysProbeUtil core.CheckBase } diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux.go b/pkg/collector/corechecks/servicediscovery/impl_linux.go index b994e0f23b0a6..a8c737762c249 100644 --- a/pkg/collector/corechecks/servicediscovery/impl_linux.go +++ b/pkg/collector/corechecks/servicediscovery/impl_linux.go @@ -25,7 +25,7 @@ func init() { } type linuxImpl struct { - getSysProbeClient func() (systemProbeClient, error) + getSysProbeClient processnet.SysProbeUtilGetter time timer ignoreCfg map[string]bool @@ -38,7 +38,7 @@ type linuxImpl struct { func newLinuxImpl(ignoreCfg map[string]bool, containerProvider proccontainers.ContainerProvider) (osImpl, error) { return &linuxImpl{ - getSysProbeClient: getSysProbeClient, + getSysProbeClient: processnet.GetRemoteSystemProbeUtil, time: realTime{}, ignoreCfg: ignoreCfg, containerProvider: containerProvider, @@ -49,7 +49,8 @@ func newLinuxImpl(ignoreCfg map[string]bool, containerProvider proccontainers.Co } func (li *linuxImpl) DiscoverServices() (*discoveredServices, error) { - sysProbe, err := li.getSysProbeClient() + socket := pkgconfigsetup.SystemProbe().GetString("system_probe_config.sysprobe_socket") + sysProbe, err := li.getSysProbeClient(socket) if err != nil { return nil, errWithCode{ err: err, @@ -182,13 +183,3 @@ func (li *linuxImpl) getServiceInfo(service model.Service) serviceInfo { LastHeartbeat: li.time.Now(), } } - -type systemProbeClient interface { - GetDiscoveryServices() (*model.ServicesResponse, error) -} - -func getSysProbeClient() (systemProbeClient, error) { - return processnet.GetRemoteSystemProbeUtil( - pkgconfigsetup.SystemProbe().GetString("system_probe_config.sysprobe_socket"), - ) -} diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux_mock.go b/pkg/collector/corechecks/servicediscovery/impl_linux_mock.go deleted file mode 100644 index 2022d4bcce6c9..0000000000000 --- a/pkg/collector/corechecks/servicediscovery/impl_linux_mock.go +++ /dev/null @@ -1,57 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016-present Datadog, Inc. - -//go:build linux - -// Code generated by MockGen. DO NOT EDIT. -// Source: impl_linux.go - -// Package servicediscovery is a generated GoMock package. -package servicediscovery - -import ( - reflect "reflect" - - model "github.com/DataDog/datadog-agent/pkg/collector/corechecks/servicediscovery/model" - gomock "github.com/golang/mock/gomock" -) - -// MocksystemProbeClient is a mock of systemProbeClient interface. -type MocksystemProbeClient struct { - ctrl *gomock.Controller - recorder *MocksystemProbeClientMockRecorder -} - -// MocksystemProbeClientMockRecorder is the mock recorder for MocksystemProbeClient. -type MocksystemProbeClientMockRecorder struct { - mock *MocksystemProbeClient -} - -// NewMocksystemProbeClient creates a new mock instance. -func NewMocksystemProbeClient(ctrl *gomock.Controller) *MocksystemProbeClient { - mock := &MocksystemProbeClient{ctrl: ctrl} - mock.recorder = &MocksystemProbeClientMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MocksystemProbeClient) EXPECT() *MocksystemProbeClientMockRecorder { - return m.recorder -} - -// GetDiscoveryListeners mocks base method. -func (m *MocksystemProbeClient) GetDiscoveryServices() (*model.ServicesResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetDiscoveryServices") - ret0, _ := ret[0].(*model.ServicesResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetDiscoveryServices indicates an expected call of GetDiscoveryServices. -func (mr *MocksystemProbeClientMockRecorder) GetDiscoveryServices() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDiscoveryServices", reflect.TypeOf((*MocksystemProbeClient)(nil).GetDiscoveryServices)) -} diff --git a/pkg/collector/corechecks/servicediscovery/impl_linux_test.go b/pkg/collector/corechecks/servicediscovery/impl_linux_test.go index 06bfe2c24a135..91bbc71c59458 100644 --- a/pkg/collector/corechecks/servicediscovery/impl_linux_test.go +++ b/pkg/collector/corechecks/servicediscovery/impl_linux_test.go @@ -22,6 +22,8 @@ import ( "github.com/DataDog/datadog-agent/pkg/aggregator/mocksender" "github.com/DataDog/datadog-agent/pkg/collector/corechecks/servicediscovery/apm" "github.com/DataDog/datadog-agent/pkg/collector/corechecks/servicediscovery/model" + "github.com/DataDog/datadog-agent/pkg/process/net" + netmocks "github.com/DataDog/datadog-agent/pkg/process/net/mocks" ) type testProc struct { @@ -573,7 +575,7 @@ func Test_linuxImpl(t *testing.T) { require.NotNil(t, check.os) for _, cr := range tc.checkRun { - mSysProbe := NewMocksystemProbeClient(ctrl) + mSysProbe := netmocks.NewSysProbeUtil(t) mSysProbe.EXPECT().GetDiscoveryServices(). Return(cr.servicesResp, nil). Times(1) @@ -584,7 +586,7 @@ func Test_linuxImpl(t *testing.T) { mTimer.EXPECT().Now().Return(cr.time).AnyTimes() // set mocks - check.os.(*linuxImpl).getSysProbeClient = func() (systemProbeClient, error) { + check.os.(*linuxImpl).getSysProbeClient = func(_ string) (net.SysProbeUtil, error) { return mSysProbe, nil } check.os.(*linuxImpl).time = mTimer diff --git a/pkg/process/checks/container.go b/pkg/process/checks/container.go index 590cb8f9ac359..8d9c8330ebd47 100644 --- a/pkg/process/checks/container.go +++ b/pkg/process/checks/container.go @@ -56,7 +56,7 @@ func (c *ContainerCheck) Init(syscfg *SysProbeConfig, info *HostInfo, _ bool) er c.containerProvider = proccontainers.GetSharedContainerProvider(c.wmeta) c.hostInfo = info - var tu *net.RemoteSysProbeUtil + var tu net.SysProbeUtil var err error if syscfg.NetworkTracerModuleEnabled { // Calling the remote tracer will cause it to initialize and check connectivity diff --git a/pkg/process/checks/net.go b/pkg/process/checks/net.go index 13b33d87f9dca..816ae56a42134 100644 --- a/pkg/process/checks/net.go +++ b/pkg/process/checks/net.go @@ -505,7 +505,7 @@ func convertAndEnrichWithServiceCtx(tags []string, tagOffsets []uint32, serviceC } // fetches network_id from the current netNS or from the system probe if necessary, where the root netNS is used -func retryGetNetworkID(sysProbeUtil *net.RemoteSysProbeUtil) (string, error) { +func retryGetNetworkID(sysProbeUtil net.SysProbeUtil) (string, error) { networkID, err := cloudproviders.GetNetworkID(context.TODO()) if err != nil && sysProbeUtil != nil { log.Infof("no network ID detected. retrying via system-probe: %s", err) diff --git a/pkg/process/checks/process.go b/pkg/process/checks/process.go index 5d905a135702c..05a7ac5c72d28 100644 --- a/pkg/process/checks/process.go +++ b/pkg/process/checks/process.go @@ -136,7 +136,7 @@ func (p *ProcessCheck) Init(syscfg *SysProbeConfig, info *HostInfo, oneShot bool p.notInitializedLogLimit = log.NewLogLimit(1, time.Minute*10) - var tu *net.RemoteSysProbeUtil + var tu net.SysProbeUtil var err error if syscfg.NetworkTracerModuleEnabled { // Calling the remote tracer will cause it to initialize and check connectivity @@ -657,7 +657,7 @@ func skipProcess( return false } -func (p *ProcessCheck) getRemoteSysProbeUtil() *net.RemoteSysProbeUtil { +func (p *ProcessCheck) getRemoteSysProbeUtil() net.SysProbeUtil { if !p.sysProbeConfig.ProcessModuleEnabled { return nil } diff --git a/pkg/process/checks/process_rt.go b/pkg/process/checks/process_rt.go index 9fd866a735ce6..33bf93f06a793 100644 --- a/pkg/process/checks/process_rt.go +++ b/pkg/process/checks/process_rt.go @@ -160,7 +160,7 @@ func calculateRate(cur, prev uint64, before time.Time) float32 { } // mergeStatWithSysprobeStats takes a process by PID map and fill the stats from system probe into the processes in the map -func mergeStatWithSysprobeStats(pids []int32, stats map[int32]*procutil.Stats, pu *net.RemoteSysProbeUtil) { +func mergeStatWithSysprobeStats(pids []int32, stats map[int32]*procutil.Stats, pu net.SysProbeUtil) { pStats, err := pu.GetProcStats(pids) if err == nil { for pid, stats := range stats { diff --git a/pkg/process/net/common.go b/pkg/process/net/common.go index 252361f6d8983..8af3c4e7e65bb 100644 --- a/pkg/process/net/common.go +++ b/pkg/process/net/common.go @@ -65,8 +65,11 @@ type RemoteSysProbeUtil struct { tracerouteClient http.Client } +// ensure that GetRemoteSystemProbeUtil implements SysProbeUtilGetter +var _ SysProbeUtilGetter = GetRemoteSystemProbeUtil + // GetRemoteSystemProbeUtil returns a ready to use RemoteSysProbeUtil. It is backed by a shared singleton. -func GetRemoteSystemProbeUtil(path string) (*RemoteSysProbeUtil, error) { +func GetRemoteSystemProbeUtil(path string) (SysProbeUtil, error) { err := CheckPath(path) if err != nil { return nil, fmt.Errorf("error setting up remote system probe util, %v", err) diff --git a/pkg/process/net/common_unsupported.go b/pkg/process/net/common_unsupported.go index af7eaef555926..0d0a502236ad5 100644 --- a/pkg/process/net/common_unsupported.go +++ b/pkg/process/net/common_unsupported.go @@ -9,12 +9,18 @@ package net import ( + "time" + model "github.com/DataDog/agent-payload/v5/process" + sysconfigtypes "github.com/DataDog/datadog-agent/cmd/system-probe/config/types" + discoverymodel "github.com/DataDog/datadog-agent/pkg/collector/corechecks/servicediscovery/model" "github.com/DataDog/datadog-agent/pkg/languagedetection/languagemodels" + nppayload "github.com/DataDog/datadog-agent/pkg/networkpath/payload" ) var _ SysProbeUtil = &RemoteSysProbeUtil{} +var _ SysProbeUtilGetter = GetRemoteSystemProbeUtil // RemoteSysProbeUtil is not supported type RemoteSysProbeUtil struct{} @@ -29,7 +35,7 @@ func CheckPath(_ string) error { // GetRemoteSystemProbeUtil is not supported // //nolint:revive // TODO(PROC) Fix revive linter -func GetRemoteSystemProbeUtil(_ string) (*RemoteSysProbeUtil, error) { +func GetRemoteSystemProbeUtil(_ string) (SysProbeUtil, error) { return &RemoteSysProbeUtil{}, ErrNotImplemented } @@ -76,3 +82,19 @@ func (r *RemoteSysProbeUtil) GetPprof(_ string) ([]byte, error) { // GetTelemetry is not supported func (r *RemoteSysProbeUtil) GetTelemetry() ([]byte, error) { return nil, ErrNotImplemented } + +func (r *RemoteSysProbeUtil) GetDiscoveryServices() (*discoverymodel.ServicesResponse, error) { + return nil, ErrNotImplemented +} + +func (r *RemoteSysProbeUtil) GetCheck(module sysconfigtypes.ModuleName) (interface{}, error) { + return nil, ErrNotImplemented +} + +func (r *RemoteSysProbeUtil) GetPing(clientID string, host string, count int, interval time.Duration, timeout time.Duration) ([]byte, error) { + return nil, ErrNotImplemented +} + +func (r *RemoteSysProbeUtil) GetTraceroute(clientID string, host string, port uint16, protocol nppayload.Protocol, maxTTL uint8, timeout time.Duration) ([]byte, error) { + return nil, ErrNotImplemented +} diff --git a/pkg/process/net/mocks/sys_probe_util.go b/pkg/process/net/mocks/sys_probe_util.go index c4a1bc3492645..1e623aac6cc23 100644 --- a/pkg/process/net/mocks/sys_probe_util.go +++ b/pkg/process/net/mocks/sys_probe_util.go @@ -3,9 +3,18 @@ package mocks import ( + languagemodels "github.com/DataDog/datadog-agent/pkg/languagedetection/languagemodels" mock "github.com/stretchr/testify/mock" + model "github.com/DataDog/datadog-agent/pkg/collector/corechecks/servicediscovery/model" + + payload "github.com/DataDog/datadog-agent/pkg/networkpath/payload" + process "github.com/DataDog/agent-payload/v5/process" + + time "time" + + types "github.com/DataDog/datadog-agent/cmd/system-probe/config/types" ) // SysProbeUtil is an autogenerated mock type for the SysProbeUtil type @@ -13,6 +22,130 @@ type SysProbeUtil struct { mock.Mock } +type SysProbeUtil_Expecter struct { + mock *mock.Mock +} + +func (_m *SysProbeUtil) EXPECT() *SysProbeUtil_Expecter { + return &SysProbeUtil_Expecter{mock: &_m.Mock} +} + +// DetectLanguage provides a mock function with given fields: pids +func (_m *SysProbeUtil) DetectLanguage(pids []int32) ([]languagemodels.Language, error) { + ret := _m.Called(pids) + + if len(ret) == 0 { + panic("no return value specified for DetectLanguage") + } + + var r0 []languagemodels.Language + var r1 error + if rf, ok := ret.Get(0).(func([]int32) ([]languagemodels.Language, error)); ok { + return rf(pids) + } + if rf, ok := ret.Get(0).(func([]int32) []languagemodels.Language); ok { + r0 = rf(pids) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]languagemodels.Language) + } + } + + if rf, ok := ret.Get(1).(func([]int32) error); ok { + r1 = rf(pids) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SysProbeUtil_DetectLanguage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DetectLanguage' +type SysProbeUtil_DetectLanguage_Call struct { + *mock.Call +} + +// DetectLanguage is a helper method to define mock.On call +// - pids []int32 +func (_e *SysProbeUtil_Expecter) DetectLanguage(pids interface{}) *SysProbeUtil_DetectLanguage_Call { + return &SysProbeUtil_DetectLanguage_Call{Call: _e.mock.On("DetectLanguage", pids)} +} + +func (_c *SysProbeUtil_DetectLanguage_Call) Run(run func(pids []int32)) *SysProbeUtil_DetectLanguage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]int32)) + }) + return _c +} + +func (_c *SysProbeUtil_DetectLanguage_Call) Return(_a0 []languagemodels.Language, _a1 error) *SysProbeUtil_DetectLanguage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_DetectLanguage_Call) RunAndReturn(run func([]int32) ([]languagemodels.Language, error)) *SysProbeUtil_DetectLanguage_Call { + _c.Call.Return(run) + return _c +} + +// GetCheck provides a mock function with given fields: module +func (_m *SysProbeUtil) GetCheck(module types.ModuleName) (interface{}, error) { + ret := _m.Called(module) + + if len(ret) == 0 { + panic("no return value specified for GetCheck") + } + + var r0 interface{} + var r1 error + if rf, ok := ret.Get(0).(func(types.ModuleName) (interface{}, error)); ok { + return rf(module) + } + if rf, ok := ret.Get(0).(func(types.ModuleName) interface{}); ok { + r0 = rf(module) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(interface{}) + } + } + + if rf, ok := ret.Get(1).(func(types.ModuleName) error); ok { + r1 = rf(module) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SysProbeUtil_GetCheck_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCheck' +type SysProbeUtil_GetCheck_Call struct { + *mock.Call +} + +// GetCheck is a helper method to define mock.On call +// - module types.ModuleName +func (_e *SysProbeUtil_Expecter) GetCheck(module interface{}) *SysProbeUtil_GetCheck_Call { + return &SysProbeUtil_GetCheck_Call{Call: _e.mock.On("GetCheck", module)} +} + +func (_c *SysProbeUtil_GetCheck_Call) Run(run func(module types.ModuleName)) *SysProbeUtil_GetCheck_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.ModuleName)) + }) + return _c +} + +func (_c *SysProbeUtil_GetCheck_Call) Return(_a0 interface{}, _a1 error) *SysProbeUtil_GetCheck_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetCheck_Call) RunAndReturn(run func(types.ModuleName) (interface{}, error)) *SysProbeUtil_GetCheck_Call { + _c.Call.Return(run) + return _c +} + // GetConnections provides a mock function with given fields: clientID func (_m *SysProbeUtil) GetConnections(clientID string) (*process.Connections, error) { ret := _m.Called(clientID) @@ -43,6 +176,91 @@ func (_m *SysProbeUtil) GetConnections(clientID string) (*process.Connections, e return r0, r1 } +// SysProbeUtil_GetConnections_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConnections' +type SysProbeUtil_GetConnections_Call struct { + *mock.Call +} + +// GetConnections is a helper method to define mock.On call +// - clientID string +func (_e *SysProbeUtil_Expecter) GetConnections(clientID interface{}) *SysProbeUtil_GetConnections_Call { + return &SysProbeUtil_GetConnections_Call{Call: _e.mock.On("GetConnections", clientID)} +} + +func (_c *SysProbeUtil_GetConnections_Call) Run(run func(clientID string)) *SysProbeUtil_GetConnections_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *SysProbeUtil_GetConnections_Call) Return(_a0 *process.Connections, _a1 error) *SysProbeUtil_GetConnections_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetConnections_Call) RunAndReturn(run func(string) (*process.Connections, error)) *SysProbeUtil_GetConnections_Call { + _c.Call.Return(run) + return _c +} + +// GetDiscoveryServices provides a mock function with given fields: +func (_m *SysProbeUtil) GetDiscoveryServices() (*model.ServicesResponse, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetDiscoveryServices") + } + + var r0 *model.ServicesResponse + var r1 error + if rf, ok := ret.Get(0).(func() (*model.ServicesResponse, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.ServicesResponse); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ServicesResponse) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SysProbeUtil_GetDiscoveryServices_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDiscoveryServices' +type SysProbeUtil_GetDiscoveryServices_Call struct { + *mock.Call +} + +// GetDiscoveryServices is a helper method to define mock.On call +func (_e *SysProbeUtil_Expecter) GetDiscoveryServices() *SysProbeUtil_GetDiscoveryServices_Call { + return &SysProbeUtil_GetDiscoveryServices_Call{Call: _e.mock.On("GetDiscoveryServices")} +} + +func (_c *SysProbeUtil_GetDiscoveryServices_Call) Run(run func()) *SysProbeUtil_GetDiscoveryServices_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *SysProbeUtil_GetDiscoveryServices_Call) Return(_a0 *model.ServicesResponse, _a1 error) *SysProbeUtil_GetDiscoveryServices_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetDiscoveryServices_Call) RunAndReturn(run func() (*model.ServicesResponse, error)) *SysProbeUtil_GetDiscoveryServices_Call { + _c.Call.Return(run) + return _c +} + // GetNetworkID provides a mock function with given fields: func (_m *SysProbeUtil) GetNetworkID() (string, error) { ret := _m.Called() @@ -71,6 +289,153 @@ func (_m *SysProbeUtil) GetNetworkID() (string, error) { return r0, r1 } +// SysProbeUtil_GetNetworkID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNetworkID' +type SysProbeUtil_GetNetworkID_Call struct { + *mock.Call +} + +// GetNetworkID is a helper method to define mock.On call +func (_e *SysProbeUtil_Expecter) GetNetworkID() *SysProbeUtil_GetNetworkID_Call { + return &SysProbeUtil_GetNetworkID_Call{Call: _e.mock.On("GetNetworkID")} +} + +func (_c *SysProbeUtil_GetNetworkID_Call) Run(run func()) *SysProbeUtil_GetNetworkID_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *SysProbeUtil_GetNetworkID_Call) Return(_a0 string, _a1 error) *SysProbeUtil_GetNetworkID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetNetworkID_Call) RunAndReturn(run func() (string, error)) *SysProbeUtil_GetNetworkID_Call { + _c.Call.Return(run) + return _c +} + +// GetPing provides a mock function with given fields: clientID, host, count, interval, timeout +func (_m *SysProbeUtil) GetPing(clientID string, host string, count int, interval time.Duration, timeout time.Duration) ([]byte, error) { + ret := _m.Called(clientID, host, count, interval, timeout) + + if len(ret) == 0 { + panic("no return value specified for GetPing") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int, time.Duration, time.Duration) ([]byte, error)); ok { + return rf(clientID, host, count, interval, timeout) + } + if rf, ok := ret.Get(0).(func(string, string, int, time.Duration, time.Duration) []byte); ok { + r0 = rf(clientID, host, count, interval, timeout) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int, time.Duration, time.Duration) error); ok { + r1 = rf(clientID, host, count, interval, timeout) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SysProbeUtil_GetPing_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPing' +type SysProbeUtil_GetPing_Call struct { + *mock.Call +} + +// GetPing is a helper method to define mock.On call +// - clientID string +// - host string +// - count int +// - interval time.Duration +// - timeout time.Duration +func (_e *SysProbeUtil_Expecter) GetPing(clientID interface{}, host interface{}, count interface{}, interval interface{}, timeout interface{}) *SysProbeUtil_GetPing_Call { + return &SysProbeUtil_GetPing_Call{Call: _e.mock.On("GetPing", clientID, host, count, interval, timeout)} +} + +func (_c *SysProbeUtil_GetPing_Call) Run(run func(clientID string, host string, count int, interval time.Duration, timeout time.Duration)) *SysProbeUtil_GetPing_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string), args[2].(int), args[3].(time.Duration), args[4].(time.Duration)) + }) + return _c +} + +func (_c *SysProbeUtil_GetPing_Call) Return(_a0 []byte, _a1 error) *SysProbeUtil_GetPing_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetPing_Call) RunAndReturn(run func(string, string, int, time.Duration, time.Duration) ([]byte, error)) *SysProbeUtil_GetPing_Call { + _c.Call.Return(run) + return _c +} + +// GetPprof provides a mock function with given fields: path +func (_m *SysProbeUtil) GetPprof(path string) ([]byte, error) { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for GetPprof") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]byte, error)); ok { + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) []byte); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SysProbeUtil_GetPprof_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPprof' +type SysProbeUtil_GetPprof_Call struct { + *mock.Call +} + +// GetPprof is a helper method to define mock.On call +// - path string +func (_e *SysProbeUtil_Expecter) GetPprof(path interface{}) *SysProbeUtil_GetPprof_Call { + return &SysProbeUtil_GetPprof_Call{Call: _e.mock.On("GetPprof", path)} +} + +func (_c *SysProbeUtil_GetPprof_Call) Run(run func(path string)) *SysProbeUtil_GetPprof_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *SysProbeUtil_GetPprof_Call) Return(_a0 []byte, _a1 error) *SysProbeUtil_GetPprof_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetPprof_Call) RunAndReturn(run func(string) ([]byte, error)) *SysProbeUtil_GetPprof_Call { + _c.Call.Return(run) + return _c +} + // GetProcStats provides a mock function with given fields: pids func (_m *SysProbeUtil) GetProcStats(pids []int32) (*process.ProcStatsWithPermByPID, error) { ret := _m.Called(pids) @@ -101,6 +466,34 @@ func (_m *SysProbeUtil) GetProcStats(pids []int32) (*process.ProcStatsWithPermBy return r0, r1 } +// SysProbeUtil_GetProcStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetProcStats' +type SysProbeUtil_GetProcStats_Call struct { + *mock.Call +} + +// GetProcStats is a helper method to define mock.On call +// - pids []int32 +func (_e *SysProbeUtil_Expecter) GetProcStats(pids interface{}) *SysProbeUtil_GetProcStats_Call { + return &SysProbeUtil_GetProcStats_Call{Call: _e.mock.On("GetProcStats", pids)} +} + +func (_c *SysProbeUtil_GetProcStats_Call) Run(run func(pids []int32)) *SysProbeUtil_GetProcStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]int32)) + }) + return _c +} + +func (_c *SysProbeUtil_GetProcStats_Call) Return(_a0 *process.ProcStatsWithPermByPID, _a1 error) *SysProbeUtil_GetProcStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetProcStats_Call) RunAndReturn(run func([]int32) (*process.ProcStatsWithPermByPID, error)) *SysProbeUtil_GetProcStats_Call { + _c.Call.Return(run) + return _c +} + // GetStats provides a mock function with given fields: func (_m *SysProbeUtil) GetStats() (map[string]interface{}, error) { ret := _m.Called() @@ -131,6 +524,33 @@ func (_m *SysProbeUtil) GetStats() (map[string]interface{}, error) { return r0, r1 } +// SysProbeUtil_GetStats_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStats' +type SysProbeUtil_GetStats_Call struct { + *mock.Call +} + +// GetStats is a helper method to define mock.On call +func (_e *SysProbeUtil_Expecter) GetStats() *SysProbeUtil_GetStats_Call { + return &SysProbeUtil_GetStats_Call{Call: _e.mock.On("GetStats")} +} + +func (_c *SysProbeUtil_GetStats_Call) Run(run func()) *SysProbeUtil_GetStats_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *SysProbeUtil_GetStats_Call) Return(_a0 map[string]interface{}, _a1 error) *SysProbeUtil_GetStats_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetStats_Call) RunAndReturn(run func() (map[string]interface{}, error)) *SysProbeUtil_GetStats_Call { + _c.Call.Return(run) + return _c +} + // GetTelemetry provides a mock function with given fields: func (_m *SysProbeUtil) GetTelemetry() ([]byte, error) { ret := _m.Called() @@ -161,6 +581,96 @@ func (_m *SysProbeUtil) GetTelemetry() ([]byte, error) { return r0, r1 } +// SysProbeUtil_GetTelemetry_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTelemetry' +type SysProbeUtil_GetTelemetry_Call struct { + *mock.Call +} + +// GetTelemetry is a helper method to define mock.On call +func (_e *SysProbeUtil_Expecter) GetTelemetry() *SysProbeUtil_GetTelemetry_Call { + return &SysProbeUtil_GetTelemetry_Call{Call: _e.mock.On("GetTelemetry")} +} + +func (_c *SysProbeUtil_GetTelemetry_Call) Run(run func()) *SysProbeUtil_GetTelemetry_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *SysProbeUtil_GetTelemetry_Call) Return(_a0 []byte, _a1 error) *SysProbeUtil_GetTelemetry_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetTelemetry_Call) RunAndReturn(run func() ([]byte, error)) *SysProbeUtil_GetTelemetry_Call { + _c.Call.Return(run) + return _c +} + +// GetTraceroute provides a mock function with given fields: clientID, host, port, protocol, maxTTL, timeout +func (_m *SysProbeUtil) GetTraceroute(clientID string, host string, port uint16, protocol payload.Protocol, maxTTL uint8, timeout time.Duration) ([]byte, error) { + ret := _m.Called(clientID, host, port, protocol, maxTTL, timeout) + + if len(ret) == 0 { + panic("no return value specified for GetTraceroute") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string, string, uint16, payload.Protocol, uint8, time.Duration) ([]byte, error)); ok { + return rf(clientID, host, port, protocol, maxTTL, timeout) + } + if rf, ok := ret.Get(0).(func(string, string, uint16, payload.Protocol, uint8, time.Duration) []byte); ok { + r0 = rf(clientID, host, port, protocol, maxTTL, timeout) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(string, string, uint16, payload.Protocol, uint8, time.Duration) error); ok { + r1 = rf(clientID, host, port, protocol, maxTTL, timeout) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SysProbeUtil_GetTraceroute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTraceroute' +type SysProbeUtil_GetTraceroute_Call struct { + *mock.Call +} + +// GetTraceroute is a helper method to define mock.On call +// - clientID string +// - host string +// - port uint16 +// - protocol payload.Protocol +// - maxTTL uint8 +// - timeout time.Duration +func (_e *SysProbeUtil_Expecter) GetTraceroute(clientID interface{}, host interface{}, port interface{}, protocol interface{}, maxTTL interface{}, timeout interface{}) *SysProbeUtil_GetTraceroute_Call { + return &SysProbeUtil_GetTraceroute_Call{Call: _e.mock.On("GetTraceroute", clientID, host, port, protocol, maxTTL, timeout)} +} + +func (_c *SysProbeUtil_GetTraceroute_Call) Run(run func(clientID string, host string, port uint16, protocol payload.Protocol, maxTTL uint8, timeout time.Duration)) *SysProbeUtil_GetTraceroute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string), args[2].(uint16), args[3].(payload.Protocol), args[4].(uint8), args[5].(time.Duration)) + }) + return _c +} + +func (_c *SysProbeUtil_GetTraceroute_Call) Return(_a0 []byte, _a1 error) *SysProbeUtil_GetTraceroute_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SysProbeUtil_GetTraceroute_Call) RunAndReturn(run func(string, string, uint16, payload.Protocol, uint8, time.Duration) ([]byte, error)) *SysProbeUtil_GetTraceroute_Call { + _c.Call.Return(run) + return _c +} + // Register provides a mock function with given fields: clientID func (_m *SysProbeUtil) Register(clientID string) error { ret := _m.Called(clientID) @@ -179,6 +689,34 @@ func (_m *SysProbeUtil) Register(clientID string) error { return r0 } +// SysProbeUtil_Register_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Register' +type SysProbeUtil_Register_Call struct { + *mock.Call +} + +// Register is a helper method to define mock.On call +// - clientID string +func (_e *SysProbeUtil_Expecter) Register(clientID interface{}) *SysProbeUtil_Register_Call { + return &SysProbeUtil_Register_Call{Call: _e.mock.On("Register", clientID)} +} + +func (_c *SysProbeUtil_Register_Call) Run(run func(clientID string)) *SysProbeUtil_Register_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *SysProbeUtil_Register_Call) Return(_a0 error) *SysProbeUtil_Register_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *SysProbeUtil_Register_Call) RunAndReturn(run func(string) error) *SysProbeUtil_Register_Call { + _c.Call.Return(run) + return _c +} + // NewSysProbeUtil creates a new instance of SysProbeUtil. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewSysProbeUtil(t interface { diff --git a/pkg/process/net/shared.go b/pkg/process/net/shared.go index b54f7ab7087e7..4ebc5bd45a294 100644 --- a/pkg/process/net/shared.go +++ b/pkg/process/net/shared.go @@ -5,7 +5,20 @@ package net -import model "github.com/DataDog/agent-payload/v5/process" +import ( + "time" + + model "github.com/DataDog/agent-payload/v5/process" + + sysconfigtypes "github.com/DataDog/datadog-agent/cmd/system-probe/config/types" + discoverymodel "github.com/DataDog/datadog-agent/pkg/collector/corechecks/servicediscovery/model" + "github.com/DataDog/datadog-agent/pkg/languagedetection/languagemodels" + nppayload "github.com/DataDog/datadog-agent/pkg/networkpath/payload" +) + +// SysProbeUtilGetter is a function that returns a SysProbeUtil for the given path +// The standard implementation is GetRemoteSysProbeUtil +type SysProbeUtilGetter func(string) (SysProbeUtil, error) // SysProbeUtil fetches info from the SysProbe running remotely type SysProbeUtil interface { @@ -15,4 +28,10 @@ type SysProbeUtil interface { Register(clientID string) error GetNetworkID() (string, error) GetTelemetry() ([]byte, error) + DetectLanguage(pids []int32) ([]languagemodels.Language, error) + GetPprof(path string) ([]byte, error) + GetDiscoveryServices() (*discoverymodel.ServicesResponse, error) + GetCheck(module sysconfigtypes.ModuleName) (interface{}, error) + GetPing(clientID string, host string, count int, interval time.Duration, timeout time.Duration) ([]byte, error) + GetTraceroute(clientID string, host string, port uint16, protocol nppayload.Protocol, maxTTL uint8, timeout time.Duration) ([]byte, error) }