Sfoglia il codice sorgente

Merge branch 'dev' of https://git.cloudwise.com/TSB/euspace into dev

Tom 1 anno fa
parent
commit
396f363747

+ 57 - 0
containers/apm_get_code_setting.go

@@ -0,0 +1,57 @@
+package containers
+
+import (
+	"fmt"
+	"github.com/coroot/coroot-node-agent/utils"
+	. "github.com/coroot/coroot-node-agent/utils/modelse"
+	klog "github.com/sirupsen/logrus"
+)
+
+func (c *Container) GetCodeSetting(r *Registry) (CodeSettingResp, error) {
+	nodeInfo := r.nodeInfo.GetNodeInfo()
+	if nodeInfo == nil {
+		return CodeSettingResp{}, fmt.Errorf("[GetCodeSetting] Unknown node info.")
+	}
+	req := CodeSettingReq{
+		AccountId: nodeInfo.AccountID,
+		HostId:    nodeInfo.HostID,
+		Appid:     c.AppInfo.AppIdHash.IntVal,
+		AgentId:   c.AppInfo.AgentId,
+	}
+	klog.Infof("[GetCodeSetting] req: %s.", utils.ToString(req))
+	resp, err := r.connServer.GetCodeSetting(req)
+	if err != nil {
+		klog.WithError(err).Errorf("[GetCodeSetting] Failed GetCodeSetting  %s.", utils.ToString(req))
+		return resp, err
+	}
+
+	//fmt.Println(resp)
+	//c.saveWhiteStackSettingInfo(resp)
+	return resp, err
+}
+
+func (c *Container) saveWhiteStackSettingInfo(resp CodeSettingResp) {
+	c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList = resp.BlackWhiteSettings.WhiteList
+	c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList = resp.BlackWhiteSettings.BlackList
+	c.WhiteSettingInfo.WhiteStackSettingInfo.OpenStack = resp.BlackWhiteSettings.CollectStack
+}
+
+func (c *Container) stackRuleUpdate(resp CodeSettingResp) bool {
+	if c.noOrigRule() {
+		return false
+	}
+	return resp.BlackWhiteSettings.WhiteList != c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList ||
+		resp.BlackWhiteSettings.BlackList != c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList
+}
+
+func (c *Container) noStackRule(resp CodeSettingResp) bool {
+	return resp.BlackWhiteSettings.WhiteList == "" && resp.BlackWhiteSettings.BlackList == ""
+}
+
+func (c *Container) hasStackRule(resp CodeSettingResp) bool {
+	return resp.BlackWhiteSettings.WhiteList != "" || resp.BlackWhiteSettings.BlackList != ""
+}
+
+func (c *Container) noOrigRule() bool {
+	return c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList == "" && c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList == ""
+}

+ 1 - 1
containers/apm_register_app.go

@@ -20,7 +20,7 @@ func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error {
 	originAppId := c.AppInfo.AppIdHash.IntVal
 	originInstanceId := c.AppInfo.InstanceIdHash.IntVal
 	whiteAppName := c.WhiteSettingInfo.AppName
-	reRegFlag := c.checkReRegTime(time.Minute)
+	reRegFlag := c.checkReRegTime(RegisterAppInterval)
 	if originAppName != whiteAppName || reRegFlag {
 		cl := "first "
 		if reRegFlag {

+ 19 - 2
containers/apm_register_host.go

@@ -3,7 +3,9 @@ package containers
 import (
 	"fmt"
 	. "github.com/coroot/coroot-node-agent/utils/modelse"
+	klog "github.com/sirupsen/logrus"
 	"runtime"
+	"time"
 )
 
 func (r *Registry) RegisterHost() error {
@@ -16,13 +18,14 @@ func (r *Registry) RegisterHost() error {
 		LicenseKey:    nodeInfo.LicenseKey,
 		HostId:        nodeInfo.HostID,
 		HostIp:        nodeInfo.HostIp,
-		HostName:      "smartagent",
+		HostName:      nodeInfo.Hostname,
 		HostNameAlias: nodeInfo.Hostname,
 		HostType:      1,
-		Version:       "0.0.1",
+		Version:       nodeInfo.AgentVersion,
 		SysVersion:    runtime.GOOS + " " + runtime.GOARCH,
 		SystemUuid:    nodeInfo.SystemUUID,
 		Ebpf:          true,
+		AgentType:     2020,
 	}
 	err := r.connServer.RegisterHost(req)
 	if err != nil {
@@ -30,3 +33,17 @@ func (r *Registry) RegisterHost() error {
 	}
 	return nil
 }
+
+func (r *Registry) TaskRegisterHost() {
+	gcTicker := time.NewTicker(RegisterHostInterval)
+	defer gcTicker.Stop()
+	for {
+		select {
+		case <-gcTicker.C:
+			err := r.RegisterHost()
+			if err != nil {
+				klog.WithError(err).Error("[task] Failed to register host")
+			}
+		}
+	}
+}

+ 22 - 2
containers/apm_stack_dispatch.go

@@ -10,6 +10,7 @@ import (
 	"github.com/coroot/coroot-node-agent/ebpftracer/tracer"
 	tracerelf "github.com/coroot/coroot-node-agent/ebpftracer/tracer"
 	"github.com/coroot/coroot-node-agent/proc"
+	"github.com/coroot/coroot-node-agent/utils"
 	. "github.com/coroot/coroot-node-agent/utils/modelse"
 	klog "github.com/sirupsen/logrus"
 	"golang.org/x/arch/arm64/arm64asm"
@@ -123,10 +124,29 @@ func (c *Container) stackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
 }
 
 func (c *Container) jvmStackTrace(tracer *ebpftracer.Tracer, pid uint32) error {
-
 	p := c.processes[pid]
+	// check version
+	libjavaso, err := utils.GetSoPath(pid, "libjava.so", c.getRootfs())
+	if err != nil {
+		p.versionFailed = true
+		klog.WithError(err).Errorf("[jvmStackTrace] Failed get so path")
+		return err
+	}
+	v, err := ebpftracer.GetJvmVersion(libjavaso)
+	if err != nil {
+		p.versionFailed = true
+		klog.WithError(err).Errorf("[jvmStackTrace] Failed get Java version")
+		return err
+	}
+	c.AppInfo.Version = v
+	major, minor, patch, err := ebpftracer.ParseVersion(v)
+	klog.Infof("[jvmStackTrace] version: %s (Major: %d, Minor: %d, Patch: %d)", v, major, minor, patch)
+	if major != 1 || minor != 8 {
+		p.versionFailed = true
+		return fmt.Errorf("[jvmStackTrace] Unsupported Java version")
+	}
 
-	err := tracer.JattachJvm(pid, c.AppInfo)
+	err = tracer.JattachJvm(pid, c.AppInfo, c.WhiteSettingInfo.WhiteStackSettingInfo.WhiteList, c.WhiteSettingInfo.WhiteStackSettingInfo.BlackList)
 	if err != nil {
 		p.stackStatus.JattachFailure()
 		return err

+ 5 - 5
containers/apm_white_list.go

@@ -17,15 +17,15 @@ func (r *Registry) getWhiteListByCodeType(codeType CodeType) []WhiteSettingInfo
 }
 
 func (r *Registry) setWhiteList(whiteData WhiteData) {
-	var openStack int
-	if !r.tracer.DisableStackTracing() {
-		openStack = 1
-	}
+	//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
+			//setting.OpenStack = openStack
 			whiteListMap[code] = append(whiteListMap[code], setting)
 		}
 	}

+ 6 - 3
containers/container.go

@@ -34,9 +34,11 @@ import (
 )
 
 var (
-	gcInterval         = 10 * time.Second
-	AllAppInfoInterval = 1 * time.Minute
-	pingTimeout        = 300 * time.Millisecond
+	gcInterval           = 10 * time.Second
+	AllAppInfoInterval   = 1 * time.Minute
+	RegisterAppInterval  = 1 * time.Minute
+	RegisterHostInterval = 10 * time.Minute
+	pingTimeout          = 300 * time.Millisecond
 )
 
 type ContainerID string
@@ -432,6 +434,7 @@ func (c *Container) Collect(ch chan<- prometheus.Metric) {
 		targetAppId := apps[conn.Dest.String()]
 		if conn.Retransmissions > 0 {
 			ch <- counter(metrics.NetRetransmits, float64(conn.Retransmissions), strInstanceID, strAppId, targetAppId, strAppName, conn.Src.String(), conn.Dest.String(), conn.ActualDest.String())
+			conn.Retransmissions = 0
 		}
 		ch <- counter(metrics.NetBytesSent, float64(conn.BytesSent), strInstanceID, strAppId, targetAppId, strAppName, conn.Src.String(), conn.Dest.String(), conn.ActualDest.String())
 		ch <- counter(metrics.NetBytesReceived, float64(conn.BytesReceived), strInstanceID, strAppId, targetAppId, strAppName, conn.Src.String(), conn.Dest.String(), conn.ActualDest.String())

+ 70 - 25
containers/container_apm.go

@@ -568,6 +568,57 @@ func (c *Container) l7AttachSuccess() {
 	c.l7Attach = true
 }
 
+func (c *Container) ctrlStack(r *Registry, pid uint32) {
+	resp, err := c.GetCodeSetting(r)
+	if err != nil {
+		klog.WithField("pid", pid).WithError(err).Error("[ctrlStack] GetCodeSetting failed.")
+		return
+	}
+
+	if resp.BlackWhiteSettings.CollectStack == OPEN_STACK {
+		// 有黑白名单规则 &&
+		// 之前有注入 先卸载再注入
+		// 之前没注入 直接注入
+		// 没有有黑白名单 直接卸载
+		if c.hasStackRule(resp) {
+			if c.stackRuleUpdate(resp) {
+				// 重新注入
+				err = c.DetachStack(pid, APP_UNINSTALL)
+				if err != nil {
+					klog.WithError(err).Errorf("[ctrlStack][end] Failed detach stack trace!")
+				}
+			}
+			klog.WithField("pid", pid).Infoln("[ctrlStack] Attach app stack.")
+			c.saveWhiteStackSettingInfo(resp)
+			err = c.AttachStack(r.tracer, pid)
+			if err != nil {
+				c.AppInfo.SetAppStackError()
+				klog.WithField("pid", pid).WithError(err).Errorf("[ctrlStack][end] Failed attach stack trace!")
+			}
+		} else {
+			if c.noOrigRule() {
+				return
+			}
+			c.saveWhiteStackSettingInfo(resp)
+			// 关闭堆栈
+			err = c.DetachStack(pid, APP_UNINSTALL)
+			if err != nil {
+				klog.WithError(err).Errorf("[ctrlStack][end] Failed detach stack trace!")
+			}
+		}
+	} else {
+		if c.noOrigRule() {
+			return
+		}
+		c.saveWhiteStackSettingInfo(resp)
+		// 关闭堆栈
+		err = c.DetachStack(pid, APP_UNINSTALL)
+		if err != nil {
+			klog.WithError(err).Errorf("[ctrlStack][end] Failed detach stack trace!")
+		}
+	}
+}
+
 func (c *Container) verifyAttachConditions(r *Registry, pid uint32) (bool, int) {
 	p := c.processes[pid]
 	if p != nil && c.checkEventReady() {
@@ -592,15 +643,16 @@ func (c *Container) verifyAttachConditions(r *Registry, pid uint32) (bool, int)
 			}
 			// 判断规则
 			if strings.Contains(cmdline, ruleVal) {
-				c.WhiteSettingInfo = setting
+				c.WhiteSettingInfo.AppName = setting.AppName
+				c.WhiteSettingInfo.Filters = setting.Filters
 				klog.WithField("pid", pid).
 					WithField("codeType", codeType.String()).
 					WithField("ruleVal", ruleVal).
 					WithField("cmdline", cmdline).
-					WithField("stack", setting.OpenStack).
+					//WithField("stack", setting.OpenStack).
 					WithField("white list", utils.ToString(whiteListByCode)).
 					Infoln("[verify] check successful.")
-				return true, setting.OpenStack
+				return true, 0
 			}
 		}
 	}
@@ -690,16 +742,21 @@ func (c *Container) DetachStack(pid uint32, detachType APP_TYPE) error {
 // 1.2.1 卸载 jvm堆栈
 func (c *Container) detachJvmStack(pid uint32) error {
 	if p := c.processes[pid]; p != nil {
-		var err error
-		// 卸载堆栈probes
-		err = p.closeStackUprobes()
-		klog.WithError(err).Infof("[detachJvmStack] closeStackUprobes")
+
 		//if p.stackStatus.IsStackUprobesSuccess() || len(p.stackUprobes) > 0 {
 		//}
 		// 卸载 JavaAgent
+		var err error
 		if p.stackStatus.IsJattachSuccess() {
+			// 卸载堆栈probes
+			err = p.closeStackUprobes()
+			if err != nil {
+				klog.WithError(err).Errorf("[detachJvmStack] closeStackUprobes")
+			}
 			err = p.uninstallJavaAgent()
-			klog.WithError(err).Infof("[detachJvmStack] uninstallJavaAgent")
+			if err != nil {
+				klog.WithError(err).Errorf("[detachJvmStack] uninstallJavaAgent")
+			}
 		}
 		return err
 	}
@@ -730,13 +787,14 @@ func (c *Container) BuildActiveApps(runtimeApps map[uint32]AppStatusInfo, pid ui
 			Status:     c.AppInfo.Status,
 			Rule:       c.WhiteSettingInfo.Filters,
 		}
-		detail.Rule = fmt.Sprintf("%s|%d", c.WhiteSettingInfo.Filters, c.WhiteSettingInfo.OpenStack)
+		detail.Rule = fmt.Sprintf("%s|%d", c.WhiteSettingInfo.Filters, c.WhiteSettingInfo.WhiteStackSettingInfo.OpenStack)
 		if c.AppInfo.UpdateAt != 0 {
 			detail.UpdateAt = time.Unix(c.AppInfo.UpdateAt, 0).Format("060102 15:04:05")
 		}
 		p := c.processes[pid]
 		if p != nil {
 			detail.StackStatus = p.stackStatus.String()
+			detail.StackStatus += fmt.Sprintf("|vFailed:%v", p.versionFailed)
 		}
 		runtimeApps[pid] = detail
 	}
@@ -745,7 +803,7 @@ func (c *Container) BuildActiveApps(runtimeApps map[uint32]AppStatusInfo, pid ui
 
 func (c *Container) AgentCtrl(r *Registry, pid uint32) {
 	var err error
-	verifyAttachConditions, openStack := c.verifyAttachConditions(r, pid)
+	verifyAttachConditions, _ := c.verifyAttachConditions(r, pid)
 
 	// UNINSTALL
 	if r.isFusing && c.Isl7AttachSuccess() {
@@ -773,20 +831,7 @@ func (c *Container) AgentCtrl(r *Registry, pid uint32) {
 		} else {
 			klog.WithField("pid", pid).Infoln("[AgentCtrl] Attach uprobes success!")
 		}
-		if openStack == OPEN_STACK {
-			klog.WithField("pid", pid).Infoln("[AgentCtrl] Attach app stack.")
-			err = c.AttachStack(r.tracer, pid)
-			if err != nil {
-				c.AppInfo.SetAppStackError()
-				klog.WithField("pid", pid).WithError(err).Errorf("[AgentCtrl][end] Failed attach stack trace!")
-				return
-			}
-		} else {
-			// 关闭堆栈
-			err = c.DetachStack(pid, APP_UNINSTALL)
-			if err != nil {
-				klog.WithError(err).Errorf("[AgentCtrl][end] Failed detach stack trace!")
-			}
-		}
+		// 堆栈控制
+		c.ctrlStack(r, pid)
 	}
 }

+ 1 - 0
containers/process.go

@@ -39,6 +39,7 @@ type Process struct {
 	jvmAttachOnce    bool
 	stackAttachOnce  bool
 	stackStatus      StackStatus
+	versionFailed    bool
 	codeType         CodeType
 	cmdline          string
 	pythonGilChecked bool

+ 1 - 0
containers/registry.go

@@ -163,6 +163,7 @@ func NewRegistry(reg prometheus.Registerer, kernelVersion string, nodeInfo *Node
 			klog.WithError(err).Errorf("Failed Register Host.")
 			return nil, err
 		}
+		try.Go(r.TaskRegisterHost, CatchFn)
 	}
 
 	if err = reg.Register(r); err != nil {

+ 0 - 7
dist/package_dir/agents/NativeAgent/conf/agent.properties

@@ -1,7 +0,0 @@
-# APM Server url.
-ConfigDomain    = http://10.0.7.115:18080
-SendDomain      = http://10.0.7.115:18080
-# License Key.
-# Logging level.
-# Optional: DEBUG, INFO, WARN, ERROR
-agent.log.level = ERROR

+ 0 - 15
dist/package_dir/agents/NativeAgent/conf/interceptors.xml

@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<interceptors>
-    <interceptor id="define-interceptor_id">
-        <definition>
-            <class_name>define-class</class_name>
-            <method_name>define-method</method_name>
-            <paramters>
-            </paramters>
-        </definition>
-        <info>
-            <uri>$this.name</uri>
-        </info>
-    </interceptor>
-
-</interceptors>

BIN
dist/package_dir/agents/NativeAgent/lib/apmAgent.jar


BIN
dist/package_dir/agents/NativeAgent/lib/apmCore.jar


BIN
dist/package_dir/agents/NativeAgent/lib/apmSpy.jar


BIN
dist/package_dir/agents/NativeAgent/plugins/cloudwise-javacode-plugin-apiurl.jar


BIN
dist/package_dir/agents/NativeAgent/plugins/cloudwise-javacode-plugin-autotracebusinesspkg.jar


+ 15 - 2
ebpftracer/stack.go

@@ -49,13 +49,25 @@ func (t *Tracer) AttachStackUprobes(path string, uprobes []tracer.Uprobe) []link
 }
 
 // JVM process stack
-func (t *Tracer) JattachJvm(pid uint32, appInfo AppInfo) error {
+func (t *Tracer) JattachJvm(pid uint32, appInfo AppInfo, whiteList, blackList string) error {
 	klog.Infoln("[Jvm stack uprobe] Attach Start AttachJVMStackUprobes", pid)
 	// TODO tiny Agent 注入
 	// TODO copy agent到 jre conf/lib/plugins
 
 	//argkv := "/opt/github/euspace/dist/package_dir/agents/NativeAgent/lib/apmAgent.jar=/opt/github/euspace/dist/package_dir/agents/NativeAgent"
-
+	if whiteList == "" && blackList == "" {
+		return nil
+	}
+	whiteList = strings.ReplaceAll(whiteList, ",", "")
+	blackList = strings.ReplaceAll(blackList, ",", "")
+	var stackRule string
+	if whiteList == "" {
+		stackRule = fmt.Sprintf("blackStack=%s", blackList) // 仅保留黑名单
+	} else if blackList == "" {
+		stackRule = fmt.Sprintf("whiteStack=%s", whiteList) // 仅保留白名单
+	} else {
+		stackRule = fmt.Sprintf("whiteStack=%s,blackStack=%s", whiteList, blackList)
+	}
 	nativeBasePath := utils.GetDefaultAgentsPath("NativeAgent")
 	kvPairs := []string{
 		fmt.Sprintf("%s=%s", filepath.Join(nativeBasePath, "lib", "apmAgent.jar"), nativeBasePath),
@@ -63,6 +75,7 @@ func (t *Tracer) JattachJvm(pid uint32, appInfo AppInfo) error {
 		fmt.Sprintf("%s=%d", "agentId", appInfo.AgentId),
 		fmt.Sprintf("%s=%d", "hostId", utils.GetHostID()),
 		fmt.Sprintf("%s=%d", "accountId", utils.GetAccountID()),
+		stackRule,
 	}
 	argkv := strings.Join(kvPairs, ",")
 	klog.Infof("[Jvm stack uprobe] params:[%s]", argkv)

+ 15 - 16
flags/flags.go

@@ -6,7 +6,6 @@ import (
 	"github.com/coroot/coroot-node-agent/utils"
 	"github.com/coroot/coroot-node-agent/utils/modelse"
 	"github.com/jedib0t/go-pretty/v6/table"
-	klog "github.com/sirupsen/logrus"
 	"gopkg.in/alecthomas/kingpin.v2"
 	"gopkg.in/ini.v1"
 	"net/url"
@@ -26,7 +25,7 @@ var (
 	EbpfFilePath        = kingpin.Flag("ebpf-path", "Set ebpf file path").Envar("EBPF_FILE").Default("").String()
 	CommonIni           = kingpin.Flag("common.ini", "Set ebpf file path").Envar("COMMON_INI").Default("/opt/cloudwise/omniagent/conf/common.ini").String()
 	ServerPrefix        = kingpin.Flag("server-prefix", "server-prefix").Envar("SERVER_PREFIX").Default("").String()
-	DisableRegisterHost = kingpin.Flag("disable-reg-host", "Disable reg host").Default("true").Envar("DISABLE_REG_HOST").Bool()
+	DisableRegisterHost = kingpin.Flag("disable-reg-host", "Disable reg host").Default("false").Envar("DISABLE_REG_HOST").Bool()
 	// agent
 	DisableE2ETracing   = kingpin.Flag("disable-e2e-tracing", "Disable e2e tracing").Default("true").Envar("DISABLE_E2E_TRACING").Bool()
 	DisableStackTracing = kingpin.Flag("disable-stack-tracing", "Disable stack tracing").Default("true").Envar("DISABLE_STACK_TRACING").Bool()
@@ -139,20 +138,20 @@ func init() {
 	}
 
 	// set tiny-agent config
-	nativeConf := utils.GetDefaultAgentsPath("NativeAgent", "conf", "agent.properties")
-	confData, err := ini.Load(nativeConf)
-	if err == nil {
-		configServer := *ConfigServer
-		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 {
-			klog.Error(err)
-		}
-	}
+	//nativeConf := utils.GetDefaultAgentsPath("NativeAgent", "conf", "agent.properties")
+	//confData, err := ini.Load(nativeConf)
+	//if err == nil {
+	//	configServer := *ConfigServer
+	//	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 {
+	//		klog.Error(err)
+	//	}
+	//}
 
 	if *RunInContainer {
 		if *HostDirPathPrefix == "" {

+ 6 - 6
main.go

@@ -165,7 +165,7 @@ func main() {
 	log.Infoln("kernel version:", kv)
 
 	// 构建节点信息
-	nodeInfo, err := node.NewNodeInfo(hostname, kv)
+	nodeInfo, err := node.NewNodeInfo(hostname, kv, version)
 	if err != nil || nodeInfo == nil {
 		log.Fatalln(err)
 	}
@@ -180,9 +180,9 @@ func main() {
 
 	whitelistNodeExternalNetworks()
 
-	machineId := nodeInfo.GetNodeInfo().SystemUUID
-	tracing.Init(machineId, hostname, version)
-	logs.Init(machineId, hostname, version)
+	SystemUUID := nodeInfo.GetNodeInfo().SystemUUID
+	tracing.Init(SystemUUID, hostname, version)
+	logs.Init(SystemUUID, hostname, version)
 
 	if *flags.RunInContainer {
 		_, err = kube.NewKubeClient()
@@ -192,7 +192,7 @@ func main() {
 	}
 
 	registry := prometheus.NewRegistry()
-	registerer := prometheus.WrapRegistererWith(prometheus.Labels{"machine_id": machineId}, registry)
+	registerer := prometheus.WrapRegistererWith(prometheus.Labels{"system_uuid": SystemUUID}, registry)
 
 	registerer.MustRegister(info("node_agent_info", version))
 
@@ -518,7 +518,7 @@ func main() {
 		fmt.Println("Response Body:", string(responseData))
 	}
 
-	if err := prom.StartAgent(machineId); err != nil {
+	if err := prom.StartAgent(SystemUUID); err != nil {
 		log.Fatalln(err)
 	}
 

+ 5 - 3
node/apm_host_info.go

@@ -12,8 +12,8 @@ import (
 	"strings"
 )
 
-func NewNodeInfo(name, kv string) (*NodeInfoT, error) {
-	ni, err := newNodeInfoFromCommonIni(name, kv)
+func NewNodeInfo(name, kv, version string) (*NodeInfoT, error) {
+	ni, err := newNodeInfoFromCommonIni(name, kv, version)
 	if err != nil {
 		klog.Errorf("Failed to create node info from common ini: %v", err)
 	} else {
@@ -34,13 +34,14 @@ func NewNodeInfo(name, kv string) (*NodeInfoT, error) {
 		HostID:        utils.GetHostID(),
 		AccountID:     utils.GetAccountID(),
 		LicenseKey:    *flags.LicenseKey,
+		AgentVersion:  version,
 	}
 	utils.SaveNodeInfo(n)
 	klog.Infof("run standalone.")
 	return n, nil
 }
 
-func newNodeInfoFromCommonIni(name, kv string) (*NodeInfoT, error) {
+func newNodeInfoFromCommonIni(name, kv, version string) (*NodeInfoT, error) {
 	if *flags.CommonIni != "" {
 		iniData, err := ini.Load(*flags.CommonIni)
 		if err != nil {
@@ -72,6 +73,7 @@ func newNodeInfoFromCommonIni(name, kv string) (*NodeInfoT, error) {
 					HostID:        host_id,
 					AccountID:     accountId,
 					LicenseKey:    *flags.LicenseKey,
+					AgentVersion:  version,
 				}
 				utils.SaveNodeInfo(n)
 				return n, nil

+ 1 - 1
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/apm_exporter.go

@@ -745,7 +745,7 @@ func buildAppMapFromEvent(traceRoot *RootDataT, sd apmTraceSpan) int {
 			traceRoot.TypeFrom = attr.Value.AsString()
 		case "time.start_at":
 			mNode.StartTime, mNode.StartTimeMs = cleanNsTime(attr.Value.AsInt64())
-			traceRoot.CollTime = mNode.StartTime
+			traceRoot.CollTime = mNode.StartTimeMs
 		case "time.end_at":
 			mNode.EndTime, mNode.EndTimeMs = cleanNsTime(attr.Value.AsInt64())
 		case "time.duration":

+ 35 - 9
utils/modelse/models.go

@@ -109,6 +109,7 @@ type RegisterHostReq struct {
 	SysVersion    string `json:"sys_version"`
 	SystemUuid    string `json:"system_uuid"`
 	Ebpf          bool   `json:"ebpf"`
+	AgentType     int    `json:"agent_type"`
 }
 
 type RegisterAppReq struct {
@@ -162,15 +163,24 @@ type WhiteListResp struct {
 }
 
 type WhiteSettingInfo struct {
-	AppName         string `json:"app_name"`
-	K8SNamespace    string `json:"k8s_namespace"`
-	K8SWorkLoadName string `json:"k8s_workLoadName"`
-	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"`
+	AppName string `json:"app_name"`
+	//K8SNamespace    string `json:"k8s_namespace"`
+	//K8SWorkLoadName string `json:"k8s_workLoadName"`
+	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"`
+
+	WhiteStackSettingInfo WhiteStackSettingT
+}
+
+type WhiteStackSettingT struct {
+	// from getCodeSetting
+	OpenStack int
+	WhiteList string
+	BlackList string
 }
 
 type Appscope struct {
@@ -281,6 +291,22 @@ type AgentInfo struct {
 	ProxyLocalIp string `json:"proxy_local_ip"`
 }
 
+type CodeSettingReq struct {
+	AccountId int   `json:"accountId"`
+	AgentId   int64 `json:"agentId"`
+	Appid     int64 `json:"appId"`
+	HostId    int64 `json:"hostId"`
+}
+
+type CodeSettingResp struct {
+	BlackWhiteSettings struct {
+		WhiteList      string `json:"white_list"`
+		BlackList      string `json:"black_list"`
+		BlackWhiteList int    `json:"black_white_list"`
+		CollectStack   int    `json:"collect_stack"`
+	} `json:"black_white_settings"`
+}
+
 type EbpfAppReq struct {
 	AccountId int `json:"account_id"`
 }

+ 1 - 0
utils/modelse/node.go

@@ -17,6 +17,7 @@ type NodeInfoT struct {
 	AccountID     int          `json:"account_id"`
 	LicenseKey    string       `json:"license_key"`
 	Lock          sync.RWMutex `json:"lock,omitempty"`
+	AgentVersion  string       `json:"agent_version"`
 }
 
 type NodeInfoInterface interface {

+ 24 - 6
utils/worker/serverWorker.go

@@ -38,6 +38,8 @@ type ServerWorker interface {
 	WhiteListV2(WhiteListReq) (WhiteDataV2, error)
 
 	PullAllAppInfo(EbpfAppReq) (EbpfAppResp, error)
+
+	GetCodeSetting(CodeSettingReq) (CodeSettingResp, error)
 	//SyncAgentInfo(RegistRequest) ([]AgentList, error)
 
 	//Heart(DaemonHeartBeatInfo) (map[string]HeartConfContent, error)
@@ -51,17 +53,33 @@ type ServerWorker interface {
 	//GetInfo() (string, string)
 }
 
+func (w *ServerHTTPWorker) GetCodeSetting(request CodeSettingReq) (CodeSettingResp, error) {
+	//log.Infof("[get GetCodeSetting] request:%v.", utils.ToString(request))
+	response := CodeSettingResp{}
+	result, err := w.requestServer("/api/v70/agent/getCodeSetting", request)
+	//log.Infof("[get GetCodeSetting] resp data:%v.", string(result))
+	if err != nil {
+		return response, err
+	}
+	err = json.Unmarshal(result, &response)
+	if err != nil {
+		log.WithError(err).Errorf("[get GetCodeSetting] Failed GetCodeSetting request:%v.", utils.ToString(request))
+		return response, err
+	}
+	return response, nil
+}
+
 func (w *ServerHTTPWorker) PullAllAppInfo(request EbpfAppReq) (EbpfAppResp, error) {
-	log.Infof("[get all appinfo] request:%v.", utils.ToString(request))
+	//log.Infof("[get all appinfo] request:%v.", utils.ToString(request))
 	response := EbpfAppResp{}
 	result, err := w.requestServer("/api/v70/ebpfAppInfo", request)
-	log.Infof("[get all appinfo] resp data:%v.", string(result))
+	//log.Infof("[get all appinfo] resp data:%v.", string(result))
 	if err != nil {
 		return response, err
 	}
 	err = json.Unmarshal(result, &response)
 	if err != nil {
-		log.WithError(err).Errorf("[get all appinfo] Failed get request:%v.", utils.ToString(request))
+		log.WithError(err).Errorf("[get all appinfo] Failed PullAllAppInfo request:%v.", utils.ToString(request))
 		return response, err
 	}
 	return response, nil
@@ -72,7 +90,7 @@ func (w *ServerHTTPWorker) RegisterHost(request RegisterHostReq) error {
 	result, err := w.requestServer("/v2/app/registerHost", request)
 	log.Infof("[server register host] resp:%v.", string(result))
 	if err != nil {
-		log.WithError(err).Errorf("[server register] Failed RegisterApp request:%v.", utils.ToString(request))
+		log.WithError(err).Errorf("[server register] Failed RegisterHost request:%v.", utils.ToString(request))
 		return err
 	}
 	return nil
@@ -99,7 +117,7 @@ func (w *ServerHTTPWorker) WhiteList(request WhiteListReq) (WhiteData, error) {
 	}
 	err = json.Unmarshal(result, &response)
 	if err != nil {
-		log.WithError(err).Errorf("[server whitelist] Failed RegisterApp request:%v.", request.String())
+		log.WithError(err).Errorf("[server whitelist] Failed Pull WhiteList request:%v.", request.String())
 		return response, err
 	}
 	return response, nil
@@ -115,7 +133,7 @@ func (w *ServerHTTPWorker) WhiteListV2(request WhiteListReq) (WhiteDataV2, error
 	}
 	err = json.Unmarshal(result, &response)
 	if err != nil {
-		log.WithError(err).Errorf("[server whitelist] Failed RegisterApp request:%v.", request.String())
+		log.WithError(err).Errorf("[server whitelist] Failed Pull WhiteListV2 request:%v.", request.String())
 		return response, err
 	}
 	return response, nil