Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/inject/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/instrumentation/bpf/net/http/server/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/instrumentation/bpffs/bpfsfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
20 changes: 10 additions & 10 deletions internal/pkg/instrumentation/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
40 changes: 20 additions & 20 deletions internal/pkg/instrumentation/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

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

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

Expand All @@ -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)
})
}
Expand Down Expand Up @@ -205,17 +205,17 @@ 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
}
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
Expand Down Expand Up @@ -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) }()
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}

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

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

Expand Down
Loading
Loading