Ver Fonte

Fixed #JiraBug28447 Euspace-resin应用抓取到的trace_id均为0-在http请求入口生成横向串联的trace_id(3)

Tom há 1 ano atrás
pai
commit
91cd06fd22
3 ficheiros alterados com 25 adições e 40 exclusões
  1. 1 1
      ebpftracer/ebpf/ebpf.c
  2. 23 38
      ebpftracer/ebpf/l7/l7.c
  3. 1 1
      ebpftracer/tracer/socket.go

+ 1 - 1
ebpftracer/ebpf/ebpf.c

@@ -52,7 +52,7 @@
 #include "tcp/retransmit.c"
 //#include "l7/uprobe_base_bpf.c"
 #include "l7/l7.c"
-#include "l7/gotls.c"
+//#include "l7/gotls.c"
 //#include "l7/openssl.c"
 #include "utrace/go/net/server.probe.bpf.c"
 #include "utrace/go/net/client.probe.bpf.c"

+ 23 - 38
ebpftracer/ebpf/l7/l7.c

@@ -841,6 +841,17 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
 //        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");
+
+        // 作为服务端统计 bytes_received 使用
+        // struct connection *accept_conn = bpf_map_lookup_elem(&active_accepts, &cid);
+        // cw_bpf_debug("socket accept bytes_received cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
+        // if (accept_conn && !is_tls){
+        //     cw_bpf_debug("socket accept bytes_received after cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
+        //     __sync_fetch_and_add(&accept_conn->bytes_received, total_size);
+        // }
+
 #if __KERNEL_FROM >= 512
     // ---------- 在http请求入口生成 横向串联的trace_id start ----------
             __u32 key = 0;
@@ -860,26 +871,13 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
             // 保存 trace_id 到psc
             cw_save_parent_tracking_span(cw_parent_span_context);
             cw_bpf_debug("[Trace Start in l7][HTTP]pid:[%d] trace_id:[%llu]\n", tid, cw_parent_span_context->trace_id);
-
-            // ---------- 在http请求入口生成 横向串联的trace_id end ----------
-            bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
-            cw_bpf_debug("[Receive][HTTP] to user space");
-
-            // 作为服务端统计 bytes_received 使用
-            // struct connection *accept_conn = bpf_map_lookup_elem(&active_accepts, &cid);
-            // cw_bpf_debug("socket accept bytes_received cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
-            // if (accept_conn && !is_tls){
-            //     cw_bpf_debug("socket accept bytes_received after cid.pid=%d, cid.fd=%d\n", cid.pid, cid.fd);
-            //     __sync_fetch_and_add(&accept_conn->bytes_received, total_size);
-            // }
-            return 0;
+    // ---------- 在http请求入口生成 横向串联的trace_id end ----------
 #else
            //bpf_tail_call PROGUP(l7_http_request)
-           bpf_printk("======== PROG_DATA_L7_HTTP_TRACE_ID_UP_IDX ========== __KERNEL_FROM < 512 ");
+           cw_bpf_debug("======== PROG_DATA_L7_HTTP_TRACE_ID_UP_IDX ========== __KERNEL_FROM < 512 pid:[%d] ",tid);
            bpf_tail_call(ctx, &NAME(progs_jmp_tp_map), PROG_DATA_L7_HTTP_TRACE_ID_TP_IDX);
-           return 0;
 #endif
-
+         return 0;
     }
 
     struct connection *conn = bpf_map_lookup_elem(&active_connections, &cid);
@@ -1342,45 +1340,32 @@ int sys_exit_recvfrom(struct trace_event_raw_sys_exit_rw__stub* ctx) {
 //    return 0;
 //}
 
-//bpf_prog_up__l7_http_request
-PROGUP(l7_http_trace_id)(struct pt_regs *ctx) {
+//bpf_prog_tp__l7_http_trace_id
+PROGTP(l7_http_trace_id)(void * ctx){
 
-    return 0 ;
-   bpf_printk("======== PROG_DATA_L7_HTTP_TRACE_ID_UP_IDX ========== l7_http_trace_id ");
     int zero1 = 0;
 
-    struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero1);
-    if (!e) {
-        return 0;
-    }
-
     struct l7_request *req = bpf_map_lookup_elem(&l7_request_heap, &zero1);
     if (!req) {
         return 0;
     }
- bpf_printk("======== PROG_DATA_L7_HTTP_TRACE_ID_UP_IDX ========== 11111111 ");
 // ---------- 在http请求入口生成 横向串联的trace_id start ----------
     __u32 key = 0;
     __u32 offset = has_cw_header(req->payload);
-//        cw_bpf_debug("pid:[%d],offset:[%d]\n",tid,offset);
     struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&apm_span_context_heap3, &key);
     if (cw_parent_span_context == NULL) {
         return -1;
     }
     __builtin_memset(cw_parent_span_context, 0, sizeof(struct apm_span_context));
 
-//    if (offset > 0) {
-//        cw_string_to_span_context(&req->payload[offset], cw_parent_span_context);
-//    } else {
-//        generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
-//    }
+    if (offset > 0) {
+        cw_string_to_span_context(&req->payload[offset], cw_parent_span_context);
+    } else {
+        generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
+    }
     // 保存 trace_id 到psc
-//    cw_save_parent_tracking_span(cw_parent_span_context);
-//    cw_bpf_debug("[Trace Start in l7][HTTP]pid:[%d] trace_id:[%llu]\n", tid, cw_parent_span_context->trace_id);
-
+    cw_save_parent_tracking_span(cw_parent_span_context);
+    cw_bpf_debug("[Trace Start in l7][HTTP] trace_id:[%llu]\n", cw_parent_span_context->trace_id);
     // ---------- 在http请求入口生成 横向串联的trace_id end ----------
-
-//    bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
-//    cw_bpf_debug("[Receive][HTTP] to user space");
     return 0;
 }

+ 1 - 1
ebpftracer/tracer/socket.go

@@ -70,7 +70,7 @@ func insert_output_prog_to_map(collection *ebpf.Collection) {
 	__insert_output_prog_to_map(collection, MAP_PROGS_JMP_UP_NAME, PROG_JAVA_BUILD_HEADER_FOR_UP, PROG_DATA_JAVA_BUILD_HEADER_UP_IDX)
 	__insert_output_prog_to_map(collection, MAP_PROGS_JMP_UP_NAME, PROG_GO_UPDATE_HEADER_FOR_UP, PROG_DATA_GO_UPDATE_HEADER_UP_IDX)
 	//add for l7.c -> is_http_request(payload) -> bpf_tail_call
-	__insert_output_prog_to_map(collection, MAP_PROGS_JMP_UP_NAME, PROG_L7_HTTP_TRACE_ID_FOR_TP, PROG_DATA_L7_HTTP_TRACE_ID_TP_IDX)
+	__insert_output_prog_to_map(collection, MAP_PROGS_JMP_TP_NAME, PROG_L7_HTTP_TRACE_ID_FOR_TP, PROG_DATA_L7_HTTP_TRACE_ID_TP_IDX)
 }
 
 func __insert_output_prog_to_map(collection *ebpf.Collection, mapName string, progName string, key uint32) {