added tracking of the number of start-, drop, and end-events in an aggregation window

Signed-off-by: Dmitri <dmitri.external@netbird.io>
This commit is contained in:
Dmitri
2026-06-10 16:06:29 +02:00
parent 101ae3ca77
commit 8f99362a25
6 changed files with 233 additions and 275 deletions
+19 -2
View File
@@ -91,6 +91,14 @@ func (am *AggregatingMemory) GetAggregatedEvents() []*types.Event {
aggregatedEvent.RxPackets += v.RxPackets
aggregatedEvent.TxBytes += v.TxBytes
aggregatedEvent.TxPackets += v.TxPackets
switch v.Type {
case types.TypeStart:
aggregatedEvent.NumOfStarts += 1
case types.TypeDrop:
aggregatedEvent.NumOfDrops += 1
case types.TypeEnd:
aggregatedEvent.NumOfEnds += 1
}
if aggregatedEvent.Timestamp.Compare(v.Timestamp) > 0 {
aggregatedEvent.Timestamp = v.Timestamp
aggregatedEvent.ID = v.ID
@@ -103,10 +111,19 @@ func (am *AggregatingMemory) GetAggregatedEvents() []*types.Event {
} else {
switch v.Protocol {
case types.ICMP, types.ICMPv6, types.TCP, types.UDP:
aggregated[lookupKey] = v
event := v.Clone()
aggregated[lookupKey] = event
switch event.Type {
case types.TypeStart:
event.NumOfStarts += 1
case types.TypeDrop:
event.NumOfDrops += 1
case types.TypeEnd:
event.NumOfEnds += 1
}
default:
lookupKey.ts = time.Now().UnixNano() // to make the lookup key unique so we don't aggregate on it
aggregated[lookupKey] = v
aggregated[lookupKey] = v.Clone()
}
}
}