|
|
@@ -14,12 +14,18 @@ func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error {
|
|
|
}
|
|
|
var err error
|
|
|
originAppName := c.AppInfo.AppName
|
|
|
+ originAppId := c.AppInfo.AppIdHash.IntVal
|
|
|
+ originInstanceId := c.AppInfo.InstanceIdHash.IntVal
|
|
|
whiteAppName := c.WhiteSettingInfo.AppName
|
|
|
- if originAppName != whiteAppName {
|
|
|
+ reRegFlag := c.checkReRegTime(time.Minute)
|
|
|
+ if originAppName != whiteAppName || reRegFlag {
|
|
|
+ cl := "first "
|
|
|
+ if reRegFlag {
|
|
|
+ cl = "re "
|
|
|
+ }
|
|
|
if c.AppInfo.CodeType.IsUnknownCode() || c.AppInfo.CodeType.IsWaitCheck() {
|
|
|
- return fmt.Errorf("[register app] Unknown app code[%s],Wait buildIDs.", c.AppInfo.CodeType.String())
|
|
|
+ return fmt.Errorf("[%sregister app] Unknown app code[%s],Wait buildIDs.", cl, c.AppInfo.CodeType.String())
|
|
|
}
|
|
|
- //c.AppInfo.AppId, err = utils.BuildInt64ID(whiteAppName).ToInt64()
|
|
|
c.AppInfo.AppIdHash.IntVal, err = utils.BuildInt64ID(whiteAppName).ToInt64()
|
|
|
c.AppInfo.AppIdHash.HashtVal = utils.BuildInt64ID(whiteAppName).ToHashByte()
|
|
|
if err != nil {
|
|
|
@@ -29,12 +35,14 @@ func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error {
|
|
|
// 注册
|
|
|
nodeInfo := r.nodeInfo.GetNodeInfo()
|
|
|
if nodeInfo == nil {
|
|
|
- return fmt.Errorf("[register app] Unknown node info.")
|
|
|
+ return fmt.Errorf("[%sregister app] Unknown node info.", cl)
|
|
|
+ }
|
|
|
+ if reRegFlag {
|
|
|
+ c.ReBuildIds(pid)
|
|
|
}
|
|
|
registerAppReq := RegisterAppReq{
|
|
|
- AppId: c.AppInfo.AppIdHash.IntVal,
|
|
|
- AppName: c.WhiteSettingInfo.AppName,
|
|
|
- // todo AccountId
|
|
|
+ AppId: c.AppInfo.AppIdHash.IntVal,
|
|
|
+ AppName: c.WhiteSettingInfo.AppName,
|
|
|
AccountId: nodeInfo.AccountID,
|
|
|
HostId: nodeInfo.HostID,
|
|
|
AgentId: c.AppInfo.AgentId,
|
|
|
@@ -45,29 +53,38 @@ func (c *Container) RegisterAppInfo(r *Registry, pid uint32) error {
|
|
|
App_type: 1,
|
|
|
AppLang: "ebpf",
|
|
|
}
|
|
|
- klog.Infof("[register app] Register App req: %s.", registerAppReq.String())
|
|
|
+ klog.Infof("[%sregister app] Register App req: %s.", cl, registerAppReq.String())
|
|
|
err = r.connServer.RegisterApp(registerAppReq)
|
|
|
if err != nil {
|
|
|
- klog.WithError(err).Errorf("[register] Failed Register App %s.", registerAppReq.String())
|
|
|
+ klog.WithError(err).Errorf("[%sregister app] Failed Register App %s.", cl, registerAppReq.String())
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+ c.AppInfo.RegisterAt = time.Now().Unix()
|
|
|
c.AppInfo.AppName = c.WhiteSettingInfo.AppName
|
|
|
|
|
|
- if originAppName == "" {
|
|
|
- c.AppInfo.RegisterAt = time.Now().Unix()
|
|
|
- }
|
|
|
-
|
|
|
- if originAppName != "" && c.Isl7AttachSuccess() {
|
|
|
- klog.Infoln("[kprobe] reset kernel proc_info.")
|
|
|
- err = r.tracer.InitKProcInfo(pid, &c.AppInfo)
|
|
|
- if err != nil {
|
|
|
- klog.WithError(err).Errorf("[kprobe] Failed reset KProcInfo.")
|
|
|
- return err
|
|
|
+ // reset kernel
|
|
|
+ if c.Isl7AttachSuccess() {
|
|
|
+ if (originAppId != c.AppInfo.AppIdHash.IntVal && originAppId != 0) ||
|
|
|
+ (originInstanceId != c.AppInfo.InstanceIdHash.IntVal && originInstanceId != 0) {
|
|
|
+ klog.Infoln("[kprobe] reset kernel proc_info.")
|
|
|
+ err = r.tracer.InitKProcInfo(pid, &c.AppInfo)
|
|
|
+ if err != nil {
|
|
|
+ klog.WithError(err).Errorf("[kprobe] Failed reset KProcInfo.")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ c.AppInfo.UpdateAt = time.Now().Unix()
|
|
|
}
|
|
|
- c.AppInfo.UpdateAt = time.Now().Unix()
|
|
|
}
|
|
|
}
|
|
|
c.AppInfo.SetAppSuccess()
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func (c *Container) checkReRegTime(duration time.Duration) bool {
|
|
|
+ if c.AppInfo.RegisterAt != 0 {
|
|
|
+ elapsed := time.Since(time.Unix(c.AppInfo.RegisterAt, 0))
|
|
|
+ return elapsed > duration
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|