Fix telemetry (and a minor cleanup) (#1384)

This commit is contained in:
Gav Wood
2019-01-10 15:47:12 +01:00
committed by GitHub
parent 42c30609d3
commit a13fda2e83
5 changed files with 45 additions and 33 deletions
+20 -1
View File
@@ -3810,7 +3810,7 @@ dependencies = [
"slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ws 0.7.9 (git+https://github.com/tomusdrw/ws-rs)", "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -4627,6 +4627,24 @@ dependencies = [
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "ws"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
"mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "ws2_32-sys" name = "ws2_32-sys"
version = "0.2.1" version = "0.2.1"
@@ -5044,6 +5062,7 @@ dependencies = [
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba"
"checksum ws 0.7.9 (git+https://github.com/tomusdrw/ws-rs)" = "<none>" "checksum ws 0.7.9 (git+https://github.com/tomusdrw/ws-rs)" = "<none>"
"checksum ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "329d3e6dd450a9c5c73024e1047f0be7e24121a68484eb0b5368977bee3cf8c3"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" "checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" "checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"
+1 -5
View File
@@ -97,15 +97,11 @@ pub struct CoreParams {
#[structopt(long = "name", value_name = "NAME")] #[structopt(long = "name", value_name = "NAME")]
name: Option<String>, name: Option<String>,
/// Should connect to the Substrate telemetry server (telemetry is off by default on local chains)
#[structopt(short = "t", long = "telemetry")]
telemetry: bool,
/// Should not connect to the Substrate telemetry server (telemetry is on by default on global chains) /// Should not connect to the Substrate telemetry server (telemetry is on by default on global chains)
#[structopt(long = "no-telemetry")] #[structopt(long = "no-telemetry")]
no_telemetry: bool, no_telemetry: bool,
/// The URL of the telemetry server. Implies --telemetry /// The URL of the telemetry server to connect to
#[structopt(long = "telemetry-url", value_name = "TELEMETRY_URL")] #[structopt(long = "telemetry-url", value_name = "TELEMETRY_URL")]
telemetry_url: Option<String>, telemetry_url: Option<String>,
+22 -25
View File
@@ -252,31 +252,28 @@ impl<Components: components::Components> Service<Components> {
)?; )?;
// Telemetry // Telemetry
let telemetry = match config.telemetry_url.clone() { let telemetry = config.telemetry_url.clone().map(|url| {
Some(url) => { let is_authority = config.roles == Roles::AUTHORITY;
let is_authority = config.roles == Roles::AUTHORITY; let pubkey = format!("{}", public_key);
let pubkey = format!("{}", public_key); let name = config.name.clone();
let name = config.name.clone(); let impl_name = config.impl_name.to_owned();
let impl_name = config.impl_name.to_owned(); let version = version.clone();
let version = version.clone(); let chain_name = config.chain_spec.name().to_owned();
let chain_name = config.chain_spec.name().to_owned(); Arc::new(tel::init_telemetry(tel::TelemetryConfig {
Some(Arc::new(tel::init_telemetry(tel::TelemetryConfig { url: url,
url: url, on_connect: Box::new(move || {
on_connect: Box::new(move || { telemetry!("system.connected";
telemetry!("system.connected"; "name" => name.clone(),
"name" => name.clone(), "implementation" => impl_name.clone(),
"implementation" => impl_name.clone(), "version" => version.clone(),
"version" => version.clone(), "config" => "",
"config" => "", "chain" => chain_name.clone(),
"chain" => chain_name.clone(), "pubkey" => &pubkey,
"pubkey" => &pubkey, "authority" => is_authority
"authority" => is_authority );
); }),
}), }))
}))) });
},
None => None,
};
Ok(Service { Ok(Service {
client, client,
+1 -1
View File
@@ -12,4 +12,4 @@ slog = "^2"
slog-json = "^2" slog-json = "^2"
slog-async = "^2" slog-async = "^2"
slog-scope = "^4" slog-scope = "^4"
ws = { git = "https://github.com/tomusdrw/ws-rs" } ws = { version = "^0.7", features = ["ssl"] }
+1 -1
View File
@@ -66,7 +66,7 @@ pub fn init_telemetry(config: TelemetryConfig) -> slog_scope::GlobalLoggerGuard
thread::spawn(move || { thread::spawn(move || {
loop { loop {
trace!(target: "telemetry", "Connecting to Telemetry..."); trace!(target: "telemetry", "Connecting to Telemetry... {:?}", config.url);
let _ = ws::connect(config.url.as_str(), |out| Connection::new(out, &*out_sync, &config)); let _ = ws::connect(config.url.as_str(), |out| Connection::new(out, &*out_sync, &config));
thread::sleep(time::Duration::from_millis(5000)); thread::sleep(time::Duration::from_millis(5000));