-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for flushing the event buffer #92
Changes from all commits
fd6750f
28d09c7
11e5caf
4a32b20
44aaccb
dab89b8
783a913
fb25f64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,10 @@ impl Aggregator { | |
loop { | ||
let should_publish = tokio::select! { | ||
_ = interval.tick() => true, | ||
_ = self.shared.flush.notified() => { | ||
tracing::debug!("event buffer approaching capacity, flushing..."); | ||
false | ||
}, | ||
cmd = self.cmds.recv() => { | ||
if let Some(Command::Instrument(watcher)) = cmd { | ||
self.attach_watcher(watcher).await; | ||
|
@@ -307,7 +311,7 @@ impl<T, const CAP: usize> EventBuf<T, CAP> { | |
// TODO does it really make sense to track the dropped events here? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we still tracking dropped events here? 😂 |
||
pub fn push_overwrite(&mut self, item: T) { | ||
if self.inner.push_overwrite(item).is_some() { | ||
self.sent -= 1; | ||
self.sent = self.sent.saturating_sub(1); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::visitors::{EventVisitor, FieldVisitor}; | ||
use crate::{Event, Shared}; | ||
use crate::{Event, Shared, EVENT_BUFFER_CAPACITY}; | ||
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; | ||
use std::sync::Arc; | ||
use std::time::Instant; | ||
|
@@ -51,6 +51,11 @@ impl Layer { | |
dropped.fetch_add(1, Ordering::Release); | ||
} | ||
} | ||
|
||
let capacity = self.tx.capacity(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you sure we need to check the capacity and not the len? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really, the idea is to catch flush when the remaining capacity in the buffer drops below half. Also |
||
if capacity <= EVENT_BUFFER_CAPACITY / 2 { | ||
self.shared.flush.notify_one(); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this return
true
instead so we publish the events?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the flush notification is about draining the events of the internal event queue (from the
Layer
to theAggregator
) not about the buffer inside the aggregator itself, that one is actually fine.