mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +00:00
Rework telemetry to replace the use of tracing with an object we pass around (#8143)
polkadot companion: paritytech/polkadot#2535
This commit is contained in:
@@ -64,7 +64,6 @@ arg_enum! {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum TracingReceiver {
|
||||
Log,
|
||||
Telemetry,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +71,6 @@ impl Into<sc_tracing::TracingReceiver> for TracingReceiver {
|
||||
fn into(self) -> sc_tracing::TracingReceiver {
|
||||
match self {
|
||||
TracingReceiver::Log => sc_tracing::TracingReceiver::Log,
|
||||
TracingReceiver::Telemetry => sc_tracing::TracingReceiver::Telemetry,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ use sc_service::config::{
|
||||
TaskExecutor, TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod,
|
||||
};
|
||||
use sc_service::{ChainSpec, TracingReceiver, KeepBlocks, TransactionStorageMode};
|
||||
use sc_telemetry::TelemetryHandle;
|
||||
use sc_tracing::logging::LoggerBuilder;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
@@ -470,7 +469,6 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
&self,
|
||||
cli: &C,
|
||||
task_executor: TaskExecutor,
|
||||
telemetry_handle: Option<TelemetryHandle>,
|
||||
) -> Result<Configuration> {
|
||||
let is_dev = self.is_dev()?;
|
||||
let chain_id = self.chain_id(is_dev)?;
|
||||
@@ -488,12 +486,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
let max_runtime_instances = self.max_runtime_instances()?.unwrap_or(8);
|
||||
let is_validator = role.is_authority();
|
||||
let (keystore_remote, keystore) = self.keystore_config(&config_dir)?;
|
||||
let telemetry_endpoints = telemetry_handle
|
||||
.as_ref()
|
||||
.and_then(|_| self.telemetry_endpoints(&chain_spec).transpose())
|
||||
.transpose()?
|
||||
// Don't initialise telemetry if `telemetry_endpoints` == Some([])
|
||||
.filter(|x| !x.is_empty());
|
||||
let telemetry_endpoints = self.telemetry_endpoints(&chain_spec)?;
|
||||
|
||||
let unsafe_pruning = self
|
||||
.import_params()
|
||||
@@ -548,7 +541,6 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
role,
|
||||
base_path: Some(base_path),
|
||||
informant_output_format: Default::default(),
|
||||
telemetry_handle,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -579,16 +571,12 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
/// 1. Sets the panic handler
|
||||
/// 2. Initializes the logger
|
||||
/// 3. Raises the FD limit
|
||||
fn init<C: SubstrateCli>(&self) -> Result<sc_telemetry::TelemetryWorker> {
|
||||
fn init<C: SubstrateCli>(&self) -> Result<()> {
|
||||
sp_panic_handler::set(&C::support_url(), &C::impl_version());
|
||||
|
||||
let mut logger = LoggerBuilder::new(self.log_filters()?);
|
||||
logger.with_log_reloading(!self.is_log_filter_reloading_disabled()?);
|
||||
|
||||
if let Some(transport) = self.telemetry_external_transport()? {
|
||||
logger.with_transport(transport);
|
||||
}
|
||||
|
||||
if let Some(tracing_targets) = self.tracing_targets()? {
|
||||
let tracing_receiver = self.tracing_receiver()?;
|
||||
logger.with_profiling(tracing_receiver, tracing_targets);
|
||||
@@ -598,7 +586,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
logger.with_colors(false);
|
||||
}
|
||||
|
||||
let telemetry_worker = logger.init()?;
|
||||
logger.init()?;
|
||||
|
||||
if let Some(new_limit) = fdlimit::raise_fd_limit() {
|
||||
if new_limit < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT {
|
||||
@@ -610,7 +598,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(telemetry_worker)
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ pub use params::*;
|
||||
pub use runner::*;
|
||||
pub use sc_service::{ChainSpec, Role};
|
||||
use sc_service::{Configuration, TaskExecutor};
|
||||
use sc_telemetry::TelemetryHandle;
|
||||
pub use sc_tracing::logging::LoggerBuilder;
|
||||
pub use sp_version::RuntimeVersion;
|
||||
use std::io::Write;
|
||||
@@ -214,16 +213,15 @@ pub trait SubstrateCli: Sized {
|
||||
&self,
|
||||
command: &T,
|
||||
task_executor: TaskExecutor,
|
||||
telemetry_handle: Option<TelemetryHandle>,
|
||||
) -> error::Result<Configuration> {
|
||||
command.create_configuration(self, task_executor, telemetry_handle)
|
||||
command.create_configuration(self, task_executor)
|
||||
}
|
||||
|
||||
/// Create a runner for the command provided in argument. This will create a Configuration and
|
||||
/// a tokio runtime
|
||||
fn create_runner<T: CliConfiguration>(&self, command: &T) -> error::Result<Runner<Self>> {
|
||||
let telemetry_worker = command.init::<Self>()?;
|
||||
Runner::new(self, command, telemetry_worker)
|
||||
command.init::<Self>()?;
|
||||
Runner::new(self, command)
|
||||
}
|
||||
|
||||
/// Native runtime version.
|
||||
|
||||
@@ -25,7 +25,6 @@ use futures::select;
|
||||
use futures::{future, future::FutureExt, Future};
|
||||
use log::info;
|
||||
use sc_service::{Configuration, TaskType, TaskManager};
|
||||
use sc_telemetry::{TelemetryHandle, TelemetryWorker};
|
||||
use sp_utils::metrics::{TOKIO_THREADS_ALIVE, TOKIO_THREADS_TOTAL};
|
||||
use std::marker::PhantomData;
|
||||
use sc_service::Error as ServiceError;
|
||||
@@ -115,7 +114,6 @@ where
|
||||
pub struct Runner<C: SubstrateCli> {
|
||||
config: Configuration,
|
||||
tokio_runtime: tokio::runtime::Runtime,
|
||||
telemetry_worker: TelemetryWorker,
|
||||
phantom: PhantomData<C>,
|
||||
}
|
||||
|
||||
@@ -124,7 +122,6 @@ impl<C: SubstrateCli> Runner<C> {
|
||||
pub fn new<T: CliConfiguration>(
|
||||
cli: &C,
|
||||
command: &T,
|
||||
telemetry_worker: TelemetryWorker,
|
||||
) -> Result<Runner<C>> {
|
||||
let tokio_runtime = build_runtime()?;
|
||||
let runtime_handle = tokio_runtime.handle().clone();
|
||||
@@ -138,16 +135,12 @@ impl<C: SubstrateCli> Runner<C> {
|
||||
}
|
||||
};
|
||||
|
||||
let telemetry_handle = telemetry_worker.handle();
|
||||
|
||||
Ok(Runner {
|
||||
config: command.create_configuration(
|
||||
cli,
|
||||
task_executor.into(),
|
||||
Some(telemetry_handle),
|
||||
)?,
|
||||
tokio_runtime,
|
||||
telemetry_worker,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
@@ -197,7 +190,6 @@ impl<C: SubstrateCli> Runner<C> {
|
||||
{
|
||||
self.print_node_infos();
|
||||
let mut task_manager = self.tokio_runtime.block_on(initialize(self.config))?;
|
||||
task_manager.spawn_handle().spawn("telemetry_worker", self.telemetry_worker.run());
|
||||
let res = self.tokio_runtime.block_on(main(task_manager.future().fuse()));
|
||||
self.tokio_runtime.block_on(task_manager.clean_shutdown());
|
||||
Ok(res?)
|
||||
@@ -236,11 +228,4 @@ impl<C: SubstrateCli> Runner<C> {
|
||||
pub fn config_mut(&mut self) -> &mut Configuration {
|
||||
&mut self.config
|
||||
}
|
||||
|
||||
/// Get a new [`TelemetryHandle`].
|
||||
///
|
||||
/// This is used when you want to register with the [`TelemetryWorker`].
|
||||
pub fn telemetry_handle(&self) -> TelemetryHandle {
|
||||
self.telemetry_worker.handle()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user