Skip to content

Commit

Permalink
[eBPF] Remove logic to not trace data sent from the client as the origin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yinjiping authored and sharang committed May 11, 2024
1 parent 257c231 commit 8ca1eb5
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 89 deletions.
2 changes: 0 additions & 2 deletions agent/src/ebpf/kernel/include/protocol_inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion agent/src/ebpf/kernel/include/socket_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions agent/src/ebpf/kernel/include/socket_trace_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 0 additions & 81 deletions agent/src/ebpf/kernel/socket_trace.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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 ==
Expand All @@ -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;

/*
Expand All @@ -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);
}
}
}
}
Expand Down

0 comments on commit 8ca1eb5

Please sign in to comment.