Skip to content

Commit 193048c

Browse files
committed
add colors for better visibility
1 parent c5bc5f9 commit 193048c

File tree

8 files changed

+62
-17
lines changed

8 files changed

+62
-17
lines changed

Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compute/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rand.workspace = true
3434
env_logger.workspace = true
3535
log.workspace = true
3636
eyre.workspace = true
37+
colored = "3.0.0"
3738

3839
# encryption (ecies) & signatures (ecdsa) & hashing & bloom-filters
3940
ecies = { version = "0.2", default-features = false, features = ["pure"] }

compute/src/gossipsub/pingpong.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use colored::Colorize;
12
use dkn_p2p::libp2p::gossipsub::MessageAcceptance;
23
use dkn_utils::get_current_time_nanos;
34
use dkn_workflows::{Model, ModelProvider};
@@ -62,7 +63,7 @@ impl PingpongHandler {
6263
return Ok(MessageAcceptance::Ignore);
6364
}
6465

65-
log::info!("Received a ping for: {}", pingpong.uuid);
66+
log::info!("Received a {} for: {}", "ping".blue(), pingpong.uuid);
6667

6768
// record ping moment
6869
node.last_pinged_at = Instant::now();

compute/src/node/diagnostic.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use colored::Colorize;
12
use dkn_p2p::libp2p::multiaddr::Protocol;
23
use std::time::Duration;
34
use tokio::time::Instant;
@@ -21,19 +22,29 @@ impl DriaComputeNode {
2122
pub(crate) async fn handle_diagnostic_refresh(&self) {
2223
let mut diagnostics = vec![format!("Diagnostics (v{}):", DRIA_COMPUTE_NODE_VERSION)];
2324

25+
// if we have not received pings for a while, we are considered offline
26+
let is_offline =
27+
self.last_pinged_at < Instant::now() - Duration::from_secs(PING_LIVENESS_SECS);
28+
2429
// print peer counts
2530
match self.p2p.peer_counts().await {
26-
Ok((mesh, all)) => {
27-
diagnostics.push(format!("Peer Count (mesh/all): {} / {}", mesh, all))
28-
}
31+
Ok((mesh, all)) => diagnostics.push(format!(
32+
"Peer Count (mesh/all): {} / {}",
33+
if mesh == 0 {
34+
"0".red()
35+
} else {
36+
mesh.to_string().white()
37+
},
38+
all
39+
)),
2940
Err(e) => log::error!("Error getting peer counts: {:?}", e),
3041
}
3142

3243
// print steps
3344
if let Ok(steps) = get_steps(&self.config.address).await {
3445
let earned = steps.score - self.initial_steps;
3546
diagnostics.push(format!(
36-
"Steps: {} total (+{} this run), within top {}%",
47+
"Steps: {} total, {} earned in this run, within top {}%",
3748
steps.score, earned, steps.percentile
3849
));
3950
}
@@ -62,10 +73,20 @@ impl DriaComputeNode {
6273
.join(", ")
6374
));
6475

76+
// add network status as well
77+
diagnostics.push(format!(
78+
"Node Status: {}",
79+
if is_offline {
80+
"OFFLINE".bold().red()
81+
} else {
82+
"ONLINE".bold().green()
83+
}
84+
));
85+
6586
log::info!("{}", diagnostics.join("\n "));
6687

67-
// check liveness of the node w.r.t last ping-pong time
68-
if self.last_pinged_at < Instant::now() - Duration::from_secs(PING_LIVENESS_SECS) {
88+
// if offline, print this error message as well
89+
if is_offline {
6990
log::error!(
7091
"Node has not received any pings for at least {} seconds & it may be unreachable!\nPlease restart your node!",
7192
PING_LIVENESS_SECS
@@ -74,7 +95,7 @@ impl DriaComputeNode {
7495

7596
// added rpc nodes check, sometimes this happens when API is down / bugs for some reason
7697
if self.dria_nodes.rpc_peerids.is_empty() {
77-
log::error!("No RPC peerids were found to be available, please restart your node!",);
98+
log::error!("No RPC peer IDs were found to be available, please restart your node!",);
7899
}
79100
}
80101

compute/src/node/gossipsub.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use colored::Colorize;
12
use dkn_p2p::libp2p::gossipsub::{Message, MessageAcceptance, MessageId};
23
use dkn_p2p::libp2p::PeerId;
34
use eyre::Result;
@@ -40,7 +41,11 @@ impl DriaComputeNode {
4041
pub async fn publish(&mut self, message: DriaMessage) -> Result<()> {
4142
let message_bytes = serde_json::to_vec(&message)?;
4243
let message_id = self.p2p.publish(&message.topic, message_bytes).await?;
43-
log::info!("Published {} message ({})", message.topic, message_id);
44+
log::info!(
45+
"Published {} message ({})",
46+
message.topic.blue(),
47+
message_id
48+
);
4449
Ok(())
4550
}
4651

@@ -80,11 +85,10 @@ impl DriaComputeNode {
8085

8186
// parse the raw gossipsub message to a prepared DKN message
8287
// the received message is expected to use IdentHash for the topic, so we can see the name of the topic immediately.
83-
log::debug!("Parsing {} message.", gossipsub_message.topic.as_str());
8488
let message: DriaMessage = match serde_json::from_slice(&gossipsub_message.data) {
8589
Ok(message) => message,
8690
Err(e) => {
87-
log::error!("Error parsing message: {:?}", e);
91+
log::error!("Error parsing {} message: {:?}", gossipsub_message.topic, e);
8892
log::debug!(
8993
"Message: {}",
9094
String::from_utf8_lossy(&gossipsub_message.data)

compute/src/node/reqres.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use colored::Colorize;
12
use dkn_p2p::libp2p::{request_response::ResponseChannel, PeerId};
23
use eyre::{eyre, Result};
34

@@ -46,7 +47,8 @@ impl DriaComputeNode {
4647
spec_request: <SpecResponder as IsResponder>::Request,
4748
) -> Result<()> {
4849
log::info!(
49-
"Got a spec request from peer {} with id {}",
50+
"Got a {} request from peer {} with id {}",
51+
"spec".green(),
5052
peer_id,
5153
spec_request.request_id
5254
);
@@ -55,7 +57,8 @@ impl DriaComputeNode {
5557
let response_data = serde_json::to_vec(&response)?;
5658

5759
log::info!(
58-
"Responding to spec request from peer {} with id {}",
60+
"Responding to {} request from peer {} with id {}",
61+
"spec".green(),
5962
peer_id,
6063
response.request_id
6164
);
@@ -75,7 +78,7 @@ impl DriaComputeNode {
7578
channel: ResponseChannel<Vec<u8>>,
7679
task_request: <TaskResponder as IsResponder>::Request,
7780
) -> Result<()> {
78-
log::info!("Received a task request from {}", peer_id);
81+
log::info!("Received a {} request from {}", "task".yellow(), peer_id);
7982

8083
let (task_input, task_metadata) =
8184
TaskResponder::prepare_worker_input(self, &task_request, channel).await?;

compute/src/reqres/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod tests {
2626

2727
use super::*;
2828

29-
// TODO: remove this test
29+
// TODO: remove this test when its done
3030
#[test]
3131
fn test_enum_serialization() {
3232
use serde::Deserialize;

compute/src/reqres/task.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(unused)]
22

3+
use colored::Colorize;
34
use dkn_p2p::libp2p::request_response::ResponseChannel;
45
use dkn_utils::get_current_time_nanos;
56
use dkn_workflows::{Entry, Executor, ModelProvider, Workflow};
@@ -122,7 +123,11 @@ impl TaskResponder {
122123
let response = match task_output.result {
123124
Ok(result) => {
124125
// prepare signed and encrypted payload
125-
log::info!("Publishing result for task {}", task_output.task_id);
126+
log::info!(
127+
"Publishing {} result for {}",
128+
"task".green(),
129+
task_output.task_id
130+
);
126131
let payload = TaskResponsePayload::new(
127132
result,
128133
&task_output.task_id,

0 commit comments

Comments
 (0)