Skip to content

Commit

Permalink
Don't use RemoteSysProbeUtil for getting profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
hmahmood committed Apr 23, 2024
1 parent fcde5ff commit 7307422
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
20 changes: 12 additions & 8 deletions cmd/agent/subcommands/flare/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ package flare

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"os"
"path"

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

Expand All @@ -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)
}
}

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

Expand Down
14 changes: 8 additions & 6 deletions cmd/agent/subcommands/flare/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions pkg/process/net/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7307422

Please sign in to comment.