diff --git a/cmd/agent/subcommands/flare/command.go b/cmd/agent/subcommands/flare/command.go index baee2aa34ec49f..64fa370e1fc5f1 100644 --- a/cmd/agent/subcommands/flare/command.go +++ b/cmd/agent/subcommands/flare/command.go @@ -8,8 +8,11 @@ package flare import ( "bytes" + "context" "encoding/json" "fmt" + "net" + "net/http" "os" "path" @@ -45,7 +48,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/config/settings" - "github.com/DataDog/datadog-agent/pkg/process/net" "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/input" @@ -155,6 +157,13 @@ func readProfileData(seconds int) (flare.ProfileData, error) { pdata := flare.ProfileData{} c := util.GetClient(false) + sysProbeClient := &http.Client{ + Transport: &http.Transport{ + DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { + return net.Dial("unix", pkgconfig.SystemProbe.GetString("system_probe_config.sysprobe_socket")) + }, + }, + } type pprofGetter func(path string) ([]byte, error) @@ -166,13 +175,8 @@ func readProfileData(seconds int) (flare.ProfileData, error) { } sysProbeGet := func() pprofGetter { - probeUtil, err := net.GetRemoteSystemProbeUtil(pkgconfig.Datadog.GetString("system_probe_config.sysprobe_socket")) return func(path string) ([]byte, error) { - if err != nil { - return nil, err - } - - return probeUtil.GetPprof(path) + return util.DoGet(sysProbeClient, "http://unix/debug/pprof"+path, util.LeaveConnectionOpen) } } @@ -241,7 +245,7 @@ func readProfileData(seconds int) (flare.ProfileData, error) { agentCollectors["trace"] = serviceProfileCollector(tcpGet("apm_config.debug.port"), traceCpusec) } - if pkgconfig.Datadog.GetBool("system_probe_config.enabled") { + if pkgconfig.SystemProbe.GetBool("system_probe_config.enabled") { agentCollectors["system-probe"] = serviceProfileCollector(sysProbeGet(), seconds) } diff --git a/cmd/agent/subcommands/flare/command_test.go b/cmd/agent/subcommands/flare/command_test.go index a40e1379001225..8731cb7bab5322 100644 --- a/cmd/agent/subcommands/flare/command_test.go +++ b/cmd/agent/subcommands/flare/command_test.go @@ -36,8 +36,6 @@ func getPprofTestServer(t *testing.T) (tcpServer *httptest.Server, unixServer *h w.Write([]byte("mutex")) case "/debug/pprof/block": w.Write([]byte("block")) - case "/debug/stats": // for system-probe only - w.WriteHeader(200) default: w.WriteHeader(500) } @@ -71,8 +69,10 @@ func TestReadProfileData(t *testing.T) { mockConfig.SetWithoutSource("apm_config.receiver_timeout", "10") mockConfig.SetWithoutSource("process_config.expvar_port", port) mockConfig.SetWithoutSource("security_agent.expvar_port", port) - mockConfig.SetWithoutSource("system_probe_config.enabled", true) - mockConfig.SetWithoutSource("system_probe_config.sysprobe_socket", sysprobeSockPath) + + mockSysProbeConfig := config.MockSystemProbe(t) + mockSysProbeConfig.SetWithoutSource("system_probe_config.enabled", true) + mockSysProbeConfig.SetWithoutSource("system_probe_config.sysprobe_socket", sysprobeSockPath) data, err := readProfileData(10) require.NoError(t, err) @@ -129,8 +129,10 @@ func TestReadProfileDataNoTraceAgent(t *testing.T) { mockConfig.SetWithoutSource("apm_config.receiver_timeout", "10") mockConfig.SetWithoutSource("process_config.expvar_port", port) mockConfig.SetWithoutSource("security_agent.expvar_port", port) - mockConfig.SetWithoutSource("system_probe_config.enabled", true) - mockConfig.SetWithoutSource("system_probe_config.sysprobe_socket", sysprobeSockPath) + + mockSysProbeConfig := config.MockSystemProbe(t) + mockSysProbeConfig.SetWithoutSource("system_probe_config.enabled", true) + mockSysProbeConfig.SetWithoutSource("system_probe_config.sysprobe_socket", sysprobeSockPath) data, err := readProfileData(10) require.Error(t, err) diff --git a/pkg/process/net/common.go b/pkg/process/net/common.go index 11fab91da21b69..ffc4c8ea62c68e 100644 --- a/pkg/process/net/common.go +++ b/pkg/process/net/common.go @@ -338,24 +338,6 @@ func (r *RemoteSysProbeUtil) DetectLanguage(pids []int32) ([]languagemodels.Lang return langs, nil } -// GetPprof queries the pprof endpoint for system-probe -func (r *RemoteSysProbeUtil) GetPprof(path string) ([]byte, error) { - var buf bytes.Buffer - req, err := http.NewRequest(http.MethodGet, pprofURL+path, &buf) - if err != nil { - return nil, err - } - - res, err := r.httpClient.Do(req) - if err != nil { - return nil, err - } - - defer res.Body.Close() - - return io.ReadAll(res.Body) -} - func (r *RemoteSysProbeUtil) init() error { resp, err := r.httpClient.Get(statsURL) if err != nil {