|
|
@@ -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)
|
|
|
}
|
|
|
}
|