diff --git a/reporter/internal/pdata/generate.go b/reporter/internal/pdata/generate.go index bde6aa18..5c3cabc8 100644 --- a/reporter/internal/pdata/generate.go +++ b/reporter/internal/pdata/generate.go @@ -7,6 +7,7 @@ import ( "crypto/rand" "slices" "strconv" + "time" log "github.com/sirupsen/logrus" "go.opentelemetry.io/collector/pdata/pcommon" @@ -17,6 +18,11 @@ import ( "go.opentelemetry.io/ebpf-profiler/reporter/internal/samples" ) +const ( + ExecutableCacheLifetime = 1 * time.Hour + FramesCacheLifetime = 1 * time.Hour +) + // Generate generates a pdata request out of internal profiles data, to be // exported. func (p Pdata) Generate(events map[samples.TraceAndMetaKey]*samples.TraceEvents) pprofile.Profiles { @@ -111,7 +117,8 @@ func (p *Pdata) setProfile( fileIDtoMapping[traceInfo.Files[i]] = idx locationMappingIndex = idx - ei, exists := p.Executables.GetAndRefresh(traceInfo.Files[i], ...) + ei, exists := p.Executables.GetAndRefresh(traceInfo.Files[i], + ExecutableCacheLifetime) // Next step: Select a proper default value, // if the name of the executable is not known yet. @@ -150,7 +157,8 @@ func (p *Pdata) setProfile( // Store interpreted frame information as a Line message: line := loc.Line().AppendEmpty() - fileIDInfoLock, exists := p.Frames.GetAndRefresh(traceInfo.Files[i], ...) + fileIDInfoLock, exists := p.Frames.GetAndRefresh(traceInfo.Files[i], + FramesCacheLifetime) if !exists { // At this point, we do not have enough information for the frame. // Therefore, we report a dummy entry and use the interpreter as filename. diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index 00510e13..71d34303 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -184,7 +184,7 @@ func (r *OTLPReporter) ReportCountForTrace(_ libpf.TraceHash, _ uint16, _ *Trace // ExecutableKnown returns true if the metadata of the Executable specified by fileID is // cached in the reporter. func (r *OTLPReporter) ExecutableKnown(fileID libpf.FileID) bool { - _, known := r.pdata.Executables.GetAndRefresh(fileID, ...) + _, known := r.pdata.Executables.GetAndRefresh(fileID, pdata.ExecutableCacheLifetime) return known } @@ -201,7 +201,8 @@ func (r *OTLPReporter) ExecutableMetadata(args *ExecutableMetadataArgs) { // cached in the reporter. func (r *OTLPReporter) FrameKnown(frameID libpf.FrameID) bool { known := false - if frameMapLock, exists := r.pdata.Frames.GetAndRefresh(frameID.FileID(), ...); exists { + if frameMapLock, exists := r.pdata.Frames.GetAndRefresh(frameID.FileID(), + pdata.FramesCacheLifetime); exists { frameMap := frameMapLock.RLock() defer frameMapLock.RUnlock(&frameMap) _, known = (*frameMap)[frameID.AddressOrLine()] @@ -218,7 +219,8 @@ func (r *OTLPReporter) FrameMetadata(args *FrameMetadataArgs) { fileID, args.FunctionName, args.FunctionOffset, args.SourceFile, args.SourceLine) - if frameMapLock, exists := r.pdata.Frames.Get(fileID); exists { + if frameMapLock, exists := r.pdata.Frames.GetAndRefresh(fileID, + pdata.FramesCacheLifetime); exists { frameMap := frameMapLock.WLock() defer frameMapLock.WUnlock(&frameMap)