-
Notifications
You must be signed in to change notification settings - Fork 137
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(iroh, iroh-gossip): introduce log-self
feature
#1544
Changes from all commits
e60dcb0
a0b8e39
0751c65
11ccf9b
e073d38
a4f997a
e3d944a
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 |
---|---|---|
|
@@ -44,6 +44,8 @@ use iroh_net::{key::PublicKey, MagicEndpoint}; | |
use tokio::sync::{mpsc, oneshot}; | ||
use tokio_util::{sync::CancellationToken, time::delay_queue}; | ||
use tracing::{debug, trace}; | ||
#[cfg(feature = "log-self")] | ||
use tracing::{trace_span, Instrument}; | ||
|
||
mod get; | ||
mod invariants; | ||
|
@@ -225,6 +227,8 @@ impl Downloader { | |
S: Store, | ||
C: CollectionParser, | ||
{ | ||
#[cfg(feature = "log-self")] | ||
let me = endpoint.peer_id().fmt_short(); | ||
let (msg_tx, msg_rx) = mpsc::channel(SERVICE_CHANNEL_CAPACITY); | ||
let dialer = iroh_gossip::net::util::Dialer::new(endpoint); | ||
|
||
|
@@ -237,6 +241,12 @@ impl Downloader { | |
|
||
let service = Service::new(getter, dialer, concurrency_limits, msg_rx); | ||
|
||
#[cfg(feature = "log-self")] | ||
{ | ||
service.run().instrument(trace_span!("downloader", %me)) | ||
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. same here, it should always attach the span and be |
||
} | ||
|
||
#[cfg(not(feature = "log-self"))] | ||
service.run() | ||
}; | ||
rt.local_pool().spawn_pinned(create_future); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,9 @@ use tokio::{ | |
task::JoinError, | ||
}; | ||
use tokio_util::sync::CancellationToken; | ||
use tracing::{debug, debug_span, error, warn, Instrument}; | ||
use tracing::{debug, error, warn}; | ||
#[cfg(feature = "log-self")] | ||
use tracing::{trace_span, Instrument}; | ||
|
||
pub use iroh_sync::ContentStatus; | ||
|
||
|
@@ -183,7 +185,8 @@ impl<S: store::Store> LiveSync<S> { | |
downloader: Downloader, | ||
) -> Self { | ||
let (to_actor_tx, to_actor_rx) = mpsc::channel(CHANNEL_CAP); | ||
let me = base32::fmt_short(endpoint.peer_id()); | ||
#[cfg(feature = "log-self")] | ||
let me = endpoint.peer_id().fmt_short(); | ||
let mut actor = Actor::new( | ||
endpoint, | ||
gossip, | ||
|
@@ -193,9 +196,12 @@ impl<S: store::Store> LiveSync<S> { | |
to_actor_rx, | ||
to_actor_tx.clone(), | ||
); | ||
let span = debug_span!("sync", %me); | ||
|
||
let task = rt.main().spawn(async move { | ||
if let Err(err) = actor.run().instrument(span).await { | ||
let fut = actor.run(); | ||
#[cfg(feature = "log-self")] | ||
let fut = fut.instrument(trace_span!("sync", %me)); | ||
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. same note, |
||
if let Err(err) = fut.await { | ||
error!("live sync failed: {err:?}"); | ||
} | ||
}); | ||
|
@@ -1016,16 +1022,3 @@ async fn notify_all(subs: &mut HashMap<u64, OnLiveEventCallback>, event: LiveEve | |
} | ||
} | ||
} | ||
|
||
/// Utilities for working with byte array identifiers | ||
// TODO: copy-pasted from iroh-gossip/src/proto/util.rs | ||
// Unify into iroh-common crate or similar | ||
pub(super) mod base32 { | ||
/// Convert to a base32 string limited to the first 10 bytes | ||
pub fn fmt_short(bytes: impl AsRef<[u8]>) -> String { | ||
let len = bytes.as_ref().len().min(10); | ||
let mut text = data_encoding::BASE32_NOPAD.encode(&bytes.as_ref()[..len]); | ||
text.make_ascii_lowercase(); | ||
text | ||
} | ||
} |
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.
since this is a spawned future I'd strongly recommend to use an
info_span
. And also to not make it depend on the feature. Every task should have it's owninfo_span
attached as a general rule.The span should also cover the bit of error handing in the lines below that are still inside this spawned task.
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.
can you explain why
info_span
? looking throughout the code we still havetrace_span
once inbaomap
,debug_span
16 times. Looking at what Frando did in his own branch for his needs he went with trace as well and it seems to work well. What's the difference?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.
My general guideline is to use
info_span
for spawned tasks, motivation:This does not mean we already do this everywhere consistently. I've done a few PRs in the past making this more consistent but it certainly isn't complete.
Now I understand your reluctance to always having this logging on and that having this as debug or trace makes it even easier to hide. but i do really think this is more useful at info.
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.
ok just to be clear about my question I don't understand what this changes, not sure what the effect of this is.
Is the effect to add the fields only from info and above? if so then don't think this will help in debugging tests
if the effect is to limit to info and below then it's probably better
but then it's confusing that trace still gives me debug logs with peer_ids.
TLDR: I'm confused about what the levels do here
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.
See also https://discord.com/channels/949724860232392765/950683937661935667/1156506832567808060 where @Frando is also asked me this question and I (hopefully!) gave a similar answer.