Implement Compaction of Desktop Shared Directory Read/Write Events#57815
Implement Compaction of Desktop Shared Directory Read/Write Events#57815rhammonds-teleport merged 1 commit intomasterfrom
Conversation
f5b97f6 to
9cd3c2a
Compare
| } | ||
| } | ||
|
|
||
| func (s *stream) compactEvents() []streamEvent { |
There was a problem hiding this comment.
Would it make sense to return an iter.Seq here instead?
| } | ||
| case tdp.SharedDirectoryReadResponse: | ||
| s.emit(ctx, audit.makeSharedDirectoryReadResponse(msg)) | ||
| audit.compactor.handleRead(ctx, audit.makeSharedDirectoryReadResponse(msg)) |
There was a problem hiding this comment.
I might just add a comment to these lines that says something like:
// shared directory audit events can be noisy, so we use a compactor
// in order to bucket them instead of writing straight to the audit log
There was a problem hiding this comment.
Same goes for handleWrite below.
| refreshInterval time.Duration | ||
| maxDelayInterval time.Duration |
There was a problem hiding this comment.
What's the difference between these two?
There was a problem hiding this comment.
I added some comments to clarify. refreshInterval defines how long to wait for the next event to arrive before flushing a given bucket. maxDelayInterval defines the maximum time a bucket should exist before flushing. Basically the latter prevents some pathological read/write scenario from delaying audit events indefinitely.
There was a problem hiding this comment.
I see, so event A and event B will be combined assuming they overlap and occur within refreshInterval, so long as the first event in this bucket occurred less than maxDelayInterval ago.
There was a problem hiding this comment.
That's right!
|
Don't forget to link this PR to the issue it closes. |
2750f20 to
ba118c6
Compare
…eads and writes Attempt #2. Read requests for a given copy operation can arrive out of order. Adjusted this approach to record all read/write events within a given time period, then find the longest contiguous set of reads/writes that can be joined into a single audit event before emitting audit event(s). bit of cleanup A bit of code cleanup plus extra test case. Removed timestamps from testing since the compaction algorithm can't really guarantee which segments will get grouped together. Fix racy tests by bringing assertions into synctest bubble and using 'flush' for syncronization. Also add more thorough test cases for timer expiration and flush behavior. lint fixes Add license header Replace unnecessary sort with 'slices.Min' Apply suggestions from code review Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com> Rename 'evnt' -> 'event' Return iterator instead of slice Abandon 'stream' terminology in favor of 'fileOperationsBucket'. This might be a better name since the code is basically sorting audit events into a set of 'buckets' and attempting to compact each bucket of events later on. Add a few comments
ba118c6 to
e470056
Compare
|
@rhammonds-teleport See the table below for backport results.
|
…eads and writes (#57815) Attempt #2. Read requests for a given copy operation can arrive out of order. Adjusted this approach to record all read/write events within a given time period, then find the longest contiguous set of reads/writes that can be joined into a single audit event before emitting audit event(s). bit of cleanup A bit of code cleanup plus extra test case. Removed timestamps from testing since the compaction algorithm can't really guarantee which segments will get grouped together. Fix racy tests by bringing assertions into synctest bubble and using 'flush' for syncronization. Also add more thorough test cases for timer expiration and flush behavior. lint fixes Add license header Replace unnecessary sort with 'slices.Min' Apply suggestions from code review Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com> Rename 'evnt' -> 'event' Return iterator instead of slice Abandon 'stream' terminology in favor of 'fileOperationsBucket'. This might be a better name since the code is basically sorting audit events into a set of 'buckets' and attempting to compact each bucket of events later on. Add a few comments
Copying files into or out of the shared directory often creates many small read/write operations that clutter the audit log. This PR aims to implement an algorithm that compacts audit events resulting from reads/writes to files within a given shared directory.
The audit compactor caches subsequent reads/writes to a given file for some configurable period of time. Once this timeout expires, audit entries are examined to determine which operations constitute sequential reads/writes that could be compacted into a single audit event. The reduced set of audit events are then emitted.
Closes #40341
Changelog: Reduce audit log clutter by compacting contiguous shared directory read/write events into a single audit log event.