Skip to content

Commit abfbfb8

Browse files
committed
plugins: rename tracers
Implement the idea shared in #1388 (comment). Overall, rename package `interpreter` to `plugins` and promote a plugin specific configuration. Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
1 parent 49a1a4f commit abfbfb8

84 files changed

Lines changed: 606 additions & 422 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ clean:
6262
@go clean -cache -i
6363
@$(MAKE) -s -C support/ebpf clean
6464
@chmod -Rf u+w go/ || true
65-
@rm -rf go .cache support/*.test interpreter/golabels/integrationtests/pprof_1_*
65+
@rm -rf go .cache support/*.test plugins/golabels/integrationtests/pprof_1_*
6666
@rm -f otelcol-ebpf-profiler cmd/otelcol-ebpf-profiler/{*.go,go.mod,go.sum} || true
6767
@cargo clean
6868

@@ -149,30 +149,30 @@ test-deps:
149149
($(MAKE) -C "$(testdata_dir)") || exit ; \
150150
)
151151

152-
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support interpreter/golabels/integrationtests
152+
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support plugins/golabels/integrationtests
153153

154154
pprof-execs: pprof_1_23 pprof_1_24 pprof_1_24_cgo pprof_1_24_cgo_pie pprof_stable pprof_stable_cgo pprof_stable_cgo_pie
155155

156156
pprof_1_23:
157-
CGO_ENABLED=0 GOTOOLCHAIN=go1.23.7 go test -C ./interpreter/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
157+
CGO_ENABLED=0 GOTOOLCHAIN=go1.23.7 go test -C ./plugins/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
158158

159159
pprof_1_24:
160-
CGO_ENABLED=0 GOTOOLCHAIN=go1.24.6 go test -C ./interpreter/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
160+
CGO_ENABLED=0 GOTOOLCHAIN=go1.24.6 go test -C ./plugins/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
161161

162162
pprof_1_24_cgo:
163-
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.6 go test -C ./interpreter/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -tags $(GO_TAGS),withcgo,integration -o ./../$@
163+
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.6 go test -C ./plugins/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -tags $(GO_TAGS),withcgo,integration -o ./../$@
164164

165165
pprof_1_24_cgo_pie:
166-
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.6 go test -C ./interpreter/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -buildmode=pie -tags $(GO_TAGS),withcgo,integration -o ./../$@
166+
CGO_ENABLED=1 GOTOOLCHAIN=go1.24.6 go test -C ./plugins/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -buildmode=pie -tags $(GO_TAGS),withcgo,integration -o ./../$@
167167

168168
pprof_stable:
169-
CGO_ENABLED=0 go test -C ./interpreter/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
169+
CGO_ENABLED=0 go test -C ./plugins/golabels/integrationtests/pprof -c -trimpath -tags $(GO_TAGS),nocgo,integration -o ./../$@
170170

171171
pprof_stable_cgo:
172-
CGO_ENABLED=1 go test -C ./interpreter/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -tags $(GO_TAGS),withcgo,integration -o ./../$@
172+
CGO_ENABLED=1 go test -C ./plugins/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -tags $(GO_TAGS),withcgo,integration -o ./../$@
173173

174174
pprof_stable_cgo_pie:
175-
CGO_ENABLED=1 go test -C ./interpreter/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -buildmode=pie -tags $(GO_TAGS),withcgo,integration -o ./../$@
175+
CGO_ENABLED=1 go test -C ./plugins/golabels/integrationtests/pprof -c -ldflags '-extldflags "-static"' -trimpath -buildmode=pie -tags $(GO_TAGS),withcgo,integration -o ./../$@
176176

177177
integration-test-binaries: generate ebpf pprof-execs
178178
$(foreach test_name, $(TEST_INTEGRATION_BINARY_DIRS), \

cli_flags.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ var (
4141
copyrightHelp = "Show copyright and short license text."
4242
collAgentAddrHelp = "The collection agent address in the format of host:port."
4343
verboseModeHelp = "Enable verbose logging and debugging capabilities."
44-
tracersHelp = "Comma-separated list of interpreter tracers to include."
4544
mapScaleFactorHelp = fmt.Sprintf("Scaling factor for eBPF map sizes. "+
4645
"Every increase by 1 doubles the map size. Increase if you see eBPF map size errors. "+
4746
"Default is %d corresponding to 4GB of executable address space, max is %d.",
@@ -133,9 +132,6 @@ func parseArgs() (*controller.Config, error) {
133132
sendErrorFramesHelp)
134133
fs.BoolVar(&args.SendIdleFrames, "send-idle-frames", false, sendIdleFramesHelp)
135134

136-
fs.StringVar(&args.Tracers, "t", "all", "Shorthand for -tracers.")
137-
fs.StringVar(&args.Tracers, "tracers", "all", tracersHelp)
138-
139135
fs.BoolVar(&args.VerboseMode, "v", false, "Shorthand for -verbose.")
140136
fs.BoolVar(&args.VerboseMode, "verbose", false, verboseModeHelp)
141137
fs.BoolVar(&args.Version, "version", false, versionHelp)

collector/config/config.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"go.opentelemetry.io/ebpf-profiler/internal/linux"
13+
"go.opentelemetry.io/ebpf-profiler/plugins"
1314
"go.opentelemetry.io/ebpf-profiler/tracer"
1415
)
1516

@@ -41,29 +42,29 @@ func (e *ErrorMode) UnmarshalText(text []byte) error {
4142

4243
// Config is the configuration for the collector.
4344
type Config struct {
44-
ReporterInterval time.Duration `mapstructure:"reporter_interval"`
45-
ReporterJitter float64 `mapstructure:"reporter_jitter"`
46-
MonitorInterval time.Duration `mapstructure:"monitor_interval"`
47-
SamplesPerSecond int `mapstructure:"samples_per_second"`
48-
ProbabilisticInterval time.Duration `mapstructure:"probabilistic_interval"`
49-
ProbabilisticThreshold uint `mapstructure:"probabilistic_threshold"`
50-
Tracers string `mapstructure:"tracers"`
51-
ClockSyncInterval time.Duration `mapstructure:"clock_sync_interval"`
52-
SendErrorFrames bool `mapstructure:"send_error_frames"`
53-
SendIdleFrames bool `mapstructure:"send_idle_frames"`
54-
VerboseMode bool `mapstructure:"verbose_mode"`
55-
OffCPUThreshold float64 `mapstructure:"off_cpu_threshold"`
56-
IncludeEnvVars string `mapstructure:"include_env_vars"`
57-
ProbeLinks []string `mapstructure:"probe_links"`
58-
LoadProbe bool `mapstructure:"load_probe"`
59-
MapScaleFactor uint `mapstructure:"map_scale_factor"`
60-
BPFVerifierLogLevel uint `mapstructure:"bpf_verifier_log_level"`
61-
NoKernelVersionCheck bool `mapstructure:"no_kernel_version_check"`
62-
MaxGRPCRetries uint32 `mapstructure:"max_grpc_retries"`
63-
MaxRPCMsgSize int `mapstructure:"max_rpc_msg_size"`
64-
BPFFSRoot string `mapstructure:"bpf_fs_root"`
65-
ErrorMode ErrorMode `mapstructure:"error_mode"`
66-
OBIProcessCtx bool `mapstructure:"obi_process_ctx"`
45+
ReporterInterval time.Duration `mapstructure:"reporter_interval"`
46+
ReporterJitter float64 `mapstructure:"reporter_jitter"`
47+
MonitorInterval time.Duration `mapstructure:"monitor_interval"`
48+
SamplesPerSecond int `mapstructure:"samples_per_second"`
49+
ProbabilisticInterval time.Duration `mapstructure:"probabilistic_interval"`
50+
ProbabilisticThreshold uint `mapstructure:"probabilistic_threshold"`
51+
Plugins plugins.PluginsConfig `mapstructure:"plugins"`
52+
ClockSyncInterval time.Duration `mapstructure:"clock_sync_interval"`
53+
SendErrorFrames bool `mapstructure:"send_error_frames"`
54+
SendIdleFrames bool `mapstructure:"send_idle_frames"`
55+
VerboseMode bool `mapstructure:"verbose_mode"`
56+
OffCPUThreshold float64 `mapstructure:"off_cpu_threshold"`
57+
IncludeEnvVars string `mapstructure:"include_env_vars"`
58+
ProbeLinks []string `mapstructure:"probe_links"`
59+
LoadProbe bool `mapstructure:"load_probe"`
60+
MapScaleFactor uint `mapstructure:"map_scale_factor"`
61+
BPFVerifierLogLevel uint `mapstructure:"bpf_verifier_log_level"`
62+
NoKernelVersionCheck bool `mapstructure:"no_kernel_version_check"`
63+
MaxGRPCRetries uint32 `mapstructure:"max_grpc_retries"`
64+
MaxRPCMsgSize int `mapstructure:"max_rpc_msg_size"`
65+
BPFFSRoot string `mapstructure:"bpf_fs_root"`
66+
ErrorMode ErrorMode `mapstructure:"error_mode"`
67+
OBIProcessCtx bool `mapstructure:"obi_process_ctx"`
6768
}
6869

6970
// Validate validates the config.

collector/factory.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"go.opentelemetry.io/ebpf-profiler/collector/config"
1717
"go.opentelemetry.io/ebpf-profiler/collector/internal/metadata"
18+
"go.opentelemetry.io/ebpf-profiler/plugins"
1819
)
1920

2021
var errInvalidConfig = errors.New("invalid config")
@@ -35,7 +36,7 @@ func defaultConfig() component.Config {
3536
SamplesPerSecond: 20,
3637
ProbabilisticInterval: 1 * time.Minute,
3738
ProbabilisticThreshold: 100,
38-
Tracers: "all",
39+
Plugins: plugins.AllPluginsConfig(),
3940
ClockSyncInterval: 3 * time.Minute,
4041
MaxGRPCRetries: 5,
4142
MaxRPCMsgSize: 32 << 20, // 32 MiB,

collector/internal/metadata/generated_status.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/controller.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"go.opentelemetry.io/ebpf-profiler/reporter"
1717
"go.opentelemetry.io/ebpf-profiler/times"
1818
"go.opentelemetry.io/ebpf-profiler/tracer"
19-
tracertypes "go.opentelemetry.io/ebpf-profiler/tracer/types"
2019
)
2120

2221
const MiB = 1 << 20
@@ -71,13 +70,7 @@ func (c *Controller) Start(ctx context.Context) error {
7170
// Start periodic synchronization with the realtime clock
7271
times.StartRealtimeSync(ctx, c.config.ClockSyncInterval)
7372

74-
log.Debugf("Determining tracers to include")
75-
includeTracers, err := tracertypes.Parse(c.config.Tracers)
76-
if err != nil {
77-
return fmt.Errorf("failed to parse the included tracers: %w", err)
78-
}
79-
80-
err = c.reporter.Start(ctx)
73+
err := c.reporter.Start(ctx)
8174
if err != nil {
8275
return fmt.Errorf("failed to start reporter: %w", err)
8376
}
@@ -94,7 +87,7 @@ func (c *Controller) Start(ctx context.Context) error {
9487
trc, err := tracer.NewTracer(ctx, &tracer.Config{
9588
TraceReporter: c.reporter,
9689
Intervals: intervals,
97-
IncludeTracers: includeTracers,
90+
PluginsConfig: c.config.Plugins,
9891
FilterErrorFrames: !c.config.SendErrorFrames,
9992
FilterIdleFrames: !c.config.SendIdleFrames,
10093
SamplesPerSecond: c.config.SamplesPerSecond,

interpreter/golabels/integrationtests/pprof/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// libraries, establishes socket connections with them and notifies them about
66
// the stack traces that we collected for their process. This allows the APM
77
// agent to associate stack traces with APM traces / transactions / spans.
8-
package apmint // import "go.opentelemetry.io/ebpf-profiler/interpreter/apmint"
8+
package apmint // import "go.opentelemetry.io/ebpf-profiler/plugins/apmint"
99

1010
import (
1111
"encoding/hex"
@@ -16,10 +16,10 @@ import (
1616

1717
"go.opentelemetry.io/ebpf-profiler/internal/log"
1818

19-
"go.opentelemetry.io/ebpf-profiler/interpreter"
2019
"go.opentelemetry.io/ebpf-profiler/libpf"
2120
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
2221
"go.opentelemetry.io/ebpf-profiler/libpf/pfunsafe"
22+
"go.opentelemetry.io/ebpf-profiler/plugins"
2323
"go.opentelemetry.io/ebpf-profiler/remotememory"
2424
"go.opentelemetry.io/ebpf-profiler/support"
2525
)
@@ -51,8 +51,8 @@ type apmProcessStorage struct {
5151
TraceSocketPath string
5252
}
5353

54-
// Loader implements interpreter.Loader.
55-
func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpreter.Data, error) {
54+
// Loader implements plugins.Loader.
55+
func Loader(_ plugins.EbpfHandler, info *plugins.LoaderInfo) (plugins.Data, error) {
5656
if !isPotentialAgentLib(info.FileName()) {
5757
return nil, nil
5858
}
@@ -104,15 +104,19 @@ type data struct {
104104
procStorageElfVA libpf.Address
105105
}
106106

107-
var _ interpreter.Data = &data{}
107+
var _ plugins.Data = &data{}
108108

109109
func (d data) String() string {
110110
return "APM integration"
111111
}
112112

113-
func (d data) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
114-
bias libpf.Address, rm remotememory.RemoteMemory,
115-
) (interpreter.Instance, error) {
113+
func (d data) Attach(ebpf plugins.EbpfHandler, pid libpf.PID,
114+
bias libpf.Address, rm remotememory.RemoteMemory, cfg plugins.Config,
115+
) (plugins.Instance, error) {
116+
if cfg.(plugins.BaseConfig).IsDisabled() {
117+
return nil, plugins.ErrPluginDisabled
118+
}
119+
116120
procStorage, err := readProcStorage(rm, bias+d.procStorageElfVA)
117121
if err != nil {
118122
return nil, fmt.Errorf("failed to read APM correlation process storage: %s", err)
@@ -143,19 +147,19 @@ func (d data) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
143147
}, nil
144148
}
145149

146-
func (d data) Unload(_ interpreter.EbpfHandler) {
150+
func (d data) Unload(_ plugins.EbpfHandler) {
147151
}
148152

149153
type Instance struct {
150154
serviceName string
151155
socket *apmAgentSocket
152-
interpreter.InstanceStubs
156+
plugins.InstanceStubs
153157
}
154158

155-
var _ interpreter.Instance = &Instance{}
159+
var _ plugins.Instance = &Instance{}
156160

157-
// Detach implements the interpreter.Instance interface.
158-
func (i *Instance) Detach(ebpf interpreter.EbpfHandler, pid libpf.PID) error {
161+
// Detach implements the plugins.Instance interface.
162+
func (i *Instance) Detach(ebpf plugins.EbpfHandler, pid libpf.PID) error {
159163
return ebpf.DeleteProcData(libpf.APMInt, pid)
160164
}
161165

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package apmint // import "go.opentelemetry.io/ebpf-profiler/interpreter/apmint"
4+
package apmint // import "go.opentelemetry.io/ebpf-profiler/plugins/apmint"
55

66
import (
77
"bufio"
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package beam // import "go.opentelemetry.io/ebpf-profiler/interpreter/beam"
4+
package beam // import "go.opentelemetry.io/ebpf-profiler/plugins/beam"
55

66
// BEAM VM Unwinder support code
77

@@ -21,9 +21,9 @@ import (
2121
"go.opentelemetry.io/ebpf-profiler/libpf/pfunsafe"
2222
npsr "go.opentelemetry.io/ebpf-profiler/nopanicslicereader"
2323

24-
"go.opentelemetry.io/ebpf-profiler/interpreter"
2524
"go.opentelemetry.io/ebpf-profiler/libpf"
2625
"go.opentelemetry.io/ebpf-profiler/lpm"
26+
"go.opentelemetry.io/ebpf-profiler/plugins"
2727
"go.opentelemetry.io/ebpf-profiler/process"
2828
"go.opentelemetry.io/ebpf-profiler/remotememory"
2929
"go.opentelemetry.io/ebpf-profiler/reporter"
@@ -32,9 +32,9 @@ import (
3232

3333
var (
3434
// regex for matching the process name
35-
beamRegex = regexp.MustCompile(`(^|\/)beam\.smp`)
36-
_ interpreter.Data = &beamData{}
37-
_ interpreter.Instance = &beamInstance{}
35+
beamRegex = regexp.MustCompile(`(^|\/)beam\.smp`)
36+
_ plugins.Data = &beamData{}
37+
_ plugins.Instance = &beamInstance{}
3838
)
3939

4040
type beamData struct {
@@ -112,7 +112,7 @@ type beamMfa struct {
112112
}
113113

114114
type beamInstance struct {
115-
interpreter.InstanceStubs
115+
plugins.InstanceStubs
116116

117117
pid libpf.PID
118118
data *beamData
@@ -129,7 +129,7 @@ type beamInstance struct {
129129
mappingGeneration uint32
130130
}
131131

132-
func Loader(ebpf interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interpreter.Data, error) {
132+
func Loader(ebpf plugins.EbpfHandler, info *plugins.LoaderInfo) (plugins.Data, error) {
133133
matches := beamRegex.FindStringSubmatch(info.FileName())
134134
if matches == nil {
135135
return nil, nil
@@ -282,7 +282,11 @@ func hashMFA(key beamMfa) uint32 {
282282
return uint32(hash.Uint64(uint64(mfhash)<<32 | uint64(key.arity)))
283283
}
284284

285-
func (d *beamData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libpf.Address, rm remotememory.RemoteMemory) (interpreter.Instance, error) {
285+
func (d *beamData) Attach(ebpf plugins.EbpfHandler, pid libpf.PID, bias libpf.Address, rm remotememory.RemoteMemory, cfg plugins.Config) (plugins.Instance, error) {
286+
if cfg.(plugins.BEAMConfig).IsDisabled() {
287+
return nil, plugins.ErrPluginDisabled
288+
}
289+
286290
log.Debugf("BEAM attaching, OTP %d, ERTS %s, bias: 0x%x", d.otpRelease, d.ertsVersion, bias)
287291

288292
data := support.BEAMProcInfo{
@@ -304,19 +308,19 @@ func (d *beamData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libp
304308
}
305309

306310
atomCache, err := freelru.New[uint32, libpf.String](
307-
interpreter.LruFunctionCacheSize, hash.Uint32)
311+
plugins.LruFunctionCacheSize, hash.Uint32)
308312
if err != nil {
309313
return nil, err
310314
}
311315

312316
mfaNameCache, err := freelru.New[beamMfa, libpf.String](
313-
interpreter.LruFunctionCacheSize, hashMFA)
317+
plugins.LruFunctionCacheSize, hashMFA)
314318
if err != nil {
315319
return nil, err
316320
}
317321

318322
stringCache, err := freelru.New[libpf.Address, libpf.String](
319-
interpreter.LruFunctionCacheSize, libpf.Address.Hash32)
323+
plugins.LruFunctionCacheSize, libpf.Address.Hash32)
320324
if err != nil {
321325
return nil, err
322326
}
@@ -334,10 +338,10 @@ func (d *beamData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID, bias libp
334338
}, nil
335339
}
336340

337-
func (d *beamData) Unload(_ interpreter.EbpfHandler) {
341+
func (d *beamData) Unload(_ plugins.EbpfHandler) {
338342
}
339343

340-
func (i *beamInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler, _ reporter.ExecutableReporter, pr process.Process, mappings []process.RawMapping) error {
344+
func (i *beamInstance) SynchronizeMappings(ebpf plugins.EbpfHandler, _ reporter.ExecutableReporter, pr process.Process, mappings []process.RawMapping) error {
341345
pid := pr.PID()
342346
i.mappingGeneration++
343347
for idx := range mappings {
@@ -379,13 +383,13 @@ func (i *beamInstance) SynchronizeMappings(ebpf interpreter.EbpfHandler, _ repor
379383
return nil
380384
}
381385

382-
func (i *beamInstance) Detach(interpreter.EbpfHandler, libpf.PID) error {
386+
func (i *beamInstance) Detach(plugins.EbpfHandler, libpf.PID) error {
383387
return nil
384388
}
385389

386390
func (i *beamInstance) Symbolize(ef libpf.EbpfFrame, frames *libpf.Frames, _ libpf.FrameMapping) error {
387391
if !ef.Type().IsInterpType(libpf.BEAM) {
388-
return interpreter.ErrMismatchInterpreterType
392+
return plugins.ErrMismatchInterpreterType
389393
}
390394
pc := libpf.Address(ef.Data())
391395
codeHeader := libpf.Address(ef.Variable(0))

0 commit comments

Comments
 (0)