Add diagnostics to tasks (#4752)

This commit is contained in:
Pierre Krieger
2020-01-29 11:46:39 +01:00
committed by GitHub
parent 34c1c4b954
commit b452867eb7
10 changed files with 117 additions and 52 deletions
+42 -20
View File
@@ -44,6 +44,7 @@ use sp_runtime::traits::{
use sp_api::ProvideRuntimeApi;
use sc_executor::{NativeExecutor, NativeExecutionDispatch};
use std::{
borrow::Cow,
io::{Read, Write, Seek},
marker::PhantomData, sync::Arc, time::SystemTime, pin::Pin
};
@@ -791,7 +792,7 @@ ServiceBuilder<
// List of asynchronous tasks to spawn. We collect them, then spawn them all at once.
let (to_spawn_tx, to_spawn_rx) =
mpsc::unbounded::<Pin<Box<dyn Future<Output = ()> + Send>>>();
mpsc::unbounded::<(Pin<Box<dyn Future<Output = ()> + Send>>, Cow<'static, str>)>();
// A side-channel for essential tasks to communicate shutdown.
let (essential_failed_tx, essential_failed_rx) = mpsc::unbounded();
@@ -816,7 +817,7 @@ ServiceBuilder<
imports_external_transactions: !config.roles.is_light(),
pool: transaction_pool.clone(),
client: client.clone(),
executor: Arc::new(SpawnTaskHandle { sender: to_spawn_tx.clone(), on_exit: exit.clone() }),
executor: SpawnTaskHandle { sender: to_spawn_tx.clone(), on_exit: exit.clone() },
});
let protocol_id = {
@@ -840,7 +841,7 @@ ServiceBuilder<
executor: {
let to_spawn_tx = to_spawn_tx.clone();
Some(Box::new(move |fut| {
if let Err(e) = to_spawn_tx.unbounded_send(fut) {
if let Err(e) = to_spawn_tx.unbounded_send((fut, From::from("libp2p-node"))) {
error!("Failed to spawn libp2p background task: {:?}", e);
}
}))
@@ -891,7 +892,10 @@ ServiceBuilder<
&BlockId::hash(notification.hash),
&notification.retracted,
);
let _ = to_spawn_tx_.unbounded_send(Box::pin(future));
let _ = to_spawn_tx_.unbounded_send((
Box::pin(future),
From::from("txpool-maintain")
));
}
let offchain = offchain.as_ref().and_then(|o| o.upgrade());
@@ -901,12 +905,18 @@ ServiceBuilder<
network_state_info.clone(),
is_validator
);
let _ = to_spawn_tx_.unbounded_send(Box::pin(future));
let _ = to_spawn_tx_.unbounded_send((
Box::pin(future),
From::from("offchain-on-block")
));
}
ready(())
});
let _ = to_spawn_tx.unbounded_send(Box::pin(select(events, exit.clone()).map(drop)));
let _ = to_spawn_tx.unbounded_send((
Box::pin(select(events, exit.clone()).map(drop)),
From::from("txpool-and-offchain-notif")
));
}
{
@@ -926,7 +936,10 @@ ServiceBuilder<
ready(())
});
let _ = to_spawn_tx.unbounded_send(Box::pin(select(events, exit.clone()).map(drop)));
let _ = to_spawn_tx.unbounded_send((
Box::pin(select(events, exit.clone()).map(drop)),
From::from("telemetry-on-block")
));
}
// Periodically notify the telemetry.
@@ -990,7 +1003,10 @@ ServiceBuilder<
ready(())
});
let _ = to_spawn_tx.unbounded_send(Box::pin(select(tel_task, exit.clone()).map(drop)));
let _ = to_spawn_tx.unbounded_send((
Box::pin(select(tel_task, exit.clone()).map(drop)),
From::from("telemetry-periodic-send")
));
// Periodically send the network state to the telemetry.
let (netstat_tx, netstat_rx) = mpsc::unbounded::<(NetworkStatus<_>, NetworkState)>();
@@ -1003,7 +1019,10 @@ ServiceBuilder<
);
ready(())
});
let _ = to_spawn_tx.unbounded_send(Box::pin(select(tel_task_2, exit.clone()).map(drop)));
let _ = to_spawn_tx.unbounded_send((
Box::pin(select(tel_task_2, exit.clone()).map(drop)),
From::from("telemetry-periodic-network-state")
));
// RPC
let (system_rpc_tx, system_rpc_rx) = mpsc::unbounded();
@@ -1079,14 +1098,17 @@ ServiceBuilder<
let rpc = start_rpc_servers(&config, gen_handler)?;
let _ = to_spawn_tx.unbounded_send(Box::pin(select(build_network_future(
config.roles,
network_mut,
client.clone(),
network_status_sinks.clone(),
system_rpc_rx,
has_bootnodes,
), exit.clone()).map(drop)));
let _ = to_spawn_tx.unbounded_send((
Box::pin(select(build_network_future(
config.roles,
network_mut,
client.clone(),
network_status_sinks.clone(),
system_rpc_rx,
has_bootnodes,
), exit.clone()).map(drop)),
From::from("network-worker")
));
let telemetry_connection_sinks: Arc<Mutex<Vec<futures::channel::mpsc::UnboundedSender<()>>>> = Default::default();
@@ -1127,9 +1149,9 @@ ServiceBuilder<
});
ready(())
});
let _ = to_spawn_tx.unbounded_send(Box::pin(select(
let _ = to_spawn_tx.unbounded_send((Box::pin(select(
future, exit.clone()
).map(drop)));
).map(drop)), From::from("telemetry-worker")));
telemetry
});
@@ -1140,7 +1162,7 @@ ServiceBuilder<
exit.clone()
).map(drop);
let _ = to_spawn_tx.unbounded_send(Box::pin(future));
let _ = to_spawn_tx.unbounded_send((Box::pin(future), From::from("grafana-server")));
}
// Instrumentation