Skip to content

Commit 336a3d9

Browse files
authored
Merge pull request #305 from coroot/instrumentation_delay
add configurable startup delay for Python GIL and Node.js event loop instrumentation
2 parents 0de4c6d + 44e3e8e commit 336a3d9

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

containers/process.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/coroot/coroot-node-agent/ebpftracer"
11+
"github.com/coroot/coroot-node-agent/flags"
1112
"github.com/coroot/coroot-node-agent/gpu"
1213
"github.com/coroot/coroot-node-agent/proc"
1314
"github.com/jpillora/backoff"
@@ -82,6 +83,15 @@ func (p *Process) isHostNs() bool {
8283

8384
func (p *Process) instrument(tracer *ebpftracer.Tracer) {
8485
defer close(p.instrumentDone)
86+
if delay := *flags.InstrumentationDelay; delay > 0 && !p.StartedAt.IsZero() {
87+
if wait := delay - time.Since(p.StartedAt); wait > 0 {
88+
select {
89+
case <-p.ctx.Done():
90+
return
91+
case <-time.After(wait):
92+
}
93+
}
94+
}
8595
b := backoff.Backoff{Factor: 2, Min: time.Second, Max: time.Minute}
8696
for {
8797
select {

flags/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var (
1919
EnableJavaAsyncProfiler = kingpin.Flag("enable-java-async-profiler", "Enable Java profiling via async-profiler (CPU, memory allocations, lock contention)").Default("false").Envar("ENABLE_JAVA_ASYNC_PROFILER").Bool()
2020
JavaAsyncProfilerDelay = kingpin.Flag("java-async-profiler-delay", "Delay in seconds before starting async-profiler after JVM process is detected").Default("30s").Envar("JAVA_ASYNC_PROFILER_DELAY").Duration()
2121
GoHeapProfilerMode = kingpin.Flag("go-heap-profiler", "Go heap profiling mode: disabled, enabled (collect from apps with profiling on), force (enable profiling in all Go apps)").Default("enabled").Envar("GO_HEAP_PROFILER").String()
22+
InstrumentationDelay = kingpin.Flag("instrumentation-delay", "Delay before enabling Python GIL and Node.js event loop instrumentation, after a process is started").Default("30s").Envar("INSTRUMENTATION_DELAY").Duration()
2223

2324
ContainerAllowlist = kingpin.Flag("container-allowlist", "List of allowed containers (regex patterns)").Envar("CONTAINER_ALLOWLIST").Strings()
2425
ContainerDenylist = kingpin.Flag("container-denylist", "List of denied containers (regex patterns)").Envar("CONTAINER_DENYLIST").Strings()

0 commit comments

Comments
 (0)