Skip to content

Commit

Permalink
[EBPF] Use SysProbeUtil interface instead of RemoteSysProbeUtil imple…
Browse files Browse the repository at this point in the history
…mentation (#30130)
  • Loading branch information
gjulianm authored Oct 15, 2024
1 parent cf88543 commit 5d1e132
Show file tree
Hide file tree
Showing 13 changed files with 603 additions and 83 deletions.
6 changes: 4 additions & 2 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/ebpf/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 4 additions & 13 deletions pkg/collector/corechecks/servicediscovery/impl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
}

type linuxImpl struct {
getSysProbeClient func() (systemProbeClient, error)
getSysProbeClient processnet.SysProbeUtilGetter
time timer

ignoreCfg map[string]bool
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"),
)
}
57 changes: 0 additions & 57 deletions pkg/collector/corechecks/servicediscovery/impl_linux_mock.go

This file was deleted.

6 changes: 4 additions & 2 deletions pkg/collector/corechecks/servicediscovery/impl_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/process/checks/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/process/checks/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/process/checks/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/process/checks/process_rt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion pkg/process/net/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion pkg/process/net/common_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
}

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

0 comments on commit 5d1e132

Please sign in to comment.