mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 03:31:45 +00:00
Integrate tracing (#6339)
Tracing Integration
- [reference](5bbf1859e9/projects/project-ideas.md (L297))
- [x] replace slog & log with tracing throughout the codebase
- [x] implement custom crit log
- [x] make relevant changes in the formatter
- [x] replace sloggers
- [x] re-write SSE logging components
cc: @macladson @eserilev
This commit is contained in:
@@ -3,6 +3,7 @@ use lighthouse_network::rpc::methods::BlocksByRangeRequest;
|
||||
use lighthouse_network::service::api_types::Id;
|
||||
use lighthouse_network::PeerId;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Sub;
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -61,6 +62,7 @@ pub trait BatchConfig {
|
||||
fn batch_attempt_hash<E: EthSpec>(blocks: &[RpcBlock<E>]) -> u64;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RangeSyncBatchConfig {}
|
||||
|
||||
impl BatchConfig for RangeSyncBatchConfig {
|
||||
@@ -93,6 +95,7 @@ pub enum BatchProcessingResult {
|
||||
NonFaultyFailure,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// A segment of a chain.
|
||||
pub struct BatchInfo<E: EthSpec, B: BatchConfig = RangeSyncBatchConfig> {
|
||||
/// Start slot of the batch.
|
||||
@@ -113,6 +116,17 @@ pub struct BatchInfo<E: EthSpec, B: BatchConfig = RangeSyncBatchConfig> {
|
||||
marker: std::marker::PhantomData<B>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec, B: BatchConfig> fmt::Display for BatchInfo<E, B> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Start Slot: {}, End Slot: {}, State: {}",
|
||||
self.start_slot, self.end_slot, self.state
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Display)]
|
||||
/// Current state of a batch
|
||||
pub enum BatchState<E: EthSpec> {
|
||||
/// The batch has failed either downloading or processing, but can be requested again.
|
||||
@@ -190,15 +204,6 @@ impl<E: EthSpec, B: BatchConfig> BatchInfo<E, B> {
|
||||
peers
|
||||
}
|
||||
|
||||
/// Return the number of times this batch has failed downloading and failed processing, in this
|
||||
/// order.
|
||||
pub fn failed_attempts(&self) -> (usize, usize) {
|
||||
(
|
||||
self.failed_download_attempts.len(),
|
||||
self.failed_processing_attempts.len(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Verifies if an incoming block belongs to this batch.
|
||||
pub fn is_expecting_block(&self, request_id: &Id) -> bool {
|
||||
if let BatchState::Downloading(_, expected_id) = &self.state {
|
||||
@@ -456,39 +461,6 @@ impl Attempt {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec, B: BatchConfig> slog::KV for &mut BatchInfo<E, B> {
|
||||
fn serialize(
|
||||
&self,
|
||||
record: &slog::Record,
|
||||
serializer: &mut dyn slog::Serializer,
|
||||
) -> slog::Result {
|
||||
slog::KV::serialize(*self, record, serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec, B: BatchConfig> slog::KV for BatchInfo<E, B> {
|
||||
fn serialize(
|
||||
&self,
|
||||
record: &slog::Record,
|
||||
serializer: &mut dyn slog::Serializer,
|
||||
) -> slog::Result {
|
||||
use slog::Value;
|
||||
Value::serialize(&self.start_slot, record, "start_slot", serializer)?;
|
||||
Value::serialize(
|
||||
&(self.end_slot - 1), // NOTE: The -1 shows inclusive blocks
|
||||
record,
|
||||
"end_slot",
|
||||
serializer,
|
||||
)?;
|
||||
serializer.emit_usize("downloaded", self.failed_download_attempts.len())?;
|
||||
serializer.emit_usize("processed", self.failed_processing_attempts.len())?;
|
||||
serializer.emit_u8("processed_no_penalty", self.non_faulty_processing_attempts)?;
|
||||
serializer.emit_arguments("state", &format_args!("{:?}", self.state))?;
|
||||
serializer.emit_arguments("batch_ty", &format_args!("{}", self.batch_type))?;
|
||||
slog::Result::Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> std::fmt::Debug for BatchState<E> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user