Skip to content

Commit

Permalink
Using ddebpf.Manager instead of manager.Manager in all relevant locat…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
DanielLavie committed Dec 19, 2024
1 parent 4fa3910 commit 2d27f50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
12 changes: 6 additions & 6 deletions pkg/network/protocols/events/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const defaultPerfHandlerSize = 100
// This essentially instantiates the perf map/ring buffers and configure the
// eBPF maps where events are enqueued.
// Note this must be called *before* manager.InitWithOptions
func Configure(cfg *config.Config, proto string, m *manager.Manager, o *manager.Options) {
func Configure(cfg *config.Config, proto string, m *ddebpf.Manager, o *manager.Options) {
if alreadySetUp(proto, m) {
return
}
Expand All @@ -63,7 +63,7 @@ func Configure(cfg *config.Config, proto string, m *manager.Manager, o *manager.
}
}

func setupPerfMap(proto string, m *manager.Manager) {
func setupPerfMap(proto string, m *ddebpf.Manager) {
handler := ddebpf.NewPerfHandler(defaultPerfHandlerSize)
mapName := eventMapName(proto)
pm := &manager.PerfMap{
Expand All @@ -90,7 +90,7 @@ func setupPerfMap(proto string, m *manager.Manager) {
setHandler(proto, handler)
}

func setupPerfRing(proto string, m *manager.Manager, o *manager.Options, numCPUs int) {
func setupPerfRing(proto string, m *ddebpf.Manager, o *manager.Options, numCPUs int) {
handler := ddebpf.NewRingBufferHandler(defaultPerfHandlerSize)
mapName := eventMapName(proto)
ringBufferSize := toPowerOf2(numCPUs * defaultPerfEventBufferSize)
Expand Down Expand Up @@ -155,12 +155,12 @@ func eventMapName(proto string) string {
// *However* in some instances this is not working on 4.14, so here we
// essentially replace `bpf_ringbuf_output` helper calls by a noop operation so
// they don't result in verifier errors even when deadcode elimination fails.
func removeRingBufferHelperCalls(m *manager.Manager) {
func removeRingBufferHelperCalls(m *ddebpf.Manager) {
// TODO: this is not the intended API usage of a `ebpf.Modifier`.
// Once we have access to the `ddebpf.Manager`, add this modifier to its list of
// `EnabledModifiers` and let it control the execution of the callbacks
patcher := ddebpf.NewHelperCallRemover(asm.FnRingbufOutput)
err := patcher.BeforeInit(m, names.NewModuleName("usm"), nil)
err := patcher.BeforeInit(m.Manager, names.NewModuleName("usm"), nil)

if err != nil {
// Our production code is actually loading on all Kernels we test on CI
Expand All @@ -178,7 +178,7 @@ func removeRingBufferHelperCalls(m *manager.Manager) {
}
}

func alreadySetUp(proto string, m *manager.Manager) bool {
func alreadySetUp(proto string, m *ddebpf.Manager) bool {
// check if we already have configured this perf map this can happen in the
// context of a failed program load succeeded by another attempt
mapName := eventMapName(proto)
Expand Down
6 changes: 2 additions & 4 deletions pkg/network/protocols/events/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"sync"
"unsafe"

manager "github.com/DataDog/ebpf-manager"

ddebpf "github.com/DataDog/datadog-agent/pkg/ebpf"
"github.com/DataDog/datadog-agent/pkg/ebpf/maps"
"github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry"
Expand Down Expand Up @@ -57,9 +55,9 @@ type Consumer[V any] struct {
// `callback` is executed once for every "event" generated on eBPF and must:
// 1) copy the data it wishes to hold since the underlying byte array is reclaimed;
// 2) be thread-safe, as the callback may be executed concurrently from multiple go-routines;
func NewConsumer[V any](proto string, ebpf *manager.Manager, callback func([]V)) (*Consumer[V], error) {
func NewConsumer[V any](proto string, ebpf *ddebpf.Manager, callback func([]V)) (*Consumer[V], error) {
batchMapName := proto + batchMapSuffix
batchMap, err := maps.GetMap[batchKey, batch](ebpf, batchMapName)
batchMap, err := maps.GetMap[batchKey, batch](ebpf.Manager, batchMapName)
if err != nil {
return nil, fmt.Errorf("unable to find map %s: %s", batchMapName, err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/network/protocols/events/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func TestConsumer(t *testing.T) {
}
}

consumer, err := NewConsumer("test", program.Manager, callback)
consumer, err := NewConsumer("test", program, callback)
require.NoError(t, err)
consumer.Start()

err = program.Start()
require.NoError(t, err)

// generate test events
generator := newEventGenerator(program.Manager, t)
generator := newEventGenerator(program, t)
for i := 0; i < numEvents; i++ {
generator.Generate(uint64(i))
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestInvalidBatchCountMetric(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { program.Stop(manager.CleanAll) })

consumer, err := NewConsumer("test", program.Manager, func([]uint64) {})
consumer, err := NewConsumer("test", program, func([]uint64) {})
require.NoError(t, err)

// We are creating a raw sample with a data length of 4, which is smaller than sizeOfBatch
Expand Down Expand Up @@ -132,7 +132,7 @@ func recordSample(c *config.Config, consumer *Consumer[uint64], sampleData []byt
}
}

func newEventGenerator(program *manager.Manager, t *testing.T) *eventGenerator {
func newEventGenerator(program *ddebpf.Manager, t *testing.T) *eventGenerator {
m, _, _ := program.GetMap("test")
require.NotNilf(t, m, "couldn't find test map")

Expand Down Expand Up @@ -211,7 +211,7 @@ func newEBPFProgram(c *config.Config) (*ddebpf.Manager, error) {

ddEbpfManager := ddebpf.NewManager(m, "usm", &ebpftelemetry.ErrorsTelemetryModifier{})

Configure(config.New(), "test", ddEbpfManager.Manager, &options)
Configure(config.New(), "test", ddEbpfManager, &options)
err = ddEbpfManager.InitWithOptions(bc, &options)
if err != nil {
return nil, err
Expand Down

0 comments on commit 2d27f50

Please sign in to comment.