From 8ca1eb5a4cbc95ddef2dab6490ea7978ffe79c36 Mon Sep 17 00:00:00 2001 From: Jiping Yin Date: Fri, 10 May 2024 17:59:30 +0800 Subject: [PATCH] [eBPF] Remove logic to not trace data sent from the client as the origin The reason for removal: 1 We already have tracing tree pruning functionality, which can prune invalid traces based on the time range of the root node (span). 2 The following scenario requires the removal of the non-tracing logic: ``` Requset threadID Response threadID Requset traceID Response traceID ------------------------------------------------------------------------------------------ server process TID-A TID-B traceID-A 0 [3] client process TID-B TID-B 0 [1] 0 [2] ``` As we can see, because the client process serves as the starting point for sending data, its request traceID is 0 (as indicated by [1]), and due to previous non-tracing logic, the value at [2] is also 0. Consequently, the data from the server and the client cannot be associated. By removing the non-tracing logic, [2] and [3] will generate a non-zero valid traceID, enabling the association of the two sets of data. --- .../ebpf/kernel/include/protocol_inference.h | 2 - agent/src/ebpf/kernel/include/socket_trace.h | 2 +- .../ebpf/kernel/include/socket_trace_common.h | 6 +- agent/src/ebpf/kernel/socket_trace.bpf.c | 81 ------------------- 4 files changed, 2 insertions(+), 89 deletions(-) diff --git a/agent/src/ebpf/kernel/include/protocol_inference.h b/agent/src/ebpf/kernel/include/protocol_inference.h index 1f681884fa9..6cc3987decc 100644 --- a/agent/src/ebpf/kernel/include/protocol_inference.h +++ b/agent/src/ebpf/kernel/include/protocol_inference.h @@ -3333,7 +3333,6 @@ infer_protocol_1(struct ctx_info_s *ctx, infer_http_message(infer_buf, count, conn_info)) != MSG_UNKNOWN) { inferred_message.protocol = PROTO_HTTP1; - conn_info->infer_reliable = 1; return inferred_message; } break; @@ -3537,7 +3536,6 @@ infer_protocol_1(struct ctx_info_s *ctx, if ((inferred_message.type = #endif infer_http_message(infer_buf, count, conn_info)) != MSG_UNKNOWN) { - conn_info->infer_reliable = 1; inferred_message.protocol = PROTO_HTTP1; #ifdef LINUX_VER_5_2_PLUS } else if (skip_proto != PROTO_REDIS && (inferred_message.type = diff --git a/agent/src/ebpf/kernel/include/socket_trace.h b/agent/src/ebpf/kernel/include/socket_trace.h index ab9294c68c8..02cc9cc9903 100644 --- a/agent/src/ebpf/kernel/include/socket_trace.h +++ b/agent/src/ebpf/kernel/include/socket_trace.h @@ -130,7 +130,7 @@ struct conn_info_s { __u16 skc_family; /* PF_INET, PF_INET6... */ __u16 sk_type; /* socket type (SOCK_STREAM, etc) */ __u8 skc_ipv6only:1; - __u8 infer_reliable:1; // Is protocol inference reliable? + __u8 reserved:1; /* * Whether the socket l7 protocol type needs * to be confirmed again. diff --git a/agent/src/ebpf/kernel/include/socket_trace_common.h b/agent/src/ebpf/kernel/include/socket_trace_common.h index 7dab600f20b..3588f8a7757 100644 --- a/agent/src/ebpf/kernel/include/socket_trace_common.h +++ b/agent/src/ebpf/kernel/include/socket_trace_common.h @@ -149,11 +149,7 @@ struct trace_key_t { } __attribute__((packed)); struct trace_info_t { - /* - * Whether traceID is zero ? - * For the client to actively send request, set traceID to zero. - */ - bool is_trace_id_zero; + __u8 reserve; __u32 update_time; // 从系统开机开始到创建/更新时的间隔时间单位是秒 __u32 peer_fd; // 用于socket之间的关联 __u64 thread_trace_id; // 线程追踪ID diff --git a/agent/src/ebpf/kernel/socket_trace.bpf.c b/agent/src/ebpf/kernel/socket_trace.bpf.c index 7ae9436d809..31ca19d27b5 100644 --- a/agent/src/ebpf/kernel/socket_trace.bpf.c +++ b/agent/src/ebpf/kernel/socket_trace.bpf.c @@ -1022,36 +1022,6 @@ static __inline void trace_process(struct socket_info_t *socket_info_ptr, * 采用的策略是:沿用上次trace_info保存的traceID。 */ - /* - * Socket A actively sends a request as a client (traceID is 0), - * and associates socket B with the thread ID. Socket B receives a - * response as the client, create new traceID as the starting point - * for the entire tracking process. There is a problem in tracking - * down like this, and a closed loop cannot be formed. This is due to - * receiving a response from socket B to start the trace, but not being - * able to get a request from socket B to finish the entire trace. - * - * (socket A) -- request -> - * | - * (socket B) <- response (traceID-1) [The starting point of trace] - * | - * (socket C) -- request -> (traceID-1) - * | - * (socket D) <- response (traceID-2) - * | - * (socket E) -- request -> (traceID-2) - * ... ... (Can't finish the whole trace) - * - * In order to avoid invalid association of the client, the behavior of creating - * a new trace on socket B is cancelled. - * - * (socket A) ------- request --------> - * | - * thread-ID - * | - * (socket B) <---- response (Here, not create new trace.) - */ - __u64 pre_trace_id = 0; int ret; if (is_socket_info_valid(socket_info_ptr) && @@ -1061,28 +1031,6 @@ static __inline void trace_process(struct socket_info_t *socket_info_ptr, } if (conn_info->direction == T_INGRESS) { - if (trace_info_ptr) { - /* - * The following scenarios do not track: - * --------------------------------------- - * [traceID : 0] - * (client-socket) request -> - * | - * thread-ID - * | - * (client-socket) <- response - */ - if (trace_info_ptr->is_trace_id_zero && - conn_info->message_type == MSG_RESPONSE && - conn_info->infer_reliable) { - if (!trace_map__delete(trace_key)) { - __sync_fetch_and_add - (&trace_stats->trace_map_count, -1); - } - return; - } - } - struct trace_info_t trace_info = { 0 }; *thread_trace_id = trace_info.thread_trace_id = (pre_trace_id == @@ -1105,19 +1053,6 @@ static __inline void trace_process(struct socket_info_t *socket_info_ptr, } } else { /* direction == T_EGRESS */ if (trace_info_ptr) { - /* - * Skip the scene below: - * ------------------------------------------------ - * (client-socket) request [traceID : 0] -> - * | - * thread-ID - * | - * (client-socket) request [traceID : 0] -> - */ - if (trace_info_ptr->is_trace_id_zero) { - return; - } - *thread_trace_id = trace_info_ptr->thread_trace_id; /* @@ -1144,22 +1079,6 @@ static __inline void trace_process(struct socket_info_t *socket_info_ptr, __sync_fetch_and_add (&trace_stats->trace_map_count, -1); } - } else { - /* - * Record the scene below: - * ------------------------------------------------ - * (client-socket) request [traceID : 0] -> - */ - if (conn_info->message_type == MSG_REQUEST - && conn_info->infer_reliable) { - struct trace_info_t trace_info = { 0 }; - trace_info.is_trace_id_zero = true; - trace_info.update_time = - time_stamp / NS_PER_SEC; - trace_map__update(trace_key, &trace_info); - __sync_fetch_and_add - (&trace_stats->trace_map_count, 1); - } } } }