Jelajahi Sumber

Feature #TASK_QT-18250 新增日志,调整success流程

Carl 1 tahun lalu
induk
melakukan
876155203b
2 mengubah file dengan 22 tambahan dan 9 penghapusan
  1. 11 4
      containers/container.go
  2. 11 5
      containers/registry.go

+ 11 - 4
containers/container.go

@@ -1451,7 +1451,6 @@ func (c *Container) AttachUprobes(tracer *ebpftracer.Tracer, pid uint32) error {
 		c.DetachUprobes(pid, APP_UPROBE_ERROR)
 		return err
 	}
-	c.l7AttachSuccess()
 	return nil
 }
 
@@ -1471,22 +1470,26 @@ func (c *Container) attachTlsUprobes(tracer *ebpftracer.Tracer, pid uint32) erro
 	if p == nil {
 		return nil
 	}
+	if p.openSslUprobesChecked || p.goTlsUprobesChecked {
+		return nil
+	}
 	if !p.openSslUprobesChecked {
+		p.openSslUprobesChecked = true
 		sslProbes, err := tracer.AttachOpenSslUprobes(pid)
 		if err != nil {
 			return err
 		}
 		p.uprobes = append(p.uprobes, sslProbes...)
-		p.openSslUprobesChecked = true
 	}
 	if !p.goTlsUprobesChecked {
+		p.goTlsUprobesChecked = true
 		codeType := c.GetCodeTypeFromCache(pid)
 		goProbes, err := tracer.AttachGoTlsUprobes(pid, &c.AppInfo, uint16(codeType))
 		if err != nil {
 			return err
 		}
 		p.uprobes = append(p.uprobes, goProbes...)
-		p.goTlsUprobesChecked = true
+		c.l7AttachSuccess()
 	}
 
 	return nil
@@ -1523,6 +1526,7 @@ func (c *Container) attachJVMUprobes(tracer *ebpftracer.Tracer, pid uint32) erro
 			major, minor, patch, err := ebpftracer.ParseVersion(v)
 			klog.Infof("[attach] version: %s (Major: %d, Minor: %d, Patch: %d)", v, major, minor, patch)
 			if major != 1 || minor != 8 {
+				klog.Errorf("[attach] Unsupported Java version.")
 				return fmt.Errorf("[attach] Unsupported Java version")
 			}
 		}
@@ -1541,8 +1545,9 @@ func (c *Container) attachJVMUprobes(tracer *ebpftracer.Tracer, pid uint32) erro
 		}
 		p.uprobes = append(p.uprobes, libNetProbes...)
 		//p.jvmUprobesChecked = true
+		c.l7AttachSuccess()
 	} else {
-		klog.Infof("[attach] %s-%d already attach", codeType.String(), pid)
+		klog.Infof("[attach] %s-%d already attach status:%v", codeType.String(), pid, c.Isl7AttachSuccess())
 	}
 	return nil
 }
@@ -1596,6 +1601,7 @@ func (c *Container) attachJavaAotUprobes(tracer *ebpftracer.Tracer, pid uint32)
 		}
 		p.uprobes = append(p.uprobes, libNetProbes...)
 		//p.jvmUprobesChecked = true
+		c.l7AttachSuccess()
 	} else {
 		klog.Infof("[attach] %s-%d already attach", codeType.String(), pid)
 	}
@@ -1635,6 +1641,7 @@ func (c *Container) attachNetCoreUprobes(tracer *ebpftracer.Tracer, pid uint32)
 			return err
 		}
 		p.uprobes = append(p.uprobes, WriteProbes...)
+		c.l7AttachSuccess()
 	}
 
 	return nil

+ 11 - 5
containers/registry.go

@@ -354,11 +354,14 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 							klog.WithError(err).Errorf("[registry] Failed registerAppInfo. pid is %d", e.Pid)
 							continue
 						}
-						c.AttachUprobes(r.tracer, e.Pid)
+						err = c.AttachUprobes(r.tracer, e.Pid)
+						if err != nil {
+							klog.WithField("pid", e.Pid).WithError(err).Errorf("[AttachUprobes] [end] Failed attach stack trace!")
+						}
 						if !r.tracer.DisableStackTracing() {
 							err = c.AttachStack(r.tracer, e.Pid)
 							if err != nil {
-								klog.WithField("pid", e.Pid).WithError(err).Errorf("[registry][end] Failed attach stack trace!")
+								klog.WithField("pid", e.Pid).WithError(err).Errorf("[registry] [end] Failed attach stack trace!")
 							}
 						}
 					}
@@ -366,7 +369,7 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 					klog.Infoln("TCP listen open from unknown container", e)
 				}
 			case ebpftracer.EventTypeAcceptOpen:
-				klog.Infoln("ebpftracer.EventTypeAcceptOpen==================", e.Pid)
+				//klog.Infoln("ebpftracer.EventTypeAcceptOpen==================", e.Pid)
 				if c := r.getOrCreateContainer(e.Pid); c != nil {
 					c.onAcceptOpen(e.Pid, e.Fd, e.SrcAddr, e.DstAddr, e.Timestamp, false, e.Duration)
 					c.eventReady()
@@ -389,12 +392,15 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 							klog.WithError(err).Errorf("[registry] Failed registerAppInfo. pid is %d", e.Pid)
 							continue
 						}
-						c.AttachUprobes(r.tracer, e.Pid)
+						err = c.AttachUprobes(r.tracer, e.Pid)
+						if err != nil {
+							klog.WithField("pid", e.Pid).WithError(err).Errorf("[AttachUprobes] [end] Failed attach stack trace!")
+						}
 						// 禁用stack
 						if !r.tracer.DisableStackTracing() {
 							err = c.AttachStack(r.tracer, e.Pid)
 							if err != nil {
-								klog.WithField("pid", e.Pid).WithError(err).Errorf("[registry][end] Failed attach stack trace!")
+								klog.WithField("pid", e.Pid).WithError(err).Errorf("[registry] [end] Failed attach stack trace!")
 							}
 						} else {
 							klog.Warnf("StackTrace tracing is disabled")