Skip to content

Commit 88aa89e

Browse files
authored
simplify eBPF telemetry and make it thread-safe (#21230)
* fixup ebpf telemetry * make thread safe * simplified ebpf telemetry * remove map exclusion * fix lint * Use function names from instruction patching * remove unused func * ignore exist error
1 parent acd4ba4 commit 88aa89e

File tree

18 files changed

+309
-421
lines changed

18 files changed

+309
-421
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ require (
8787
github.com/DataDog/datadog-go/v5 v5.3.1-0.20231115110321-54ec306d83b2
8888
// do not update datadog-operator to 1.2.1 because the indirect dependency github.com/DataDog/datadog-api-client-go/v2 v2.15.0 is trigger a huge Go heap memory increase.
8989
github.com/DataDog/datadog-operator v1.1.0
90-
github.com/DataDog/ebpf-manager v0.3.7
90+
github.com/DataDog/ebpf-manager v0.3.8
9191
github.com/DataDog/go-tuf v1.0.2-0.5.2
9292
github.com/DataDog/gopsutil v1.2.2
9393
github.com/DataDog/nikos v1.12.1

go.sum

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

pkg/ebpf/c/bpf_telemetry.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ static void *(*bpf_telemetry_update_patch)(unsigned long, ...) = (void *)PATCH_T
1818
({ \
1919
long errno_ret, errno_slot; \
2020
errno_ret = fn(&map, args); \
21-
if (errno_ret < 0) { \
22-
unsigned long err_telemetry_key; \
23-
LOAD_CONSTANT(MK_KEY(map), err_telemetry_key); \
21+
unsigned long err_telemetry_key; \
22+
LOAD_CONSTANT(MK_KEY(map), err_telemetry_key); \
23+
if (errno_ret < 0 && err_telemetry_key > 0) { \
2424
map_err_telemetry_t *entry = \
2525
bpf_map_lookup_elem(&map_err_telemetry_map, &err_telemetry_key); \
2626
if (entry) { \
@@ -35,7 +35,7 @@ static void *(*bpf_telemetry_update_patch)(unsigned long, ...) = (void *)PATCH_T
3535
/* Patched instruction for 4.14+: __sync_fetch_and_add(target, 1);
3636
* This patch point is placed here because the above instruction
3737
* fails on the 4.4 verifier. On 4.4 this instruction is replaced
38-
* with a nop: r1 = r1 */ \
38+
* with a nop: r1 = r1 */ \
3939
bpf_telemetry_update_patch((unsigned long)target, add); \
4040
} \
4141
} \
@@ -60,9 +60,9 @@ static void *(*bpf_telemetry_update_patch)(unsigned long, ...) = (void *)PATCH_T
6060
int helper_indx = -1; \
6161
long errno_slot; \
6262
long errno_ret = fn(__VA_ARGS__); \
63-
if (errno_ret < 0) { \
64-
unsigned long telemetry_program_id; \
65-
LOAD_CONSTANT("telemetry_program_id_key", telemetry_program_id); \
63+
unsigned long telemetry_program_id; \
64+
LOAD_CONSTANT("telemetry_program_id_key", telemetry_program_id); \
65+
if (errno_ret < 0 && telemetry_program_id > 0) { \
6666
helper_err_telemetry_t *entry = \
6767
bpf_map_lookup_elem(&helper_err_telemetry_map, &telemetry_program_id); \
6868
if (entry) { \
@@ -73,7 +73,7 @@ static void *(*bpf_telemetry_update_patch)(unsigned long, ...) = (void *)PATCH_T
7373
/* This is duplicated below because on clang 14.0.6 the compiler
7474
* concludes that this if-check will always force errno_slot in range
7575
* (0, T_MAX_ERRNO-1], and removes the bounds check, causing the verifier
76-
* to trip. Duplicating this check forces clang not to omit the check */ \
76+
* to trip. Duplicating this check forces clang not to omit the check */ \
7777
errno_slot &= (T_MAX_ERRNO - 1); \
7878
} \
7979
errno_slot &= (T_MAX_ERRNO - 1); \
@@ -83,7 +83,7 @@ static void *(*bpf_telemetry_update_patch)(unsigned long, ...) = (void *)PATCH_T
8383
/* Patched instruction for 4.14+: __sync_fetch_and_add(target, 1);
8484
* This patch point is placed here because the above instruction
8585
* fails on the 4.4 verifier. On 4.4 this instruction is replaced
86-
* with a nop: r1 = r1 */ \
86+
* with a nop: r1 = r1 */ \
8787
bpf_telemetry_update_patch((unsigned long)target, add); \
8888
} \
8989
} \

pkg/network/protocols/events/consumer_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,16 @@ func newEBPFProgram(c *config.Config) (*manager.Manager, error) {
134134
}
135135
defer bc.Close()
136136

137-
m := &manager.Manager{
137+
bpfTelemetry := bpftelemetry.NewEBPFTelemetry()
138+
m := bpftelemetry.NewManager(&manager.Manager{
138139
Probes: []*manager.Probe{
139140
{
140141
ProbeIdentificationPair: manager.ProbeIdentificationPair{
141142
EBPFFuncName: "tracepoint__syscalls__sys_enter_write",
142143
},
143144
},
144145
},
145-
}
146+
}, bpfTelemetry)
146147
options := manager.Options{
147148
RLimit: &unix.Rlimit{
148149
Cur: math.MaxUint64,
@@ -163,14 +164,11 @@ func newEBPFProgram(c *config.Config) (*manager.Manager, error) {
163164
},
164165
}
165166

166-
Configure("test", m, &options)
167-
m.InstructionPatcher = func(m *manager.Manager) error {
168-
return bpftelemetry.PatchEBPFTelemetry(m, true, nil)
169-
}
167+
Configure("test", m.Manager, &options)
170168
err = m.InitWithOptions(bc, options)
171169
if err != nil {
172170
return nil, err
173171
}
174172

175-
return m, nil
173+
return m.Manager, nil
176174
}

0 commit comments

Comments
 (0)