@@ -17,9 +17,10 @@ import (
1717)
1818
1919const (
20- defaultDeletePodsAfter = 2 * time .Minute
21- defaultCleanCacheInterval = 10 * time .Minute
22- defaultMaxEstimatedCPLatency = 5 * time .Second
20+ defaultDeletePodsAfter = 2 * time .Minute
21+ defaultCleanCacheInterval = 10 * time .Minute
22+ defaultMaxEstimatedCPLatency = 5 * time .Second
23+ defaultShortLivedConnInterval = 0
2324
2425 prometheusNamespace = "stackstate_process_agent"
2526 prometheusSubsystem = "observer"
@@ -54,6 +55,8 @@ type Observer struct {
5455 maxControlPlaneLatency int64
5556 // just used for testing
5657 nowFunc func () time.Time
58+ // if the connection is younger than this interval, we consider it a short lived connection and we don't try to correlate it.
59+ shortLivedConnInterval time.Duration
5760
5861 // Metrics
5962 controlPlaneLatency prometheus.Histogram
@@ -114,6 +117,12 @@ func WithPodDebugEndpoint() ObserverOption {
114117 }
115118}
116119
120+ func WithShortLivedConnectionsInterval (interval time.Duration ) ObserverOption {
121+ return func (o * Observer ) {
122+ o .shortLivedConnInterval = interval
123+ }
124+ }
125+
117126// NewObserver creates a new Observer instance.
118127func NewObserver (reg prometheus.Registerer , opts ... ObserverOption ) (* Observer , error ) {
119128 // we need the boot time because all what we receive from ebpf is the time in nanoseconds since boot
@@ -131,6 +140,7 @@ func NewObserver(reg prometheus.Registerer, opts ...ObserverOption) (*Observer,
131140 cleanCacheInterval : defaultCleanCacheInterval ,
132141 deletePodsAfter : defaultDeletePodsAfter ,
133142 nowFunc : time .Now ,
143+ shortLivedConnInterval : defaultShortLivedConnInterval ,
134144
135145 controlPlaneLatency : prometheus .NewHistogram (prometheus.HistogramOpts {
136146 Namespace : prometheusNamespace ,
@@ -198,7 +208,7 @@ func NewObserver(reg prometheus.Registerer, opts ...ObserverOption) (*Observer,
198208 // update it after we apply the options, since nowFunc can be overridden
199209 obs .lastCacheClean = obs .nowFunc ()
200210
201- log .Infof ("Observer created with clean cache interval: %s, delete pods after: %s" , obs .cleanCacheInterval , obs .deletePodsAfter )
211+ log .Infof ("Observer created ( clean cache interval: %s), ( delete pods after: %s), (short lived connections interval: %s) " , obs .cleanCacheInterval , obs .deletePodsAfter , obs . shortLivedConnInterval )
202212 return obs , nil
203213}
204214
@@ -352,6 +362,18 @@ func (o *Observer) ConnectionNeedsRetry(nsFromBoot time.Duration) bool {
352362 return false
353363}
354364
365+ // FilterShortLivedConnection returns true if the connection is short lived and should be ignored.
366+ func (o * Observer ) FilterShortLivedConnection (nsFromBoot time.Duration ) bool {
367+ // if the interval is not configured we return false
368+ if o .shortLivedConnInterval == 0 {
369+ return false
370+ }
371+
372+ connCreationTime := o .bootTime + int64 (nsFromBoot .Seconds ())
373+ // if the connection is younger than the configured interval we consider it a short lived connection
374+ return connCreationTime > (o .nowFunc ().Unix () - int64 (o .shortLivedConnInterval .Seconds ()))
375+ }
376+
355377// ResolvePodsByIPs resolves the pods by their IPs, returning the PodInfo for each IP.
356378func (o * Observer ) ResolvePodsByIPs (srcIP , dstIP util.Address , nsFromBoot time.Duration ) (* PodInfo , * PodInfo ) {
357379 o .access .RLock ()
0 commit comments