Skip to content

Commit

Permalink
Revert "refactor go_redis.h"
Browse files Browse the repository at this point in the history
This reverts commit 4ce7ab5.
  • Loading branch information
marctc committed Sep 24, 2024
1 parent 2f3e513 commit 2f76f1c
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions bpf/go_redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, goroutine_key_t); // key: goroutine id
__type(key, void *); // key: goroutine id
__type(value, redis_client_req_t); // the request
__uint(max_entries, MAX_CONCURRENT_REQUESTS);
} ongoing_redis_requests SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, goroutine_key_t); // key: goroutine id
__type(value, void *); // the *Conn
__type(key, void *); // key: goroutine id
__type(value, void *); // the *Conn
__uint(max_entries, MAX_CONCURRENT_REQUESTS);
} redis_writes SEC(".maps");

Expand All @@ -34,13 +34,11 @@ static __always_inline void setup_request(void *goroutine_addr) {
.type = EVENT_GO_REDIS,
.start_monotime_ns = bpf_ktime_get_ns(),
};
goroutine_key_t g_key = {};
goroutine_key_from_id(&g_key, goroutine_addr);

// We don't look up in the headers, no http/grpc request, therefore 0 as last argument
client_trace_parent(goroutine_addr, &req.tp, 0);

bpf_map_update_elem(&ongoing_redis_requests, &g_key, &req, BPF_ANY);
bpf_map_update_elem(&ongoing_redis_requests, &goroutine_addr, &req, BPF_ANY);
}

// github.com/redis/go-redis/v9.(*baseClient)._process
Expand All @@ -61,10 +59,8 @@ int uprobe_redis_process_ret(struct pt_regs *ctx) {
bpf_dbg_printk("=== uprobe/redis _process returns === ");
void *goroutine_addr = GOROUTINE_PTR(ctx);
bpf_dbg_printk("goroutine_addr %lx", goroutine_addr);
goroutine_key_t g_key = {};
goroutine_key_from_id(&g_key, goroutine_addr);

redis_client_req_t *req = bpf_map_lookup_elem(&ongoing_redis_requests, &g_key);
redis_client_req_t *req = bpf_map_lookup_elem(&ongoing_redis_requests, &goroutine_addr);
if (req) {
redis_client_req_t *trace = bpf_ringbuf_reserve(&events, sizeof(redis_client_req_t), 0);
if (trace) {
Expand All @@ -76,7 +72,7 @@ int uprobe_redis_process_ret(struct pt_regs *ctx) {
}
}

bpf_map_delete_elem(&ongoing_redis_requests, &g_key);
bpf_map_delete_elem(&ongoing_redis_requests, &goroutine_addr);

return 0;
}
Expand All @@ -94,14 +90,12 @@ int uprobe_redis_with_writer(struct pt_regs *ctx) {
off_table_t *ot = get_offsets_table();

bpf_dbg_printk("goroutine_addr %lx", goroutine_addr);
goroutine_key_t g_key = {};
goroutine_key_from_id(&g_key, goroutine_addr);

redis_client_req_t *req = bpf_map_lookup_elem(&ongoing_redis_requests, &g_key);
redis_client_req_t *req = bpf_map_lookup_elem(&ongoing_redis_requests, &goroutine_addr);

if (!req) {
setup_request(goroutine_addr);
req = bpf_map_lookup_elem(&ongoing_redis_requests, &g_key);
req = bpf_map_lookup_elem(&ongoing_redis_requests, &goroutine_addr);
}

if (req) {
Expand All @@ -112,7 +106,7 @@ int uprobe_redis_with_writer(struct pt_regs *ctx) {
cn_ptr + go_offset_of(ot, (go_offset){.v = _redis_conn_bw_pos}));
bpf_dbg_printk("bw_ptr %llx", bw_ptr);

bpf_map_update_elem(&redis_writes, &g_key, &bw_ptr, BPF_ANY);
bpf_map_update_elem(&redis_writes, &goroutine_addr, &bw_ptr, BPF_ANY);

if (cn_ptr) {
void *tcp_conn_ptr = cn_ptr + 8;
Expand Down Expand Up @@ -141,13 +135,11 @@ int uprobe_redis_with_writer_ret(struct pt_regs *ctx) {
void *goroutine_addr = GOROUTINE_PTR(ctx);
off_table_t *ot = get_offsets_table();
bpf_dbg_printk("goroutine_addr %lx", goroutine_addr);
goroutine_key_t g_key = {};
goroutine_key_from_id(&g_key, goroutine_addr);

redis_client_req_t *req = bpf_map_lookup_elem(&ongoing_redis_requests, &g_key);
redis_client_req_t *req = bpf_map_lookup_elem(&ongoing_redis_requests, &goroutine_addr);

if (req) {
void **bw_ptr = bpf_map_lookup_elem(&redis_writes, &g_key);
void **bw_ptr = bpf_map_lookup_elem(&redis_writes, &goroutine_addr);

if (bw_ptr) {
void *bw = *bw_ptr;
Expand Down
Binary file modified pkg/internal/ebpf/gotracer/bpf_arm64_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_debug_arm64_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_debug_x86_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_tp_arm64_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_tp_debug_arm64_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_tp_debug_x86_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_tp_x86_bpfel.o
Binary file not shown.
Binary file modified pkg/internal/ebpf/gotracer/bpf_x86_bpfel.o
Binary file not shown.

0 comments on commit 2f76f1c

Please sign in to comment.