Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ddebpf.Manager in consumer_test.go and related files #32391

Closed
wants to merge 3 commits into from
Closed
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
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
13 changes: 8 additions & 5 deletions pkg/network/protocols/events/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"
"unsafe"

ebpftelemetry "github.com/DataDog/datadog-agent/pkg/ebpf/telemetry"
manager "github.com/DataDog/ebpf-manager"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/features"
Expand Down Expand Up @@ -131,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 @@ -172,7 +173,7 @@ func (e *eventGenerator) Stop() {
e.testFile.Close()
}

func newEBPFProgram(c *config.Config) (*manager.Manager, error) {
func newEBPFProgram(c *config.Config) (*ddebpf.Manager, error) {
bc, err := bytecode.GetReader(c.BPFDir, "usm_events_test-debug.o")
if err != nil {
return nil, err
Expand Down Expand Up @@ -208,11 +209,13 @@ func newEBPFProgram(c *config.Config) (*manager.Manager, error) {
},
}

Configure(config.New(), "test", m, &options)
err = m.InitWithOptions(bc, options)
ddEbpfManager := ddebpf.NewManager(m, "usm", &ebpftelemetry.ErrorsTelemetryModifier{})
val06 marked this conversation as resolved.
Show resolved Hide resolved

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

return m, nil
return ddEbpfManager, nil
}
Loading