|
|
@@ -286,9 +286,9 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
{
|
|
|
// __u64 trace_id = get_apm_trace_id(pid, fd);
|
|
|
__u64 trace_id = get_fd_trace_id(pid, fd);
|
|
|
- cw_bpf_debug("[trace end][Response][HTTP] pid:%d,fd:%d,trace_id:%llu", pid, fd, trace_id);
|
|
|
+ cw_bpf_debug("[Trace End in l7][Response][HTTP] pid:%d,fd:%d,trace_id:%llu", tid, fd, trace_id);
|
|
|
// 清除trace信息
|
|
|
- clear_trace(pid, tid, fd);
|
|
|
+ cw_clear_trace(pid, tid, fd);
|
|
|
// 发送事件到用户空间 start
|
|
|
struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
|
|
|
if (!e) {
|
|
|
@@ -350,8 +350,10 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
}
|
|
|
|
|
|
if (is_http_request(payload)) {
|
|
|
- cw_bpf_debug("[Kernel Enter] [HTTP]:TGID:%d|FD:%d",k.pid,k.fd);
|
|
|
- req->protocol = PROTOCOL_HTTP;
|
|
|
+ cw_bpf_debug("");
|
|
|
+ cw_bpf_debug("-----[Kernel Enter][HTTP]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
|
|
|
+
|
|
|
+ req->protocol = PROTOCOL_HTTP;
|
|
|
// struct apm_trace_key_t trace_key = {0};
|
|
|
// trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);
|
|
|
// cw_bpf_debug("[Enter] [HTTP]:goid:%llu",trace_key.goid);
|
|
|
@@ -547,7 +549,6 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
bpf_map_update_elem(&active_l7_requests, &k, req, BPF_NOEXIST);
|
|
|
}
|
|
|
|
|
|
- cw_bpf_debug("[trace start][Receive][HTTP]:thread_id:%d\n",tid);
|
|
|
// cw_bpf_debug("[Receive][HTTP] payload1:%s|type:%s\n",payload,"type");
|
|
|
// __u64 goid = 0;
|
|
|
// goid = get_rw_goid(120 * NS_PER_SEC, 1);
|
|
|
@@ -556,18 +557,20 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
// cw_bpf_debug("[Receive][HTTP]:thread_id:%d|goid:%d|FD:%d\n", tid, goid, k.fd);
|
|
|
|
|
|
|
|
|
- // apm trace
|
|
|
- struct apm_trace_key_t trace_key = {0};
|
|
|
- trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);
|
|
|
-
|
|
|
- // fd trace
|
|
|
- struct fd_trace_key_t fd_trace_key = {0};
|
|
|
- fd_trace_key = get_fd_trace_key(pid, k.fd);
|
|
|
-
|
|
|
- // trace info
|
|
|
- struct apm_trace_info_t trace_info = {0};
|
|
|
- __u64 uid_base = bpf_ktime_get_ns();
|
|
|
- trace_info.trace_id = bpf_get_current_pid_tgid() + uid_base;
|
|
|
+// // apm trace
|
|
|
+// struct apm_trace_key_t trace_key = {0};
|
|
|
+// trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);
|
|
|
+//
|
|
|
+// // fd trace
|
|
|
+// struct fd_trace_key_t fd_trace_key = {0};
|
|
|
+// fd_trace_key = get_fd_trace_key(pid, k.fd);
|
|
|
+//
|
|
|
+// // trace info
|
|
|
+ struct apm_trace_info_t trace_info = cw_save_trace_info(id,pid, k.fd);
|
|
|
+// __u64 uid_base = bpf_ktime_get_ns();
|
|
|
+// trace_info.trace_id = bpf_get_current_pid_tgid() + uid_base;
|
|
|
+ cw_bpf_debug("\n");
|
|
|
+ cw_bpf_debug("[Trace Start in l7][Receive][HTTP]pid:[%d]|GOID:[%d]|FD:%d", tid, trace_info.trace_key.goid,k.fd);
|
|
|
|
|
|
e->trace_start = 1;
|
|
|
e->trace_end = 0;
|
|
|
@@ -576,9 +579,11 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
e->payload_size = ret;
|
|
|
COPY_PAYLOAD(e->payload, ret, payload);
|
|
|
|
|
|
+ // pid_tgid:trace_id
|
|
|
+// thread_trace_key =
|
|
|
// 入口方法缓存
|
|
|
- bpf_map_update_elem(&trace_info_heap, &trace_key, &trace_info, BPF_NOEXIST);
|
|
|
- bpf_map_update_elem(&fd_trace_info_heap, &fd_trace_key, &trace_info, BPF_NOEXIST);
|
|
|
+// bpf_map_update_elem(&trace_info_heap, &trace_key, &trace_info, BPF_NOEXIST);
|
|
|
+// bpf_map_update_elem(&fd_trace_info_heap, &fd_trace_key, &trace_info, BPF_NOEXIST);
|
|
|
bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
cw_bpf_debug("[Receive][HTTP] to user space");
|
|
|
return 0;
|
|
|
@@ -638,8 +643,6 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
if (e->protocol == PROTOCOL_HTTP) {
|
|
|
__u64 trace_id = get_apm_trace_id(pid, tid);
|
|
|
e->trace_id = trace_id;
|
|
|
- cw_bpf_debug("[Kernel Response][HTTP] [Trace ID] trace_id:%llu", e->trace_id);
|
|
|
- cw_bpf_debug("[Kernel Response][HTTP]:TGID:%d|type:%s|FD:%d\n",k.pid,"",k.fd);
|
|
|
struct apm_span_context * sc = cw_get_current_tracking_span();
|
|
|
if (sc) {
|
|
|
cw_copy_byte_arrays(sc->assumed_app_id, e->assumed_app_id, APM_ASSUMED_APP_ID_SIZE);
|
|
|
@@ -656,6 +659,25 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
// cw_bpf_debug("[Response][HTTP222] resp-payload:%s",payload);
|
|
|
|
|
|
response = is_http_response(payload, &e->status);
|
|
|
+// if (trace_id == 0) {
|
|
|
+// __u64 goid = get_current_goroutine();
|
|
|
+// cw_bpf_debug("[Kernel End] go_id:%llu",goid);
|
|
|
+//
|
|
|
+// }
|
|
|
+ if (e->trace_id == 0){
|
|
|
+ struct thread_trace_key_t t_key = get_thread_trace_key(id);
|
|
|
+ struct apm_trace_info_t *trace_info = bpf_map_lookup_elem(&thread_trace_info_heap, &t_key);
|
|
|
+ if (trace_info) {
|
|
|
+ if (trace_info->trace_id == 0){
|
|
|
+ cw_bpf_debug("get trace_id from enter pid:[%d]|thread_trace_key_t:[%llu]", tid,trace_info->trace_id);
|
|
|
+ e->trace_id=trace_info->trace_id;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 从子事件的头获取线程id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cw_bpf_debug("[Kernel End][HTTP]:pid:[%d]|CURRENT-GOID:[%llu]|trace_id:[%llu]---------\n", tid, get_current_goroutine(),e->trace_id);
|
|
|
+
|
|
|
} else if (e->protocol == PROTOCOL_POSTGRES) {
|
|
|
response = is_postgres_response(payload, ret, &e->status);
|
|
|
if (req->request_type == POSTGRES_FRAME_PARSE) {
|