observability: tracing gum, automatically cross ref traceID (#5079)

* add some gum

* bump expander

* gum

* fix all remaining issues

* last fixup

* Update node/gum/proc-macro/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* change

* netowrk

* fixins

* chore

* allow optional fmt str + args, prep for expr as kv field

* tracing -> gum rename fallout

* restrict further

* allow multiple levels of field accesses

* another round of docs and a slip of the pen

* update ADR

* fixup lock fiel

* use target: instead of target=

* minors

* fix

* chore

* Update node/gum/README.md

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
This commit is contained in:
Bernhard Schuster
2022-03-15 12:05:16 +01:00
committed by GitHub
parent fa359fd1f7
commit d631f1dea8
130 changed files with 1708 additions and 808 deletions
@@ -236,7 +236,7 @@ pub(crate) fn compute_assignments(
config.assignment_keys.is_empty() ||
config.validator_groups.is_empty()
{
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
n_cores = config.n_cores,
has_assignment_keys = !config.assignment_keys.is_empty(),
@@ -255,7 +255,7 @@ pub(crate) fn compute_assignments(
Err(sc_keystore::Error::Unavailable) => None,
Err(sc_keystore::Error::Io(e)) if e.kind() == std::io::ErrorKind::NotFound => None,
Err(e) => {
tracing::warn!(target: LOG_TARGET, "Encountered keystore error: {:?}", e);
gum::warn!(target: LOG_TARGET, "Encountered keystore error: {:?}", e);
None
},
}
@@ -263,7 +263,7 @@ pub(crate) fn compute_assignments(
match key {
None => {
tracing::trace!(target: LOG_TARGET, "No assignment key");
gum::trace!(target: LOG_TARGET, "No assignment key");
return HashMap::new()
},
Some(k) => k,
@@ -277,7 +277,7 @@ pub(crate) fn compute_assignments(
.map(|(c_hash, core, _)| (c_hash, core))
.collect::<Vec<_>>();
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
assignable_cores = leaving_cores.len(),
"Assigning to candidates from different backing groups"
@@ -333,7 +333,7 @@ fn compute_relay_vrf_modulo_assignments(
if let Some((candidate_hash, _)) =
leaving_cores.clone().into_iter().find(|(_, c)| c == core)
{
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?core,
@@ -415,7 +415,7 @@ fn compute_relay_vrf_delay_assignments(
};
if used {
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?core,
@@ -138,7 +138,7 @@ async fn imported_block_info(
.as_ref()
.map_or(true, |s| session_index < s.earliest_session())
{
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
"Block {} is from ancient session {}. Skipping",
block_hash,
@@ -188,11 +188,7 @@ async fn imported_block_info(
{
Some(s) => s,
None => {
tracing::debug!(
target: LOG_TARGET,
"Session info unavailable for block {}",
block_hash,
);
gum::debug!(target: LOG_TARGET, "Session info unavailable for block {}", block_hash,);
return Ok(None)
},
@@ -227,7 +223,7 @@ async fn imported_block_info(
}
},
None => {
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
"BABE VRF info unavailable for block {}",
block_hash,
@@ -238,12 +234,12 @@ async fn imported_block_info(
}
};
tracing::trace!(target: LOG_TARGET, n_assignments = assignments.len(), "Produced assignments");
gum::trace!(target: LOG_TARGET, n_assignments = assignments.len(), "Produced assignments");
let force_approve =
block_header.digest.convert_first(|l| match ConsensusLog::from_digest_item(l) {
Ok(Some(ConsensusLog::ForceApprove(num))) if num < block_header.number => {
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?block_hash,
current_number = block_header.number,
@@ -256,7 +252,7 @@ async fn imported_block_info(
Ok(Some(_)) => None,
Ok(None) => None,
Err(err) => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?err,
?block_hash,
@@ -313,7 +309,7 @@ pub(crate) async fn handle_new_head(
match h_rx.await? {
Err(e) => {
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
"Chain API subsystem temporarily unreachable {}",
e,
@@ -322,7 +318,7 @@ pub(crate) async fn handle_new_head(
return Ok(Vec::new())
},
Ok(None) => {
tracing::warn!(target: LOG_TARGET, "Missing header for new head {}", head);
gum::warn!(target: LOG_TARGET, "Missing header for new head {}", head);
return Ok(Vec::new())
},
Ok(Some(h)) => h,
@@ -332,7 +328,7 @@ pub(crate) async fn handle_new_head(
// Update session info based on most recent head.
match state.cache_session_info_for_head(ctx, head).await {
Err(e) => {
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
?head,
?e,
@@ -342,7 +338,7 @@ pub(crate) async fn handle_new_head(
return Ok(Vec::new())
},
Ok(Some(a @ SessionWindowUpdate::Advanced { .. })) => {
tracing::info!(
gum::info!(
target: LOG_TARGET,
update = ?a,
"Advanced session window for approvals",
@@ -404,7 +400,7 @@ pub(crate) async fn handle_new_head(
if !lost_to_finality {
// Such errors are likely spurious, but this prevents us from getting gaps
// in the approval-db.
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Unable to gather info about imported block {:?}. Skipping chain.",
(block_hash, block_header.number),
@@ -419,7 +415,7 @@ pub(crate) async fn handle_new_head(
imported_blocks_and_info
};
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
imported_blocks = imported_blocks_and_info.len(),
"Inserting imported blocks into database"
@@ -458,7 +454,7 @@ pub(crate) async fn handle_new_head(
let num_candidates = included_candidates.len();
let approved_bitfield = {
if needed_approvals == 0 {
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
block_hash = ?block_hash,
"Insta-approving all candidates",
@@ -476,7 +472,7 @@ pub(crate) async fn handle_new_head(
}
}
if result.any() {
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
block_hash = ?block_hash,
"Insta-approving {}/{} candidates as the number of validators is too low",
@@ -510,7 +506,7 @@ pub(crate) async fn handle_new_head(
};
if let Some(up_to) = force_approve {
tracing::debug!(target: LOG_TARGET, ?block_hash, up_to, "Enacting force-approve");
gum::debug!(target: LOG_TARGET, ?block_hash, up_to, "Enacting force-approve");
let approved_hashes = crate::ops::force_approve(db, block_hash, up_to)
.map_err(|e| SubsystemError::with_origin("approval-voting", e))?;
@@ -521,7 +517,7 @@ pub(crate) async fn handle_new_head(
}
}
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?block_hash,
block_number = block_header.number,
@@ -561,7 +557,7 @@ pub(crate) async fn handle_new_head(
});
}
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
head = ?head,
chain_length = approval_meta.len(),
+41 -43
View File
@@ -621,7 +621,7 @@ impl State {
let session_info = match self.session_info(block_entry.session()) {
Some(s) => s,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Unknown session info for {}",
block_entry.session()
@@ -718,7 +718,7 @@ where
match rx.await? {
Ok(number) => Some(number),
Err(err) => {
tracing::warn!(target: LOG_TARGET, ?err, "Failed fetching finalized number");
gum::warn!(target: LOG_TARGET, ?err, "Failed fetching finalized number");
None
},
}
@@ -962,13 +962,11 @@ async fn handle_actions(
match confirmation_rx.await {
Err(oneshot::Canceled) => {
tracing::debug!(target: LOG_TARGET, "Dispute coordinator confirmation lost",)
gum::debug!(target: LOG_TARGET, "Dispute coordinator confirmation lost",)
},
Ok(ImportStatementsResult::ValidImport) => {},
Ok(ImportStatementsResult::InvalidImport) => tracing::warn!(
target: LOG_TARGET,
"Failed to import statements of validity",
),
Ok(ImportStatementsResult::InvalidImport) =>
gum::warn!(target: LOG_TARGET, "Failed to import statements of validity",),
}
},
Action::NoteApprovedInChainSelection(block_hash) => {
@@ -1004,7 +1002,7 @@ fn distribution_messages_for_activation(
let block_entry = match db.load_block_entry(&block_hash)? {
Some(b) => b,
None => {
tracing::warn!(target: LOG_TARGET, ?block_hash, "Missing block entry");
gum::warn!(target: LOG_TARGET, ?block_hash, "Missing block entry");
continue
},
@@ -1021,7 +1019,7 @@ fn distribution_messages_for_activation(
let candidate_entry = match db.load_candidate_entry(&candidate_hash)? {
Some(c) => c,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?block_hash,
?candidate_hash,
@@ -1068,7 +1066,7 @@ fn distribution_messages_for_activation(
}
},
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?block_hash,
?candidate_hash,
@@ -1105,7 +1103,7 @@ async fn handle_from_overseer(
Ok(block_imported_candidates) => {
// Schedule wakeups for all imported candidates.
for block_batch in block_imported_candidates {
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
block_number = ?block_batch.block_number,
block_hash = ?block_batch.block_hash,
@@ -1122,7 +1120,7 @@ async fn handle_from_overseer(
if let Some(our_tranche) = our_tranche {
let tick = our_tranche as Tick + block_batch.block_tick;
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
tranche = our_tranche,
candidate_hash = ?c_hash,
@@ -1150,7 +1148,7 @@ async fn handle_from_overseer(
actions
},
FromOverseer::Signal(OverseerSignal::BlockFinalized(block_hash, block_number)) => {
tracing::debug!(target: LOG_TARGET, ?block_hash, ?block_number, "Block finalized");
gum::debug!(target: LOG_TARGET, ?block_hash, ?block_number, "Block finalized");
*last_finalized_height = Some(block_number);
crate::ops::canonicalize(db, block_number, block_hash)
@@ -1262,7 +1260,7 @@ async fn handle_approved_ancestor(
let entry = match db.load_block_entry(&block_hash)? {
None => {
let block_number = target_number.saturating_sub(i as u32);
tracing::info!(
gum::info!(
target: LOG_TARGET,
unknown_number = ?block_number,
unknown_hash = ?block_hash,
@@ -1303,7 +1301,7 @@ async fn handle_approved_ancestor(
block_descriptions.clear();
let unapproved: Vec<_> = entry.unapproved_candidates().collect();
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
"Block {} is {} blocks deep and has {}/{} candidates unapproved",
block_hash,
@@ -1315,7 +1313,7 @@ async fn handle_approved_ancestor(
for candidate_hash in unapproved {
match db.load_candidate_entry(&candidate_hash)? {
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?candidate_hash,
"Missing expected candidate in DB",
@@ -1325,7 +1323,7 @@ async fn handle_approved_ancestor(
},
Some(c_entry) => match c_entry.approval_entry(&block_hash) {
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -1357,7 +1355,7 @@ async fn handle_approved_ancestor(
};
match a_entry.our_assignment() {
None => tracing::debug!(
None => gum::debug!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -1374,7 +1372,7 @@ async fn handle_approved_ancestor(
let approved =
triggered && { a_entry.local_statements().1.is_some() };
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -1394,7 +1392,7 @@ async fn handle_approved_ancestor(
}
}
tracing::debug!(
gum::debug!(
target: LOG_TARGET,
"approved blocks {}-[{}]-{}",
target_number,
@@ -1507,7 +1505,7 @@ fn schedule_wakeup_action(
};
match maybe_action {
Some(Action::ScheduleWakeup { ref tick, .. }) => tracing::trace!(
Some(Action::ScheduleWakeup { ref tick, .. }) => gum::trace!(
target: LOG_TARGET,
tick,
?candidate_hash,
@@ -1515,7 +1513,7 @@ fn schedule_wakeup_action(
block_tick,
"Scheduling next wakeup.",
),
None => tracing::trace!(
None => gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -1633,7 +1631,7 @@ fn check_and_import_assignment(
if is_duplicate {
AssignmentCheckResult::AcceptedDuplicate
} else {
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
validator = assignment.validator.0,
candidate_hash = ?assigned_candidate_hash,
@@ -1756,7 +1754,7 @@ fn check_and_import_approval<T>(
// importing the approval can be heavy as it may trigger acceptance for a series of blocks.
let t = with_response(ApprovalCheckResult::Accepted);
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
validator_index = approval.validator.0,
validator = ?pubkey,
@@ -1877,7 +1875,7 @@ fn advance_approval_state(
let is_approved = check.is_approved(tick_now.saturating_sub(APPROVAL_DELAY));
if is_approved {
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -1906,7 +1904,7 @@ fn advance_approval_state(
(is_approved, status)
} else {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -2021,7 +2019,7 @@ fn process_wakeup(
let session_info = match state.session_info(block_entry.session()) {
Some(i) => i,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Missing session info for live block {} in session {}",
relay_block,
@@ -2040,7 +2038,7 @@ fn process_wakeup(
let tranche_now = state.clock.tranche_now(state.slot_duration_millis, block_entry.slot());
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
tranche = tranche_now,
?candidate_hash,
@@ -2100,7 +2098,7 @@ fn process_wakeup(
block_entry.candidates().iter().position(|(_, h)| &candidate_hash == h);
if let Some(i) = index_in_candidate {
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
para_id = ?candidate_receipt.descriptor.para_id,
@@ -2185,7 +2183,7 @@ async fn launch_approval(
let candidate_hash = candidate.hash();
let para_id = candidate.descriptor.para_id;
tracing::trace!(target: LOG_TARGET, ?candidate_hash, ?para_id, "Recovering data.");
gum::trace!(target: LOG_TARGET, ?candidate_hash, ?para_id, "Recovering data.");
let timer = metrics.time_recover_and_approve();
ctx.send_message(AvailabilityRecoveryMessage::RecoverAvailableData(
@@ -2219,7 +2217,7 @@ async fn launch_approval(
Ok(Err(e)) => {
match &e {
&RecoveryError::Unavailable => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?para_id,
?candidate_hash,
@@ -2230,7 +2228,7 @@ async fn launch_approval(
metrics_guard.take().on_approval_unavailable();
},
&RecoveryError::Invalid => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?para_id,
?candidate_hash,
@@ -2261,7 +2259,7 @@ async fn launch_approval(
Ok(Err(_)) => return ApprovalState::failed(validator_index, candidate_hash),
Ok(Ok(Some(code))) => code,
Ok(Ok(None)) => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Validation code unavailable for block {:?} in the state of block {:?} (a recent descendant)",
candidate.descriptor.relay_parent,
@@ -2297,7 +2295,7 @@ async fn launch_approval(
// Validation checked out. Issue an approval command. If the underlying service is unreachable,
// then there isn't anything we can do.
tracing::trace!(target: LOG_TARGET, ?candidate_hash, ?para_id, "Candidate Valid");
gum::trace!(target: LOG_TARGET, ?candidate_hash, ?para_id, "Candidate Valid");
let expected_commitments_hash = candidate.commitments_hash;
if commitments.hash() == expected_commitments_hash {
@@ -2322,7 +2320,7 @@ async fn launch_approval(
}
},
Ok(Ok(ValidationResult::Invalid(reason))) => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
?reason,
?candidate_hash,
@@ -2346,7 +2344,7 @@ async fn launch_approval(
return ApprovalState::failed(validator_index, candidate_hash)
},
Ok(Err(e)) => {
tracing::error!(
gum::error!(
target: LOG_TARGET,
err = ?e,
?candidate_hash,
@@ -2385,7 +2383,7 @@ async fn issue_approval(
let candidate_index = match block_entry.candidates().iter().position(|e| e.1 == candidate_hash)
{
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Candidate hash {} is not present in the block entry's candidates for relay block {}",
candidate_hash,
@@ -2401,7 +2399,7 @@ async fn issue_approval(
let session_info = match state.session_info(block_entry.session()) {
Some(s) => s,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Missing session info for live block {} in session {}",
block_hash,
@@ -2416,7 +2414,7 @@ async fn issue_approval(
let candidate_hash = match block_entry.candidate(candidate_index as usize) {
Some((_, h)) => h.clone(),
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Received malformed request to approve out-of-bounds candidate index {} included at block {:?}",
candidate_index,
@@ -2431,7 +2429,7 @@ async fn issue_approval(
let candidate_entry = match db.load_candidate_entry(&candidate_hash)? {
Some(c) => c,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Missing entry for candidate index {} included at block {:?}",
candidate_index,
@@ -2446,7 +2444,7 @@ async fn issue_approval(
let validator_pubkey = match session_info.validators.get(validator_index.0 as usize) {
Some(p) => p,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
"Validator index {} out of bounds in session {}",
validator_index.0,
@@ -2462,7 +2460,7 @@ async fn issue_approval(
let sig = match sign_approval(&state.keystore, &validator_pubkey, candidate_hash, session) {
Some(sig) => sig,
None => {
tracing::warn!(
gum::warn!(
target: LOG_TARGET,
validator_index = ?validator_index,
session,
@@ -2485,7 +2483,7 @@ async fn issue_approval(
)
.expect("Statement just signed; should pass checks; qed");
tracing::trace!(
gum::trace!(
target: LOG_TARGET,
?candidate_hash,
?block_hash,
@@ -512,7 +512,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(
}
async fn overseer_send(overseer: &mut VirtualOverseer, msg: FromOverseer<ApprovalVotingMessage>) {
tracing::trace!("Sending message:\n{:?}", &msg);
gum::trace!("Sending message:\n{:?}", &msg);
overseer
.send(msg)
.timeout(TIMEOUT)
@@ -525,7 +525,7 @@ async fn overseer_recv(overseer: &mut VirtualOverseer) -> AllMessages {
.await
.expect(&format!("{:?} is enough to receive messages.", TIMEOUT));
tracing::trace!("Received message:\n{:?}", &msg);
gum::trace!("Received message:\n{:?}", &msg);
msg
}
@@ -534,7 +534,7 @@ async fn overseer_recv_with_timeout(
overseer: &mut VirtualOverseer,
timeout: Duration,
) -> Option<AllMessages> {
tracing::trace!("Waiting for message...");
gum::trace!("Waiting for message...");
overseer.recv().timeout(timeout).await
}