|
|
@@ -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 {
|