From 269fd57aad422188ed6e6354748a00088d32a7c5 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 28 Mar 2024 21:46:43 +0800 Subject: [PATCH] refac(console): match span id earlier Follow the same pattern applied in #533 to match the span id earlier to avoid checking twice. --- tokio-console/src/state/async_ops.rs | 14 ++++++++------ tokio-console/src/state/resources.rs | 13 ++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tokio-console/src/state/async_ops.rs b/tokio-console/src/state/async_ops.rs index d10b6ecdf..46fcdb487 100644 --- a/tokio-console/src/state/async_ops.rs +++ b/tokio-console/src/state/async_ops.rs @@ -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; } }; @@ -160,7 +163,6 @@ impl AsyncOpsState { } }; - let span_id = async_op.id?.id; let stats = AsyncOpStats::from_proto( stats_update.remove(&span_id)?, meta, diff --git a/tokio-console/src/state/resources.rs b/tokio-console/src/state/resources.rs index 9787fd103..4d467f772 100644 --- a/tokio-console/src/state/resources.rs +++ b/tokio-console/src/state/resources.rs @@ -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; } }; @@ -201,7 +205,6 @@ impl ResourcesState { } }; - let span_id = resource.id?.id; let stats = ResourceStats::from_proto( stats_update.remove(&span_id)?, meta,