From 011a57420fc6f2195ba14c284114db80e495e455 Mon Sep 17 00:00:00 2001 From: Nikolay Sivko Date: Thu, 14 Mar 2024 13:41:28 +0300 Subject: [PATCH] retry app type detection during container initialization --- containers/process.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/containers/process.go b/containers/process.go index e384bc8..2ee592d 100644 --- a/containers/process.go +++ b/containers/process.go @@ -2,8 +2,11 @@ package containers import ( "context" + "os" "time" + "github.com/jpillora/backoff" + "github.com/cilium/ebpf/link" "github.com/coroot/coroot-node-agent/proc" "github.com/mdlayher/taskstats" @@ -32,7 +35,7 @@ func NewProcess(pid uint32, stats *taskstats.Stats) *Process { defer ns.Close() p := &Process{Pid: pid, StartedAt: stats.BeginTime, NetNsId: ns.UniqueId()} p.ctx, p.cancelFunc = context.WithCancel(context.Background()) - p.instrument() + go p.instrument() return p } @@ -41,11 +44,26 @@ func (p *Process) isHostNs() bool { } func (p *Process) instrument() { - if dotNetAppName, err := dotNetApp(p.Pid); err == nil { - if dotNetAppName != "" { - p.dotNetMonitor = NewDotNetMonitor(p.ctx, p.Pid, dotNetAppName) + b := backoff.Backoff{Factor: 2, Min: time.Second, Max: time.Minute} + for { + select { + case <-p.ctx.Done(): + return + default: + dest, err := os.Readlink(proc.Path(p.Pid, "exe")) + if err != nil { + return + } + if dest != "/" { + if dotNetAppName, err := dotNetApp(p.Pid); err == nil { + if dotNetAppName != "" { + p.dotNetMonitor = NewDotNetMonitor(p.ctx, p.Pid, dotNetAppName) + } + return + } + } + time.Sleep(b.Duration()) } - return } }