Forráskód Böngészése

Feature #TASK_QT-18250 grpc server uprobe点挂载成功。

rock 7 hónapja
szülő
commit
1ab0635cb1
2 módosított fájl, 44 hozzáadás és 21 törlés
  1. 5 0
      ebpftracer/ebpf/utrace/go/net/grpc.server.probe.bpf.c
  2. 39 21
      ebpftracer/tls.go

+ 5 - 0
ebpftracer/ebpf/utrace/go/net/grpc.server.probe.bpf.c

@@ -180,6 +180,8 @@ handleStream(struct pt_regs *ctx, void *stream_ptr, struct go_iface *go_context)
         return 0;
     }
 
+    bpf_printk("start get apm data\n");
+
     struct l7_request_key k = {};
     k.pid = pid;
     k.fd = 0;
@@ -284,6 +286,7 @@ int uprobe_server_handleStream(struct pt_regs *ctx) {
 SEC("uprobe/server_handleStream2")
 int uprobe_server_handleStream2(struct pt_regs *ctx) {
     u64 server_stream_pos = 4;
+    bpf_printk("enter uprobe_server_handleStream2\n");
     void *server_stream_ptr = get_argument(ctx, server_stream_pos);
     if (server_stream_ptr == NULL) {
         bpf_printk("grpc:server:uprobe/server_handleStream2: failed to get ServerStream arg");
@@ -333,6 +336,7 @@ int uprobe_server_handleStream2_Returns(struct pt_regs *ctx) {
 
 	pid = id >> 32;
 	tid =  (__u32)id;
+    bpf_printk("enter uprobe_server_handleStream2_Returns\n");
 
     struct l7_request_key k = {};
     k.pid = pid;
@@ -506,6 +510,7 @@ int uprobe_http2Server_WriteStatus(struct pt_regs *ctx) {
 // This is only compatible with versions > 1.69.0 of the Server.
 SEC("uprobe/http2Server_WriteStatus2")
 int uprobe_http2Server_WriteStatus2(struct pt_regs *ctx) {
+    bpf_printk("enter uprobe_http2Server_WriteStatus2\n");
     u64 server_stream_pos = 2;
     void *server_stream_ptr = get_argument(ctx, server_stream_pos);
     if (server_stream_ptr == NULL) {

+ 39 - 21
ebpftracer/tls.go

@@ -31,7 +31,9 @@ const (
 	goRunqget             = "runtime.runqget"
 	goServeHTTP           = "net/http.serverHandler.ServeHTTP"
 	goTransport           = "net/http.(*Transport).roundTrip"
+	goGrpcServerHandleStream = "google.golang.org/grpc.(*Server).handleStream"
 	goGrpcHttp2OperateHeader = "google.golang.org/grpc/internal/transport.(*http2Server).operateHeaders"
+	goGrpcServerWritestatus = "google.golang.org/grpc/internal/transport.(*http2Server).writeStatus"
 )
 
 var (
@@ -295,7 +297,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 		}
 		switch s.Name {
 		case goTlsWriteSymbol, goTlsReadSymbol:
-		case goExecute, goNewproc1, goRunqget, goServeHTTP, goTransport, goGrpcHttp2OperateHeader:
+		case goExecute, goNewproc1, goRunqget, goServeHTTP, goTransport, goGrpcHttp2OperateHeader,goGrpcServerHandleStream:
 		default:
 			continue
 		}
@@ -385,26 +387,42 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, appInfo *AppInfo, codeType uint1
 			}
 			klog.Infoln("goGrpcHttp2OperateHeader ok")
 			links = append(links, l)
-			// sStart := s.Value - textSection.Addr
-			// sEnd := sStart + s.Size
-			// if sEnd > textSectionLen {
-			// 	continue
-			// }
-			// sBytes := textSectionData[sStart:sEnd]
-			// returnOffsets := getReturnOffsets(ef.Machine, sBytes)
-			// if len(returnOffsets) == 0 {
-			// 	err = fmt.Errorf("failed to attach uprobe_http2Server_operateHeader no return offsets found")
-			// 	klog.Errorln(err)
-			// 	return nil, err
-			// }
-			// for _, offset := range returnOffsets {
-			// 	l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_HandlerFunc_ServeHTTP_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
-			// 	if err != nil {
-			// 		klog.WithError(err).Errorln(fmt.Errorf("failed to attach exit_runtime_newproc1 uprobe"))
-			// 		return nil, err
-			// 	}
-			// 	links = append(links, l)
-			// }
+		case goGrpcServerWritestatus:
+			l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_http2Server_WriteStatus2"], &link.UprobeOptions{Address: address})
+			if err != nil {
+				klog.WithError(err).Errorln("failed to attach uprobe_http2Server_WriteStatus2 uprobe")
+				continue
+			}
+			klog.Infoln("google.golang.org/grpc/internal/transport.(*http2Server).writeStatus ok")
+			links = append(links, l)
+		case goGrpcServerHandleStream:
+			l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_server_handleStream2"], &link.UprobeOptions{Address: address})
+			if err != nil {
+				klog.WithError(err).Errorln("failed to attach uprobe_server_handleStream2 uprobe")
+				continue
+			}
+			klog.Infoln("google.golang.org/grpc.(*Server).handleStream ok")
+			links = append(links, l)
+			sStart := s.Value - textSection.Addr
+			sEnd := sStart + s.Size
+			if sEnd > textSectionLen {
+				continue
+			}
+			sBytes := textSectionData[sStart:sEnd]
+			returnOffsets := getReturnOffsets(ef.Machine, sBytes)
+			if len(returnOffsets) == 0 {
+				err = fmt.Errorf("failed to attach uprobe_server_handleStream2 no return offsets found")
+				klog.Errorln(err)
+				return nil, err
+			}
+			for _, offset := range returnOffsets {
+				l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_server_handleStream2_Returns"], &link.UprobeOptions{Address: address, Offset: uint64(offset)})
+				if err != nil {
+					klog.WithError(err).Errorln(fmt.Errorf("failed to attach exit_runtime_newproc1 uprobe"))
+					return nil, err
+				}
+				links = append(links, l)
+			}
 		case goServeHTTP:
 			l, err := exe.Uprobe(s.Name, t.uprobes["uprobe_HandlerFunc_ServeHTTP"], &link.UprobeOptions{Address: address})
 			if err != nil {