From 1a8f02d7432107b95a9cf5bc1bad26ebff039c0d Mon Sep 17 00:00:00 2001 From: Nayef Ghattas Date: Wed, 20 Nov 2024 11:23:44 +0100 Subject: [PATCH] reporter: ensure that actively used executables do not expire Fixes https://github.com/open-telemetry/opentelemetry-ebpf-profiler/issues/244 --- reporter/otlp_reporter.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index b140f412..2b384be6 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -33,6 +33,10 @@ import ( "go.opentelemetry.io/ebpf-profiler/libpf/xsync" ) +const ( + executableCacheLifetime = 1 * time.Hour +) + var ( cgroupv2PathPattern = regexp.MustCompile(`0:.*?:(.*)`) ) @@ -155,7 +159,7 @@ func NewOTLP(cfg *Config) (*OTLPReporter, error) { if err != nil { return nil, err } - executables.SetLifetime(1 * time.Hour) // Allow GC to clean stale items. + executables.SetLifetime(executableCacheLifetime) // Allow GC to clean stale items. frames, err := lru.NewSynced[libpf.FileID, *xsync.RWMutex[map[libpf.AddressOrLineno]sourceInfo]]( @@ -582,7 +586,9 @@ func (r *OTLPReporter) getProfile() (profile *profiles.Profile, startTS, endTS u fileIDtoMapping[traceInfo.files[i]] = idx locationMappingIndex = idx - execInfo, exists := r.executables.Get(traceInfo.files[i]) + // Ensure that actively used executables do not expire. + execInfo, exists := r.executables.GetAndRefresh(traceInfo.files[i], + executableCacheLifetime) // Next step: Select a proper default value, // if the name of the executable is not known yet.