Skip to content

Commit

Permalink
Extend reporter interface to support symbol upload (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
athre0z authored and rockdaboot committed Aug 7, 2024
1 parent 1b4c0ea commit cac5730
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
8 changes: 6 additions & 2 deletions interpreter/dotnet/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"fmt"
"hash/fnv"
"os"
"path"
"slices"
"strings"
Expand Down Expand Up @@ -630,8 +631,11 @@ func (i *dotnetInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler,
info.simpleName, info.guid)

if !info.reported {
symbolReporter.ExecutableMetadata(context.TODO(),
info.fileID, path.Base(m.Path), info.guid)
open := func() (process.ReadAtCloser, error) {
return os.Open(m.Path)
}
symbolReporter.ExecutableMetadata(context.TODO(), info.fileID, path.Base(m.Path),
info.guid, libpf.Dotnet, open)
info.reported = true
}

Expand Down
3 changes: 2 additions & 1 deletion processmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ type symbolReporterMockup struct{}

func (s *symbolReporterMockup) ReportFallbackSymbol(_ libpf.FrameID, _ string) {}

func (s *symbolReporterMockup) ExecutableMetadata(_ context.Context, _ libpf.FileID, _, _ string) {
func (s *symbolReporterMockup) ExecutableMetadata(_ context.Context, _ libpf.FileID, _, _ string,
_ libpf.InterpreterType, _ reporter.ExecutableOpener) {
}

func (s *symbolReporterMockup) FrameMetadata(_ libpf.FileID, _ libpf.AddressOrLineno,
Expand Down
6 changes: 5 additions & 1 deletion processmanager/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ func (pm *ProcessManager) getELFInfo(pr process.Process, mapping *process.Mappin
}

buildID, _ := ef.GetBuildID()
pm.reporter.ExecutableMetadata(context.TODO(), fileID, baseName, buildID)
mapping2 := *mapping // copy to avoid races if callee saves the closure
open := func() (process.ReadAtCloser, error) {
return pr.OpenMappingFile(&mapping2)
}
pm.reporter.ExecutableMetadata(context.TODO(), fileID, baseName, buildID, libpf.Native, open)

return info
}
Expand Down
11 changes: 10 additions & 1 deletion reporter/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/elastic/otel-profiling-agent/libpf"
"github.com/elastic/otel-profiling-agent/process"
"github.com/elastic/otel-profiling-agent/util"
)

Expand Down Expand Up @@ -48,13 +49,21 @@ type TraceReporter interface {
SupportsReportTraceEvent() bool
}

type ExecutableOpener = func() (process.ReadAtCloser, error)

type SymbolReporter interface {
// ReportFallbackSymbol enqueues a fallback symbol for reporting, for a given frame.
ReportFallbackSymbol(frameID libpf.FrameID, symbol string)

// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information before a periodic reporting to the backend.
ExecutableMetadata(ctx context.Context, fileID libpf.FileID, fileName, buildID string)
//
// The `open` argument can be used to open the executable for reading. Interpreters
// that don't support this may pass a `nil` function pointer. Implementations that
// wish to upload executables should NOT block this function to do so and instead just
// open the file and then enqueue the upload in the background.
ExecutableMetadata(ctx context.Context, fileID libpf.FileID, fileName, buildID string,
interp libpf.InterpreterType, open ExecutableOpener)

// FrameMetadata accepts metadata associated with a frame and caches this information before
// a periodic reporting to the backend.
Expand Down
4 changes: 2 additions & 2 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (r *OTLPReporter) ReportFallbackSymbol(frameID libpf.FrameID, symbol string

// ExecutableMetadata accepts a fileID with the corresponding filename
// and caches this information.
func (r *OTLPReporter) ExecutableMetadata(_ context.Context,
fileID libpf.FileID, fileName, buildID string) {
func (r *OTLPReporter) ExecutableMetadata(_ context.Context, fileID libpf.FileID, fileName,
buildID string, _ libpf.InterpreterType, _ ExecutableOpener) {
r.executables.Add(fileID, execInfo{
fileName: fileName,
buildID: buildID,
Expand Down
3 changes: 2 additions & 1 deletion tools/coredump/coredump.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"unsafe"

cebpf "github.com/cilium/ebpf"
"github.com/elastic/otel-profiling-agent/reporter"

"github.com/elastic/otel-profiling-agent/config"
"github.com/elastic/otel-profiling-agent/libpf"
Expand Down Expand Up @@ -65,7 +66,7 @@ func newSymbolizationCache() *symbolizationCache {
}

func (c *symbolizationCache) ExecutableMetadata(_ context.Context, fileID libpf.FileID,
fileName, _ string) {
fileName, _ string, _ libpf.InterpreterType, _ reporter.ExecutableOpener) {
c.files[fileID] = fileName
}

Expand Down
9 changes: 6 additions & 3 deletions tracer/ebpf_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
cebpf "github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"

"github.com/elastic/otel-profiling-agent/libpf"
"github.com/elastic/otel-profiling-agent/config"
"github.com/elastic/otel-profiling-agent/host"
hostmeta "github.com/elastic/otel-profiling-agent/hostmetadata/host"
"github.com/elastic/otel-profiling-agent/libpf"
"github.com/elastic/otel-profiling-agent/reporter"
"github.com/elastic/otel-profiling-agent/rlimit"
"github.com/elastic/otel-profiling-agent/support"
"github.com/elastic/otel-profiling-agent/util"
Expand Down Expand Up @@ -97,8 +98,10 @@ func (f mockIntervals) PIDCleanupInterval() time.Duration { return 1 * time.Seco

type mockReporter struct{}

func (f mockReporter) ExecutableMetadata(_ context.Context, _ libpf.FileID, _, _ string) {}
func (f mockReporter) ReportFallbackSymbol(_ libpf.FrameID, _ string) {}
func (f mockReporter) ExecutableMetadata(_ context.Context, _ libpf.FileID, _, _ string,
_ libpf.InterpreterType, _ reporter.ExecutableOpener) {
}
func (f mockReporter) ReportFallbackSymbol(_ libpf.FrameID, _ string) {}
func (f mockReporter) FrameMetadata(_ libpf.FileID, _ libpf.AddressOrLineno, _ util.SourceLineno,
_ uint32, _, _ string) {
}
Expand Down
2 changes: 1 addition & 1 deletion tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func processKernelModulesMetadata(ctx context.Context,
}

result[nameStr] = fileID
rep.ExecutableMetadata(ctx, fileID, nameStr, buildID)
rep.ExecutableMetadata(ctx, fileID, nameStr, buildID, libpf.Kernel, nil)
})

return result, nil
Expand Down

0 comments on commit cac5730

Please sign in to comment.