-
Notifications
You must be signed in to change notification settings - Fork 622
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
fix: apply log_summary_style
to state sync phase message
#8735
Changes from 4 commits
f1fe08d
13b508b
e4ff5d0
d4f297e
77f57f0
a361770
da60b24
32f61b1
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
//! | ||
|
||
use ansi_term::Color::{Purple, Yellow}; | ||
use ansi_term::Style; | ||
use chrono::{DateTime, Duration, Utc}; | ||
use futures::{future, FutureExt}; | ||
use near_async::messaging::CanSendAsync; | ||
|
@@ -176,6 +177,7 @@ impl StateSync { | |
now: DateTime<Utc>, | ||
state_parts_task_scheduler: &dyn Fn(ApplyStatePartsRequest), | ||
state_split_scheduler: &dyn Fn(StateSplitRequest), | ||
use_colour: bool, | ||
) -> Result<(bool, bool), near_chain::Error> { | ||
let mut all_done = true; | ||
let mut update_sync_status = false; | ||
|
@@ -276,30 +278,12 @@ impl StateSync { | |
%shard_id, | ||
timeout_sec = self.timeout.num_seconds(), | ||
"State sync didn't download the state, sending StateRequest again"); | ||
tracing::info!(target: "sync", | ||
tracing::info!( | ||
target: "sync", | ||
%shard_id, | ||
%sync_hash, | ||
?me, | ||
phase = ?match shard_sync_download.status { | ||
ShardSyncStatus::StateDownloadHeader => format!("{} requests sent {}, last target {:?}", | ||
Purple.bold().paint("HEADER".to_string()), | ||
shard_sync_download.downloads[0].state_requests_count, | ||
shard_sync_download.downloads[0].last_target), | ||
ShardSyncStatus::StateDownloadParts => { let mut text = "".to_string(); | ||
for (i, download) in shard_sync_download.downloads.iter().enumerate() { | ||
text.push_str(&format!("[{}: {}, {}, {:?}] ", | ||
Yellow.bold().paint(i.to_string()), | ||
download.done, | ||
download.state_requests_count, | ||
download.last_target)); | ||
} | ||
format!("{} [{}: is_done, requests sent, last target] {}", | ||
Purple.bold().paint("PARTS"), | ||
Yellow.bold().paint("part_id"), | ||
text) | ||
} | ||
_ => unreachable!("timeout cannot happen when all state is downloaded"), | ||
}, | ||
phase = format_shard_sync_phase(&shard_sync_download, use_colour), | ||
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. I wonder if this would be better served by splitting the phase up into different tracing KVs? for example state_requests_count and last_target could both easily be KVs I think 🤔 Though adding colors to that would be even harder. 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. I'm worried about the I'll consider simplifying the log line in the future. Coutning the number of |
||
"State sync status"); | ||
} | ||
|
||
|
@@ -618,6 +602,7 @@ impl StateSync { | |
tracking_shards: Vec<ShardId>, | ||
state_parts_task_scheduler: &dyn Fn(ApplyStatePartsRequest), | ||
state_split_scheduler: &dyn Fn(StateSplitRequest), | ||
use_colour: bool, | ||
) -> Result<StateSyncResult, near_chain::Error> { | ||
let _span = tracing::debug_span!(target: "sync", "run", sync = "StateSync").entered(); | ||
tracing::debug!(target: "sync", %sync_hash, ?tracking_shards, "syncing state"); | ||
|
@@ -651,6 +636,7 @@ impl StateSync { | |
now, | ||
state_parts_task_scheduler, | ||
state_split_scheduler, | ||
use_colour, | ||
)?; | ||
|
||
if have_block && all_done { | ||
|
@@ -973,6 +959,45 @@ impl StateSync { | |
} | ||
} | ||
|
||
fn paint(s: &str, colour: Style, use_colour: bool) -> String { | ||
if use_colour { | ||
colour.paint(s).to_string() | ||
} else { | ||
s.to_string() | ||
} | ||
} | ||
|
||
/// Formats the given ShardSyncDownload for logging. | ||
fn format_shard_sync_phase(shard_sync_download: &ShardSyncDownload, use_colour: bool) -> String { | ||
match shard_sync_download.status { | ||
ShardSyncStatus::StateDownloadHeader => format!( | ||
"{} requests sent {}, last target {:?}", | ||
paint("HEADER", Purple.bold(), use_colour), | ||
shard_sync_download.downloads[0].state_requests_count, | ||
shard_sync_download.downloads[0].last_target | ||
), | ||
ShardSyncStatus::StateDownloadParts => { | ||
let mut text = "".to_string(); | ||
for (i, download) in shard_sync_download.downloads.iter().enumerate() { | ||
text.push_str(&format!( | ||
"[{}: {}, {}, {:?}] ", | ||
paint(&i.to_string(), Yellow.bold(), use_colour), | ||
download.done, | ||
download.state_requests_count, | ||
download.last_target | ||
)); | ||
} | ||
format!( | ||
"{} [{}: is_done, requests sent, last target] {}", | ||
paint("PARTS", Purple.bold(), use_colour), | ||
paint("part_id", Yellow.bold(), use_colour), | ||
text | ||
) | ||
} | ||
_ => unreachable!("timeout cannot happen when all state is downloaded"), | ||
} | ||
} | ||
|
||
/// Create an abstract collection of elements to be shuffled. | ||
/// Each element will appear in the shuffled output exactly `limit` times. | ||
/// Use it as an iterator to access the shuffled collection. | ||
|
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.
Somewhat unfortunate that we must thread this through like that…