diff --git a/tracer/ebpf_integration_test.go b/tracer/ebpf_integration_test.go index 331b5deb..e5b5bc00 100644 --- a/tracer/ebpf_integration_test.go +++ b/tracer/ebpf_integration_test.go @@ -14,6 +14,7 @@ import ( cebpf "github.com/cilium/ebpf" "github.com/cilium/ebpf/link" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -244,3 +245,11 @@ Loop: }) } } + +func TestAllTracers(t *testing.T) { + coll, err := support.LoadCollectionSpec(false) + require.NoError(t, err) + + _, _, err = initializeMapsAndPrograms(coll, tracertypes.AllTracers(), nil, false, 1, false, 0) + require.NoError(t, err) +} diff --git a/tracer/tracer.go b/tracer/tracer.go index f3e3f8ee..388d2007 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -266,10 +266,20 @@ func NewTracer(ctx context.Context, cfg *Config) (*Tracer, error) { return nil, fmt.Errorf("failed to read kernel symbols: %v", err) } + // Loading specifications about eBPF programs and maps from the embedded elf file + // does not load them into the kernel. + // A collection specification holds the information about eBPF programs and maps. + // References to eBPF maps in the eBPF programs are just placeholders that need to be + // replaced by the actual loaded maps later on with RewriteMaps before loading the + // programs into the kernel. + coll, err := support.LoadCollectionSpec(cfg.DebugTracer) + if err != nil { + return nil, fmt.Errorf("failed to load specification for tracers: %v", err) + } + // Based on includeTracers we decide later which are loaded into the kernel. - ebpfMaps, ebpfProgs, err := initializeMapsAndPrograms(cfg.IncludeTracers, kernelSymbols, - cfg.FilterErrorFrames, cfg.MapScaleFactor, cfg.KernelVersionCheck, cfg.DebugTracer, - cfg.BPFVerifierLogLevel) + ebpfMaps, ebpfProgs, err := initializeMapsAndPrograms(coll, cfg.IncludeTracers, kernelSymbols, + cfg.FilterErrorFrames, cfg.MapScaleFactor, cfg.KernelVersionCheck, cfg.BPFVerifierLogLevel) if err != nil { return nil, fmt.Errorf("failed to load eBPF code: %v", err) } @@ -369,20 +379,10 @@ func buildStackDeltaTemplates(coll *cebpf.CollectionSpec) error { // initializeMapsAndPrograms loads the definitions for the eBPF maps and programs provided // by the embedded elf file and loads these into the kernel. -func initializeMapsAndPrograms(includeTracers types.IncludedTracers, +func initializeMapsAndPrograms(coll *cebpf.CollectionSpec, includeTracers types.IncludedTracers, kernelSymbols *libpf.SymbolMap, filterErrorFrames bool, mapScaleFactor int, - kernelVersionCheck bool, debugTracer bool, bpfVerifierLogLevel uint32) ( + kernelVersionCheck bool, bpfVerifierLogLevel uint32) ( ebpfMaps map[string]*cebpf.Map, ebpfProgs map[string]*cebpf.Program, err error) { - // Loading specifications about eBPF programs and maps from the embedded elf file - // does not load them into the kernel. - // A collection specification holds the information about eBPF programs and maps. - // References to eBPF maps in the eBPF programs are just placeholders that need to be - // replaced by the actual loaded maps later on with RewriteMaps before loading the - // programs into the kernel. - coll, err := support.LoadCollectionSpec(debugTracer) - if err != nil { - return nil, nil, fmt.Errorf("failed to load specification for tracers: %v", err) - } err = buildStackDeltaTemplates(coll) if err != nil { diff --git a/tracer/types/parse.go b/tracer/types/parse.go index fbe7787a..eee3a8df 100644 --- a/tracer/types/parse.go +++ b/tracer/types/parse.go @@ -156,3 +156,11 @@ func Parse(tracers string) (IncludedTracers, error) { return result, nil } + +// AllTracers is a shortcut that returns an element with all +// tracers enabled. +func AllTracers() IncludedTracers { + var result IncludedTracers + result.enableAll() + return result +}