Skip to content

Commit

Permalink
Use kprobe for unreliable recvmsg return probe (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Aug 16, 2024
1 parent c8f170d commit fe36f90
Show file tree
Hide file tree
Showing 25 changed files with 63 additions and 15 deletions.
44 changes: 29 additions & 15 deletions bpf/http_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,24 +434,12 @@ int BPF_KPROBE(kprobe_tcp_recvmsg, struct sock *sk, struct msghdr *msg, size_t l
return 0;
}

SEC("kretprobe/tcp_recvmsg")
int BPF_KRETPROBE(kretprobe_tcp_recvmsg, int copied_len) {
u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
}

static __always_inline int return_recvmsg(void *ctx, u64 id, int copied_len) {
recv_args_t *args = bpf_map_lookup_elem(&active_recv_args, &id);

bpf_dbg_printk("=== tcp_recvmsg ret id=%d args=%llx copied_len %d ===", id, args, copied_len);
bpf_dbg_printk("=== return recvmsg id=%d args=%llx copied_len %d ===", id, args, copied_len);

if (!args) {
goto done;
}

if (copied_len <= 0) {
bpf_map_delete_elem(&active_recv_args, &id);
if (!args || (copied_len <= 0)) {
goto done;
}

Expand Down Expand Up @@ -502,6 +490,32 @@ int BPF_KRETPROBE(kretprobe_tcp_recvmsg, int copied_len) {
return 0;
}

SEC("kprobe/tcp_cleanup_rbuf")
int BPF_KPROBE(kprobe_tcp_cleanup_rbuf, struct sock *sk, int copied) {
u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
}

bpf_dbg_printk("=== tcp_cleanup_rbuf id=%d copied_len %d ===", id, copied);

return return_recvmsg(ctx, id, copied);
}

SEC("kretprobe/tcp_recvmsg")
int BPF_KRETPROBE(kretprobe_tcp_recvmsg, int copied_len) {
u64 id = bpf_get_current_pid_tgid();

if (!valid_pid(id)) {
return 0;
}

bpf_dbg_printk("=== kretprobe_tcp_recvmsg id=%d copied_len %d ===", id, copied_len);

return return_recvmsg(ctx, id, copied_len);
}

// Fall-back in case we don't see kretprobe on tcp_recvmsg in high network volume situations
SEC("socket/http_filter")
int socket__http_filter(struct __sk_buff *skb) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_arm64_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_arm64_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_debug_arm64_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_debug_arm64_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_debug_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_debug_x86_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_tp_arm64_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_arm64_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_tp_debug_arm64_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_debug_arm64_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_tp_debug_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_debug_x86_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_tp_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_tp_x86_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/bpf_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/internal/ebpf/httpfltr/bpf_x86_bpfel.o
Binary file not shown.
3 changes: 3 additions & 0 deletions pkg/internal/ebpf/httpfltr/httpfltr.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ func (p *Tracer) KProbes() map[string]ebpfcommon.FunctionPrograms {
Start: p.bpfObjects.KprobeTcpRecvmsg,
End: p.bpfObjects.KretprobeTcpRecvmsg,
},
"tcp_cleanup_rbuf": {
Start: p.bpfObjects.KprobeTcpCleanupRbuf, // this kprobe runs the same code as recvmsg return, we use it because kretprobes can be unreliable.
},
"sys_clone": {
Required: true,
End: p.bpfObjects.KretprobeSysClone,
Expand Down
1 change: 1 addition & 0 deletions test/oats/kafka/docker-compose-beyla-java-kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down
1 change: 1 addition & 0 deletions test/oats/kafka/docker-compose-beyla-python-kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down
1 change: 1 addition & 0 deletions test/oats/redis/docker-compose-beyla-go-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down
1 change: 1 addition & 0 deletions test/oats/redis/docker-compose-beyla-redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down
1 change: 1 addition & 0 deletions test/oats/sql/docker-compose-beyla-gosqlclient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down
1 change: 1 addition & 0 deletions test/oats/sql/docker-compose-beyla-sql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ services:
BEYLA_METRICS_INTERVAL: "10ms"
BEYLA_BPF_BATCH_TIMEOUT: "10ms"
BEYLA_LOG_LEVEL: "DEBUG"
BEYLA_BPF_DEBUG: "true"
OTEL_EXPORTER_OTLP_ENDPOINT: "http://collector:4318"
depends_on:
testserver:
Expand Down

0 comments on commit fe36f90

Please sign in to comment.