Skip to content

Commit

Permalink
refac(console): match span id earlier
Browse files Browse the repository at this point in the history
Follow the same pattern applied in tokio-rs#533 to match the span id
earlier to avoid checking twice.
  • Loading branch information
Rustin170506 committed Apr 6, 2024
1 parent af2ba7c commit 269fd57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
14 changes: 8 additions & 6 deletions tokio-console/src/state/async_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,17 @@ impl AsyncOpsState {

self.async_ops
.insert_with(visibility, update.new_async_ops, |ids, async_op| {
if async_op.id.is_none() {
tracing::warn!(?async_op, "skipping async op with no id");
}

let span_id = match async_op.id.as_ref() {
Some(id) => id.id,
None => {
tracing::warn!(?async_op, "skipping async op with no id");
return None;
}
};
let meta_id = match async_op.metadata.as_ref() {
Some(id) => id.id,
None => {
tracing::warn!(?async_op, "async op has no metadata ID, skipping");
tracing::warn!(?async_op, "async op has no metadata id, skipping");
return None;
}
};
Expand All @@ -160,7 +163,6 @@ impl AsyncOpsState {
}
};

let span_id = async_op.id?.id;
let stats = AsyncOpStats::from_proto(
stats_update.remove(&span_id)?,
meta,
Expand Down
13 changes: 8 additions & 5 deletions tokio-console/src/state/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,18 @@ impl ResourcesState {
let mut stats_update = update.stats_update;
self.resources
.insert_with(visibility, update.new_resources, |ids, resource| {
if resource.id.is_none() {
tracing::warn!(?resource, "skipping resource with no id");
}
let span_id = match resource.id.as_ref() {
Some(id) => id.id,
None => {
tracing::warn!(?resource, "skipping resource with no id");
return None;
}
};

let meta_id = match resource.metadata.as_ref() {
Some(id) => id.id,
None => {
tracing::warn!(?resource, "resource has no metadata ID, skipping");
tracing::warn!(?resource, "resource has no metadata id skipping");
return None;
}
};
Expand All @@ -201,7 +205,6 @@ impl ResourcesState {
}
};

let span_id = resource.id?.id;
let stats = ResourceStats::from_proto(
stats_update.remove(&span_id)?,
meta,
Expand Down

0 comments on commit 269fd57

Please sign in to comment.