Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 81309d1

Browse files
authored
approval-distribution: Add approvals/assignments spans on all paths (#7317)
* approval-distribution: Add approvals/assignments spans on all paths The approval and assignment logic gets called from multiple paths, so make sure we create a tracing span on all paths to make debugging easier and be able and correlate with the spans from approval-voting. Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io> * Tag each label with a difference tracing name Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io> * Address review feedback Use the source to determine the tag name Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io> --------- Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
1 parent cf0ecdd commit 81309d1

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

node/jaeger/src/spans.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl Span {
277277
}
278278

279279
/// Derive a child span from `self`.
280-
pub fn child(&self, name: &'static str) -> Self {
280+
pub fn child(&self, name: &str) -> Self {
281281
match self {
282282
Self::Enabled(inner) => Self::Enabled(inner.child(name)),
283283
Self::Disabled => Self::Disabled,
@@ -297,11 +297,22 @@ impl Span {
297297
self
298298
}
299299

300+
/// Attach a peer-id tag to the span.
300301
#[inline(always)]
301302
pub fn with_peer_id(self, peer: &PeerId) -> Self {
302303
self.with_string_tag("peer-id", &peer.to_base58())
303304
}
304305

306+
/// Attach a `peer-id` tag to the span when peer is present.
307+
#[inline(always)]
308+
pub fn with_optional_peer_id(self, peer: Option<&PeerId>) -> Self {
309+
if let Some(peer) = peer {
310+
self.with_peer_id(peer)
311+
} else {
312+
self
313+
}
314+
}
315+
305316
/// Attach a candidate hash to the span.
306317
#[inline(always)]
307318
pub fn with_candidate(self, candidate_hash: CandidateHash) -> Self {

node/network/approval-distribution/src/lib.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,21 @@ impl State {
725725
) where
726726
R: CryptoRng + Rng,
727727
{
728+
let _span = self
729+
.spans
730+
.get(&assignment.block_hash)
731+
.map(|span| {
732+
span.child(if source.peer_id().is_some() {
733+
"peer-import-and-distribute-assignment"
734+
} else {
735+
"local-import-and-distribute-assignment"
736+
})
737+
})
738+
.unwrap_or_else(|| jaeger::Span::new(&assignment.block_hash, "distribute-assignment"))
739+
.with_string_tag("block-hash", format!("{:?}", assignment.block_hash))
740+
.with_optional_peer_id(source.peer_id().as_ref())
741+
.with_stage(jaeger::Stage::ApprovalDistribution);
742+
728743
let block_hash = assignment.block_hash;
729744
let validator_index = assignment.validator;
730745

@@ -985,6 +1000,21 @@ impl State {
9851000
source: MessageSource,
9861001
vote: IndirectSignedApprovalVote,
9871002
) {
1003+
let _span = self
1004+
.spans
1005+
.get(&vote.block_hash)
1006+
.map(|span| {
1007+
span.child(if source.peer_id().is_some() {
1008+
"peer-import-and-distribute-approval"
1009+
} else {
1010+
"local-import-and-distribute-approval"
1011+
})
1012+
})
1013+
.unwrap_or_else(|| jaeger::Span::new(&vote.block_hash, "distribute-approval"))
1014+
.with_string_tag("block-hash", format!("{:?}", vote.block_hash))
1015+
.with_optional_peer_id(source.peer_id().as_ref())
1016+
.with_stage(jaeger::Stage::ApprovalDistribution);
1017+
9881018
let block_hash = vote.block_hash;
9891019
let validator_index = vote.validator;
9901020
let candidate_index = vote.candidate_index;
@@ -1724,14 +1754,6 @@ impl ApprovalDistribution {
17241754
state.handle_new_blocks(ctx, metrics, metas, rng).await;
17251755
},
17261756
ApprovalDistributionMessage::DistributeAssignment(cert, candidate_index) => {
1727-
let _span = state
1728-
.spans
1729-
.get(&cert.block_hash)
1730-
.map(|span| span.child("import-and-distribute-assignment"))
1731-
.unwrap_or_else(|| jaeger::Span::new(&cert.block_hash, "distribute-assignment"))
1732-
.with_string_tag("block-hash", format!("{:?}", cert.block_hash))
1733-
.with_stage(jaeger::Stage::ApprovalDistribution);
1734-
17351757
gum::debug!(
17361758
target: LOG_TARGET,
17371759
"Distributing our assignment on candidate (block={}, index={})",
@@ -1751,14 +1773,6 @@ impl ApprovalDistribution {
17511773
.await;
17521774
},
17531775
ApprovalDistributionMessage::DistributeApproval(vote) => {
1754-
let _span = state
1755-
.spans
1756-
.get(&vote.block_hash)
1757-
.map(|span| span.child("import-and-distribute-approval"))
1758-
.unwrap_or_else(|| jaeger::Span::new(&vote.block_hash, "distribute-approval"))
1759-
.with_string_tag("block-hash", format!("{:?}", vote.block_hash))
1760-
.with_stage(jaeger::Stage::ApprovalDistribution);
1761-
17621776
gum::debug!(
17631777
target: LOG_TARGET,
17641778
"Distributing our approval vote on candidate (block={}, index={})",

0 commit comments

Comments
 (0)