|
|
@@ -207,6 +207,13 @@ struct {
|
|
|
__uint(max_entries, 32768);
|
|
|
} active_l7_requests_mysql_resp_header_ctx SEC(".maps");
|
|
|
|
|
|
+struct {
|
|
|
+ __uint(type, BPF_MAP_TYPE_LRU_HASH);
|
|
|
+ __uint(key_size, sizeof(struct l7_request_key));
|
|
|
+ __uint(value_size, 4);
|
|
|
+ __uint(max_entries, 32768);
|
|
|
+} active_l7_requests_kafka_resp_header_ctx SEC(".maps");
|
|
|
+
|
|
|
struct {
|
|
|
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
|
|
|
__type(key, int);
|
|
|
@@ -558,8 +565,9 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
|
|
|
if (is_http_request(payload)) {
|
|
|
cw_bpf_debug("");
|
|
|
- cw_bpf_debug("-----[Kernel HTTP Enter]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
|
|
|
- __u8 type = 0;
|
|
|
+ // cw_bpf_debug("-----[Kernel HTTP Enter]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
|
|
|
+ bpf_printk("-----[Kernel HTTP Enter]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
|
|
|
+ __u8 type = 0;
|
|
|
__u64 trace_id = 0;
|
|
|
struct apm_trace_key_t trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);
|
|
|
struct apm_trace_info_t * trace_info = get_apm_trace_info_by_trace_key(trace_key);
|
|
|
@@ -688,13 +696,13 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
} else if (is_kafka_request(payload, size, &req->request_id)) {
|
|
|
req->protocol = PROTOCOL_KAFKA;
|
|
|
struct l7_request *prev_req = bpf_map_lookup_elem(&active_l7_requests, &k);
|
|
|
+ bpf_printk("-----[kafka HTTP Enter]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
|
|
|
if (prev_req && prev_req->protocol == PROTOCOL_KAFKA) {
|
|
|
req->ns = prev_req->ns;
|
|
|
}
|
|
|
cw_bpf_debug("[Request][KAFKA] start -------->");
|
|
|
- bpf_printk("[Request][KAFKA] start -------->");
|
|
|
cw_bpf_debug("[Request][KAFKA] correlation_id start is %d -------->", req->request_id);
|
|
|
- bpf_printk("[Request][KAFKA] correlation_id start is %d -------->", req->request_id);
|
|
|
+ bpf_printk("[Request][KAFKA] correlation_id start is %d, k.pid is %d, k.fd is %d -------->", req->request_id, k.pid, k.fd);
|
|
|
// __u64 before_topic_length;
|
|
|
// __s16 s16_method_type;
|
|
|
// __s16 topic_length = kafka_request_topic_length_data(payload, size, &s16_method_type, &before_topic_length);
|
|
|
@@ -1242,14 +1250,43 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
return 0;
|
|
|
}
|
|
|
} else if (e->protocol == PROTOCOL_KAFKA) {
|
|
|
+ if(ret == 4) {
|
|
|
+ //sava header to ctx and return
|
|
|
+ char resp_packet_header[4];
|
|
|
+ bpf_probe_read(resp_packet_header,4, payload);
|
|
|
+ bpf_map_update_elem(&active_l7_requests_kafka_resp_header_ctx, &k, resp_packet_header, BPF_ANY);
|
|
|
+ bpf_map_update_elem(&active_l7_requests, &k, req, BPF_ANY);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
e->component_sport = conn->sport;
|
|
|
e->component_dport = conn->dport;
|
|
|
__builtin_memcpy(&e->component_saddr, &conn->saddr, sizeof(e->component_saddr));
|
|
|
__builtin_memcpy(&e->component_daddr, &conn->daddr, sizeof(e->component_daddr));
|
|
|
- __s32 real_request_id;
|
|
|
- response = is_kafka_response(payload, req->request_id, &real_request_id);
|
|
|
- cw_bpf_debug("[Request][KAFKA] end -------->");
|
|
|
- bpf_printk("[Request][KAFKA] end -------->");
|
|
|
+ char* resp_packet_header = bpf_map_lookup_elem(&active_l7_requests_kafka_resp_header_ctx, &k);
|
|
|
+ if(resp_packet_header) {
|
|
|
+ __s32 kafka_response_length;
|
|
|
+ bpf_read(resp_packet_header, kafka_response_length);
|
|
|
+ kafka_response_length = bpf_ntohl(kafka_response_length);
|
|
|
+ if (kafka_response_length == ret)
|
|
|
+ {
|
|
|
+ __s32 real_request_id = 0;
|
|
|
+ response = is_kafka_response(payload, ret, req->request_id, &real_request_id);
|
|
|
+ // cw_bpf_debug("[Request][KAFKA] end -------->");
|
|
|
+ // bpf_printk("[Request][KAFKA] end k.pid is %d k.fd is %d ",k.pid, k.fd);
|
|
|
+ // bpf_printk("[Request][KAFKA] end req->request_id is %d, real_request_id is %d>", req->request_id, real_request_id);
|
|
|
+ cw_bpf_debug("[Request][KAFKA] end -------->");
|
|
|
+ bpf_printk("[Request][KAFKA] end k.pid is %d k.fd is %d ",k.pid, k.fd);
|
|
|
+ bpf_printk("[Request][KAFKA] end sport is %d, dport is %d>", e->component_sport, e->component_dport);
|
|
|
+ bpf_printk("[Request][KAFKA] end req->request_id is %d, real_request_id is %d>", req->request_id, real_request_id);
|
|
|
+ }
|
|
|
+ if(response) {
|
|
|
+ bpf_map_delete_elem(&active_l7_requests_kafka_resp_header_ctx, &k);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // else {
|
|
|
+ // __s32 real_request_id = 0;
|
|
|
+ // response = is_kafka_response(payload, ret, req->request_id, &real_request_id);
|
|
|
+ // }
|
|
|
// cw_bpf_debug("[Request][KAFKA] correlation_id end is %d, real is %d -------->", req->request_id, real_request_id);
|
|
|
|
|
|
// if(response)
|
|
|
@@ -1268,6 +1305,10 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
}
|
|
|
if (e->trace_id == 0){
|
|
|
e->trace_id = get_apm_trace_id(pid,tid);
|
|
|
+ if (e->protocol == PROTOCOL_KAFKA)
|
|
|
+ {
|
|
|
+ bpf_printk("[Request][KAFKA] end e->trace_id is %d ",e->trace_id);
|
|
|
+ }
|
|
|
}
|
|
|
e->end_at = bpf_ktime_get_ns();
|
|
|
e->start_at = req->ns;
|