Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Rework telemetry to replace the use of tracing with an object we pass around #8143

Merged
merged 108 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
39e3c9a
Rework sc-telemetry to not use tracing internally
cecton Feb 17, 2021
7d94122
Issue with telemetry usage in ProfilingLayer
cecton Feb 11, 2021
9aa9a6a
WIP
cecton Feb 11, 2021
af2c532
WIP
cecton Feb 11, 2021
942addb
WIP
cecton Feb 11, 2021
29bda72
WIP
cecton Feb 11, 2021
faad155
WIP
cecton Feb 11, 2021
d09bef4
Oh no this is terrible
cecton Feb 17, 2021
4f3d24b
WIP
cecton Feb 12, 2021
6a8040f
WIP
cecton Feb 12, 2021
244982a
WIP
cecton Feb 12, 2021
5fbc85c
WIP
cecton Feb 17, 2021
e06d06d
Rename TelemetryHandle to TelemetryWorkerHandle
cecton Feb 17, 2021
e3a4c64
Rename Telemetry to TelemetryHandle
cecton Feb 17, 2021
c9a60aa
WIP
cecton Feb 17, 2021
1b099fe
CLEANUP
cecton Feb 17, 2021
98ccd2a
CLEANUP
cecton Feb 17, 2021
d1055f4
CLEANUP
cecton Feb 17, 2021
280bd25
CLEANUP
cecton Feb 17, 2021
14bdec1
CLEANUP
cecton Feb 17, 2021
9ed97f1
CLEANUP
cecton Feb 17, 2021
b88989d
CLEANUP
cecton Feb 17, 2021
420f357
Fix todo
cecton Feb 17, 2021
391efa2
CLEANUP
cecton Feb 17, 2021
69aa516
fmt
cecton Feb 17, 2021
9148541
Adapt more code
cecton Feb 17, 2021
8210e35
Adapt more code
cecton Feb 17, 2021
a7bec3d
Adapt even MORE code
cecton Feb 17, 2021
f399174
Adapt more code...
cecton Feb 17, 2021
eb180de
Doc
cecton Feb 17, 2021
f3f7c78
Instantiate telemetry worker from sc-cli instead of sc-tracing
cecton Feb 18, 2021
985eb93
Update doc
cecton Feb 18, 2021
4eca8bf
Rename send() to send_telemetry()
cecton Feb 18, 2021
dabdb14
Fix doc
cecton Feb 18, 2021
3f9e73e
Remove IdGenerator and global variable
cecton Feb 18, 2021
eaeb79a
Pass the telemetry worker handle down from the runner instead of the …
cecton Feb 18, 2021
6f0563f
Moving TelemetryWorker creation to the user
cecton Feb 18, 2021
81f7df8
Make Tracing bounded channel and use it in telemetry
cecton Feb 19, 2021
6dd32f4
start_telemetry now return errors instead of logging
cecton Feb 19, 2021
c7139fd
Automatic split line
cecton Feb 19, 2021
993040b
Forgot /g at the end again...
cecton Feb 19, 2021
5581a85
Missed replacements
cecton Feb 19, 2021
54390e7
Use telemetry in trait fn instead of fn argument
cecton Feb 19, 2021
30d11b5
Remove ClientTelemetry
cecton Feb 19, 2021
147d5d4
Adapt code
cecton Feb 19, 2021
2759a3f
Merge commit 2c99434c8bab9230040cebe727e687f5a4c6d229 (no conflict)
cecton Feb 19, 2021
9d88fb2
Merge commit f53d72f0fdadf56c34f3199bea96c652633f82a9 (conflicts)
cecton Feb 19, 2021
f708211
Apply suggestions from code review
cecton Feb 24, 2021
1401067
Added missing license
cecton Feb 24, 2021
afd6056
Fix indentation with spaces
cecton Feb 24, 2021
526d877
Improve doc
cecton Feb 24, 2021
fc1ce16
Use Mutex and make Telemetry work with immutable
cecton Feb 24, 2021
c1fac06
Optimization?
cecton Feb 24, 2021
8aebf81
Replace code using mem with Vec::retain
cecton Feb 25, 2021
87cc352
Merge commit fd88fbf7e05b3bea3e8324e2661c586353b48a43 (no conflict)
cecton Feb 25, 2021
71c0193
Merge commit 59494855205374e8f27fb131425dfd78897a9298 (conflicts)
cecton Feb 25, 2021
2627e25
Merge commit 1c34ccf6c88188b173286bf28c279409eff0eebb (no conflict)
cecton Feb 25, 2021
640e4e3
Merge commit 7a6d60de2d19c67831859a9014e315f5ec7a3870 (conflicts)
cecton Feb 25, 2021
c1d2eb2
Merge commit 1febf99d6385ff9ff934a9b16a53234b4858bf5c (no conflict)
cecton Feb 25, 2021
e306664
Revert "Optimization?"
cecton Feb 25, 2021
a95c2c4
Fixing stuff
cecton Feb 25, 2021
ab5179e
Fixing other stuff
cecton Feb 25, 2021
1a47b96
Fix more stuff
cecton Feb 25, 2021
0587055
Fix browser telemetry
cecton Feb 25, 2021
ee8eae6
Temporary changes
cecton Feb 26, 2021
0f6bc8f
WIP
cecton Feb 26, 2021
3e2c066
debug
cecton Feb 26, 2021
7ac7728
Forgot to wrap the payload
cecton Feb 26, 2021
49541ab
Revert "Temporary changes"
cecton Feb 26, 2021
133770f
Fix some tests
cecton Feb 26, 2021
7bb9bf5
Fix doc test
cecton Feb 26, 2021
cd8d77b
Fix tests
cecton Feb 26, 2021
0808536
Fix more tests
cecton Feb 26, 2021
3b23031
Fixes
cecton Feb 26, 2021
4d02b5f
Fix tests
cecton Feb 26, 2021
462b20e
Merge commit a6ff3d3be40de2496a705a237483b2c3a541b143 (no conflict)
cecton Feb 27, 2021
1b5df60
Revert TracingBounded channel
cecton Mar 3, 2021
9dae7e4
Replace channel with futures' mpsc channel
cecton Mar 3, 2021
4ad1643
Apply suggestions from code review
cecton Mar 3, 2021
31e08fa
Apply suggestion
cecton Mar 3, 2021
0650ca9
Apply suggestions from code review
cecton Mar 3, 2021
13c62f3
WIP
cecton Mar 3, 2021
051985e
Fix invalid unreachable!()
cecton Mar 3, 2021
8d68021
Remove global_counter
cecton Mar 3, 2021
0195902
Do not create telemetry worker if not necessary
cecton Mar 3, 2021
d3468c9
Merge commit e5e8197f4530a2ea6b0ee419699ad45379e96774 (no conflict)
cecton Mar 3, 2021
5f61065
Merge commit a8c2bc66ea8667a1dcbafa13ce184b020bd6f84b (no conflict)
cecton Mar 4, 2021
8e0dfd5
Revert finality-grandpa
cecton Mar 4, 2021
560bb31
WIP
cecton Mar 4, 2021
ddd2bf7
WIP
cecton Mar 4, 2021
a67f8f4
WIP
cecton Mar 4, 2021
9b6851c
WIP
cecton Mar 4, 2021
3dde350
WIP
cecton Mar 4, 2021
ae35cf7
WIP
cecton Mar 4, 2021
b48c01e
WIP
cecton Mar 4, 2021
d591bb4
WIP
cecton Mar 4, 2021
8228e0c
WIP
cecton Mar 4, 2021
f10ae74
WIP
cecton Mar 4, 2021
450cebe
WIP
cecton Mar 4, 2021
9fad6f8
WIP
cecton Mar 4, 2021
a0d2206
Fix doc test
cecton Mar 4, 2021
e1881e0
Add a method with_transport for when transport is needed
cecton Mar 5, 2021
0c6e384
Merge commit adca4983ce51652600fdee4415a81e621fceee6f (no conflict)
cecton Mar 10, 2021
d545ebd
Merge commit 79ddc796ed130810ac9e620493154c3cac9f290a (conflicts)
cecton Mar 10, 2021
f8df9a4
Merge commit a94749cb5321cbc43403ead66a1c915236720f8d (no conflict)
cecton Mar 10, 2021
0fcce2e
Merge commit 8fca15b79bef42c53faad849652c8f5a9936b369 (conflicts)
cecton Mar 10, 2021
81ba8cb
Merge commit ef50a44531b807685c9fc17adbaded9998acce39 (no conflict)
cecton Mar 10, 2021
179f310
Merge commit 3adefdcea47a26c4904651e108129fd6b6ce132a (conflicts)
cecton Mar 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 56 additions & 16 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use sc_consensus_aura::{ImportQueueParams, StartAuraParams, SlotProportion};
use sc_finality_grandpa::SharedVoterState;
use sc_keystore::LocalKeystore;
use sc_telemetry::TelemetrySpan;
use sc_telemetry::{Telemetry, TelemetryWorker};

// Our native executor instance.
native_executor_instance!(
Expand All @@ -38,6 +38,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
AuraPair
>,
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
Option<Telemetry>,
)
>, ServiceError> {
if config.keystore_remote.is_some() {
Expand All @@ -46,10 +47,28 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
}
let inherent_data_providers = InherentDataProviders::new();

let telemetry = config.telemetry_endpoints.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(
&config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
)?;
let client = Arc::new(client);

let telemetry = telemetry
.map(|(worker, telemetry)| {
task_manager.spawn_handle().spawn("telemetry", worker.run());
telemetry
});

let select_chain = sc_consensus::LongestChain::new(backend.clone());

let transaction_pool = sc_transaction_pool::BasicPool::new_full(
Expand All @@ -61,7 +80,10 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
);

let (grandpa_block_import, grandpa_link) = sc_finality_grandpa::block_import(
client.clone(), &(client.clone() as Arc<_>), select_chain.clone(),
client.clone(),
&(client.clone() as Arc<_>),
select_chain.clone(),
telemetry.as_ref().map(|x| x.handle()),
)?;

let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
Expand All @@ -79,6 +101,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
slot_duration: sc_consensus_aura::slot_duration(&*client)?,
registry: config.prometheus_registry(),
check_for_equivocation: Default::default(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
},
)?;

Expand All @@ -91,7 +114,7 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
select_chain,
transaction_pool,
inherent_data_providers,
other: (aura_block_import, grandpa_link),
other: (aura_block_import, grandpa_link, telemetry),
})
}

Expand All @@ -113,7 +136,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
select_chain,
transaction_pool,
inherent_data_providers,
other: (block_import, grandpa_link),
other: (block_import, grandpa_link, mut telemetry),
} = new_partial(&config)?;

if let Some(url) = &config.keystore_remote {
Expand Down Expand Up @@ -167,10 +190,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
})
};

let telemetry_span = TelemetrySpan::new();
let _telemetry_span_entered = telemetry_span.enter();

let (_rpc_handlers, telemetry_connection_notifier) = sc_service::spawn_tasks(
let _rpc_handlers = sc_service::spawn_tasks(
sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
Expand All @@ -184,7 +204,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
network_status_sinks,
system_rpc_tx,
config,
telemetry_span: Some(telemetry_span.clone()),
telemetry: telemetry.as_mut(),
},
)?;

Expand All @@ -194,6 +214,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
client.clone(),
transaction_pool,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|x| x.handle()),
);

let can_author_with =
Expand All @@ -213,6 +234,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
can_author_with,
sync_oracle: network.clone(),
block_proposal_slot_portion: SlotProportion::new(2f32 / 3f32),
telemetry: telemetry.as_ref().map(|x| x.handle()),
},
)?;

Expand All @@ -237,6 +259,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
observer_enabled: false,
keystore,
is_authority: role.is_authority(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
};

if enable_grandpa {
Expand All @@ -250,10 +273,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
config: grandpa_config,
link: grandpa_link,
network,
telemetry_on_connect: telemetry_connection_notifier.map(|x| x.on_connect_stream()),
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
};

// the GRANDPA voter task is considered infallible, i.e.
Expand All @@ -270,8 +293,26 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>

/// Builds a new service for a light client.
pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError> {
let telemetry = config.telemetry_endpoints.clone()
.filter(|x| !x.is_empty())
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
let worker = TelemetryWorker::new(16)?;
let telemetry = worker.handle().new_telemetry(endpoints);
Ok((worker, telemetry))
})
.transpose()?;

let (client, backend, keystore_container, mut task_manager, on_demand) =
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(
&config,
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
)?;

let mut telemetry = telemetry
.map(|(worker, telemetry)| {
task_manager.spawn_handle().spawn("telemetry", worker.run());
telemetry
});

config.network.extra_sets.push(sc_finality_grandpa::grandpa_peers_set_config());

Expand All @@ -289,6 +330,7 @@ pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError>
client.clone(),
&(client.clone() as Arc<_>),
select_chain.clone(),
telemetry.as_ref().map(|x| x.handle()),
)?;

let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
Expand All @@ -307,6 +349,7 @@ pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError>
slot_duration: sc_consensus_aura::slot_duration(&*client)?,
registry: config.prometheus_registry(),
check_for_equivocation: Default::default(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
},
)?;

Expand All @@ -327,9 +370,6 @@ pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError>
);
}

let telemetry_span = TelemetrySpan::new();
let _telemetry_span_entered = telemetry_span.enter();

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
remote_blockchain: Some(backend.remote_blockchain()),
transaction_pool,
Expand All @@ -343,7 +383,7 @@ pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError>
network,
network_status_sinks,
system_rpc_tx,
telemetry_span: Some(telemetry_span.clone()),
telemetry: telemetry.as_mut(),
})?;

network_starter.start_network();
Expand Down
1 change: 1 addition & 0 deletions bin/node/bench/src/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl core::Benchmark for ConstructionBenchmark {
context.client.clone(),
self.transactions.clone().into(),
None,
None,
);
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
inherent_data_providers
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ try-runtime-cli = { version = "0.9.0", optional = true, path = "../../../utils/f
wasm-bindgen = { version = "0.2.57", optional = true }
wasm-bindgen-futures = { version = "0.4.18", optional = true }
browser-utils = { package = "substrate-browser-utils", path = "../../../utils/browser", optional = true, version = "0.9.0"}
libp2p-wasm-ext = { version = "0.27", features = ["websocket"], optional = true }

[target.'cfg(target_arch="x86_64")'.dependencies]
node-executor = { version = "2.0.0", path = "../executor", features = [ "wasmtime" ] }
Expand Down Expand Up @@ -148,6 +149,7 @@ browser = [
"browser-utils",
"wasm-bindgen",
"wasm-bindgen-futures",
"libp2p-wasm-ext",
]
cli = [
"node-executor/wasmi-errno",
Expand Down
14 changes: 4 additions & 10 deletions bin/node/cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use log::info;
use wasm_bindgen::prelude::*;
use browser_utils::{
Client,
browser_configuration, init_logging_and_telemetry, set_console_error_panic_hook,
browser_configuration, init_logging, set_console_error_panic_hook,
};

/// Starts the client.
Expand All @@ -37,18 +37,14 @@ async fn start_inner(
log_directives: String,
) -> Result<Client, Box<dyn std::error::Error>> {
set_console_error_panic_hook();
let telemetry_worker = init_logging_and_telemetry(&log_directives)?;
init_logging(&log_directives)?;
let chain_spec = match chain_spec {
Some(chain_spec) => ChainSpec::from_json_bytes(chain_spec.as_bytes().to_vec())
.map_err(|e| format!("{:?}", e))?,
None => crate::chain_spec::development_config(),
};

let telemetry_handle = telemetry_worker.handle();
let config = browser_configuration(
chain_spec,
Some(telemetry_handle),
).await?;
let config = browser_configuration(chain_spec).await?;

info!("Substrate browser node");
info!("✌️ version {}", config.impl_version);
Expand All @@ -60,10 +56,8 @@ async fn start_inner(
// Create the service. This is the most heavy initialization step.
let (task_manager, rpc_handlers) =
crate::service::new_light_base(config)
.map(|(components, rpc_handlers, _, _, _, _)| (components, rpc_handlers))
.map(|(components, rpc_handlers, _, _, _)| (components, rpc_handlers))
.map_err(|e| format!("{:?}", e))?;

task_manager.spawn_handle().spawn("telemetry", telemetry_worker.run());

Ok(browser_utils::start_client(task_manager, rpc_handlers))
}
2 changes: 1 addition & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ pub(crate) mod tests {
Ok(sc_service_test::TestNetComponents::new(task_manager, client, network, transaction_pool))
},
|config| {
let (keep_alive, _, _, client, network, transaction_pool) = new_light_base(config)?;
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
Ok(sc_service_test::TestNetComponents::new(keep_alive, client, network, transaction_pool))
}
);
Expand Down
Loading