Skip to content

Commit af35e3b

Browse files
fix: restrict file agg events to ai agents
1 parent 5729892 commit af35e3b

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

server/ingester/event/decoder/decoder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ func splitFilePath(fullPath string) (string, string) {
402402
return "", fullPath
403403
}
404404

405+
func shouldAggregateFileAggEvent(rootPID uint32) bool {
406+
return rootPID != 0
407+
}
408+
405409
func (d *Decoder) emitFileAggItems(items []*dbwriter.FileAggEventStore) {
406410
if len(items) == 0 {
407411
return
@@ -456,7 +460,7 @@ func (d *Decoder) writeRawFileEvent(vtapId uint16, e *pb.ProcEvent) {
456460

457461
d.export(s)
458462
d.rawFileWriter().Write(s)
459-
if d.fileAggReducer != nil {
463+
if d.fileAggReducer != nil && shouldAggregateFileAggEvent(s.RootPID) {
460464
d.emitFileAggItems(d.fileAggReducer.Add(s))
461465
}
462466
}

server/ingester/event/decoder/decoder_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,12 @@ func TestExtractFileMgmtTargets(t *testing.T) {
259259
t.Fatalf("chmod targets = (%d,%d,%d)", uid, gid, mode)
260260
}
261261
}
262+
263+
func TestShouldAggregateFileAggEvent(t *testing.T) {
264+
if shouldAggregateFileAggEvent(0) {
265+
t.Fatalf("expected root pid 0 to skip file_agg_event aggregation")
266+
}
267+
if !shouldAggregateFileAggEvent(42) {
268+
t.Fatalf("expected non-zero root pid to allow file_agg_event aggregation")
269+
}
270+
}

server/ingester/event/decoder/file_agg_reducer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func shouldSplitFileAggByIdleGap(current, next *dbwriter.FileAggEventStore) bool
113113
}
114114

115115
func (r *FileAggReducer) Add(raw *dbwriter.EventStore) []*dbwriter.FileAggEventStore {
116+
if raw == nil || raw.RootPID == 0 {
117+
return nil
118+
}
116119
next := cloneRawFileEventToAgg(raw)
117120
if next == nil {
118121
return nil

server/ingester/event/decoder/file_agg_reducer_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,19 @@ func TestFileAggReducerSplitsSameKeyWhenIdleGapExceeded(t *testing.T) {
195195
t.Fatalf("remaining event_count = %d, want 1", remaining[0].EventCount)
196196
}
197197
}
198+
199+
func TestFileAggReducerSkipsNonAiAgentEvent(t *testing.T) {
200+
reducer := NewFileAggReducer()
201+
raw := makeRawFileEvent("bash", "read", "plain.txt", 16)
202+
raw.RootPID = 0
203+
204+
flushed := reducer.Add(raw)
205+
if flushed != nil {
206+
t.Fatalf("add returned %d flushed items, want nil", len(flushed))
207+
}
208+
209+
remaining := reducer.Flush()
210+
if remaining != nil {
211+
t.Fatalf("flush returned %d items, want nil", len(remaining))
212+
}
213+
}

0 commit comments

Comments
 (0)