Skip to content

Commit

Permalink
Merge pull request #162 from coroot/partial_zk_reads
Browse files Browse the repository at this point in the history
handle partial Zookeeper reads
  • Loading branch information
def authored Dec 25, 2024
2 parents 1da58fa + 8ed2571 commit 1dbf538
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
20 changes: 10 additions & 10 deletions ebpftracer/ebpf.go

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion ebpftracer/ebpf/l7/l7.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,11 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
return 0; // keeping the query in the map
}
} else if (e->protocol == PROTOCOL_ZOOKEEPER) {
response = is_zk_response(payload, total_size, &e->status);
response = is_zk_response(payload, total_size, &e->status, req->partial);
if (response == 2) { // partial
req->partial = 1;
return 0; // keeping the query in the map
}
} else if (e->protocol == PROTOCOL_DUBBO2) {
response = is_dubbo2_response(payload, &e->status);
}
Expand Down
16 changes: 12 additions & 4 deletions ebpftracer/ebpf/l7/zookeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ int is_zk_request(char *buf, __u64 buf_size) {
}

static __always_inline
int is_zk_response(char *buf, __u64 buf_size, __s32 *status) {
int is_zk_response(char *buf, __u64 buf_size, __s32 *status, __u8 partial) {
if (partial == 0 && buf_size == 4) { //partial read
return 2;
}
struct zk_response_header resp = {};
bpf_read(buf, resp);
if (bpf_ntohl(resp.length)+4 != buf_size) {
return 0;
if (partial) {
bpf_read(buf, resp.xid);
bpf_read(buf+12, resp.err_code);
} else {
bpf_read(buf, resp);
if (bpf_ntohl(resp.length)+4 != buf_size) {
return 0;
}
}
__s32 xid = bpf_ntohl(resp.xid);
if (xid < 0 && xid != -1 && xid != -2) {
Expand Down

0 comments on commit 1dbf538

Please sign in to comment.