Skip to content

Commit

Permalink
service discovery: Use pclntab symbol extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
guyarb committed Sep 8, 2024
1 parent 329610a commit 5afa2bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
12 changes: 8 additions & 4 deletions pkg/collector/corechecks/servicediscovery/apm/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ func goDetector(pid int, _ []string, _ map[string]string, _ usm.DetectorContextM
}
defer elfFile.Close()

_, err = bininspect.GetAnySymbolWithPrefix(elfFile, ddTraceGoPrefix, ddTraceGoMaxLength)
if err != nil {
return None
if _, err = bininspect.GetAnySymbolWithPrefix(elfFile, ddTraceGoPrefix, ddTraceGoMaxLength); err == nil {
return Provided
}

return Provided
// We failed to find symbols in the regular symbols section, now we can try the pclntab
if _, err = bininspect.GetAnySymbolWithPrefixPCLNTAB(elfFile, ddTraceGoPrefix, ddTraceGoMaxLength); err == nil {
return Provided
}
return None

}

func pythonDetectorFromMapsReader(reader io.Reader) Instrumentation {
Expand Down
21 changes: 16 additions & 5 deletions pkg/collector/corechecks/servicediscovery/apm/detect_nix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,29 @@ func Test_pythonDetector(t *testing.T) {
func TestGoDetector(t *testing.T) {
curDir, err := testutil.CurDir()
require.NoError(t, err)
serverBin, err := usmtestutil.BuildGoBinaryWrapper(filepath.Join(curDir, "testutil"), "instrumented")
serverBinWithSymbols, err := usmtestutil.BuildGoBinaryWrapper(filepath.Join(curDir, "testutil"), "instrumented")
require.NoError(t, err)
serverBinWithoutSymbols, err := usmtestutil.BuildGoBinaryWrapperWithoutSymbols(filepath.Join(curDir, "testutil"), "instrumented")
require.NoError(t, err)

cmdWithSymbols := exec.Command(serverBinWithSymbols)
require.NoError(t, cmdWithSymbols.Start())
t.Cleanup(func() {
_ = cmdWithSymbols.Process.Kill()
})

cmd := exec.Command(serverBin)
require.NoError(t, cmd.Start())
cmdWithoutSymbols := exec.Command(serverBinWithoutSymbols)
require.NoError(t, cmdWithoutSymbols.Start())
t.Cleanup(func() {
_ = cmd.Process.Kill()
_ = cmdWithoutSymbols.Process.Kill()
})

result := goDetector(os.Getpid(), nil, nil, nil)
require.Equal(t, result, None)

result = goDetector(cmd.Process.Pid, nil, nil, nil)
result = goDetector(cmdWithSymbols.Process.Pid, nil, nil, nil)
require.Equal(t, result, Provided)

result = goDetector(cmdWithoutSymbols.Process.Pid, nil, nil, nil)
require.Equal(t, result, Provided)
}

0 comments on commit 5afa2bc

Please sign in to comment.