Skip to content

Commit

Permalink
Merge pull request #73 from coroot/fix_dotnet_app_detection
Browse files Browse the repository at this point in the history
retry app type detection during container initialization
  • Loading branch information
def committed Mar 14, 2024
2 parents 2c95818 + 011a574 commit 6b88611
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions containers/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
}

Expand Down

0 comments on commit 6b88611

Please sign in to comment.