From 80aadf1920624f92fb50459ba6be14444ede9e21 Mon Sep 17 00:00:00 2001 From: Gav Date: Fri, 15 Jun 2018 23:32:33 +0200 Subject: [PATCH] Fix for previous cleanup --- Cargo.lock | 6 +++--- polkadot/cli/src/informant.rs | 4 ++-- polkadot/service/src/lib.rs | 2 +- polkadot/telemetry/Cargo.toml | 2 +- polkadot/telemetry/src/lib.rs | 24 +++++++++++++----------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a116e1a7857d..d6a928c89659e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1382,7 +1382,7 @@ dependencies = [ "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-primitives 0.1.0", "polkadot-service 0.2.0", - "polkadot-telemetry 0.1.0", + "polkadot-telemetry 0.2.0", "polkadot-transaction-pool 0.1.0", "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1532,7 +1532,7 @@ dependencies = [ "polkadot-keystore 0.1.0", "polkadot-primitives 0.1.0", "polkadot-runtime 0.1.0", - "polkadot-telemetry 0.1.0", + "polkadot-telemetry 0.2.0", "polkadot-transaction-pool 0.1.0", "slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-client 0.1.0", @@ -1557,7 +1557,7 @@ dependencies = [ [[package]] name = "polkadot-telemetry" -version = "0.1.0" +version = "0.2.0" dependencies = [ "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/polkadot/cli/src/informant.rs b/polkadot/cli/src/informant.rs index 67ae098825fda..dab75e7a9e9ed 100644 --- a/polkadot/cli/src/informant.rs +++ b/polkadot/cli/src/informant.rs @@ -54,7 +54,7 @@ pub fn start(service: &Service, handle: reactor::Handle) }; let txpool_status = txpool.light_status(); info!(target: "polkadot", "{} ({} peers), best: #{} ({})", status, sync_status.num_peers, best_block.number, hash); - telemetry!("system.interval"; "status" => status, "peers" => num_peers, "height" => best_block.number, "best" => %hash, "txcount" => txpool_status.transaction_count); + telemetry!("system.interval"; "status" => status, "peers" => num_peers, "height" => best_block.number, "best" => ?hash, "txcount" => txpool_status.transaction_count); } else { warn!("Error getting best block information"); } @@ -64,7 +64,7 @@ pub fn start(service: &Service, handle: reactor::Handle) let client = service.client(); let display_block_import = client.import_notification_stream().for_each(|n| { info!(target: "polkadot", "Imported #{} ({})", n.header.number, n.hash); - telemetry!("block.import"; "height" => n.header.number, "best" => %n.hash); + telemetry!("block.import"; "height" => n.header.number, "best" => ?n.hash); Ok(()) }); diff --git a/polkadot/service/src/lib.rs b/polkadot/service/src/lib.rs index b553cdcbb461b..f3b5d9f9999cc 100644 --- a/polkadot/service/src/lib.rs +++ b/polkadot/service/src/lib.rs @@ -415,7 +415,7 @@ impl Service let api = api_creator(client.clone()); let best_header = client.best_block_header()?; info!("Best block is #{}", best_header.number); - telemetry!("node.start"; "height" => best_header.number, "best" => %best_header.hash()); + telemetry!("node.start"; "height" => best_header.number, "best" => ?best_header.hash()); let transaction_pool = Arc::new(TransactionPool::new(config.transaction_pool)); let transaction_pool_adapter = Arc::new(TransactionPoolAdapter { pool: transaction_pool.clone(), diff --git a/polkadot/telemetry/Cargo.toml b/polkadot/telemetry/Cargo.toml index e08faffcff525..6cc9618e309ee 100644 --- a/polkadot/telemetry/Cargo.toml +++ b/polkadot/telemetry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "polkadot-telemetry" -version = "0.1.0" +version = "0.2.0" authors = ["Parity Technologies "] description = "Telemetry utils" diff --git a/polkadot/telemetry/src/lib.rs b/polkadot/telemetry/src/lib.rs index dc6df572bf683..c2534acacfb11 100644 --- a/polkadot/telemetry/src/lib.rs +++ b/polkadot/telemetry/src/lib.rs @@ -47,7 +47,14 @@ pub fn init_telemetry(config: TelemetryConfig) -> slog_scope::GlobalLoggerGuard let log = slog::Logger::root( slog_async::Async::new( slog_json::Json::default( - TelemetryWriter::from_config(config) + TelemetryWriter { + buffer: vec![], + out: Mutex::new( + ws::ClientBuilder::new(&config.url).ok().and_then(|mut x| x.connect(None).ok()) + ), + config, + first_time: true, // ensures that on_connect will be called. + } ).fuse() ).build().fuse(), o!() ); @@ -64,20 +71,15 @@ struct TelemetryWriter { buffer: Vec, out: Mutex>>>, config: TelemetryConfig, + first_time: bool, } impl TelemetryWriter { - fn from_config(config: TelemetryConfig) -> Self { - TelemetryWriter { - buffer: vec![], - out: Mutex::new( - ws::ClientBuilder::new(&config.url).ok().and_then(|mut x| x.connect(None).ok()) - ), - config: config, + fn ensure_connected(&mut self) { + if self.first_time { + (self.config.on_connect)(); + self.first_time = false; } - } - - fn ensure_connected(&self) { let mut client = self.out.lock(); if client.is_none() { *client = ws::ClientBuilder::new(&self.config.url).ok().and_then(|mut x| x.connect(None).ok());