Jelajahi Sumber

Feature #TASK_QT-18250 op对接

Carl 7 bulan lalu
induk
melakukan
1eb2621d3d

+ 1 - 1
containers/apm_register_app.go

@@ -64,7 +64,7 @@ func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error {
 			CodeType:    c.AppInfo.CodeType.Int(),
 			App_type:    1,
 			AppLang:     "ebpf",
-			Sys:         "",
+			Sys:         nodeInfo.SysTag,
 		}
 		//klog.Infof("[%sregister app] Register App req: %s.", cl, registerAppReq.String())
 		klog.Infof("[%sregister app] Register App", cl)

+ 2 - 1
flags/flags.go

@@ -68,7 +68,8 @@ var (
 	FuseTryMax        = kingpin.Flag("fuse_try_max", "The maximum number of the fuse operation try").Default("3").Envar("FUSE_TRY_MAX").Int()
 	// debug
 	Test = kingpin.Flag("test", "Only test").Default("false").Envar("TEST").Bool()
-
+	// op 新增配置
+	SysTag = kingpin.Flag("sys-tag", "sys tag").Envar("CW_SYS").Default("").String()
 	// l7
 	MysqlDefault = kingpin.Flag("mysql-default", "Default MySQL protocol when port-based detection fails").Envar("MYSQL_DEFAULT").Default("mysql").String()
 

+ 19 - 0
node/apm_host_info.go

@@ -2,6 +2,7 @@ package node
 
 import (
 	"encoding/base64"
+	"encoding/json"
 	"fmt"
 	"github.com/coroot/coroot-node-agent/flags"
 	"github.com/coroot/coroot-node-agent/kube"
@@ -49,6 +50,7 @@ func NewNodeInfo(name, kv, version string) (*NodeInfoT, error) {
 		AccountID:     utils.GetAccountID(),
 		LicenseKey:    *flags.LicenseKey,
 		AgentVersion:  version,
+		SysTag:        *flags.SysTag,
 	}
 	utils.SaveNodeInfo(n)
 	return n, nil
@@ -58,6 +60,7 @@ func newNodeInfoFromCommonIni(name, kv, version string) (*NodeInfoT, error) {
 	if *flags.CommonIni != "" {
 		iniData, err := ini.Load(*flags.CommonIni)
 		if err != nil {
+			klog.Errorf("Failed to load common ini file: %v", err)
 			return nil, err
 		}
 		if iniData == nil {
@@ -67,6 +70,7 @@ func newNodeInfoFromCommonIni(name, kv, version string) (*NodeInfoT, error) {
 		uuid := iniData.Section("common").Key("system_uuid").String()
 		host_id, err := iniData.Section("common").Key("host_id").Int64()
 		if err != nil {
+			klog.Errorf("Failed to get host_id: %v", err)
 			return nil, err
 		}
 		token := iniData.Section("common").Key("token").String()
@@ -76,6 +80,17 @@ func newNodeInfoFromCommonIni(name, kv, version string) (*NodeInfoT, error) {
 		}
 		account_and_user_string := strings.Split(string(account_and_user_byte), "@")
 		if len(account_and_user_string) > 0 {
+			tagsStr := iniData.Section("common").Key("tags").String()
+			tagT := struct {
+				HostTag struct {
+					SystemTag []string `json:"sys"`
+				} `json:"host_tag"`
+			}{}
+			err := json.Unmarshal([]byte(tagsStr), &tagT)
+			if err != nil {
+				return nil, err
+			}
+			sysTag := strings.Join(tagT.HostTag.SystemTag, ",")
 			accountId, err := strconv.Atoi(account_and_user_string[0])
 			if err == nil {
 				n := &NodeInfoT{
@@ -87,9 +102,13 @@ func newNodeInfoFromCommonIni(name, kv, version string) (*NodeInfoT, error) {
 					AccountID:     accountId,
 					LicenseKey:    *flags.LicenseKey,
 					AgentVersion:  version,
+					SysTag:        sysTag,
 				}
 				utils.SaveNodeInfo(n)
 				return n, nil
+			} else {
+				klog.Errorf("Failed to strconv accountId: %v", err)
+				return nil, err
 			}
 		}
 	}

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

@@ -87,6 +87,8 @@ type RootDataT struct {
 	// op 新增字段
 	Pid         uint32 `json:"pid"`
 	ContainerID string `json:"container_id"`
+	Sys         string `json:"sys"`
+	SystemUUID  string `json:"system_uuid"`
 }
 
 // ParamStruct 定义目标结构
@@ -412,6 +414,8 @@ func buildLevelFromEvent(sdl *RootDataT) {
 func initRootDataFromEvent() RootDataT {
 	hostID := utils.GetHostID()
 	accountID := utils.GetAccountID()
+	sysTag := utils.GetSysTag()
+	systemUUID := utils.GetSystemUUID()
 	data := RootDataT{
 		// todo AccountId
 		AccountId:       accountID,
@@ -456,6 +460,8 @@ func initRootDataFromEvent() RootDataT {
 		VipIds:          []interface{}{},
 		SrcAddr:         "",
 		DestinationAddr: "",
+		Sys:             sysTag,
+		SystemUUID:      systemUUID,
 	}
 	return data
 }

+ 16 - 0
utils/id.go

@@ -46,6 +46,22 @@ func GetAccountID() int {
 	return 0
 }
 
+// GetSys
+func GetSysTag() string {
+	if NODE_INFO != nil {
+		return NODE_INFO.SysTag
+	}
+	return ""
+}
+
+// GetSys
+func GetSystemUUID() string {
+	if NODE_INFO != nil {
+		return NODE_INFO.SystemUUID
+	}
+	return ""
+}
+
 func GetHostIP() string {
 	if NODE_INFO != nil {
 		return NODE_INFO.HostIp

+ 1 - 0
utils/modelse/node.go

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