Skip to content
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

fix(subscriber): do not report excessive polling (#378) #440

Merged
merged 6 commits into from
Jul 3, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 22 additions & 40 deletions console-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,36 +789,27 @@ where
}

fn on_enter(&self, id: &span::Id, cx: Context<'_, S>) {
fn update<S: Subscriber + for<'a> LookupSpan<'a>>(
span: &SpanRef<S>,
at: Option<Instant>,
) -> Option<Instant> {
if let Some(span) = cx.span(id) {
let now = Instant::now();
let exts = span.extensions();
// if the span we are entering is a task or async op, record the
// poll stats.
if let Some(stats) = exts.get::<Arc<stats::TaskStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.start_poll(at);
Some(at)
let is_relevant = if let Some(stats) = exts.get::<Arc<stats::TaskStats>>() {
stats.start_poll(now);
true
} else if let Some(stats) = exts.get::<Arc<stats::AsyncOpStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.start_poll(at);
Some(at)
stats.start_poll(now);
true
// otherwise, is the span a resource? in that case, we also want
// to enter it, although we don't care about recording poll
// stats.
} else if exts.get::<Arc<stats::ResourceStats>>().is_some() {
MatteoNardi marked this conversation as resolved.
Show resolved Hide resolved
Some(at.unwrap_or_else(Instant::now))
true
} else {
None
}
}
false
MatteoNardi marked this conversation as resolved.
Show resolved Hide resolved
};

if let Some(span) = cx.span(id) {
if let Some(now) = update(&span, None) {
if let Some(parent) = span.parent() {
update(&parent, Some(now));
}
if is_relevant {
self.current_spans
.get_or_default()
.borrow_mut()
Expand All @@ -833,36 +824,27 @@ where
}

fn on_exit(&self, id: &span::Id, cx: Context<'_, S>) {
fn update<S: Subscriber + for<'a> LookupSpan<'a>>(
span: &SpanRef<S>,
at: Option<Instant>,
) -> Option<Instant> {
if let Some(span) = cx.span(id) {
let exts = span.extensions();
let now = Instant::now();
// if the span we are entering is a task or async op, record the
// poll stats.
if let Some(stats) = exts.get::<Arc<stats::TaskStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.end_poll(at);
Some(at)
let is_relevant = if let Some(stats) = exts.get::<Arc<stats::TaskStats>>() {
stats.end_poll(now);
true
} else if let Some(stats) = exts.get::<Arc<stats::AsyncOpStats>>() {
let at = at.unwrap_or_else(Instant::now);
stats.end_poll(at);
Some(at)
stats.end_poll(now);
true
// otherwise, is the span a resource? in that case, we also want
// to enter it, although we don't care about recording poll
// stats.
} else if exts.get::<Arc<stats::ResourceStats>>().is_some() {
Some(at.unwrap_or_else(Instant::now))
true
} else {
None
}
}
false
MatteoNardi marked this conversation as resolved.
Show resolved Hide resolved
};

if let Some(span) = cx.span(id) {
if let Some(now) = update(&span, None) {
if let Some(parent) = span.parent() {
update(&parent, Some(now));
}
if is_relevant {
self.current_spans.get_or_default().borrow_mut().pop(id);

self.record(|| record::Event::Exit {
Expand Down