Explorar o código

Merge branch 'dev-white-list' into dev

Carl hai 1 ano
pai
achega
0f8f666f52

+ 23 - 16
containers/apm_stack_dispatch.go

@@ -28,12 +28,12 @@ type uprobesDef struct {
 	RetAddress uint64
 }
 
-func (c *Container) StackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
-	// 禁用stack
-	if tracer.DisableStackTracing() {
-		klog.Warnf("StackTrace tracing is disabled")
-		return nil
-	}
+func (c *Container) AttachStack(tracer *ebpftracer.Tracer, pid uint32) error {
+	//// 禁用stack
+	//if tracer.DisableStackTracing() {
+	//	klog.Warnf("StackTrace tracing is disabled")
+	//	return nil
+	//}
 
 	if common.IsOpenFilter() && !common.IsFilterPid(pid) {
 		klog.Warnf("StackTrace %d tracing is filter", pid)
@@ -51,10 +51,12 @@ func (c *Container) StackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
 		return fmt.Errorf("unknown process %d", pid)
 	}
 
-	if p.stackUprobesChecked {
+	if p.stackAttachOnce {
 		return nil
 	}
 
+	p.stackAttachOnce = true
+
 	switch codeType {
 	case CodeTypeJava:
 		return c.jvmStackTrace(tracer, pid)
@@ -69,7 +71,7 @@ func (c *Container) stackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
 		return fmt.Errorf("unknown process %d", pid)
 	}
 
-	if p.stackUprobesChecked {
+	if p.stackAttachOnce {
 		return nil
 	}
 
@@ -114,29 +116,34 @@ func (c *Container) stackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
 	}
 	//codeType := c.GetCodeTypeFromCache(pid)
 	//tracer.InitKProcInfo(pid, c.instanceID, uint16(codeType))
-	p.uprobes = append(p.uprobes, tracer.AttachStackUprobes(path, c.Uprobes)...)
-	p.stackUprobesChecked = true
+	p.stackUprobes = append(p.stackUprobes, tracer.AttachStackUprobes(path, c.Uprobes)...)
+	p.stackAttachOnce = true
 
 	return nil
 }
 
 func (c *Container) jvmStackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
-	// 禁用stack
-	if tracer.DisableStackTracing() {
-		return nil
-	}
 
 	p := c.processes[pid]
 
+	err := tracer.JattachJvm(pid, c.AppInfo)
+	if err != nil {
+		p.stackStatus.JattachFailure()
+		return err
+	} else {
+		p.stackStatus.JattachSuccess()
+	}
+
 	jvmStackProbes, err := tracer.AttachJVMStackUprobes(pid, c.AppInfo)
 
 	if err != nil {
+		p.stackStatus.StackUprobesFailure()
 		klog.WithError(err).Errorf("[jvmStackTrace] Failed attach jvm stack.")
 		return err
 	}
 
-	p.uprobes = append(p.uprobes, jvmStackProbes...)
-	p.stackUprobesChecked = true
+	p.stackUprobes = append(p.stackUprobes, jvmStackProbes...)
+	p.stackStatus.StackUprobesSuccess()
 
 	return nil
 }

+ 9 - 1
containers/apm_white_list.go

@@ -10,21 +10,29 @@ import (
 type WhiteListMap map[string][]WhiteSettingInfo
 
 func (r *Registry) getWhiteListByCodeType(codeType CodeType) []WhiteSettingInfo {
+	//if true {
+	//	return r.getWhiteListAll()
+	//}
 	return r.whiteListRules[codeType.WhiteCodeString()]
 }
 
 func (r *Registry) setWhiteList(whiteData WhiteData) {
+	var openStack int
+	if !r.tracer.DisableStackTracing() {
+		openStack = 1
+	}
 	whiteListMap := make(WhiteListMap)
 	for _, scop := range whiteData.Appscope {
 		code := scop.Code
 		for _, setting := range scop.Settings {
+			setting.OpenStack = openStack
 			whiteListMap[code] = append(whiteListMap[code], setting)
 		}
 	}
 	r.whiteListRules = whiteListMap
 }
 
-func (r *Registry) getWhiteList() (bool, error) {
+func (r *Registry) pullWhiteList() (bool, error) {
 	if common.IsOpenFilter() {
 		return false, nil
 	}

+ 56 - 0
containers/apm_white_list_v2.go

@@ -0,0 +1,56 @@
+package containers
+
+import (
+	"fmt"
+	"github.com/coroot/coroot-node-agent/common"
+	. "github.com/coroot/coroot-node-agent/utils/modelse"
+	log "github.com/sirupsen/logrus"
+)
+
+func (r *Registry) getWhiteListAll() []WhiteSettingInfo {
+	return r.whiteListRules["all"]
+}
+
+func (r *Registry) setWhiteListV2(whiteData WhiteDataV2) {
+	whiteListMap := make(WhiteListMap)
+	code := "all"
+	for _, setting := range whiteData.SettingList {
+		setting.Filters = setting.ProcessKey
+		whiteListMap[code] = append(whiteListMap[code], setting)
+	}
+	r.whiteListRules = whiteListMap
+}
+
+func (r *Registry) pullWhiteListV2() (bool, error) {
+	if common.IsOpenFilter() {
+		return false, nil
+	}
+	nodeInfo := r.nodeInfo.GetNodeInfo()
+	if nodeInfo == nil {
+		return false, fmt.Errorf("could not find node info")
+	}
+
+	whiteListReq := WhiteListReq{
+		HostId:    nodeInfo.HostID,
+		AccountId: nodeInfo.AccountID,
+		WhiteType: 2,
+	}
+	whiteData, err := r.connServer.WhiteListV2(whiteListReq)
+
+	if err != nil {
+		log.Errorf("report WhiteList info error is %v.", err)
+		return false, err
+	}
+
+	//fmt.Println(r.whiteLastUpdatedTime)
+	//fmt.Println(whiteData.LastUpdatedTime)
+	// 不用更新
+	if r.whiteLastUpdatedTime == whiteData.LastUpdatedTime {
+		return false, nil
+	}
+
+	// 更新时间
+	r.whiteLastUpdatedTime = whiteData.LastUpdatedTime
+	r.setWhiteListV2(whiteData)
+	return true, nil
+}

+ 5 - 6
containers/container.go

@@ -1415,8 +1415,7 @@ func (c *Container) attachUprobes(tracer *ebpftracer.Tracer, pid uint32) error {
 		err = c.attachNetCoreUprobes(tracer, pid)
 	}
 	if err != nil {
-		// TODO 条件卸载
-		c.errorClose(pid, 0)
+		c.DetachUprobes(pid, ERROR_DETACH)
 		return err
 	}
 	c.l7AttachSuccess()
@@ -1469,8 +1468,8 @@ func (c *Container) attachJVMUprobes(tracer *ebpftracer.Tracer, pid uint32) erro
 		return nil
 	}
 	codeType := c.GetCodeTypeFromCache(pid)
-	if !p.jvmUprobesChecked {
-		p.jvmUprobesChecked = true
+	if !p.jvmAttachOnce {
+		p.jvmAttachOnce = true
 		rootfs := c.getRootfs()
 		tracer.InitKProcInfo(pid, &c.AppInfo)
 
@@ -1530,7 +1529,8 @@ func (c *Container) attachNetCoreUprobes(tracer *ebpftracer.Tracer, pid uint32)
 	if p == nil {
 		return nil
 	}
-	if !p.jvmUprobesChecked {
+	if !p.jvmAttachOnce {
+		p.jvmAttachOnce = true
 		//codeType := c.GetCodeTypeFromCache(pid)
 		tracer.InitKProcInfo(pid, &c.AppInfo)
 		p.uprobes = append(p.uprobes, tracer.AttachNetCoreNetThreadUprobes(pid)...)
@@ -1547,7 +1547,6 @@ func (c *Container) attachNetCoreUprobes(tracer *ebpftracer.Tracer, pid uint32)
 			return err
 		}
 		p.uprobes = append(p.uprobes, WriteProbes...)
-		p.jvmUprobesChecked = true
 	}
 
 	return nil

+ 96 - 15
containers/container_apm.go

@@ -5,6 +5,7 @@ import (
 	"bytes"
 	"debug/elf"
 	"fmt"
+	"github.com/cilium/ebpf/link"
 	"github.com/coroot/coroot-node-agent/flags"
 	"os"
 	"path"
@@ -497,19 +498,20 @@ func (c *Container) l7AttachSuccess() {
 	c.l7Attach = true
 }
 
-func (c *Container) verifyAttachConditions(r *Registry, pid uint32) bool {
+func (c *Container) verifyAttachConditions(r *Registry, pid uint32) (bool, int) {
 	p := c.processes[pid]
 	if p != nil && c.checkEventReady() {
 		codeType := c.GetCodeTypeFromCache(pid)
 		if codeType.IsUnknownCode() {
 			klog.WithField("pid", pid).Debug("[verify] unknown language.")
-			return false
+			return false, 0
 		}
 		cmdline := p.GetCmdline()
 		if len(cmdline) == 0 {
-			return false
+			return false, 0
 		}
-		whiteListByCode := r.getWhiteListByCodeType(codeType)
+		//whiteListByCode := r.getWhiteListByCodeType(codeType)
+		whiteListByCode := r.getWhiteListAll()
 		//klog.WithField("pid", pid).WithField("codeType", codeType.String()).
 		//	Infof("[verify] white list %v", utils.ToString(whiteListByCode))
 		// 当前语言的白名单规则
@@ -525,30 +527,109 @@ func (c *Container) verifyAttachConditions(r *Registry, pid uint32) bool {
 					WithField("codeType", codeType.String()).
 					WithField("ruleVal", ruleVal).
 					WithField("cmdline", cmdline).
+					WithField("stack", setting.OpenStack).
 					WithField("white list", utils.ToString(whiteListByCode)).
 					Infoln("[verify] check successful.")
-				return true
+				return true, setting.OpenStack
 			}
 		}
 	}
-	return false
+	return false, 0
 }
 
-func (c *Container) detachUprobes(pid uint32) {
+// 1.卸载入口
+func (c *Container) Detach(pid uint32, detachType int) {
 	c.lock.Lock()
 	defer c.lock.Unlock()
+
+	if p := c.processes[pid]; p != nil {
+		err := c.DetachUprobes(pid, detachType)
+		if err != nil {
+			return
+		}
+		err = c.DetachStack(pid)
+		if err != nil {
+			return
+		}
+		// 关闭7层监控
+		c.l7Attach = false
+		// 变更应用为卸载状态
+		c.AppInfo.AppUninstall()
+	}
+}
+
+// 1.1卸载uprobe
+func (c *Container) DetachUprobes(pid uint32, detachType int) error {
 	// close uprobe
 	if p := c.processes[pid]; p != nil {
-		if len(p.uprobes) > 0 {
-			klog.Infof("detachUprobes", pid)
-			// 关闭应用层uprobes
-			p.DynamicClose(1)
-			// 关闭7层监控
-			c.l7Attach = false
-			// 变更应用为卸载状态
-			c.AppInfo.AppUninstall()
+		for _, u := range p.uprobes {
+			err := u.Close()
+			if err != nil {
+				return err
+			}
+		}
+		p.uprobes = []link.Link{}
+		switch detachType {
+		case UNINSTALL_DETACH:
+			codeType := c.GetCodeTypeFromCache(pid)
+			switch codeType {
+			case CodeTypeJava:
+				p.jvmAttachOnce = false
+			case CodeTypeGo:
+				p.goTlsUprobesChecked = false
+				p.openSslUprobesChecked = false
+			default:
+
+			}
+		case ERROR_DETACH:
+			klog.Infof("[DetachUprobes] ERROR_DETACH for pid %d", pid)
+		default:
 		}
+	} else {
+		return fmt.Errorf("[DetachUprobes] cannot find uprobe for pid %d", pid)
 	}
+	return nil
+}
+
+// 1.2卸载堆栈
+func (c *Container) DetachStack(pid uint32) error {
+	if p := c.processes[pid]; p != nil {
+		var err error
+		codeType := c.GetCodeTypeFromCache(pid)
+		switch codeType {
+		case CodeTypeJava:
+			err = c.detachJvmStack(pid)
+		default:
+			err = p.closeStackUprobes()
+		}
+		if err != nil {
+			klog.WithError(err).Errorln("[detachStack] failed to detach stack")
+			return err
+		}
+		p.stackAttachOnce = false
+	} else {
+		return fmt.Errorf("[DetachStack] cannot find uprobe for pid %d", pid)
+	}
+	return nil
+}
+
+// 1.2.1 卸载 jvm堆栈
+func (c *Container) detachJvmStack(pid uint32) error {
+	if p := c.processes[pid]; p != nil {
+		var err error
+		if p.stackStatus.IsJattachSuccess() {
+			// 卸载 JavaAgent
+			err = p.uninstallJavaAgent()
+			klog.WithError(err).Errorln("[detachJvmStack] uninstallJavaAgent")
+		}
+		if p.stackStatus.IsStackUprobesSuccess() || len(p.stackUprobes) > 0 {
+			// 卸载堆栈probes
+			err = p.closeStackUprobes()
+			klog.WithError(err).Errorln("[detachJvmStack] closeStackUprobes")
+		}
+		return err
+	}
+	return nil
 }
 
 func (c *Container) getRootfs() string {

+ 47 - 9
containers/process.go

@@ -32,11 +32,13 @@ type Process struct {
 	isGolangApp   bool
 
 	uprobes               []link.Link
+	stackUprobes          []link.Link
 	goTlsUprobesChecked   bool
 	openSslUprobesChecked bool
-	jvmUprobesChecked     bool
-	stackUprobesChecked   bool
 
+	jvmAttachOnce    bool
+	stackAttachOnce  bool
+	stackStatus      StackStatus
 	codeType         CodeType
 	cmdline          string
 	pythonGilChecked bool
@@ -118,14 +120,48 @@ func (p *Process) Close() {
 	}
 }
 
+func (p *Process) closeStackUprobes() error {
+	for _, u := range p.stackUprobes {
+		err := u.Close()
+		if err != nil {
+			return err
+		}
+	}
+	p.stackUprobes = []link.Link{}
+	p.stackStatus.StackUprobesClose()
+	return nil
+}
+
 func (p *Process) DynamicClose(closeType int) {
 	for _, u := range p.uprobes {
 		_ = u.Close()
 	}
-	p.goTlsUprobesChecked = false
-	p.openSslUprobesChecked = false
-	p.jvmUprobesChecked = false
-	if p.codeType.IsJvmCode() && p.stackUprobesChecked {
+	//p.goTlsUprobesChecked = false
+	//p.openSslUprobesChecked = false
+	//p.jvmUprobesChecked = false
+	//if p.codeType.IsJvmCode() && p.stackUprobesChecked {
+	//	nativeBasePath := utils.GetDefaultAgentsPath("NativeAgent")
+	//	kvPairs := []string{
+	//		fmt.Sprintf("%s=%s", filepath.Join(nativeBasePath, "lib", "apmAgent.jar"), nativeBasePath),
+	//		"UNINSTALL",
+	//	}
+	//	argkv := strings.Join(kvPairs, ",")
+	//	args := []string{"load", "instrument", "false", argkv}
+	//	jattacher := jattach.JvmJattacher{
+	//		Pid:         p.Pid,
+	//		Args:        args,
+	//		PrintOutput: 1,
+	//	}
+	//	_, err := jattacher.JDetach()
+	//	if err == nil {
+	//		//p.stackUprobesChecked = false
+	//	}
+	//}
+	p.uprobes = []link.Link{}
+}
+
+func (p *Process) uninstallJavaAgent() error {
+	if p.codeType.IsJvmCode() && p.stackAttachOnce {
 		nativeBasePath := utils.GetDefaultAgentsPath("NativeAgent")
 		kvPairs := []string{
 			fmt.Sprintf("%s=%s", filepath.Join(nativeBasePath, "lib", "apmAgent.jar"), nativeBasePath),
@@ -139,11 +175,13 @@ func (p *Process) DynamicClose(closeType int) {
 			PrintOutput: 1,
 		}
 		_, err := jattacher.JDetach()
-		if err == nil {
-			//p.stackUprobesChecked = false
+		if err != nil {
+			return err
 		}
+		p.stackStatus.JattachClose()
+		return nil
 	}
-	p.uprobes = []link.Link{}
+	return nil
 }
 
 func (p *Process) GetCmdline() string {

+ 36 - 15
containers/registry.go

@@ -40,6 +40,8 @@ var (
 	cronjobPodScheduleWindow = 7 * 24 * time.Hour
 )
 
+const OPEN_STACK = 1
+
 type ProcessInfo struct {
 	Pid         uint32
 	ContainerId ContainerID
@@ -68,7 +70,7 @@ type Registry struct {
 	trafficStatsLastUpdated time.Time
 	trafficStatsLock        sync.Mutex
 	trafficStatsUpdateCh    chan *TrafficStatsUpdate
-	nodeInfo             *NodeInfoT
+	nodeInfo                *NodeInfoT
 }
 
 var (
@@ -134,7 +136,7 @@ func NewRegistry(reg prometheus.Registerer, kernelVersion string, nodeInfo *Node
 		tracer:               ebpftracer.NewTracer(kernelVersion, *flags.DisableL7Tracing, *flags.DisableE2ETracing, *flags.DisableStackTracing),
 		whiteListRules:       make(WhiteListMap),
 		trafficStatsUpdateCh: make(chan *TrafficStatsUpdate),
-		nodeInfo:       nodeInfo,
+		nodeInfo:             nodeInfo,
 	}
 	// 初始化软负载集群节点
 	proxyClient, clientErr := NewProxyClient(*flags.ConfigServer, false)
@@ -202,7 +204,8 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 	for {
 		select {
 		case now := <-gcTicker.C:
-			_, err := r.getWhiteList()
+			//_, err := r.pullWhiteList()
+			_, err := r.pullWhiteListV2()
 			if err != nil {
 				klog.WithError(err).Errorf("connWhiteList error")
 			}
@@ -210,7 +213,7 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 			for pid, c := range r.containersByPid {
 				if c != nil {
 					if c != nil && !common.IsOpenFilter() {
-						verifyAttachConditions := c.verifyAttachConditions(r, pid)
+						verifyAttachConditions, openStack := c.verifyAttachConditions(r, pid)
 						if verifyAttachConditions {
 							err = c.RegisterAppInfo(r, pid)
 							if err == nil {
@@ -221,10 +224,19 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 								} else {
 									klog.WithField("pid", pid).Infoln("[registry] Attach uprobes success!")
 								}
-								klog.WithField("pid", pid).Infoln("[registry] Attach app stack.")
-								err = c.StackTrace(r.tracer, pid)
-								if err != nil {
-									klog.WithField("pid", pid).WithError(err).Errorf("[registry][end] Failed attach stack trace!")
+								if openStack == OPEN_STACK {
+									klog.WithField("pid", pid).Infoln("[registry] Attach app stack.")
+									err = c.AttachStack(r.tracer, pid)
+									if err != nil {
+										klog.WithField("pid", pid).WithError(err).Errorf("[registry][end] Failed attach stack trace!")
+									}
+								} else {
+									// 未开启、成功、关闭、错误注入
+									// 关闭堆栈
+									err = c.DetachStack(pid)
+									if err != nil {
+										klog.WithError(err).Errorf("[registry][end] Failed detach stack trace!")
+									}
 								}
 							} else {
 								klog.WithError(err).Errorf("[registry] Failed registerAppInfo.")
@@ -233,7 +245,7 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 
 						if !verifyAttachConditions && c.checkL7AttachReady() {
 							// detach
-							c.detachUprobes(pid)
+							c.Detach(pid, UNINSTALL_DETACH)
 						}
 					}
 					if c.AppInfo.AppName != "" {
@@ -249,7 +261,9 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 							Sport:      c.AppInfo.Sport,
 							RegisterAt: time.Unix(c.AppInfo.RegisterAt, 0).Format("060102 15:04:05"),
 							Status:     c.AppInfo.Status,
+							Rule:       c.WhiteSettingInfo.Filters,
 						}
+						detail.Rule = fmt.Sprintf("%s|%d", c.WhiteSettingInfo.Filters, c.WhiteSettingInfo.OpenStack)
 						if c.AppInfo.UpdateAt != 0 {
 							detail.UpdateAt = time.Unix(c.AppInfo.UpdateAt, 0).Format("060102 15:04:05")
 						}
@@ -370,9 +384,11 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 							continue
 						}
 						c.attachUprobes(r.tracer, e.Pid)
-						err = c.StackTrace(r.tracer, e.Pid)
-						if err != nil {
-							klog.WithField("pid", e.Pid).WithError(err).Errorf("[registry][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!")
+							}
 						}
 					}
 				} else {
@@ -401,9 +417,14 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 							continue
 						}
 						c.attachUprobes(r.tracer, e.Pid)
-						err = c.StackTrace(r.tracer, e.Pid)
-						if err != nil {
-							klog.WithField("pid", e.Pid).WithError(err).Errorf("[registry][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!")
+							}
+						} else {
+							klog.Warnf("StackTrace tracing is disabled")
 						}
 					}
 				} else {

+ 2 - 2
dist/package_dir/agents/NativeAgent/conf/agent.properties

@@ -1,6 +1,6 @@
 # APM Server url.
-ConfigDomain    = http://10.0.16.250:18084/apm
-SendDomain      = http://10.0.16.250:18084/apm
+ConfigDomain    = http://10.0.7.115:18080
+SendDomain      = http://10.0.7.115:18080
 # License Key.
 # Logging level.
 # Optional: DEBUG, INFO, WARN, ERROR

+ 1 - 0
ebpftracer/ebpf/l7/l7.c

@@ -873,6 +873,7 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
 	        e->end_at = bpf_ktime_get_ns();
 	        e->duration = e->end_at - req->ns;
             e->payload_size = ret;
+	        e->trace_id = get_apm_trace_id(pid, tid);
             COPY_PAYLOAD(e->payload, ret, payload);
             send_event(ctx, e, cid, conn);
             bpf_map_delete_elem(&active_l7_requests, &k);

+ 7 - 2
ebpftracer/stack.go

@@ -49,7 +49,7 @@ func (t *Tracer) AttachStackUprobes(path string, uprobes []tracer.Uprobe) []link
 }
 
 // JVM process stack
-func (t *Tracer) AttachJVMStackUprobes(pid uint32, appInfo AppInfo) ([]link.Link, error) {
+func (t *Tracer) JattachJvm(pid uint32, appInfo AppInfo) error {
 	klog.Infoln("[Jvm stack uprobe] Attach Start AttachJVMStackUprobes", pid)
 	// TODO tiny Agent 注入
 	//argkv := "/opt/github/euspace/dist/package_dir/agents/NativeAgent/lib/apmAgent.jar=/opt/github/euspace/dist/package_dir/agents/NativeAgent"
@@ -75,9 +75,14 @@ func (t *Tracer) AttachJVMStackUprobes(pid uint32, appInfo AppInfo) ([]link.Link
 	res, err := jattacher.JAttach()
 	klog.Infof("[Jvm stack uprobe] JAttach Result: %d", res)
 	if err != nil {
-		return nil, err
+		return err
 	}
 
+	return nil
+}
+
+func (t *Tracer) AttachJVMStackUprobes(pid uint32, appInfo AppInfo) ([]link.Link, error) {
+
 	//path = utils.GetDefaultAgentsPath("NativeAgent", "libnativeAgent.so")
 	//tmp/NativeAgentSo2297066477572820801.tmp
 	path, err := FindNativeSoFromMapped(pid, "NativeAgentSo", ".tmp")

+ 8 - 2
flags/flags.go

@@ -130,7 +130,11 @@ func init() {
 	nativeConf := utils.GetDefaultAgentsPath("NativeAgent", "conf", "agent.properties")
 	confData, err := ini.Load(nativeConf)
 	if err == nil {
-		confData.Section(ini.DEFAULT_SECTION).Key("ConfigDomain").SetValue(*ConfigServer + *ServerPrefix)
+		var configServer string
+		if !strings.HasPrefix(*ConfigServer, "http") {
+			configServer = fmt.Sprintf("http://%s", *ConfigServer)
+		}
+		confData.Section(ini.DEFAULT_SECTION).Key("ConfigDomain").SetValue(configServer + *ServerPrefix)
 		confData.Section(ini.DEFAULT_SECTION).Key("SendDomain").SetValue(*DataServer + *ServerPrefix)
 		err = confData.SaveTo(nativeConf)
 		if err != nil {
@@ -167,6 +171,7 @@ func DumpTableFeatures() {
 			pid,
 			info.ProcName,
 			info.AppName,
+			info.Rule,
 			info.Language,
 			service,
 			info.AppID,
@@ -181,13 +186,14 @@ func DumpTableFeatures() {
 		"pid",
 		"process",
 		"app name",
+		"app rule",
 		"code",
 		"service",
 		"app id",
 		//"agent id",
 		"first register at",
 		"update at",
-		"status",
+		"app status",
 	})
 	fmt.Println(t.Render())
 	os.Exit(0)

+ 9 - 0
utils/modelse/models.go

@@ -151,6 +151,7 @@ func (w *WhiteListReq) String() string {
 type WhiteListReq struct {
 	HostId    int64 `json:"host_id"`
 	AccountId int   `json:"account_id"`
+	WhiteType int   `json:"white_type"`
 }
 
 type WhiteListResp struct {
@@ -166,6 +167,9 @@ type WhiteSettingInfo struct {
 	Filters         string `json:"filters"`
 	Type            string `json:"type"`
 	PodName         string `json:"pod_name"`
+	ProcessKey      string `json:"process_key"`
+	OpenStack       int    `json:"collect_stack"`
+	UpdateTime      int64  `json:"update_time"`
 }
 
 type Appscope struct {
@@ -180,6 +184,11 @@ type WhiteData struct {
 	Appscope        []Appscope `json:"appscope"`
 }
 
+type WhiteDataV2 struct {
+	SettingList     []WhiteSettingInfo `json:"appscope"`
+	LastUpdatedTime int                `json:"last_updated_time"`
+}
+
 type ReportRequest struct {
 	RegistRequest
 	AgentID     string `json:"agent_id"`

+ 51 - 0
utils/modelse/stack_status.go

@@ -0,0 +1,51 @@
+package modelse
+
+import "fmt"
+
+type StackStatus uint8
+
+// 定义状态的位图常量
+const (
+	JattachSuccess StackStatus = 1 << 0
+	JattachFailure StackStatus = 0 << 0
+
+	StackUprobesSuccess StackStatus = 1 << 1
+	StackUprobesFailure StackStatus = 0 << 1
+)
+
+func (s StackStatus) IsJattachSuccess() bool {
+	return s&JattachSuccess != 0
+}
+
+func (s StackStatus) IsStackUprobesSuccess() bool {
+	return s&StackUprobesSuccess != 0
+}
+
+func (s *StackStatus) JattachSuccess() {
+	*s |= JattachSuccess
+}
+
+func (s *StackStatus) JattachFailure() {
+	*s &^= JattachSuccess
+}
+
+func (s *StackStatus) JattachClose() {
+	*s &^= JattachSuccess
+}
+
+func (s *StackStatus) StackUprobesSuccess() {
+	*s |= StackUprobesSuccess
+}
+
+func (s *StackStatus) StackUprobesFailure() {
+	*s &^= StackUprobesSuccess
+}
+
+func (s *StackStatus) StackUprobesClose() {
+	*s &^= StackUprobesSuccess
+}
+
+func (s StackStatus) String() string {
+	return fmt.Sprintf("Jattach: %v, StackUprobes: %v",
+		s.IsJattachSuccess(), s.IsStackUprobesSuccess())
+}

+ 10 - 0
utils/modelse/status.go

@@ -1,5 +1,7 @@
 package modelse
 
+var RuntimeApps map[uint32]AppStatusInfo
+
 type AppStatusInfo struct {
 	Pid        uint32   `json:"pid"`
 	ProcName   string   `json:"proc_name"`
@@ -13,4 +15,12 @@ type AppStatusInfo struct {
 	RegisterAt string   `json:"register_at"`
 	UpdateAt   string   `json:"update_at"`
 	Status     APP_TYPE `json:"status"`
+	Rule       string   `json:"rule"`
+	OpenStack  bool     `json:"openstack"`
 }
+
+const (
+	UNINSTALL_DETACH int = iota
+	ERROR_DETACH
+	FUSE_DETACH
+)

+ 18 - 0
utils/worker/serverWorker.go

@@ -35,6 +35,8 @@ type ServerWorker interface {
 
 	WhiteList(WhiteListReq) (WhiteData, error)
 
+	WhiteListV2(WhiteListReq) (WhiteDataV2, error)
+
 	//SyncAgentInfo(RegistRequest) ([]AgentList, error)
 
 	//Heart(DaemonHeartBeatInfo) (map[string]HeartConfContent, error)
@@ -86,6 +88,22 @@ func (w *ServerHTTPWorker) WhiteList(request WhiteListReq) (WhiteData, error) {
 	return response, nil
 }
 
+func (w *ServerHTTPWorker) WhiteListV2(request WhiteListReq) (WhiteDataV2, error) {
+	log.Infof("[server whitelist] request:%v.", request.String())
+	response := WhiteDataV2{}
+	result, err := w.requestServer("/api/v1/agent/whitelist", request)
+	log.Infof("[server whitelist] resp data:%v.", string(result))
+	if err != nil {
+		return response, err
+	}
+	err = json.Unmarshal(result, &response)
+	if err != nil {
+		log.WithError(err).Errorf("[server whitelist] Failed RegisterApp request:%v.", request.String())
+		return response, err
+	}
+	return response, nil
+}
+
 type ServerHTTPWorker struct {
 	currentIndex    int // 标识当前使用的是那个链接方式
 	countTotal      int // 在重试链接server时,统计重试的次数,用来是否遍历了一轮