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

Commit

Permalink
Fix for previous cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gavofyork committed Jun 15, 2018
1 parent d924faf commit 80aadf1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions polkadot/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn start<B, E>(service: &Service<B, E>, 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");
}
Expand All @@ -64,7 +64,7 @@ pub fn start<B, E>(service: &Service<B, E>, 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(())
});

Expand Down
2 changes: 1 addition & 1 deletion polkadot/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl<B, E> Service<B, E>
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(),
Expand Down
2 changes: 1 addition & 1 deletion polkadot/telemetry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadot-telemetry"
version = "0.1.0"
version = "0.2.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Telemetry utils"

Expand Down
24 changes: 13 additions & 11 deletions polkadot/telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
);
Expand All @@ -64,20 +71,15 @@ struct TelemetryWriter {
buffer: Vec<u8>,
out: Mutex<Option<ws::sync::Client<Box<ws::stream::sync::NetworkStream + Send>>>>,
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());
Expand Down

0 comments on commit 80aadf1

Please sign in to comment.