diff --git a/instrumentation.go b/instrumentation.go index 023cfb5f3b..314c6a6a53 100644 --- a/instrumentation.go +++ b/instrumentation.go @@ -47,7 +47,7 @@ const ( // Instrumentation manages and controls all OpenTelemetry Go // auto-instrumentation. type Instrumentation struct { - target *process.TargetDetails + target *process.Info analyzer *process.Analyzer manager *instrumentation.Manager diff --git a/internal/pkg/inject/consts.go b/internal/pkg/inject/consts.go index 5337e0d420..b3aac1c970 100644 --- a/internal/pkg/inject/consts.go +++ b/internal/pkg/inject/consts.go @@ -148,8 +148,8 @@ func WithOffset(key string, id structfield.ID, ver *semver.Version) Option { return WithKeyValue(key, off.Offset) } -func FindOffset(id structfield.ID, td *process.TargetDetails) (structfield.OffsetKey, error) { - fd, err := td.OpenExe() +func FindOffset(id structfield.ID, info *process.Info) (structfield.OffsetKey, error) { + fd, err := info.OpenExe() if err != nil { return structfield.OffsetKey{}, err } diff --git a/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go b/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go index 4cdef93cbf..bad9b4f574 100644 --- a/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go +++ b/internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go @@ -257,8 +257,8 @@ type tracerIDContainsSchemaURL struct{} // https://github.com/open-telemetry/opentelemetry-go/pull/5426/files var schemaAddedToTracerKeyVer = semver.New(1, 28, 0, "", "") -func (c tracerIDContainsSchemaURL) InjectOption(td *process.TargetDetails) (inject.Option, error) { - ver, ok := td.Modules["go.opentelemetry.io/otel"] +func (c tracerIDContainsSchemaURL) InjectOption(info *process.Info) (inject.Option, error) { + ver, ok := info.Modules["go.opentelemetry.io/otel"] if !ok { return nil, fmt.Errorf("unknown module version: %s", pkg) } @@ -273,8 +273,8 @@ var scopeAttributesAddedToTracerKeyVer = semver.New(1, 32, 0, "", "") // tracerIDContainsScopeAttributes is a Probe Const defining whether the tracer key contains scope attributes. type tracerIDContainsScopeAttributes struct{} -func (c tracerIDContainsScopeAttributes) InjectOption(td *process.TargetDetails) (inject.Option, error) { - ver, ok := td.Modules["go.opentelemetry.io/otel"] +func (c tracerIDContainsScopeAttributes) InjectOption(info *process.Info) (inject.Option, error) { + ver, ok := info.Modules["go.opentelemetry.io/otel"] if !ok { return nil, fmt.Errorf("unknown module version: %s", pkg) } diff --git a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go index 0e3a94d2d7..a1bff0d13f 100644 --- a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go +++ b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/client/probe.go @@ -41,8 +41,8 @@ var ( type writeStatusConst struct{} -func (w writeStatusConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - ver, ok := td.Modules[pkg] +func (w writeStatusConst) InjectOption(info *process.Info) (inject.Option, error) { + ver, ok := info.Modules[pkg] if !ok { return nil, fmt.Errorf("unknown module version: %s", pkg) } diff --git a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go index 213e3f90d7..0f194fe558 100644 --- a/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go +++ b/internal/pkg/instrumentation/bpf/google.golang.org/grpc/server/probe.go @@ -198,8 +198,8 @@ type framePosConst struct{} // https://github.com/grpc/grpc-go/pull/6716/files#diff-4058722211b8d52e2d5b0c0b7542059ed447a04017b69520d767e94a9493409eR334 var paramChangeVer = semver.New(1, 60, 0, "", "") -func (c framePosConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - ver, ok := td.Modules[pkg] +func (c framePosConst) InjectOption(info *process.Info) (inject.Option, error) { + ver, ok := info.Modules[pkg] if !ok { return nil, fmt.Errorf("unknown module version: %s", pkg) } @@ -214,8 +214,8 @@ var ( serverAddr = false ) -func (w serverAddrConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - ver, ok := td.Modules[pkg] +func (w serverAddrConst) InjectOption(info *process.Info) (inject.Option, error) { + ver, ok := info.Modules[pkg] if !ok { return nil, fmt.Errorf("unknown module version: %s", pkg) } diff --git a/internal/pkg/instrumentation/bpf/net/http/server/probe.go b/internal/pkg/instrumentation/bpf/net/http/server/probe.go index ee66760324..fa3bbb2f58 100644 --- a/internal/pkg/instrumentation/bpf/net/http/server/probe.go +++ b/internal/pkg/instrumentation/bpf/net/http/server/probe.go @@ -151,15 +151,15 @@ var ( isPatternPathSupported = false ) -func (c patternPathSupportedConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - isPatternPathSupported = td.GoVersion.GreaterThanEqual(patternPathMinVersion) +func (c patternPathSupportedConst) InjectOption(info *process.Info) (inject.Option, error) { + isPatternPathSupported = info.GoVersion.GreaterThanEqual(patternPathMinVersion) return inject.WithKeyValue("pattern_path_supported", isPatternPathSupported), nil } type swissMapsUsedConst struct{} -func (c swissMapsUsedConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - isUsingGoSwissMaps := td.GoVersion.GreaterThanEqual(goMapsVersion) +func (c swissMapsUsedConst) InjectOption(info *process.Info) (inject.Option, error) { + isUsingGoSwissMaps := info.GoVersion.GreaterThanEqual(goMapsVersion) return inject.WithKeyValue("swiss_maps_used", isUsingGoSwissMaps), nil } diff --git a/internal/pkg/instrumentation/bpffs/bpfsfs_linux.go b/internal/pkg/instrumentation/bpffs/bpfsfs_linux.go index 85539eb8c8..a228b648ee 100644 --- a/internal/pkg/instrumentation/bpffs/bpfsfs_linux.go +++ b/internal/pkg/instrumentation/bpffs/bpfsfs_linux.go @@ -16,12 +16,12 @@ import ( const bpfFsPath = "/sys/fs/bpf" // PathForTargetApplication returns the path to the BPF file-system for the given target. -func PathForTargetApplication(target *process.TargetDetails) string { +func PathForTargetApplication(target *process.Info) string { return fmt.Sprintf("%s/%d", bpfFsPath, target.PID) } // Mount mounts the BPF file-system for the given target. -func Mount(target *process.TargetDetails) error { +func Mount(target *process.Info) error { if !isBPFFSMounted() { // Directory does not exist, create it and mount if err := os.MkdirAll(bpfFsPath, 0o755); err != nil { @@ -49,6 +49,6 @@ func isBPFFSMounted() bool { } // Cleanup removes the BPF file-system for the given target. -func Cleanup(target *process.TargetDetails) error { +func Cleanup(target *process.Info) error { return os.RemoveAll(PathForTargetApplication(target)) } diff --git a/internal/pkg/instrumentation/manager.go b/internal/pkg/instrumentation/manager.go index 7858e3fbc2..9f06556018 100644 --- a/internal/pkg/instrumentation/manager.go +++ b/internal/pkg/instrumentation/manager.go @@ -56,7 +56,7 @@ type Manager struct { globalImpl bool cp ConfigProvider exe *link.Executable - td *process.TargetDetails + proc *process.Info stop context.CancelCauseFunc runningProbesWG sync.WaitGroup currentConfig Config @@ -130,7 +130,7 @@ func (m *Manager) GetRelevantFuncs() map[string]interface{} { // FilterUnusedProbes filterers probes whose functions are already instrumented // out of the Manager. -func (m *Manager) FilterUnusedProbes(target *process.TargetDetails) { +func (m *Manager) FilterUnusedProbes(target *process.Info) { existingFuncMap := make(map[string]interface{}) for _, f := range target.Functions { existingFuncMap[f.Name] = nil @@ -184,7 +184,7 @@ func isProbeEnabled(id probe.ID, c Config) bool { } func (m *Manager) applyConfig(c Config) error { - if m.td == nil { + if m.proc == nil { return errors.New("failed to apply config: target details not set") } if m.exe == nil { @@ -211,7 +211,7 @@ func (m *Manager) applyConfig(c Config) error { if !currentlyEnabled && newEnabled { m.logger.Info("Enabling probe", "id", id) - err = errors.Join(err, p.Load(m.exe, m.td, c.SamplingConfig)) + err = errors.Join(err, p.Load(m.exe, m.proc, c.SamplingConfig)) if err == nil { m.runProbe(p) } @@ -250,7 +250,7 @@ func (m *Manager) ConfigLoop(ctx context.Context) { } } -func (m *Manager) Load(ctx context.Context, target *process.TargetDetails) error { +func (m *Manager) Load(ctx context.Context, target *process.Info) error { if len(m.probes) == 0 { return errors.New("no instrumentation for target process") } @@ -273,7 +273,7 @@ func (m *Manager) Load(ctx context.Context, target *process.TargetDetails) error return err } - m.td = target + m.proc = target m.state = managerStateLoaded return nil @@ -343,7 +343,7 @@ func (m *Manager) Stop() error { defer m.probeMu.Unlock() m.logger.Debug("Shutting down all probes") - err := m.cleanup(m.td) + err := m.cleanup(m.proc) // Wait for all probes to stop. m.runningProbesWG.Wait() @@ -352,7 +352,7 @@ func (m *Manager) Stop() error { return err } -func (m *Manager) loadProbes(target *process.TargetDetails) error { +func (m *Manager) loadProbes(target *process.Info) error { // Remove resource limits for kernels <5.11. if err := rlimitRemoveMemlock(); err != nil { return err @@ -384,7 +384,7 @@ func (m *Manager) loadProbes(target *process.TargetDetails) error { return nil } -func (m *Manager) mount(target *process.TargetDetails) error { +func (m *Manager) mount(target *process.Info) error { if target.AllocationDetails != nil { m.logger.Debug("Mounting bpffs", "allocations_details", target.AllocationDetails) } else { @@ -393,7 +393,7 @@ func (m *Manager) mount(target *process.TargetDetails) error { return bpffsMount(target) } -func (m *Manager) cleanup(target *process.TargetDetails) error { +func (m *Manager) cleanup(target *process.Info) error { ctx := context.Background() err := m.cp.Shutdown(context.Background()) for _, i := range m.probes { diff --git a/internal/pkg/instrumentation/manager_test.go b/internal/pkg/instrumentation/manager_test.go index afb4d31af5..1079438b66 100644 --- a/internal/pkg/instrumentation/manager_test.go +++ b/internal/pkg/instrumentation/manager_test.go @@ -35,14 +35,14 @@ func TestProbeFiltering(t *testing.T) { t.Run("empty target details", func(t *testing.T) { m := fakeManager(t) - td := process.TargetDetails{ + info := process.Info{ PID: 1, Functions: []*binary.Func{}, GoVersion: ver, Modules: map[string]*semver.Version{}, AllocationDetails: nil, } - m.FilterUnusedProbes(&td) + m.FilterUnusedProbes(&info) assert.Empty(t, m.probes) }) @@ -53,14 +53,14 @@ func TestProbeFiltering(t *testing.T) { {Name: "net/http.(*Transport).roundTrip"}, } - td := process.TargetDetails{ + info := process.Info{ PID: 1, Functions: httpFuncs, GoVersion: ver, Modules: map[string]*semver.Version{}, AllocationDetails: nil, } - m.FilterUnusedProbes(&td) + m.FilterUnusedProbes(&info) assert.Len(t, m.probes, 1) // one function, single probe }) @@ -72,14 +72,14 @@ func TestProbeFiltering(t *testing.T) { {Name: "net/http.serverHandler.ServeHTTP"}, } - td := process.TargetDetails{ + info := process.Info{ PID: 1, Functions: httpFuncs, GoVersion: ver, Modules: map[string]*semver.Version{}, AllocationDetails: nil, } - m.FilterUnusedProbes(&td) + m.FilterUnusedProbes(&info) assert.Len(t, m.probes, 2) }) @@ -92,14 +92,14 @@ func TestProbeFiltering(t *testing.T) { {Name: "net/http.serverHandler.ServeHTTP"}, } - td := process.TargetDetails{ + info := process.Info{ PID: 1, Functions: httpFuncs, GoVersion: ver, Modules: map[string]*semver.Version{}, AllocationDetails: nil, } - m.FilterUnusedProbes(&td) + m.FilterUnusedProbes(&info) assert.Len(t, m.probes, 1) }) } @@ -205,8 +205,8 @@ func mockExeAndBpffs(t *testing.T) { t.Cleanup(func() { rlimitRemoveMemlock = origRlimitRemoveMemlock }) origBpffsMount := bpffsMount - bpffsMount = func(td *process.TargetDetails) error { - if td == nil { + bpffsMount = func(info *process.Info) error { + if info == nil { return errors.New("target is nil in Mount") } return nil @@ -214,8 +214,8 @@ func mockExeAndBpffs(t *testing.T) { t.Cleanup(func() { bpffsMount = origBpffsMount }) origBpffsCleanup := bpffsCleanup - bpffsCleanup = func(td *process.TargetDetails) error { - if td == nil { + bpffsCleanup = func(info *process.Info) error { + if info == nil { return errors.New("target is nil in Cleanup") } return nil @@ -254,7 +254,7 @@ func TestRunStoppingByContext(t *testing.T) { ctx, stopCtx := context.WithCancel(context.Background()) errCh := make(chan error, 1) - err = m.Load(ctx, &process.TargetDetails{PID: 1000}) + err = m.Load(ctx, &process.Info{PID: 1000}) require.NoError(t, err) go func() { errCh <- m.Run(ctx) }() @@ -303,7 +303,7 @@ func TestRunStoppingByStop(t *testing.T) { ctx := context.Background() errCh := make(chan error, 1) - err = m.Load(ctx, &process.TargetDetails{PID: 1000}) + err = m.Load(ctx, &process.Info{PID: 1000}) require.NoError(t, err) time.AfterFunc(100*time.Millisecond, func() { @@ -339,7 +339,7 @@ func newSlowProbe(stop chan struct{}) slowProbe { } } -func (p slowProbe) Load(*link.Executable, *process.TargetDetails, *sampling.Config) error { +func (p slowProbe) Load(*link.Executable, *process.Info, *sampling.Config) error { return nil } @@ -358,7 +358,7 @@ type noopProbe struct { var _ probe.Probe = (*noopProbe)(nil) -func (p *noopProbe) Load(*link.Executable, *process.TargetDetails, *sampling.Config) error { +func (p *noopProbe) Load(*link.Executable, *process.Info, *sampling.Config) error { p.loaded.Store(true) return nil } @@ -433,7 +433,7 @@ func TestConfigProvider(t *testing.T) { mockExeAndBpffs(t) runCtx, cancel := context.WithCancel(context.Background()) - err := m.Load(runCtx, &process.TargetDetails{PID: 1000}) + err := m.Load(runCtx, &process.Info{PID: 1000}) require.NoError(t, err) runErr := make(chan error, 1) @@ -532,7 +532,7 @@ func newHangingProbe() *hangingProbe { return &hangingProbe{closeReturned: make(chan struct{})} } -func (p *hangingProbe) Load(*link.Executable, *process.TargetDetails, *sampling.Config) error { +func (p *hangingProbe) Load(*link.Executable, *process.Info, *sampling.Config) error { return nil } @@ -567,7 +567,7 @@ func TestRunStopDeadlock(t *testing.T) { ctx, stopCtx := context.WithCancel(context.Background()) errCh := make(chan error, 1) - err = m.Load(ctx, &process.TargetDetails{PID: 1000}) + err = m.Load(ctx, &process.Info{PID: 1000}) require.NoError(t, err) go func() { errCh <- m.Run(ctx) }() @@ -632,7 +632,7 @@ func TestStopBeforeRun(t *testing.T) { mockExeAndBpffs(t) - err = m.Load(context.Background(), &process.TargetDetails{PID: 1000}) + err = m.Load(context.Background(), &process.Info{PID: 1000}) require.NoError(t, err) require.True(t, p.loaded.Load()) diff --git a/internal/pkg/instrumentation/probe/probe.go b/internal/pkg/instrumentation/probe/probe.go index e766e9e0b8..9c8c485a9b 100644 --- a/internal/pkg/instrumentation/probe/probe.go +++ b/internal/pkg/instrumentation/probe/probe.go @@ -40,7 +40,7 @@ type Probe interface { // It also attaches the eBPF programs to the target process. // TODO: currently passing Sampler as an initial configuration - this will be // updated to a more generic configuration in the future. - Load(*link.Executable, *process.TargetDetails, *sampling.Config) error + Load(*link.Executable, *process.Info, *sampling.Config) error // Run runs the events processing loop. Run(func(ptrace.ScopeSpans)) @@ -115,23 +115,23 @@ func (i *Base[BPFObj, BPFEvent]) Spec() (*ebpf.CollectionSpec, error) { } // Load loads all instrumentation offsets. -func (i *Base[BPFObj, BPFEvent]) Load(exec *link.Executable, td *process.TargetDetails, sampler *sampling.Config) error { +func (i *Base[BPFObj, BPFEvent]) Load(exec *link.Executable, info *process.Info, sampler *sampling.Config) error { spec, err := i.SpecFn() if err != nil { return err } - err = i.InjectConsts(td, spec) + err = i.InjectConsts(info, spec) if err != nil { return err } - i.collection, err = i.buildEBPFCollection(td, spec) + i.collection, err = i.buildEBPFCollection(info, spec) if err != nil { return err } - err = i.loadUprobes(exec, td) + err = i.loadUprobes(exec, info) if err != nil { return err } @@ -151,7 +151,7 @@ func (i *Base[BPFObj, BPFEvent]) Load(exec *link.Executable, td *process.TargetD return nil } -func (i *Base[BPFObj, BPFEvent]) InjectConsts(td *process.TargetDetails, spec *ebpf.CollectionSpec) error { +func (i *Base[BPFObj, BPFEvent]) InjectConsts(info *process.Info, spec *ebpf.CollectionSpec) error { var err error var opts []inject.Option for _, cnst := range i.Consts { @@ -159,7 +159,7 @@ func (i *Base[BPFObj, BPFEvent]) InjectConsts(td *process.TargetDetails, spec *e cnst = l.SetLogger(i.Logger) } - o, e := cnst.InjectOption(td) + o, e := cnst.InjectOption(info) err = errors.Join(err, e) if e == nil && o != nil { opts = append(opts, o) @@ -172,11 +172,11 @@ func (i *Base[BPFObj, BPFEvent]) InjectConsts(td *process.TargetDetails, spec *e return inject.Constants(spec, opts...) } -func (i *Base[BPFObj, BPFEvent]) loadUprobes(exec *link.Executable, td *process.TargetDetails) error { +func (i *Base[BPFObj, BPFEvent]) loadUprobes(exec *link.Executable, info *process.Info) error { for _, up := range i.Uprobes { var skip bool for _, pc := range up.PackageConstraints { - if pc.Constraints.Check(td.Modules[pc.Package]) { + if pc.Constraints.Check(info.Modules[pc.Package]) { continue } @@ -188,7 +188,7 @@ func (i *Base[BPFObj, BPFEvent]) loadUprobes(exec *link.Executable, td *process. logFn = i.Logger.Warn default: // Unknown and FailureModeError. - return fmt.Errorf("uprobe %s package constraint (%s) not met, version %v", up.Sym, pc.Constraints.String(), td.Modules[pc.Package]) + return fmt.Errorf("uprobe %s package constraint (%s) not met, version %v", up.Sym, pc.Constraints.String(), info.Modules[pc.Package]) } logFn( @@ -197,7 +197,7 @@ func (i *Base[BPFObj, BPFEvent]) loadUprobes(exec *link.Executable, td *process. "symbol", up.Sym, "package", pc.Package, "constraint", pc.Constraints.String(), - "version", td.Modules[pc.Package], + "version", info.Modules[pc.Package], ) skip = true @@ -207,7 +207,7 @@ func (i *Base[BPFObj, BPFEvent]) loadUprobes(exec *link.Executable, td *process. continue } - err := up.load(exec, td, i.collection) + err := up.load(exec, info, i.collection) if err != nil { var logFn func(string, ...any) switch up.FailureMode { @@ -241,7 +241,7 @@ func (i *Base[BPFObj, BPFEvent]) initReader() error { return nil } -func (i *Base[BPFObj, BPFEvent]) buildEBPFCollection(td *process.TargetDetails, spec *ebpf.CollectionSpec) (*ebpf.Collection, error) { +func (i *Base[BPFObj, BPFEvent]) buildEBPFCollection(info *process.Info, spec *ebpf.CollectionSpec) (*ebpf.Collection, error) { obj := new(BPFObj) if c, ok := ((interface{})(obj)).(io.Closer); ok { i.closers = append(i.closers, c) @@ -249,7 +249,7 @@ func (i *Base[BPFObj, BPFEvent]) buildEBPFCollection(td *process.TargetDetails, sOpts := &ebpf.CollectionOptions{ Maps: ebpf.MapOptions{ - PinPath: bpffs.PathForTargetApplication(td), + PinPath: bpffs.PathForTargetApplication(info), }, } c, err := utils.InitializeEBPFCollection(spec, sOpts) @@ -383,8 +383,8 @@ type Uprobe struct { closers atomic.Pointer[[]io.Closer] } -func (u *Uprobe) load(exec *link.Executable, target *process.TargetDetails, c *ebpf.Collection) error { - offset, err := target.GetFunctionOffset(u.Sym) +func (u *Uprobe) load(exec *link.Executable, info *process.Info, c *ebpf.Collection) error { + offset, err := info.GetFunctionOffset(u.Sym) if err != nil { return err } @@ -396,7 +396,7 @@ func (u *Uprobe) load(exec *link.Executable, target *process.TargetDetails, c *e if !ok { return fmt.Errorf("entry probe %s not found", u.EntryProbe) } - opts := &link.UprobeOptions{Address: offset, PID: target.PID} + opts := &link.UprobeOptions{Address: offset, PID: info.PID} l, err := exec.Uprobe("", entryProg, opts) if err != nil { return err @@ -409,13 +409,13 @@ func (u *Uprobe) load(exec *link.Executable, target *process.TargetDetails, c *e if !ok { return fmt.Errorf("return probe %s not found", u.ReturnProbe) } - retOffsets, err := target.GetFunctionReturns(u.Sym) + retOffsets, err := info.GetFunctionReturns(u.Sym) if err != nil { return err } for _, ret := range retOffsets { - opts := &link.UprobeOptions{Address: ret, PID: target.PID} + opts := &link.UprobeOptions{Address: ret, PID: info.PID} l, err := exec.Uprobe("", retProg, opts) if err != nil { return err @@ -455,7 +455,7 @@ func (u *Uprobe) Close() error { type Const interface { // InjectOption returns the inject.Option to run for the Const when running // inject.Constants. - InjectOption(td *process.TargetDetails) (inject.Option, error) + InjectOption(*process.Info) (inject.Option, error) } type setLogger interface { @@ -482,8 +482,8 @@ func (c StructFieldConst) SetLogger(l *slog.Logger) Const { // InjectOption returns the appropriately configured [inject.WithOffset] if the // version of the struct field module is known. If it is not, an error is // returned. -func (c StructFieldConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - ver, ok := td.Modules[c.ID.ModPath] +func (c StructFieldConst) InjectOption(info *process.Info) (inject.Option, error) { + ver, ok := info.Modules[c.ID.ModPath] if !ok { return nil, fmt.Errorf("unknown module: %s", c.ID.ModPath) } @@ -499,7 +499,7 @@ func (c StructFieldConst) InjectOption(td *process.TargetDetails) (inject.Option } var err error - off, err = inject.FindOffset(c.ID, td) + off, err = inject.FindOffset(c.ID, info) if err != nil { return nil, fmt.Errorf("failed to find offset for %q: %w", c.ID, err) } @@ -529,9 +529,9 @@ type StructFieldConstMaxVersion struct { // If the module version is not known, an error is returned. If the module // version is known but is greater than or equal to the MaxVersion, no offset // is injected. -func (c StructFieldConstMaxVersion) InjectOption(td *process.TargetDetails) (inject.Option, error) { +func (c StructFieldConstMaxVersion) InjectOption(info *process.Info) (inject.Option, error) { sf := c.StructField - ver, ok := td.Modules[sf.ID.ModPath] + ver, ok := info.Modules[sf.ID.ModPath] if !ok { return nil, fmt.Errorf("unknown module version: %s", sf.ID.ModPath) } @@ -540,7 +540,7 @@ func (c StructFieldConstMaxVersion) InjectOption(td *process.TargetDetails) (inj return nil, nil } - return sf.InjectOption(td) + return sf.InjectOption(info) } // StructFieldConstMinVersion is a [Const] for a struct field offset. These struct field @@ -556,9 +556,9 @@ type StructFieldConstMinVersion struct { // the MinVersion. If the module version is not known, an error is returned. // If the module version is known but is less than the MinVersion, no offset is // injected. -func (c StructFieldConstMinVersion) InjectOption(td *process.TargetDetails) (inject.Option, error) { +func (c StructFieldConstMinVersion) InjectOption(info *process.Info) (inject.Option, error) { sf := c.StructField - ver, ok := td.Modules[sf.ID.ModPath] + ver, ok := info.Modules[sf.ID.ModPath] if !ok { return nil, fmt.Errorf("unknown module version: %s", sf.ID.ModPath) } @@ -567,7 +567,7 @@ func (c StructFieldConstMinVersion) InjectOption(td *process.TargetDetails) (inj return nil, nil } - return sf.InjectOption(td) + return sf.InjectOption(info) } // AllocationConst is a [Const] for all the allocation details that need to be @@ -577,11 +577,11 @@ type AllocationConst struct{} // InjectOption returns the appropriately configured // [inject.WithAllocationDetails] if the [process.AllocationDetails] within td // are not nil. An error is returned if [process.AllocationDetails] is nil. -func (c AllocationConst) InjectOption(td *process.TargetDetails) (inject.Option, error) { - if td.AllocationDetails == nil { +func (c AllocationConst) InjectOption(info *process.Info) (inject.Option, error) { + if info.AllocationDetails == nil { return nil, errors.New("no allocation details") } - return inject.WithAllocationDetails(*td.AllocationDetails), nil + return inject.WithAllocationDetails(*info.AllocationDetails), nil } // KeyValConst is a [Const] for a generic key-value pair. @@ -595,6 +595,6 @@ type KeyValConst struct { } // InjectOption returns the appropriately configured [inject.WithKeyValue]. -func (c KeyValConst) InjectOption(*process.TargetDetails) (inject.Option, error) { +func (c KeyValConst) InjectOption(*process.Info) (inject.Option, error) { return inject.WithKeyValue(c.Key, c.Val), nil } diff --git a/internal/pkg/instrumentation/testutils/testutils.go b/internal/pkg/instrumentation/testutils/testutils.go index c64c26d8c6..41dd9c3d90 100644 --- a/internal/pkg/instrumentation/testutils/testutils.go +++ b/internal/pkg/instrumentation/testutils/testutils.go @@ -21,7 +21,7 @@ var testGoVersion = semver.New(1, 22, 1, "", "") type TestProbe interface { Spec() (*ebpf.CollectionSpec, error) - InjectConsts(td *process.TargetDetails, spec *ebpf.CollectionSpec) error + InjectConsts(*process.Info, *ebpf.CollectionSpec) error } func ProbesLoad(t *testing.T, p TestProbe, libs map[string]*semver.Version) { @@ -30,7 +30,7 @@ func ProbesLoad(t *testing.T, p TestProbe, libs map[string]*semver.Version) { return } - td := &process.TargetDetails{ + info := &process.Info{ PID: 1, AllocationDetails: &process.AllocationDetails{ StartAddr: 140434497441792, @@ -42,15 +42,15 @@ func ProbesLoad(t *testing.T, p TestProbe, libs map[string]*semver.Version) { GoVersion: testGoVersion, } for k, v := range libs { - td.Modules[k] = v + info.Modules[k] = v } - err = bpffs.Mount(td) + err = bpffs.Mount(info) if !assert.NoError(t, err) { return } defer func() { - _ = bpffs.Cleanup(td) + _ = bpffs.Cleanup(info) }() spec, err := p.Spec() @@ -61,14 +61,14 @@ func ProbesLoad(t *testing.T, p TestProbe, libs map[string]*semver.Version) { // Inject the same constants as the BPF program. // It is important to inject the same constants as those that will be used in the actual run, // since From Linux 5.5 the verifier will use constants to eliminate dead code. - err = p.InjectConsts(td, spec) + err = p.InjectConsts(info, spec) if !assert.NoError(t, err) { return } opts := ebpf.CollectionOptions{ Maps: ebpf.MapOptions{ - PinPath: bpffs.PathForTargetApplication(td), + PinPath: bpffs.PathForTargetApplication(info), }, } diff --git a/internal/pkg/process/analyze.go b/internal/pkg/process/analyze.go index 553a60eac5..435fd979a3 100644 --- a/internal/pkg/process/analyze.go +++ b/internal/pkg/process/analyze.go @@ -16,8 +16,8 @@ import ( "go.opentelemetry.io/auto/internal/pkg/process/binary" ) -// TargetDetails are the details about a target function. -type TargetDetails struct { +// Info are the details about a target process. +type Info struct { PID int Functions []*binary.Func GoVersion *semver.Version @@ -26,8 +26,8 @@ type TargetDetails struct { } // GetFunctionOffset returns the offset for of the function with name. -func (t *TargetDetails) GetFunctionOffset(name string) (uint64, error) { - for _, f := range t.Functions { +func (i *Info) GetFunctionOffset(name string) (uint64, error) { + for _, f := range i.Functions { if f.Name == name { return f.Offset, nil } @@ -38,8 +38,8 @@ func (t *TargetDetails) GetFunctionOffset(name string) (uint64, error) { // GetFunctionReturns returns the return value of the call for the function // with name. -func (t *TargetDetails) GetFunctionReturns(name string) ([]uint64, error) { - for _, f := range t.Functions { +func (i *Info) GetFunctionReturns(name string) ([]uint64, error) { + for _, f := range i.Functions { if f.Name == name { return f.ReturnOffsets, nil } @@ -49,14 +49,14 @@ func (t *TargetDetails) GetFunctionReturns(name string) ([]uint64, error) { } // OpenExe opens the executable of the target process for reading. -func (t *TargetDetails) OpenExe() (*os.File, error) { - path := fmt.Sprintf("/proc/%d/exe", t.PID) +func (i *Info) OpenExe() (*os.File, error) { + path := fmt.Sprintf("/proc/%d/exe", i.PID) return os.Open(path) } // Analyze returns the target details for an actively running process. -func (a *Analyzer) Analyze(pid int, relevantFuncs map[string]interface{}) (*TargetDetails, error) { - result := &TargetDetails{PID: pid} +func (a *Analyzer) Analyze(pid int, relevantFuncs map[string]interface{}) (*Info, error) { + result := &Info{PID: pid} f, err := result.OpenExe() if err != nil {