Telemetry - change NetworkState from string to json (#2338)

* change NetworkState from string to json in telemetry
This commit is contained in:
mattrutherford
2019-04-22 18:30:01 +01:00
committed by GitHub
parent 07268022cc
commit 778bf0256f
6 changed files with 42 additions and 10 deletions
+27
View File
@@ -737,6 +737,14 @@ name = "environmental"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "erased-serde"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.12.0"
@@ -2997,6 +3005,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "slog"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "slog-async"
@@ -3014,6 +3025,7 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3029,6 +3041,16 @@ dependencies = [
"slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "slog_derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.31 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "smallvec"
version = "0.6.8"
@@ -4090,6 +4112,7 @@ version = "1.0.0"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4101,6 +4124,8 @@ dependencies = [
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"slog_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"substrate-peerset 1.0.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -5309,6 +5334,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983"
"checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a"
"checksum environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c7464757b80de8930c91c9afe77ddce501826bf9d134a87db2c67d9dc177e2c"
"checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60"
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
"checksum exit-future 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "87559b08e99a81a92bbb867d237543e43495857749f688e0773390a20d56c61c"
"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
@@ -5526,6 +5552,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e544d16c6b230d84c866662fe55e31aacfca6ae71e6fc49ae9a311cb379bfc2f"
"checksum slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc0d2aff1f8f325ef660d9a0eb6e6dcd20b30b3f581a5897f58bf42d061c37a"
"checksum slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "60c04b4726fa04595ccf2c2dad7bcd15474242c4c5e109a8a376e8a2c9b1539a"
"checksum slog_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eff3b513cf2e0d1a60e1aba152dc72bedc5b05585722bb3cebd7bcb1e31b98f"
"checksum smallvec 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "88aea073965ab29f6edb5493faf96ad662fb18aa9eeb186a3b7057951605ed15"
"checksum snow 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7251f8920e9043106cfe466c04ed3eb257b8315a7699259c4fd0af6dffb6aef6"
"checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55"
+1 -1
View File
@@ -82,7 +82,7 @@ pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExe
(proc.cpu_usage(), proc.memory())
} else { (0.0, 0) };
let network_state = serde_json::to_string(&network.network_state()).unwrap_or_default();
let network_state = network.network_state();
telemetry!(
SUBSTRATE_INFO;
+4
View File
@@ -29,6 +29,10 @@ tokio-timer = "0.2"
unsigned-varint = { version = "0.2.1", features = ["codec"] }
void = "1.0"
slog = { version = "^2", features = ["nested-values"] }
slog_derive = "0.1.1"
erased-serde = "0.3.9"
[dev-dependencies]
tempdir = "0.3"
+6 -5
View File
@@ -31,7 +31,8 @@ pub use libp2p::{Multiaddr, multiaddr, build_multiaddr};
pub use libp2p::{identity, PeerId, core::PublicKey};
use libp2p::core::nodes::ConnectedPoint;
use serde_derive::Serialize;
use serde_derive::{Deserialize, Serialize};
use slog_derive::SerdeValue;
use std::{collections::{HashMap, HashSet}, error, fmt, time::Duration};
/// Protocol / handler id
@@ -92,7 +93,7 @@ impl From<multiaddr::Error> for ParseErr {
/// Meant for general diagnostic purposes.
///
/// **Warning**: This API is not stable.
#[derive(Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerdeValue)]
#[serde(rename_all = "camelCase")]
pub struct NetworkState {
/// PeerId of the local node.
@@ -113,7 +114,7 @@ pub struct NetworkState {
pub peerset: serde_json::Value,
}
#[derive(Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkStatePeer {
/// How we are connected to the node.
@@ -132,14 +133,14 @@ pub struct NetworkStatePeer {
pub known_addresses: HashSet<Multiaddr>,
}
#[derive(Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkStateNotConnectedPeer {
/// List of addresses known for this node.
pub known_addresses: HashSet<Multiaddr>,
}
#[derive(Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum NetworkStatePeerEndpoint {
/// We are dialing the given address.
+1 -1
View File
@@ -10,7 +10,7 @@ parking_lot = "0.7.1"
error-chain = "0.12"
lazy_static = "1.0"
log = "0.4"
slog = "^2"
slog = {version = "^2", features = ["nested-values"]}
tokio = "0.1.7"
exit-future = "0.1"
serde = "1.0"
+3 -3
View File
@@ -12,8 +12,8 @@ log = "0.4"
rand = "0.6"
serde = "1.0.81"
serde_derive = "1.0"
slog = "^2"
slog-json = "^2"
slog-async = "^2"
slog = { version = "^2", features = ["nested-values"] }
slog-json = { version = "^2", features = ["nested-values"] }
slog-async = { version = "^2", features = ["nested-values"] }
slog-scope = "^4"
ws = { version = "^0.7", features = ["ssl"] }