Fix telemetry span not entering properly & enter span in sc-cli (#7951)

* WIP

* WIP

* Test

* bug fix

* WIP

* Revert "WIP"

This reverts commit 4e51e9adfdf0dc7cf37b562b60a0e83ca1d0b00d.

* doc

* Improve comment on why all spans are preserved

* Added missing suggestion from previous PR

* Use BoxFuture

* Move TelemetrySpan creation to sc-cli, need to test...

* Test code

* Adapt user code

* Revert "Test code"

This reverts commit 333806b2fe1626efaa2691f9f44d0b4dd979bc36.

* Update client/service/src/task_manager/mod.rs

Co-authored-by: David <dvdplm@gmail.com>

* Better & simpler solution

Co-authored-by: David <dvdplm@gmail.com>
This commit is contained in:
Cecile Tonglet
2021-01-29 13:03:21 +01:00
committed by GitHub
parent 4268fa0996
commit bea4a6524d
9 changed files with 47 additions and 54 deletions
+10 -21
View File
@@ -55,7 +55,6 @@ use sc_telemetry::{
telemetry,
ConnectionMessage,
TelemetryConnectionNotifier,
TelemetrySpan,
SUBSTRATE_INFO,
};
use sp_transaction_pool::MaintainedTransactionPool;
@@ -184,7 +183,6 @@ type TFullParts<TBl, TRtApi, TExecDisp> = (
Arc<TFullBackend<TBl>>,
KeystoreContainer,
TaskManager,
Option<TelemetrySpan>,
);
type TLightParts<TBl, TRtApi, TExecDisp> = (
@@ -193,7 +191,6 @@ type TLightParts<TBl, TRtApi, TExecDisp> = (
KeystoreContainer,
TaskManager,
Arc<OnDemand<TBl>>,
Option<TelemetrySpan>,
);
/// Light client backend type with a specific hash type.
@@ -308,10 +305,9 @@ pub fn new_full_parts<TBl, TRtApi, TExecDisp>(
{
let keystore_container = KeystoreContainer::new(&config.keystore)?;
let telemetry_span = config.telemetry_endpoints.as_ref().map(|_| TelemetrySpan::new());
let task_manager = {
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
TaskManager::new(config.task_executor.clone(), registry, telemetry_span.clone())?
TaskManager::new(config.task_executor.clone(), registry, config.telemetry_span.clone())?
};
let executor = NativeExecutor::<TExecDisp>::new(
@@ -367,7 +363,6 @@ pub fn new_full_parts<TBl, TRtApi, TExecDisp>(
backend,
keystore_container,
task_manager,
telemetry_span,
))
}
@@ -379,10 +374,9 @@ pub fn new_light_parts<TBl, TRtApi, TExecDisp>(
TExecDisp: NativeExecutionDispatch + 'static,
{
let keystore_container = KeystoreContainer::new(&config.keystore)?;
let telemetry_span = config.telemetry_endpoints.as_ref().map(|_| TelemetrySpan::new());
let task_manager = {
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
TaskManager::new(config.task_executor.clone(), registry, telemetry_span.clone())?
TaskManager::new(config.task_executor.clone(), registry, config.telemetry_span.clone())?
};
let executor = NativeExecutor::<TExecDisp>::new(
@@ -421,7 +415,7 @@ pub fn new_light_parts<TBl, TRtApi, TExecDisp>(
config.prometheus_config.as_ref().map(|config| config.registry.clone()),
)?);
Ok((client, backend, keystore_container, task_manager, on_demand, telemetry_span))
Ok((client, backend, keystore_container, task_manager, on_demand))
}
/// Create an instance of db-backed client.
@@ -473,8 +467,6 @@ pub fn new_client<E, Block, RA>(
pub struct SpawnTasksParams<'a, TBl: BlockT, TCl, TExPool, TRpc, Backend> {
/// The service configuration.
pub config: Configuration,
/// Telemetry span, if any.
pub telemetry_span: Option<TelemetrySpan>,
/// A shared client returned by `new_full_parts`/`new_light_parts`.
pub client: Arc<TCl>,
/// A shared backend returned by `new_full_parts`/`new_light_parts`.
@@ -567,7 +559,6 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
let SpawnTasksParams {
mut config,
task_manager,
telemetry_span,
client,
on_demand,
backend,
@@ -588,13 +579,11 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
config.dev_key_seed.clone().map(|s| vec![s]).unwrap_or_default(),
)?;
let telemetry_connection_notifier = telemetry_span
.and_then(|span| init_telemetry(
&mut config,
span,
network.clone(),
client.clone(),
));
let telemetry_connection_notifier = init_telemetry(
&mut config,
network.clone(),
client.clone(),
);
info!("📦 Highest known block at #{}", chain_info.best_number);
@@ -692,11 +681,11 @@ async fn transaction_notifications<TBl, TExPool>(
fn init_telemetry<TBl: BlockT, TCl: BlockBackend<TBl>>(
config: &mut Configuration,
telemetry_span: TelemetrySpan,
network: Arc<NetworkService<TBl, <TBl as BlockT>::Hash>>,
client: Arc<TCl>,
) -> Option<TelemetryConnectionNotifier> {
let endpoints = config.telemetry_endpoints()?.clone();
let telemetry_span = config.telemetry_span.clone()?;
let endpoints = config.telemetry_endpoints.clone()?;
let genesis_hash = client.block_hash(Zero::zero()).ok().flatten().unwrap_or_default();
let connection_message = ConnectionMessage {
name: config.network.node_name.to_owned(),
+4 -10
View File
@@ -101,6 +101,10 @@ pub struct Configuration {
/// This is a handle to a `TelemetryWorker` instance. It is used to initialize the telemetry for
/// a substrate node.
pub telemetry_handle: Option<sc_telemetry::TelemetryHandle>,
/// Telemetry span.
///
/// This span is entered for every background task spawned using the TaskManager.
pub telemetry_span: Option<sc_telemetry::TelemetrySpan>,
/// The default number of 64KB pages to allocate for Wasm execution
pub default_heap_pages: Option<u64>,
/// Should offchain workers be executed.
@@ -207,16 +211,6 @@ impl Configuration {
self.prometheus_config.as_ref().map(|config| &config.registry)
}
/// Returns the telemetry endpoints if any and if the telemetry handle exists.
pub(crate) fn telemetry_endpoints(&self) -> Option<&TelemetryEndpoints> {
if self.telemetry_handle.is_none() {
return None;
}
// Don't initialise telemetry if `telemetry_endpoints` == Some([])
self.telemetry_endpoints.as_ref().filter(|x| !x.is_empty())
}
/// Returns the network protocol id from the chain spec, or the default.
pub fn protocol_id(&self) -> sc_network::config::ProtocolId {
let protocol_id_full = match self.chain_spec.protocol_id() {
@@ -91,10 +91,7 @@ impl SpawnTaskHandle {
metrics.tasks_ended.with_label_values(&[name, "finished"]).inc_by(0);
}
let telemetry_span = self.telemetry_span.clone();
let future = async move {
let _telemetry_entered = telemetry_span.as_ref().map(|x| x.enter());
if let Some(metrics) = metrics {
// Add some wrappers around `task`.
let task = {
@@ -127,7 +124,11 @@ impl SpawnTaskHandle {
}
};
let join_handle = self.executor.spawn(Box::pin(future.in_current_span()), task_type);
let join_handle = {
let _span = self.telemetry_span.as_ref().map(|s| s.enter());
self.executor.spawn(Box::pin(future.in_current_span()), task_type)
};
let mut task_notifier = self.task_notifier.clone();
self.executor.spawn(
Box::pin(async move {