From c284e2855751c149a3906d69be3163c53fcc6150 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 14:16:37 +1300 Subject: [PATCH 01/29] Very WIP --- Cargo.lock | 34 ++++-- Cargo.toml | 2 + core/cli/src/lib.rs | 2 + core/cli/src/params.rs | 10 ++ core/grafana-data-source/Cargo.toml | 16 +++ core/grafana-data-source/src/lib.rs | 122 ++++++++++++++++++++++ core/grafana-data-source/test/Cargo.toml | 11 ++ core/grafana-data-source/test/src/main.rs | 5 + core/service/src/config.rs | 3 + 9 files changed, 199 insertions(+), 6 deletions(-) create mode 100644 core/grafana-data-source/Cargo.toml create mode 100644 core/grafana-data-source/src/lib.rs create mode 100644 core/grafana-data-source/test/Cargo.toml create mode 100644 core/grafana-data-source/test/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index c3c3e66c12e95..0ebbe37c2eb18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,6 +416,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1144,6 +1145,27 @@ dependencies = [ "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "grafana-data-source" +version = "2.0.0" +dependencies = [ + "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "grafana-data-source-test" +version = "2.0.0" +dependencies = [ + "grafana-data-source 2.0.0", + "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "h2" version = "0.1.26" @@ -1153,7 +1175,7 @@ dependencies = [ "bytes 0.4.12 (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.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1276,7 +1298,7 @@ dependencies = [ [[package]] name = "http" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1291,7 +1313,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1335,7 +1357,7 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3800,7 +3822,7 @@ dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6913,7 +6935,7 @@ dependencies = [ "checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" "checksum hmac-drbg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe727d41d2eec0a6574d887914347e5ff96a3b87177817e2a9820c5c87fecc2" "checksum hmac-drbg 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6e570451493f10f6581b48cdd530413b63ea9e780f544bfd3bdcaa0d89d1a7b" -"checksum http 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "372bcb56f939e449117fb0869c2e8fd8753a8223d92a172c6e808cf123a5b6e4" +"checksum http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf" "checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" diff --git a/Cargo.toml b/Cargo.toml index 8d3d04c4d0595..4c7f08527ef73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,8 @@ members = [ "core/externalities", "core/finality-grandpa", "core/finality-grandpa/primitives", + "core/grafana-data-source", + "core/grafana-data-source/test", "core/inherents", "core/keyring", "core/keystore", diff --git a/core/cli/src/lib.rs b/core/cli/src/lib.rs index b49f686ae62f7..937911d118208 100644 --- a/core/cli/src/lib.rs +++ b/core/cli/src/lib.rs @@ -735,9 +735,11 @@ where let rpc_interface: &str = if cli.rpc_external { "0.0.0.0" } else { "127.0.0.1" }; let ws_interface: &str = if cli.ws_external { "0.0.0.0" } else { "127.0.0.1" }; + let grafana_interface: &str = if cli.grafana_external { "0.0.0.0" } else { "127.0.0.1" }; config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), cli.rpc_port)?); config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)?); + config.grafana_port = Some(parse_address(&format!("{}:{}", grafana_interface, 9955), cli.grafana_port)?); config.rpc_ws_max_connections = cli.ws_max_connections; config.rpc_cors = cli.rpc_cors.unwrap_or_else(|| if is_dev { diff --git a/core/cli/src/params.rs b/core/cli/src/params.rs index 4480736066400..26e9d4f35f0f2 100644 --- a/core/cli/src/params.rs +++ b/core/cli/src/params.rs @@ -332,6 +332,12 @@ pub struct RunCmd { #[structopt(long = "ws-external")] pub ws_external: bool, + /// Listen to all Grafana data source interfaces. + /// + /// Default is local. + #[structopt(long = "grafana-external")] + pub grafana_external: bool, + /// Specify HTTP RPC server TCP port. #[structopt(long = "rpc-port", value_name = "PORT")] pub rpc_port: Option, @@ -354,6 +360,10 @@ pub struct RunCmd { #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] pub rpc_cors: Option, + /// Specify Grafana data source server TCP Port. + #[structopt(long = "grafana-port", value_name = "PORT")] + pub grafana_port: Option, + /// Specify the state pruning mode, a number of blocks to keep or 'archive'. /// /// Default is to keep all block states if the node is running as a diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml new file mode 100644 index 0000000000000..ef02bf40d0065 --- /dev/null +++ b/core/grafana-data-source/Cargo.toml @@ -0,0 +1,16 @@ +[package] +description = "Grafana data source server" +name = "grafana-data-source" +version = "2.0.0" +license = "GPL-3.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +hyper = "0.12.35" +futures = "0.1.29" +serde_json = "1.0.41" +http = "0.1.19" +serde = { version = "1.0.101", features = ["derive"] } +chrono = { version = "0.4.9", features = ["serde"] } +rand = "*" \ No newline at end of file diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs new file mode 100644 index 0000000000000..1e859a49aa602 --- /dev/null +++ b/core/grafana-data-source/src/lib.rs @@ -0,0 +1,122 @@ +use serde::{Serialize, Deserialize, de::DeserializeOwned}; +use hyper::{Body, Request, Response, header, service::service_fn, Server}; +use futures::{future, Future, stream::Stream}; +use chrono::{DateTime, Utc, Duration}; +use rand::{thread_rng, Rng}; + +type GenericError = Box; +type ResponseFuture = Box, Error=GenericError> + Send>; + +#[derive(Serialize, Deserialize, Debug)] +enum TargetType { + #[serde(rename = "timeseries")] + Timeseries, + #[serde(rename = "table")] + Table +} + +#[derive(Serialize, Deserialize)] +pub struct SearchRequest { + target: String +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct QueryRequest { + interval_ms: u64, + max_data_points: u64, + targets: Vec, + range: Range, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Target { + target: Metric, + #[serde(rename = "type")] + target_type: TargetType, +} + +#[derive(Serialize, Deserialize, Debug)] +struct Range { + from: DateTime, + to: DateTime, +} + +#[derive(Serialize, Deserialize, Debug)] +struct TimeseriesData { + target: Metric, + datapoints: Vec<(f32, u64)> +} + +#[derive(Serialize, Deserialize, Debug, Copy, Clone)] +enum Metric { + #[serde(rename = "a")] + A, + #[serde(rename = "ab")] + Ab, + #[serde(rename = "abc")] + Abc +} + +fn api_response(req: Request) -> ResponseFuture { + match req.uri().path() { + "/" => Box::new(future::ok(Response::new(Body::empty()))), + "/search" => { + respond(req, |_: SearchRequest| { + [Metric::A, Metric::Ab, Metric::Abc] + }) + }, + "/query" => { + respond(req, |req: QueryRequest| { + req.targets.iter() + .map(|target| { + // Create some bogus data points + let datapoints = (0 .. 1000) + .map(|i| ( + thread_rng().gen_range(0.0, 10_000.0), + (Utc::now() - Duration::days(i)) + )) + .filter(|(_, timestamp)| timestamp >= &req.range.from && timestamp <= &req.range.to) + .map(|(i, datetime)| (i, datetime.timestamp_millis() as u64)) + .collect(); + + TimeseriesData { + target: target.target, datapoints + } + }) + .collect::>() + }) + }, + _ => Box::new(future::ok(Response::new(Body::empty()))), + } +} + +fn respond(req: Request, transformation: T) -> ResponseFuture + where + Req: DeserializeOwned, + Res: Serialize, + T: Fn(Req) -> Res + Send + Sync + 'static +{ + Box::new(req.into_body() + .concat2() + .from_err() + .and_then(move |entire_body| { + let req = serde_json::from_slice(entire_body.as_ref())?; + let res = transformation(req); + + let string = serde_json::to_string(&res)?; + + Response::builder() + .header(header::CONTENT_TYPE, "application/json") + .body(Body::from(string)) + .map_err(|e| e.into()) + }) + ) +} + +pub fn run_server(address: &std::net::SocketAddr) -> impl Future { + Server::bind(address) + .serve(|| service_fn(api_response)) + .map_err(|e| eprintln!("server error: {}", e)) +} \ No newline at end of file diff --git a/core/grafana-data-source/test/Cargo.toml b/core/grafana-data-source/test/Cargo.toml new file mode 100644 index 0000000000000..ae4de8d11ae71 --- /dev/null +++ b/core/grafana-data-source/test/Cargo.toml @@ -0,0 +1,11 @@ +[package] +description = "Grafana data source server test" +name = "grafana-data-source-test" +version = "2.0.0" +license = "GPL-3.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +hyper = "0.12.35" +grafana-data-source = { path = ".." } \ No newline at end of file diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs new file mode 100644 index 0000000000000..8ca8d689753c2 --- /dev/null +++ b/core/grafana-data-source/test/src/main.rs @@ -0,0 +1,5 @@ +use grafana_data_source::run_server; + +fn main() { + hyper::rt::run(run_server(&"127.0.0.1:8080".parse().unwrap())); +} \ No newline at end of file diff --git a/core/service/src/config.rs b/core/service/src/config.rs index a1ba83753f402..dc8b6d2349316 100644 --- a/core/service/src/config.rs +++ b/core/service/src/config.rs @@ -73,6 +73,8 @@ pub struct Configuration { pub rpc_ws_max_connections: Option, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, + /// Grafana data source http port. `None` if disabled. + pub grafana_port: Option, /// Telemetry service URL. `None` if disabled. pub telemetry_endpoints: Option, /// External WASM transport for the telemetry. If `Some`, when connection to a telemetry @@ -125,6 +127,7 @@ impl Configuration where rpc_ws: None, rpc_ws_max_connections: None, rpc_cors: Some(vec![]), + grafana_port: None, telemetry_endpoints: None, telemetry_external_transport: None, default_heap_pages: None, From eda126f2efb473b9e6bbdad1da24f09e21c30e9c Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 16:13:00 +1300 Subject: [PATCH 02/29] record_metrics macro works --- Cargo.lock | 5 +- core/grafana-data-source/Cargo.toml | 14 +- core/grafana-data-source/src/lib.rs | 148 ++++------------------ core/grafana-data-source/src/server.rs | 63 +++++++++ core/grafana-data-source/src/types.rs | 44 +++++++ core/grafana-data-source/test/Cargo.toml | 5 +- core/grafana-data-source/test/src/main.rs | 21 ++- 7 files changed, 164 insertions(+), 136 deletions(-) create mode 100644 core/grafana-data-source/src/server.rs create mode 100644 core/grafana-data-source/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index 0ebbe37c2eb18..6ec19dc3ac079 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1151,9 +1151,9 @@ version = "2.0.0" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1164,6 +1164,7 @@ version = "2.0.0" dependencies = [ "grafana-data-source 2.0.0", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml index ef02bf40d0065..8770b81ad2112 100644 --- a/core/grafana-data-source/Cargo.toml +++ b/core/grafana-data-source/Cargo.toml @@ -7,10 +7,10 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -hyper = "0.12.35" -futures = "0.1.29" -serde_json = "1.0.41" -http = "0.1.19" -serde = { version = "1.0.101", features = ["derive"] } -chrono = { version = "0.4.9", features = ["serde"] } -rand = "*" \ No newline at end of file +hyper = "0.12" +futures = "0.1" +serde_json = "1" +serde = { version = "1", features = ["derive"] } +chrono = { version = "0.4", features = ["serde"] } +lazy_static = "1.4" +parking_lot = "0.9" diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index 1e859a49aa602..840ad5e6a5693 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -1,122 +1,26 @@ -use serde::{Serialize, Deserialize, de::DeserializeOwned}; -use hyper::{Body, Request, Response, header, service::service_fn, Server}; -use futures::{future, Future, stream::Stream}; -use chrono::{DateTime, Utc, Duration}; -use rand::{thread_rng, Rng}; - -type GenericError = Box; -type ResponseFuture = Box, Error=GenericError> + Send>; - -#[derive(Serialize, Deserialize, Debug)] -enum TargetType { - #[serde(rename = "timeseries")] - Timeseries, - #[serde(rename = "table")] - Table -} - -#[derive(Serialize, Deserialize)] -pub struct SearchRequest { - target: String -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct QueryRequest { - interval_ms: u64, - max_data_points: u64, - targets: Vec, - range: Range, -} - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Target { - target: Metric, - #[serde(rename = "type")] - target_type: TargetType, -} - -#[derive(Serialize, Deserialize, Debug)] -struct Range { - from: DateTime, - to: DateTime, -} - -#[derive(Serialize, Deserialize, Debug)] -struct TimeseriesData { - target: Metric, - datapoints: Vec<(f32, u64)> -} - -#[derive(Serialize, Deserialize, Debug, Copy, Clone)] -enum Metric { - #[serde(rename = "a")] - A, - #[serde(rename = "ab")] - Ab, - #[serde(rename = "abc")] - Abc -} - -fn api_response(req: Request) -> ResponseFuture { - match req.uri().path() { - "/" => Box::new(future::ok(Response::new(Body::empty()))), - "/search" => { - respond(req, |_: SearchRequest| { - [Metric::A, Metric::Ab, Metric::Abc] - }) - }, - "/query" => { - respond(req, |req: QueryRequest| { - req.targets.iter() - .map(|target| { - // Create some bogus data points - let datapoints = (0 .. 1000) - .map(|i| ( - thread_rng().gen_range(0.0, 10_000.0), - (Utc::now() - Duration::days(i)) - )) - .filter(|(_, timestamp)| timestamp >= &req.range.from && timestamp <= &req.range.to) - .map(|(i, datetime)| (i, datetime.timestamp_millis() as u64)) - .collect(); - - TimeseriesData { - target: target.target, datapoints - } - }) - .collect::>() - }) - }, - _ => Box::new(future::ok(Response::new(Body::empty()))), - } -} - -fn respond(req: Request, transformation: T) -> ResponseFuture - where - Req: DeserializeOwned, - Res: Serialize, - T: Fn(Req) -> Res + Send + Sync + 'static -{ - Box::new(req.into_body() - .concat2() - .from_err() - .and_then(move |entire_body| { - let req = serde_json::from_slice(entire_body.as_ref())?; - let res = transformation(req); - - let string = serde_json::to_string(&res)?; - - Response::builder() - .header(header::CONTENT_TYPE, "application/json") - .body(Body::from(string)) - .map_err(|e| e.into()) - }) - ) -} - -pub fn run_server(address: &std::net::SocketAddr) -> impl Future { - Server::bind(address) - .serve(|| service_fn(api_response)) - .map_err(|e| eprintln!("server error: {}", e)) -} \ No newline at end of file +use lazy_static::lazy_static; +use chrono::DateTime; +use std::collections::HashMap; +use parking_lot::RwLock; + +mod types; +mod server; +pub use server::run_server; +pub use chrono::Utc; + +type Metrics = HashMap)>>; + +lazy_static! { + pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); +} + +#[macro_export] +macro_rules! record_metrics( + ($($key:expr => $value:expr),+) => { + use $crate::{Utc, METRICS}; + let mut metrics = METRICS.write(); + $( + metrics.entry(String::from($key)).or_insert_with(Vec::new).push(($value, Utc::now())); + )+ + } +); \ No newline at end of file diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs new file mode 100644 index 0000000000000..996823abc45b8 --- /dev/null +++ b/core/grafana-data-source/src/server.rs @@ -0,0 +1,63 @@ +use serde::{Serialize, de::DeserializeOwned}; +use hyper::{Body, Request, Response, header, service::service_fn, Server}; +use futures::{future, Future, stream::Stream}; +use crate::{METRICS, types::{SearchRequest, QueryRequest, TimeseriesData}}; + +type GenericError = Box; +type ResponseFuture = Box, Error=GenericError> + Send>; + +fn api_response(req: Request) -> ResponseFuture { + match req.uri().path() { + "/" => Box::new(future::ok(Response::new(Body::empty()))), + "/search" => respond(req, |_: SearchRequest| METRICS.read().keys().cloned().collect::>()), + "/query" => { + respond(req, |req: QueryRequest| { + let metrics = METRICS.read(); + + req.targets.iter() + .map(|target| { + let datapoints = metrics.get(&target.target).iter() + .flat_map(|&vec| vec) + .filter(|(_, timestamp)| req.range.from <= *timestamp && *timestamp <= req.range.to) + .map(|(value, timestamp)| (*value, timestamp.timestamp_millis() as u64)) + .collect(); + + TimeseriesData { + target: target.target.clone(), datapoints + } + }) + .collect::>() + }) + }, + _ => Box::new(future::ok(Response::new(Body::empty()))), + } +} + +fn respond(req: Request, transformation: T) -> ResponseFuture + where + Req: DeserializeOwned, + Res: Serialize, + T: Fn(Req) -> Res + Send + Sync + 'static +{ + Box::new(req.into_body() + .concat2() + .from_err() + .and_then(move |entire_body| { + let req = serde_json::from_slice(entire_body.as_ref())?; + let res = transformation(req); + + let string = serde_json::to_string(&res)?; + + Response::builder() + .header(header::CONTENT_TYPE, "application/json") + .body(Body::from(string)) + .map_err(|e| e.into()) + }) + ) +} + +pub fn run_server(address: &std::net::SocketAddr) -> impl Future { + Server::bind(address) + .serve(|| service_fn(api_response)) + .map_err(|e| eprintln!("server error: {}", e)) +} diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs new file mode 100644 index 0000000000000..ccdb5a7911c8a --- /dev/null +++ b/core/grafana-data-source/src/types.rs @@ -0,0 +1,44 @@ +use serde::{Serialize, Deserialize}; +use chrono::{DateTime, Utc}; + +#[derive(Serialize, Deserialize, Debug)] +pub enum TargetType { + #[serde(rename = "timeseries")] + Timeseries, + #[serde(rename = "table")] + Table +} + +#[derive(Serialize, Deserialize)] +pub struct SearchRequest { + target: String +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct QueryRequest { + interval_ms: u64, + max_data_points: u64, + pub targets: Vec, + pub range: Range, +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct Target { + pub target: String, + #[serde(rename = "type")] + target_type: TargetType, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Range { + pub from: DateTime, + pub to: DateTime, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct TimeseriesData { + pub target: String, + pub datapoints: Vec<(f32, u64)> +} diff --git a/core/grafana-data-source/test/Cargo.toml b/core/grafana-data-source/test/Cargo.toml index ae4de8d11ae71..adf95931922e6 100644 --- a/core/grafana-data-source/test/Cargo.toml +++ b/core/grafana-data-source/test/Cargo.toml @@ -7,5 +7,6 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -hyper = "0.12.35" -grafana-data-source = { path = ".." } \ No newline at end of file +hyper = "0.12" +grafana-data-source = { path = ".." } +rand = "0.7" diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index 8ca8d689753c2..ecfa3529d8411 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -1,5 +1,20 @@ -use grafana_data_source::run_server; +use grafana_data_source::{run_server, record_metrics}; +use std::{thread::{spawn, sleep}, time::Duration}; +use rand::Rng; fn main() { - hyper::rt::run(run_server(&"127.0.0.1:8080".parse().unwrap())); -} \ No newline at end of file + let handle = spawn(|| { + let mut rng = rand::thread_rng(); + + loop { + let random = rng.gen_range(0.0, 1000.0); + record_metrics!( + "random data" => random, + "random^2" => random * random + ); + sleep(Duration::from_secs(1)); + } + }); + hyper::rt::run(run_server(&"127.0.0.1:9955".parse().unwrap())); + handle.join().unwrap(); +} From d2c17534fc35afaf9af2b47e5e99489bd74f6b84 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 18:41:20 +1300 Subject: [PATCH 03/29] Integrate into service --- Cargo.lock | 2 ++ core/grafana-data-source/src/lib.rs | 9 +++++---- core/grafana-data-source/src/server.rs | 11 ++++++++--- core/grafana-data-source/src/types.rs | 2 +- core/grafana-data-source/test/Cargo.toml | 1 + core/grafana-data-source/test/src/main.rs | 2 +- core/service/Cargo.toml | 1 + core/service/src/builder.rs | 19 +++++++++++++++++++ 8 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ec19dc3ac079..3d18a591fe3c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1162,6 +1162,7 @@ dependencies = [ name = "grafana-data-source-test" version = "2.0.0" dependencies = [ + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "grafana-data-source 2.0.0", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5529,6 +5530,7 @@ dependencies = [ "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "grafana-data-source 2.0.0", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "node-executor 2.0.0", diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index 840ad5e6a5693..c5c47bedd7c54 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -8,7 +8,7 @@ mod server; pub use server::run_server; pub use chrono::Utc; -type Metrics = HashMap)>>; +type Metrics = HashMap<&'static str, Vec<(f32, DateTime)>>; lazy_static! { pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); @@ -16,11 +16,12 @@ lazy_static! { #[macro_export] macro_rules! record_metrics( - ($($key:expr => $value:expr),+) => { + ($($key:expr => $value:expr),*) => { use $crate::{Utc, METRICS}; let mut metrics = METRICS.write(); + let now = Utc::now(); $( - metrics.entry(String::from($key)).or_insert_with(Vec::new).push(($value, Utc::now())); - )+ + metrics.entry($key).or_insert_with(Vec::new).push(($value as f32, now)); + )* } ); \ No newline at end of file diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 996823abc45b8..ae3a631ca1be0 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -9,14 +9,18 @@ type ResponseFuture = Box, Error=GenericError> + fn api_response(req: Request) -> ResponseFuture { match req.uri().path() { "/" => Box::new(future::ok(Response::new(Body::empty()))), - "/search" => respond(req, |_: SearchRequest| METRICS.read().keys().cloned().collect::>()), + "/search" => respond(req, |req: SearchRequest| { + // Filter and return metrics relating to the search term + METRICS.read().keys().filter(|key| key.starts_with(&req.target)).cloned().collect::>() + }), "/query" => { respond(req, |req: QueryRequest| { let metrics = METRICS.read(); + // Return timeseries data related to the specified metrics req.targets.iter() .map(|target| { - let datapoints = metrics.get(&target.target).iter() + let datapoints = metrics.get(target.target.as_str()).iter() .flat_map(|&vec| vec) .filter(|(_, timestamp)| req.range.from <= *timestamp && *timestamp <= req.range.to) .map(|(value, timestamp)| (*value, timestamp.timestamp_millis() as u64)) @@ -56,8 +60,9 @@ fn respond(req: Request, transformation: T) -> ResponseFuture ) } -pub fn run_server(address: &std::net::SocketAddr) -> impl Future { +pub fn run_server>(address: &std::net::SocketAddr, shutdown: F) -> impl Future { Server::bind(address) .serve(|| service_fn(api_response)) + .with_graceful_shutdown(shutdown) .map_err(|e| eprintln!("server error: {}", e)) } diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index ccdb5a7911c8a..2241d1cb73ee9 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -11,7 +11,7 @@ pub enum TargetType { #[derive(Serialize, Deserialize)] pub struct SearchRequest { - target: String + pub target: String } #[derive(Serialize, Deserialize, Debug)] diff --git a/core/grafana-data-source/test/Cargo.toml b/core/grafana-data-source/test/Cargo.toml index adf95931922e6..c299d867a1330 100644 --- a/core/grafana-data-source/test/Cargo.toml +++ b/core/grafana-data-source/test/Cargo.toml @@ -10,3 +10,4 @@ edition = "2018" hyper = "0.12" grafana-data-source = { path = ".." } rand = "0.7" +futures = "0.1" diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index ecfa3529d8411..2098715e28ac0 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -15,6 +15,6 @@ fn main() { sleep(Duration::from_secs(1)); } }); - hyper::rt::run(run_server(&"127.0.0.1:9955".parse().unwrap())); + hyper::rt::run(run_server(&"127.0.0.1:9955".parse().unwrap(), futures::future::empty())); handle.join().unwrap(); } diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml index 04371087eff2e..11527177d6217 100644 --- a/core/service/Cargo.toml +++ b/core/service/Cargo.toml @@ -40,6 +40,7 @@ tel = { package = "substrate-telemetry", path = "../../core/telemetry" } offchain = { package = "substrate-offchain", path = "../../core/offchain" } parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../authority-discovery/primitives", default-features = false } +grafana-data-source = { path = "../grafana-data-source" } [dev-dependencies] substrate-test-runtime-client = { path = "../test-runtime/client" } diff --git a/core/service/src/builder.rs b/core/service/src/builder.rs index b2a6cc731ac3b..9dc02d35be7a9 100644 --- a/core/service/src/builder.rs +++ b/core/service/src/builder.rs @@ -48,6 +48,7 @@ use std::{io::{Read, Write, Seek}, marker::PhantomData, sync::Arc, sync::atomic: use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use tel::{telemetry, SUBSTRATE_INFO}; use transaction_pool::txpool::{self, ChainApi, Pool as TransactionPool}; +use grafana_data_source::{self, record_metrics}; /// Aggregator for the components required to build a service. /// @@ -965,6 +966,17 @@ ServiceBuilder< "bandwidth_upload" => bandwidth_upload, "used_state_cache_size" => used_state_cache_size, ); + record_metrics!( + "peers" => num_peers, + "height" => best_number, + "txcount" => txpool_status.ready, + "cpu" => cpu_usage, + "memory" => memory, + "finalized_height" => finalized_number, + "bandwidth_download" => bandwidth_download, + "bandwidth_upload" => bandwidth_upload, + "used_state_cache_size" => used_state_cache_size + ); Ok(()) }).select(exit.clone()).then(|_| Ok(())); @@ -1100,6 +1112,13 @@ ServiceBuilder< telemetry }); + // Grafana data source + if let Some(port) = config.grafana_port { + let _ = to_spawn_tx.unbounded_send(Box::new( + grafana_data_source::run_server(&port, exit.clone()) + )); + } + Ok(Service { client, network, From df401075f4e41ce3fe05d51b4027e323dc0bf188 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 18:59:07 +1300 Subject: [PATCH 04/29] Licenses and documentation --- core/grafana-data-source/src/lib.rs | 30 +++++++++++++++++++++++ core/grafana-data-source/src/server.rs | 19 ++++++++++++++ core/grafana-data-source/src/types.rs | 16 ++++++++++++ core/grafana-data-source/test/src/main.rs | 16 ++++++++++++ 4 files changed, 81 insertions(+) diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index c5c47bedd7c54..412a0df08ee61 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -1,3 +1,28 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! [Grafana] data source server +//! +//! To display node statistics with [Grafana], this module exposes a `run_server` function that starts up a HTTP server +//! that conforms to the [`grafana-json-data-source`] API. The `record_metrics` macro can be used to pass metrics to +//! this server. +//! +//! [Grafana]: https://grafana.com/ +//! [`grafana-json-data-source`]: https://github.com/simPod/grafana-json-datasource + use lazy_static::lazy_static; use chrono::DateTime; use std::collections::HashMap; @@ -5,15 +30,20 @@ use parking_lot::RwLock; mod types; mod server; + pub use server::run_server; +/// Re-export `Utc` from `chrono` so that it can be used in `record_metrics`. +/// pub use chrono::Utc; type Metrics = HashMap<&'static str, Vec<(f32, DateTime)>>; lazy_static! { + /// The `RwLock` wrapping the metrics. Not intended to be used directly. pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); } +/// Write metrics to `METRICS`. #[macro_export] macro_rules! record_metrics( ($($key:expr => $value:expr),*) => { diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index ae3a631ca1be0..26ea528b3967f 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -1,3 +1,19 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + use serde::{Serialize, de::DeserializeOwned}; use hyper::{Body, Request, Response, header, service::service_fn, Server}; use futures::{future, Future, stream::Stream}; @@ -60,6 +76,9 @@ fn respond(req: Request, transformation: T) -> ResponseFuture ) } +/// Start the data source server. +/// +/// The server shuts down cleanly when `shutdown` resolves. pub fn run_server>(address: &std::net::SocketAddr, shutdown: F) -> impl Future { Server::bind(address) .serve(|| service_fn(api_response)) diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index 2241d1cb73ee9..cd85b1fa33bc4 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -1,3 +1,19 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + use serde::{Serialize, Deserialize}; use chrono::{DateTime, Utc}; diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index 2098715e28ac0..e7ebde8643bab 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -1,3 +1,19 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + use grafana_data_source::{run_server, record_metrics}; use std::{thread::{spawn, sleep}, time::Duration}; use rand::Rng; From eb5ac016705419414b07e921142230fcff5cbfe6 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 19:02:13 +1300 Subject: [PATCH 05/29] Remove unused Debugs, make respond function clearer --- core/grafana-data-source/src/server.rs | 6 +++--- core/grafana-data-source/src/types.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 26ea528b3967f..6a24649500514 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -25,12 +25,12 @@ type ResponseFuture = Box, Error=GenericError> + fn api_response(req: Request) -> ResponseFuture { match req.uri().path() { "/" => Box::new(future::ok(Response::new(Body::empty()))), - "/search" => respond(req, |req: SearchRequest| { + "/search" => map_request_to_response(req, |req: SearchRequest| { // Filter and return metrics relating to the search term METRICS.read().keys().filter(|key| key.starts_with(&req.target)).cloned().collect::>() }), "/query" => { - respond(req, |req: QueryRequest| { + map_request_to_response(req, |req: QueryRequest| { let metrics = METRICS.read(); // Return timeseries data related to the specified metrics @@ -53,7 +53,7 @@ fn api_response(req: Request) -> ResponseFuture { } } -fn respond(req: Request, transformation: T) -> ResponseFuture +fn map_request_to_response(req: Request, transformation: T) -> ResponseFuture where Req: DeserializeOwned, Res: Serialize, diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index cd85b1fa33bc4..1ae22cb85f0e7 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -17,7 +17,7 @@ use serde::{Serialize, Deserialize}; use chrono::{DateTime, Utc}; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize)] pub enum TargetType { #[serde(rename = "timeseries")] Timeseries, @@ -30,7 +30,7 @@ pub struct SearchRequest { pub target: String } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct QueryRequest { interval_ms: u64, @@ -39,7 +39,7 @@ pub struct QueryRequest { pub range: Range, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Target { pub target: String, @@ -47,13 +47,13 @@ pub struct Target { target_type: TargetType, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize)] pub struct Range { pub from: DateTime, pub to: DateTime, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize)] pub struct TimeseriesData { pub target: String, pub datapoints: Vec<(f32, u64)> From b62f12f1c64b66452885f72d381835d6517a4d79 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 19:36:37 +1300 Subject: [PATCH 06/29] Conform to line widths, fix service test --- core/cli/src/lib.rs | 4 +++- core/grafana-data-source/src/lib.rs | 6 +++--- core/grafana-data-source/src/server.rs | 14 +++++++++++--- core/service/test/src/lib.rs | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/cli/src/lib.rs b/core/cli/src/lib.rs index 937911d118208..0610dd511f4ba 100644 --- a/core/cli/src/lib.rs +++ b/core/cli/src/lib.rs @@ -739,7 +739,9 @@ where config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), cli.rpc_port)?); config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)?); - config.grafana_port = Some(parse_address(&format!("{}:{}", grafana_interface, 9955), cli.grafana_port)?); + config.grafana_port = Some( + parse_address(&format!("{}:{}", grafana_interface, 9955), cli.grafana_port)? + ); config.rpc_ws_max_connections = cli.ws_max_connections; config.rpc_cors = cli.rpc_cors.unwrap_or_else(|| if is_dev { diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index 412a0df08ee61..af17662a65368 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -16,9 +16,9 @@ //! [Grafana] data source server //! -//! To display node statistics with [Grafana], this module exposes a `run_server` function that starts up a HTTP server -//! that conforms to the [`grafana-json-data-source`] API. The `record_metrics` macro can be used to pass metrics to -//! this server. +//! To display node statistics with [Grafana], this module exposes a `run_server` function that +//! starts up a HTTP server that conforms to the [`grafana-json-data-source`] API. The +//! `record_metrics` macro can be used to pass metrics to this server. //! //! [Grafana]: https://grafana.com/ //! [`grafana-json-data-source`]: https://github.com/simPod/grafana-json-datasource diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 6a24649500514..78034fd6c5e6c 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -27,7 +27,11 @@ fn api_response(req: Request) -> ResponseFuture { "/" => Box::new(future::ok(Response::new(Body::empty()))), "/search" => map_request_to_response(req, |req: SearchRequest| { // Filter and return metrics relating to the search term - METRICS.read().keys().filter(|key| key.starts_with(&req.target)).cloned().collect::>() + METRICS.read() + .keys() + .filter(|key| key.starts_with(&req.target)) + .cloned() + .collect::>() }), "/query" => { map_request_to_response(req, |req: QueryRequest| { @@ -38,7 +42,9 @@ fn api_response(req: Request) -> ResponseFuture { .map(|target| { let datapoints = metrics.get(target.target.as_str()).iter() .flat_map(|&vec| vec) - .filter(|(_, timestamp)| req.range.from <= *timestamp && *timestamp <= req.range.to) + .filter(|(_, timestamp)| { + req.range.from <= *timestamp && *timestamp <= req.range.to + }) .map(|(value, timestamp)| (*value, timestamp.timestamp_millis() as u64)) .collect(); @@ -79,7 +85,9 @@ fn map_request_to_response(req: Request, transformation: T) - /// Start the data source server. /// /// The server shuts down cleanly when `shutdown` resolves. -pub fn run_server>(address: &std::net::SocketAddr, shutdown: F) -> impl Future { +pub fn run_server(address: &std::net::SocketAddr, shutdown: F) -> impl Future + where F: Future +{ Server::bind(address) .serve(|| service_fn(api_response)) .with_graceful_shutdown(shutdown) diff --git a/core/service/test/src/lib.rs b/core/service/test/src/lib.rs index 806996576ff90..c321fea7ff9a0 100644 --- a/core/service/test/src/lib.rs +++ b/core/service/test/src/lib.rs @@ -184,6 +184,7 @@ fn node_config ( rpc_ws: None, rpc_ws_max_connections: None, rpc_cors: None, + grafana_port: None, telemetry_endpoints: None, telemetry_external_transport: None, default_heap_pages: None, From 9947f72ab5fd0766ccc253250bea62793ea17bd8 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 21:51:09 +1300 Subject: [PATCH 07/29] Switch to storing the timestamps as millis instead --- core/grafana-data-source/src/lib.rs | 7 +++---- core/grafana-data-source/src/server.rs | 9 +++++---- core/grafana-data-source/src/types.rs | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index af17662a65368..b2c0d78c8edb7 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -24,7 +24,6 @@ //! [`grafana-json-data-source`]: https://github.com/simPod/grafana-json-datasource use lazy_static::lazy_static; -use chrono::DateTime; use std::collections::HashMap; use parking_lot::RwLock; @@ -36,7 +35,7 @@ pub use server::run_server; /// pub use chrono::Utc; -type Metrics = HashMap<&'static str, Vec<(f32, DateTime)>>; +type Metrics = HashMap<&'static str, Vec<(f32, i64)>>; lazy_static! { /// The `RwLock` wrapping the metrics. Not intended to be used directly. @@ -49,9 +48,9 @@ macro_rules! record_metrics( ($($key:expr => $value:expr),*) => { use $crate::{Utc, METRICS}; let mut metrics = METRICS.write(); - let now = Utc::now(); + let now = Utc::now().timestamp_millis(); $( metrics.entry($key).or_insert_with(Vec::new).push(($value as f32, now)); )* } -); \ No newline at end of file +); diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 78034fd6c5e6c..2ab439bc60ea5 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -37,15 +37,16 @@ fn api_response(req: Request) -> ResponseFuture { map_request_to_response(req, |req: QueryRequest| { let metrics = METRICS.read(); + let to = req.range.to.timestamp_millis(); + let from = req.range.from.timestamp_millis(); + // Return timeseries data related to the specified metrics req.targets.iter() .map(|target| { let datapoints = metrics.get(target.target.as_str()).iter() .flat_map(|&vec| vec) - .filter(|(_, timestamp)| { - req.range.from <= *timestamp && *timestamp <= req.range.to - }) - .map(|(value, timestamp)| (*value, timestamp.timestamp_millis() as u64)) + .cloned() + .filter(|&(_, timestamp)| from <= timestamp && timestamp <= to) .collect(); TimeseriesData { diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index 1ae22cb85f0e7..ab98eb7455b83 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -40,7 +40,6 @@ pub struct QueryRequest { } #[derive(Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct Target { pub target: String, #[serde(rename = "type")] @@ -56,5 +55,5 @@ pub struct Range { #[derive(Serialize, Deserialize)] pub struct TimeseriesData { pub target: String, - pub datapoints: Vec<(f32, u64)> + pub datapoints: Vec<(f32, i64)> } From 562e588e6179e42a1b233a93b03ef6f9e5c0d5b8 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 11:17:24 +0100 Subject: [PATCH 08/29] Update core/grafana-data-source/src/lib.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> --- core/grafana-data-source/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index b2c0d78c8edb7..4e8aa3c764373 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify From 6384f253be305863eca17973e6b0198353f26fb6 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 23:18:52 +1300 Subject: [PATCH 09/29] Transform timestamps to i64 in serialization --- core/grafana-data-source/src/lib.rs | 12 +++++++----- core/grafana-data-source/src/server.rs | 5 +---- core/grafana-data-source/src/types.rs | 13 ++++++++++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index b2c0d78c8edb7..130c9570e9472 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -31,9 +31,6 @@ mod types; mod server; pub use server::run_server; -/// Re-export `Utc` from `chrono` so that it can be used in `record_metrics`. -/// -pub use chrono::Utc; type Metrics = HashMap<&'static str, Vec<(f32, i64)>>; @@ -42,13 +39,18 @@ lazy_static! { pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); } +/// Get the current unix timestamp in milliseconds. +pub fn now_millis() -> i64 { + chrono::Utc::now().timestamp_millis() +} + /// Write metrics to `METRICS`. #[macro_export] macro_rules! record_metrics( ($($key:expr => $value:expr),*) => { - use $crate::{Utc, METRICS}; + use $crate::{METRICS, now_millis}; let mut metrics = METRICS.write(); - let now = Utc::now().timestamp_millis(); + let now = now_millis(); $( metrics.entry($key).or_insert_with(Vec::new).push(($value as f32, now)); )* diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 2ab439bc60ea5..4a7cbb55399a0 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -37,16 +37,13 @@ fn api_response(req: Request) -> ResponseFuture { map_request_to_response(req, |req: QueryRequest| { let metrics = METRICS.read(); - let to = req.range.to.timestamp_millis(); - let from = req.range.from.timestamp_millis(); - // Return timeseries data related to the specified metrics req.targets.iter() .map(|target| { let datapoints = metrics.get(target.target.as_str()).iter() .flat_map(|&vec| vec) .cloned() - .filter(|&(_, timestamp)| from <= timestamp && timestamp <= to) + .filter(|&(_, timestamp)| req.range.from <= timestamp && timestamp <= req.range.to) .collect(); TimeseriesData { diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index ab98eb7455b83..a489585c2f97d 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -15,7 +15,6 @@ // along with Substrate. If not, see . use serde::{Serialize, Deserialize}; -use chrono::{DateTime, Utc}; #[derive(Serialize, Deserialize)] pub enum TargetType { @@ -48,8 +47,16 @@ pub struct Target { #[derive(Serialize, Deserialize)] pub struct Range { - pub from: DateTime, - pub to: DateTime, + #[serde(deserialize_with = "date_to_timestamp_ms")] + pub from: i64, + #[serde(deserialize_with = "date_to_timestamp_ms")] + pub to: i64, +} + +// Deserialize a timestamp via a `DateTime` +fn date_to_timestamp_ms<'de, D: serde::Deserializer<'de>>(timestamp: D) -> Result { + Deserialize::deserialize(timestamp) + .map(|date: chrono::DateTime| date.timestamp_millis()) } #[derive(Serialize, Deserialize)] From 0815876dd3516c4f8902ffdf70f40e1afadfae02 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Oct 2019 23:19:51 +1300 Subject: [PATCH 10/29] Fix license date --- core/grafana-data-source/src/server.rs | 2 +- core/grafana-data-source/src/types.rs | 2 +- core/grafana-data-source/test/src/main.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 4a7cbb55399a0..c683f3fc6eafe 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index a489585c2f97d..174d0b38577d3 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index e7ebde8643bab..e9c01f18ebb1e 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify From 05b92b7202caa83c484ec6cdd7da193c8b4f7e67 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 26 Oct 2019 00:12:59 +1300 Subject: [PATCH 11/29] Binary sort to find selection range for metrics --- core/grafana-data-source/src/server.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index c683f3fc6eafe..405501397a42c 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -40,11 +40,16 @@ fn api_response(req: Request) -> ResponseFuture { // Return timeseries data related to the specified metrics req.targets.iter() .map(|target| { - let datapoints = metrics.get(target.target.as_str()).iter() - .flat_map(|&vec| vec) - .cloned() - .filter(|&(_, timestamp)| req.range.from <= timestamp && timestamp <= req.range.to) - .collect(); + let datapoints = metrics.get(target.target.as_str()) + .map(|metric| { + let from = metric.binary_search_by_key(&req.range.from, |&(_, t)| t) + .unwrap_or_else(|i| i); + let to = metric.binary_search_by_key(&req.range.to, |&(_, t)| t) + .unwrap_or_else(|i| i); + + metric[from .. to].to_vec() + }) + .unwrap_or_else(Vec::new); TimeseriesData { target: target.target.clone(), datapoints From 003613ec8cedca39ab2f77d759467bca721639ba Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 26 Oct 2019 13:36:46 +1300 Subject: [PATCH 12/29] Obey maxDataPoints --- core/grafana-data-source/src/server.rs | 29 ++++++++++++++++++++++++-- core/grafana-data-source/src/types.rs | 5 ++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 405501397a42c..e2441ebb5b72e 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -46,8 +46,16 @@ fn api_response(req: Request) -> ResponseFuture { .unwrap_or_else(|i| i); let to = metric.binary_search_by_key(&req.range.to, |&(_, t)| t) .unwrap_or_else(|i| i); - - metric[from .. to].to_vec() + + let metric = &metric[from .. to]; + + if metric.len() > req.max_datapoints { + // Avoid returning more than `max_datapoints` (mostly to stop + // the web browser from having to do a ton of work) + select_points(metric, req.max_datapoints) + } else { + metric.to_vec() + } }) .unwrap_or_else(Vec::new); @@ -96,3 +104,20 @@ pub fn run_server(address: &std::net::SocketAddr, shutdown: F) -> impl Future .with_graceful_shutdown(shutdown) .map_err(|e| eprintln!("server error: {}", e)) } + +// Evenly select `num_points` points from a slice +fn select_points(slice: &[T], num_points: usize) -> Vec { + (0 .. num_points - 1) + .map(|i| slice[i * slice.len() / (num_points - 1)]) + .chain(slice.last().cloned()) + .collect() +} + +#[test] +fn test_select_points() { + let array = [1, 2, 3, 4, 5]; + assert_eq!(select_points(&array, 2), vec![1, 5]); + assert_eq!(select_points(&array, 3), vec![1, 3, 5]); + assert_eq!(select_points(&array, 4), vec![1, 2, 4, 5]); + assert_eq!(select_points(&array, 5), vec![1, 2, 3, 4, 5]); +} diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index 174d0b38577d3..f105e3eea76f0 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -30,10 +30,9 @@ pub struct SearchRequest { } #[derive(Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] pub struct QueryRequest { - interval_ms: u64, - max_data_points: u64, + #[serde(rename = "maxDataPoints")] + pub max_datapoints: usize, pub targets: Vec, pub range: Range, } From de23d0c39cb5e4cf0d1ca2ab7c1c7f2cab658265 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sun, 27 Oct 2019 17:01:22 +1300 Subject: [PATCH 13/29] Run a cleaning future --- Cargo.lock | 11 ++++ core/grafana-data-source/Cargo.toml | 2 + core/grafana-data-source/src/lib.rs | 7 +-- core/grafana-data-source/src/server.rs | 71 +++++++++++++---------- core/grafana-data-source/src/types.rs | 21 +------ core/grafana-data-source/src/util.rs | 43 ++++++++++++++ core/grafana-data-source/test/src/main.rs | 15 ++++- 7 files changed, 116 insertions(+), 54 deletions(-) create mode 100644 core/grafana-data-source/src/util.rs diff --git a/Cargo.lock b/Cargo.lock index 3d18a591fe3c0..ab08f697e58a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1156,6 +1156,8 @@ dependencies = [ "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "stream-cancel 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4626,6 +4628,14 @@ name = "static_slice" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "stream-cancel" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "stream-cipher" version = "0.3.2" @@ -7169,6 +7179,7 @@ dependencies = [ "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "92a7e0c5e3dfb52e8fbe0e63a1b947bbb17b4036408b151353c4491374931362" +"checksum stream-cancel 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d62fea0968935ec8eedcf671b2738bf49c58e133db968097c301d32e32eaedf" "checksum stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml index 8770b81ad2112..856513e047180 100644 --- a/core/grafana-data-source/Cargo.toml +++ b/core/grafana-data-source/Cargo.toml @@ -14,3 +14,5 @@ serde = { version = "1", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } lazy_static = "1.4" parking_lot = "0.9" +tokio-timer = "0.2" +stream-cancel = "0.4" \ No newline at end of file diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index d095d971666bd..a03f57565522b 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -29,8 +29,10 @@ use parking_lot::RwLock; mod types; mod server; +mod util; pub use server::run_server; +pub use util::now_millis; type Metrics = HashMap<&'static str, Vec<(f32, i64)>>; @@ -39,11 +41,6 @@ lazy_static! { pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); } -/// Get the current unix timestamp in milliseconds. -pub fn now_millis() -> i64 { - chrono::Utc::now().timestamp_millis() -} - /// Write metrics to `METRICS`. #[macro_export] macro_rules! record_metrics( diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index e2441ebb5b72e..b599728d78402 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -17,7 +17,9 @@ use serde::{Serialize, de::DeserializeOwned}; use hyper::{Body, Request, Response, header, service::service_fn, Server}; use futures::{future, Future, stream::Stream}; -use crate::{METRICS, types::{SearchRequest, QueryRequest, TimeseriesData}}; +use chrono::{Duration, Utc}; +use stream_cancel::StreamExt; +use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; type GenericError = Box; type ResponseFuture = Box, Error=GenericError> + Send>; @@ -25,34 +27,32 @@ type ResponseFuture = Box, Error=GenericError> + fn api_response(req: Request) -> ResponseFuture { match req.uri().path() { "/" => Box::new(future::ok(Response::new(Body::empty()))), - "/search" => map_request_to_response(req, |req: SearchRequest| { - // Filter and return metrics relating to the search term + "/search" => map_request_to_response(req, |target: Target| { + // Filter and return metrics relating to the target METRICS.read() .keys() - .filter(|key| key.starts_with(&req.target)) + .filter(|key| key.starts_with(&target.target)) .cloned() .collect::>() }), "/query" => { - map_request_to_response(req, |req: QueryRequest| { + map_request_to_response(req, |query: Query| { let metrics = METRICS.read(); // Return timeseries data related to the specified metrics - req.targets.iter() + query.targets.iter() .map(|target| { let datapoints = metrics.get(target.target.as_str()) .map(|metric| { - let from = metric.binary_search_by_key(&req.range.from, |&(_, t)| t) - .unwrap_or_else(|i| i); - let to = metric.binary_search_by_key(&req.range.to, |&(_, t)| t) - .unwrap_or_else(|i| i); + let from = util::find_index(&metric, query.range.from); + let to = util::find_index(&metric, query.range.to); let metric = &metric[from .. to]; - if metric.len() > req.max_datapoints { + if metric.len() > query.max_datapoints { // Avoid returning more than `max_datapoints` (mostly to stop // the web browser from having to do a ton of work) - select_points(metric, req.max_datapoints) + util::select_points(metric, query.max_datapoints) } else { metric.to_vec() } @@ -97,27 +97,38 @@ fn map_request_to_response(req: Request, transformation: T) - /// /// The server shuts down cleanly when `shutdown` resolves. pub fn run_server(address: &std::net::SocketAddr, shutdown: F) -> impl Future - where F: Future + where F: Future + Clone { Server::bind(address) .serve(|| service_fn(api_response)) - .with_graceful_shutdown(shutdown) - .map_err(|e| eprintln!("server error: {}", e)) + .with_graceful_shutdown(shutdown.clone()) + .map_err(|_| ()) + // Clean up week-old metrics once a day + .join(clean_up(Duration::days(1), Duration::weeks(1), shutdown)) + .map(|_| ()) } -// Evenly select `num_points` points from a slice -fn select_points(slice: &[T], num_points: usize) -> Vec { - (0 .. num_points - 1) - .map(|i| slice[i * slice.len() / (num_points - 1)]) - .chain(slice.last().cloned()) - .collect() -} +// Remove all metrics before a certain duration every so often. +fn clean_up(every: Duration, before: Duration, exit: F) -> impl Future + where F: Future +{ + tokio_timer::Interval::new_interval(every.to_std().unwrap()) + .take_until(exit) + .for_each(move |_| { + let oldest_allowed = (Utc::now() - before).timestamp_millis(); -#[test] -fn test_select_points() { - let array = [1, 2, 3, 4, 5]; - assert_eq!(select_points(&array, 2), vec![1, 5]); - assert_eq!(select_points(&array, 3), vec![1, 3, 5]); - assert_eq!(select_points(&array, 4), vec![1, 2, 4, 5]); - assert_eq!(select_points(&array, 5), vec![1, 2, 3, 4, 5]); -} + let mut metrics = METRICS.write(); + + for metric in metrics.values_mut() { + // Find the index of the oldest allowed timestamp and cut out all those before it. + let index = util::find_index(&metric, oldest_allowed); + + if index > 0 { + *metric = metric[index..].to_vec(); + } + } + + futures::future::ok(()) + }) + .map_err(|_| ()) +} \ No newline at end of file diff --git a/core/grafana-data-source/src/types.rs b/core/grafana-data-source/src/types.rs index f105e3eea76f0..773fcb652d5dc 100644 --- a/core/grafana-data-source/src/types.rs +++ b/core/grafana-data-source/src/types.rs @@ -17,33 +17,18 @@ use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize)] -pub enum TargetType { - #[serde(rename = "timeseries")] - Timeseries, - #[serde(rename = "table")] - Table -} - -#[derive(Serialize, Deserialize)] -pub struct SearchRequest { - pub target: String +pub struct Target { + pub target: String, } #[derive(Serialize, Deserialize)] -pub struct QueryRequest { +pub struct Query { #[serde(rename = "maxDataPoints")] pub max_datapoints: usize, pub targets: Vec, pub range: Range, } -#[derive(Serialize, Deserialize)] -pub struct Target { - pub target: String, - #[serde(rename = "type")] - target_type: TargetType, -} - #[derive(Serialize, Deserialize)] pub struct Range { #[serde(deserialize_with = "date_to_timestamp_ms")] diff --git a/core/grafana-data-source/src/util.rs b/core/grafana-data-source/src/util.rs new file mode 100644 index 0000000000000..52e25e39236b7 --- /dev/null +++ b/core/grafana-data-source/src/util.rs @@ -0,0 +1,43 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +/// Get the current unix timestamp in milliseconds. +pub fn now_millis() -> i64 { + chrono::Utc::now().timestamp_millis() +} + +// find the index of a timestamp +pub fn find_index(slice: &[(f32, i64)], timestamp: i64) -> usize { + slice.binary_search_by_key(×tamp, |&(_, timestamp)| timestamp) + .unwrap_or_else(|index| index) +} + +// Evenly select `num_points` points from a slice +pub fn select_points(slice: &[T], num_points: usize) -> Vec { + (0 .. num_points - 1) + .map(|i| slice[i * slice.len() / (num_points - 1)]) + .chain(slice.last().cloned()) + .collect() +} + +#[test] +fn test_select_points() { + let array = [1, 2, 3, 4, 5]; + assert_eq!(select_points(&array, 2), vec![1, 5]); + assert_eq!(select_points(&array, 3), vec![1, 3, 5]); + assert_eq!(select_points(&array, 4), vec![1, 2, 4, 5]); + assert_eq!(select_points(&array, 5), vec![1, 2, 3, 4, 5]); +} \ No newline at end of file diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index e9c01f18ebb1e..e34bdfdfe9f72 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -18,6 +18,19 @@ use grafana_data_source::{run_server, record_metrics}; use std::{thread::{spawn, sleep}, time::Duration}; use rand::Rng; +// futures::future::empty is not cloneable. +#[derive(Clone)] +struct EmptyFuture; + +impl futures::Future for EmptyFuture { + type Item = (); + type Error = (); + + fn poll(&mut self) -> futures::Poll<(), ()> { + Ok(futures::Async::NotReady) + } +} + fn main() { let handle = spawn(|| { let mut rng = rand::thread_rng(); @@ -31,6 +44,6 @@ fn main() { sleep(Duration::from_secs(1)); } }); - hyper::rt::run(run_server(&"127.0.0.1:9955".parse().unwrap(), futures::future::empty())); + hyper::rt::run(run_server(&"127.0.0.1:9955".parse().unwrap(), EmptyFuture)); handle.join().unwrap(); } From 1d4b25d095c10e8aa73c557f2b731363e1b76779 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sun, 27 Oct 2019 17:06:36 +1300 Subject: [PATCH 14/29] Newlines at EOF --- core/grafana-data-source/Cargo.toml | 2 +- core/grafana-data-source/src/server.rs | 2 +- core/grafana-data-source/src/util.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml index 856513e047180..85e52dfb8d803 100644 --- a/core/grafana-data-source/Cargo.toml +++ b/core/grafana-data-source/Cargo.toml @@ -15,4 +15,4 @@ chrono = { version = "0.4", features = ["serde"] } lazy_static = "1.4" parking_lot = "0.9" tokio-timer = "0.2" -stream-cancel = "0.4" \ No newline at end of file +stream-cancel = "0.4" diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index b599728d78402..df570e24bfd7e 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -131,4 +131,4 @@ fn clean_up(every: Duration, before: Duration, exit: F) -> impl Future Date: Mon, 28 Oct 2019 22:54:25 +0000 Subject: [PATCH 15/29] Update core/service/Cargo.toml Co-Authored-By: Pierre Krieger --- core/service/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml index 76c02f519ee42..2e7f1ca0f5df4 100644 --- a/core/service/Cargo.toml +++ b/core/service/Cargo.toml @@ -38,7 +38,6 @@ rpc = { package = "substrate-rpc", path = "../../core/rpc" } tel = { package = "substrate-telemetry", path = "../../core/telemetry" } offchain = { package = "substrate-offchain", path = "../../core/offchain" } parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } -authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../authority-discovery/primitives", default-features = false } grafana-data-source = { path = "../grafana-data-source" } [dev-dependencies] From e700971fc7867f37c77aa5f382b1f42a6f1b67fe Mon Sep 17 00:00:00 2001 From: Ashley Date: Mon, 28 Oct 2019 22:54:43 +0000 Subject: [PATCH 16/29] Update core/grafana-data-source/src/lib.rs Co-Authored-By: Pierre Krieger --- core/grafana-data-source/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index a03f57565522b..e288189c14411 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -38,6 +38,7 @@ type Metrics = HashMap<&'static str, Vec<(f32, i64)>>; lazy_static! { /// The `RwLock` wrapping the metrics. Not intended to be used directly. + #[doc(hidden)] pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); } From db7a7117a81bfd9ddbe2e9ed7e20c8d4d0f1df63 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 29 Oct 2019 12:03:20 +1300 Subject: [PATCH 17/29] Fix indentation --- core/grafana-data-source/src/lib.rs | 4 ++-- core/grafana-data-source/test/src/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/grafana-data-source/src/lib.rs b/core/grafana-data-source/src/lib.rs index e288189c14411..f1bdb9e373464 100644 --- a/core/grafana-data-source/src/lib.rs +++ b/core/grafana-data-source/src/lib.rs @@ -38,8 +38,8 @@ type Metrics = HashMap<&'static str, Vec<(f32, i64)>>; lazy_static! { /// The `RwLock` wrapping the metrics. Not intended to be used directly. - #[doc(hidden)] - pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); + #[doc(hidden)] + pub static ref METRICS: RwLock = RwLock::new(Metrics::new()); } /// Write metrics to `METRICS`. diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index e34bdfdfe9f72..cb24fa4145028 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -38,9 +38,9 @@ fn main() { loop { let random = rng.gen_range(0.0, 1000.0); record_metrics!( - "random data" => random, - "random^2" => random * random - ); + "random data" => random, + "random^2" => random * random + ); sleep(Duration::from_secs(1)); } }); From b314fb2369a9c02fd7a8de081c9f13da973574ef Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 29 Oct 2019 12:29:30 +1300 Subject: [PATCH 18/29] Improve select_points --- core/grafana-data-source/src/server.rs | 12 +++--------- core/grafana-data-source/src/util.rs | 11 ++++++++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index df570e24bfd7e..85cb774c24279 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -47,15 +47,9 @@ fn api_response(req: Request) -> ResponseFuture { let from = util::find_index(&metric, query.range.from); let to = util::find_index(&metric, query.range.to); - let metric = &metric[from .. to]; - - if metric.len() > query.max_datapoints { - // Avoid returning more than `max_datapoints` (mostly to stop - // the web browser from having to do a ton of work) - util::select_points(metric, query.max_datapoints) - } else { - metric.to_vec() - } + // Avoid returning more than `max_datapoints` (mostly to stop + // the web browser from having to do a ton of work) + util::select_points(&metric[from .. to], query.max_datapoints) }) .unwrap_or_else(Vec::new); diff --git a/core/grafana-data-source/src/util.rs b/core/grafana-data-source/src/util.rs index e55fdd166d5c4..cd27c440f7ded 100644 --- a/core/grafana-data-source/src/util.rs +++ b/core/grafana-data-source/src/util.rs @@ -25,8 +25,14 @@ pub fn find_index(slice: &[(f32, i64)], timestamp: i64) -> usize { .unwrap_or_else(|index| index) } -// Evenly select `num_points` points from a slice +// Evenly select up to `num_points` points from a slice pub fn select_points(slice: &[T], num_points: usize) -> Vec { + if num_points == 0 { + return Vec::new(); + } else if num_points >= slice.len() { + return slice.to_owned(); + } + (0 .. num_points - 1) .map(|i| slice[i * slice.len() / (num_points - 1)]) .chain(slice.last().cloned()) @@ -36,8 +42,11 @@ pub fn select_points(slice: &[T], num_points: usize) -> Vec { #[test] fn test_select_points() { let array = [1, 2, 3, 4, 5]; + assert_eq!(select_points(&array, 0), Vec::::new()); + assert_eq!(select_points(&array, 1), vec![5]); assert_eq!(select_points(&array, 2), vec![1, 5]); assert_eq!(select_points(&array, 3), vec![1, 3, 5]); assert_eq!(select_points(&array, 4), vec![1, 2, 4, 5]); assert_eq!(select_points(&array, 5), vec![1, 2, 3, 4, 5]); + assert_eq!(select_points(&array, 6), vec![1, 2, 3, 4, 5]); } From 02a695d9de4287958ce51b3e94dfdb836630fb03 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sun, 3 Nov 2019 17:10:50 +1300 Subject: [PATCH 19/29] Made test more accurate --- Cargo.lock | 3 +- core/grafana-data-source/Cargo.toml | 1 - core/grafana-data-source/src/server.rs | 13 ++---- core/grafana-data-source/test/Cargo.toml | 3 ++ core/grafana-data-source/test/src/main.rs | 56 +++++++++++++++++------ 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ffb357f26ac25..c90f03568a491 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1400,7 +1400,6 @@ dependencies = [ "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", - "stream-cancel 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1413,6 +1412,8 @@ dependencies = [ "grafana-data-source 2.0.0", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "stream-cancel 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml index 85e52dfb8d803..d4dbb4870ed12 100644 --- a/core/grafana-data-source/Cargo.toml +++ b/core/grafana-data-source/Cargo.toml @@ -15,4 +15,3 @@ chrono = { version = "0.4", features = ["serde"] } lazy_static = "1.4" parking_lot = "0.9" tokio-timer = "0.2" -stream-cancel = "0.4" diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 85cb774c24279..c2e174a1fcac8 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -18,7 +18,6 @@ use serde::{Serialize, de::DeserializeOwned}; use hyper::{Body, Request, Response, header, service::service_fn, Server}; use futures::{future, Future, stream::Stream}; use chrono::{Duration, Utc}; -use stream_cancel::StreamExt; use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; type GenericError = Box; @@ -91,23 +90,21 @@ fn map_request_to_response(req: Request, transformation: T) - /// /// The server shuts down cleanly when `shutdown` resolves. pub fn run_server(address: &std::net::SocketAddr, shutdown: F) -> impl Future - where F: Future + Clone + where F: Future { Server::bind(address) .serve(|| service_fn(api_response)) - .with_graceful_shutdown(shutdown.clone()) + .with_graceful_shutdown(shutdown) .map_err(|_| ()) // Clean up week-old metrics once a day - .join(clean_up(Duration::days(1), Duration::weeks(1), shutdown)) + .select(clean_up(Duration::days(1), Duration::weeks(1))) .map(|_| ()) + .map_err(|_| ()) } // Remove all metrics before a certain duration every so often. -fn clean_up(every: Duration, before: Duration, exit: F) -> impl Future - where F: Future -{ +fn clean_up(every: Duration, before: Duration) -> impl Future { tokio_timer::Interval::new_interval(every.to_std().unwrap()) - .take_until(exit) .for_each(move |_| { let oldest_allowed = (Utc::now() - before).timestamp_millis(); diff --git a/core/grafana-data-source/test/Cargo.toml b/core/grafana-data-source/test/Cargo.toml index c299d867a1330..3747385342453 100644 --- a/core/grafana-data-source/test/Cargo.toml +++ b/core/grafana-data-source/test/Cargo.toml @@ -11,3 +11,6 @@ hyper = "0.12" grafana-data-source = { path = ".." } rand = "0.7" futures = "0.1" +ctrlc = "3.1" +tokio = "0.1" +stream-cancel = "0.4" diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index cb24fa4145028..ad083bc0c732b 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -15,35 +15,61 @@ // along with Substrate. If not, see . use grafana_data_source::{run_server, record_metrics}; -use std::{thread::{spawn, sleep}, time::Duration}; +use std::{time::Duration, sync::atomic::{AtomicBool, Ordering}}; use rand::Rng; +use futures::{Async, Future, Stream}; +use stream_cancel::StreamExt; +use tokio::{runtime::Runtime, timer::Interval}; -// futures::future::empty is not cloneable. -#[derive(Clone)] -struct EmptyFuture; +static EXIT: AtomicBool = AtomicBool::new(false); -impl futures::Future for EmptyFuture { +struct ExitFuture; + +impl futures::Future for ExitFuture { type Item = (); type Error = (); fn poll(&mut self) -> futures::Poll<(), ()> { - Ok(futures::Async::NotReady) + let value = EXIT.load(Ordering::Relaxed); + + println!("Polling, got: {}", value); + + if value { + Ok(Async::Ready(())) + } else { + Ok(Async::NotReady) + } } } fn main() { - let handle = spawn(|| { - let mut rng = rand::thread_rng(); + ctrlc::set_handler(|| { + println!(" - Ctrl-C received"); + EXIT.store(true, Ordering::Relaxed); + }).unwrap(); + + let address = "127.0.0.1:9955".parse().unwrap(); - loop { - let random = rng.gen_range(0.0, 1000.0); + let randomness_future = Interval::new_interval(Duration::from_secs(1)) + .take_until(ExitFuture) + .for_each(move |_| { + let random = rand::thread_rng().gen_range(0.0, 1000.0); record_metrics!( "random data" => random, "random^2" => random * random ); - sleep(Duration::from_secs(1)); - } - }); - hyper::rt::run(run_server(&"127.0.0.1:9955".parse().unwrap(), EmptyFuture)); - handle.join().unwrap(); + futures::future::ok(()) + }) + .map_err(|_| ()) + .map(|_| println!("Shutting down randomness future")); + + let server_future = run_server(&address, ExitFuture) + .map(|_| println!("Shutting down server future")); + + let mut rt = Runtime::new().unwrap(); + + rt.spawn(randomness_future); + rt.spawn(server_future); + + rt.shutdown_on_idle().wait().unwrap(); } From df13752546f8de7a10c24782f6d2b0b0d62a54eb Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 7 Nov 2019 13:57:35 +1300 Subject: [PATCH 20/29] Inprogress --- Cargo.lock | 417 +++++++++++++++++++++- core/grafana-data-source/Cargo.toml | 8 +- core/grafana-data-source/src/server.rs | 134 +++---- core/grafana-data-source/test/Cargo.toml | 6 +- core/grafana-data-source/test/src/main.rs | 69 ++-- core/service/src/builder.rs | 2 +- 6 files changed, 518 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c90f03568a491..eb47d1e939b99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1211,6 +1211,29 @@ name = "futures" version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-channel" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-channel-preview" version = "0.3.0-alpha.19" @@ -1220,6 +1243,11 @@ dependencies = [ "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-core-preview" version = "0.3.0-alpha.19" @@ -1234,6 +1262,16 @@ dependencies = [ "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-executor" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-executor-preview" version = "0.3.0-alpha.19" @@ -1244,11 +1282,27 @@ dependencies = [ "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-io" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-io-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-preview" version = "0.3.0-alpha.19" @@ -1262,11 +1316,21 @@ dependencies = [ "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-sink" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-sink-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-task" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-timer" version = "0.4.0" @@ -1277,6 +1341,33 @@ dependencies = [ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-timer" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-util" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-macro 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-util-preview" version = "0.3.0-alpha.19" @@ -1394,13 +1485,15 @@ name = "grafana-data-source" version = "2.0.0" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.13.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1408,12 +1501,10 @@ name = "grafana-data-source-test" version = "2.0.0" dependencies = [ "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "grafana-data-source 2.0.0", - "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "stream-cancel 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1433,6 +1524,26 @@ dependencies = [ "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "h2" +version = "0.2.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "indexmap 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hash-db" version = "0.15.2" @@ -1567,6 +1678,15 @@ dependencies = [ "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "http-body" +version = "0.2.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "httparse" version = "1.3.4" @@ -1627,6 +1747,36 @@ dependencies = [ "want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hyper" +version = "0.13.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "h2 0.2.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "http-body 0.2.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-net 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.3.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tower-make 0.3.0-alpha.2a (registry+https://github.com/rust-lang/crates.io-index)", + "tower-service 0.3.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", + "want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hyper-tls" version = "0.3.2" @@ -1914,6 +2064,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "lazycell" @@ -3271,6 +3424,24 @@ dependencies = [ "fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pin-project" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "pin-project-internal 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pin-utils" version = "0.1.0-alpha.4" @@ -3351,6 +3522,11 @@ dependencies = [ "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro-nested" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "proc-macro2" version = "0.4.30" @@ -5024,14 +5200,6 @@ name = "static_slice" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "stream-cancel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "stream-cipher" version = "0.3.2" @@ -6426,6 +6594,27 @@ dependencies = [ "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-fs 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-macros 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-net 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.3.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-buf" version = "0.1.1" @@ -6446,6 +6635,18 @@ dependencies = [ "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-codec" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-current-thread" version = "0.1.6" @@ -6475,6 +6676,24 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-executor" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-fs" version = "0.1.6" @@ -6485,6 +6704,19 @@ dependencies = [ "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-fs" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-io" version = "0.1.12" @@ -6495,6 +6727,52 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-io" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-macros" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-net" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-reactor" version = "0.1.10" @@ -6535,6 +6813,17 @@ dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-sync" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-tcp" version = "0.1.3" @@ -6575,6 +6864,19 @@ dependencies = [ "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-timer" +version = "0.3.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-tls" version = "0.2.1" @@ -6624,6 +6926,50 @@ dependencies = [ "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tower-make" +version = "0.3.0-alpha.2a" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tower-service 0.3.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tower-service" +version = "0.3.0-alpha.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "tracing" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing-attributes 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tracing-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tracing-core" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "traitobject" version = "0.1.0" @@ -6905,6 +7251,15 @@ dependencies = [ "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wasi" version = "0.7.0" @@ -7484,14 +7839,24 @@ dependencies = [ "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" +"checksum futures 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98fcd817da24593c8e88e1be8a8d7371d87f777285b9324634e4f05d2c1dc266" +"checksum futures-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f9d78ee44e3067fa297c8c2c2313b98d014be8a3783387c500b50d7b769603" "checksum futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e5f4df964fa9c1c2f8bddeb5c3611631cacd93baf810fc8bb2fb4b495c263a" +"checksum futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30f0ab78f035d7ed5d52689f4b05a56c15ad80097f1d860e644bdc9dba3831f2" "checksum futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" +"checksum futures-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e36969e0468b1725a2db2930039be052459f40a8aa00070c02de8ceb3673c100" "checksum futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "75236e88bd9fe88e5e8bfcd175b665d0528fe03ca4c5207fabc028c8f9d93e98" +"checksum futures-io 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3376fa54783931f5d59e44ff3b95ff9762ba191674bf23c0e16cdcf1faf49b99" "checksum futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "f4914ae450db1921a56c91bde97a27846287d062087d4a652efc09bb3a01ebda" +"checksum futures-macro 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c97ef88dd44b07643c0667d3cfdac3bb6d8ca96940df755934e0c94047d1ac" "checksum futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3b1dce2a0267ada5c6ff75a8ba864b4e679a9e2aa44262af7a3b5516d530d76e" +"checksum futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "346db18b3daf3e81f94023cd628230a01f34b1e64c5849f2a8308e678e1a21de" "checksum futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "86f148ef6b69f75bb610d4f9a2336d4fc88c4b5b67129d1a340dd0fd362efeec" +"checksum futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4ace133f7db73ad31e358cf07b495e45dd767c552f321602b8158da059359a2" "checksum futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33" +"checksum futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7946248e9429ff093345d3e8fdf4eb0f9b2d79091611c9c14f744971a6f8be45" +"checksum futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef4c1d6c4ceb5fcff9e8d84d76bc20ed918c61d64fe68325c0c3b611b3d9cffe" "checksum futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce968633c17e5f97936bd2797b6e38fb56cf16a7422319f7ec2e30d3c470e8d" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" @@ -7505,6 +7870,7 @@ dependencies = [ "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" "checksum goblin 0.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "e3fa261d919c1ae9d1e4533c4a2f99e10938603c4208d56c05bec7a872b661b0" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" +"checksum h2 0.2.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0f107db1419ef8271686187b1a5d47c6431af4a7f4d98b495e7b7fc249bb0a78" "checksum hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d23bd4e7b5eda0d0f3a307e8b381fdc8ba9000f26fbe912250c0a4cc3956364a" "checksum hash256-std-hasher 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "92c171d55b98633f4ed3860808f004099b36c1cc29c42cfc53aa8591b21efcf2" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" @@ -7521,10 +7887,12 @@ dependencies = [ "checksum hmac-drbg 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6e570451493f10f6581b48cdd530413b63ea9e780f544bfd3bdcaa0d89d1a7b" "checksum http 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e06e336150b178206af098a055e3621e8336027e2b4d126bda0bc64824baaf" "checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" +"checksum http-body 0.2.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1f3aef6f3de2bd8585f5b366f3f550b5774500b4764d00cf00f903c95749eec3" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" "checksum hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" "checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" +"checksum hyper 0.13.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2d05aa523087ac0b9d8b93dd80d5d482a697308ed3b0dca7b0667511a7fa7cdc" "checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" @@ -7654,6 +8022,8 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" +"checksum pin-project 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c5fce7042b4e4338a3f868e563fff394709c3ff62cf6908d407dd9e2caff96ed" +"checksum pin-project-internal 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7644b4721cc27235f667e735da8732f5b781c442157315674c0cb7f28b4cabf3" "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" @@ -7664,6 +8034,7 @@ dependencies = [ "checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" "checksum proc-macro-error 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" "checksum proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "114cdf1f426eb7f550f01af5f53a33c0946156f6814aec939b3bd77e844f9a9d" +"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" "checksum prost 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96d14b1c185652833d24aaad41c5832b0be5616a590227c1fbff57c616754b23" @@ -7760,7 +8131,6 @@ dependencies = [ "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "92a7e0c5e3dfb52e8fbe0e63a1b947bbb17b4036408b151353c4491374931362" -"checksum stream-cancel 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d62fea0968935ec8eedcf671b2738bf49c58e133db968097c301d32e32eaedf" "checksum stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum string-interner 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd710eadff449a1531351b0e43eb81ea404336fa2f56c777427ab0e32a4cf183" @@ -7793,23 +8163,37 @@ dependencies = [ "checksum tiny-keccak 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" "checksum tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4574b75faccaacddb9b284faecdf0b544b80b6b294f3d062d325c5726a209c20" "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" +"checksum tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1f17f5d6ab0f35c1506678b28fb1798bdf74fcb737e9843c7b17b73e426eba38" "checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" +"checksum tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9f5d22fd1e84bd4045d28813491cb7d7caae34d45c80517c2213f09a85e8787a" "checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "82c65483db54eb91b4ef3a9389a3364558590faf30ce473141707c0e16fda975" "checksum tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f27ee0e6db01c5f0b2973824547ce7e637b2ed79b891a9677b0de9bd532b6ac" +"checksum tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9ee9ceecf69145923834ea73f32ba40c790fd877b74a7817dd0b089f1eb9c7c8" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" +"checksum tokio-fs 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bf85e16971e06e680c622e0c1b455be94b086275c5ddcd6d4a83a2bfbb83cda" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" +"checksum tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "112784d5543df30660b04a72ca423bfbd90e8bb32f94dcf610f15401218b22c5" +"checksum tokio-macros 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "86b616374bcdadd95974e1f0dfca07dc913f1163c53840c0d664aca35114964e" +"checksum tokio-net 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a441682cd32f3559383112c4a7f372f5c9fa1950c5cf8c8dd05274a2ce8c2654" "checksum tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c56391be9805bc80163151c0b9e5164ee64f4b0200962c346fea12773158f22d" "checksum tokio-rustls 0.10.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e5cebc3ca33110e460c4d2e7c5e863b159fadcbf125449d896720695b2af709" "checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" +"checksum tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4f1aaeb685540f7407ea0e27f1c9757d258c7c6bf4e3eb19da6fc59b747239d2" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" +"checksum tokio-timer 0.3.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b97c1587fe71018eb245a4a9daa13a5a3b681bbc1f7fdadfe24720e141472c13" "checksum tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c" "checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" "checksum toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c04dffffeac90885436d23c692517bb5b8b3f8863e4afc15023628d067d667b7" +"checksum tower-make 0.3.0-alpha.2a (registry+https://github.com/rust-lang/crates.io-index)" = "316d47dd40cde4ac5d88110eaf9a10a4e2a68612d9c056cd2aa24e37dcb484cd" +"checksum tower-service 0.3.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)" = "63ff37396cd966ce43bea418bfa339f802857495f797dafa00bea5b7221ebdfa" +"checksum tracing 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ff4e4f59e752cb3beb5b61c6d5e11191c7946231ba84faec2902c9efdd8691c5" +"checksum tracing-attributes 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a4263b12c3d3c403274493eb805966093b53214124796552d674ca1dd5d27c2b" +"checksum tracing-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bc913647c520c959b6d21e35ed8fa6984971deca9f0a2fcb8c51207e0c56af1d" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum trie-bench 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3073600c543ed001319d7e092c46dfd8c245af1a218ec5c75eb01582660a2b3e" "checksum trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0b62d27e8aa1c07414549ac872480ac82380bab39e730242ab08d82d7cc098a" @@ -7844,6 +8228,7 @@ dependencies = [ "checksum wabt-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af5d153dc96aad7dc13ab90835b892c69867948112d95299e522d370c4e13a08" "checksum walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9658c94fa8b940eab2250bd5a457f9c48b748420d71293b165c8cdbe2f55f71e" "checksum want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" +"checksum want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" "checksum wasm-bindgen 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "cd34c5ba0d228317ce388e87724633c57edca3e7531feb4e25e35aaa07a656af" "checksum wasm-bindgen-backend 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "927196b315c23eed2748442ba675a4c54a1a079d90d9bdc5ad16ce31cf90b15b" diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml index d4dbb4870ed12..b5f77c44ba9af 100644 --- a/core/grafana-data-source/Cargo.toml +++ b/core/grafana-data-source/Cargo.toml @@ -7,11 +7,13 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -hyper = "0.12" -futures = "0.1" +hyper = { version = "0.13.0-alpha.4", features = ["unstable-stream"] } +futures = "0.3" +futures-util = "0.3" serde_json = "1" serde = { version = "1", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } lazy_static = "1.4" parking_lot = "0.9" -tokio-timer = "0.2" +futures-timer = "1.0" +derive_more = "0.15" diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index c2e174a1fcac8..542ee25deb19b 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -15,25 +15,34 @@ // along with Substrate. If not, see . use serde::{Serialize, de::DeserializeOwned}; -use hyper::{Body, Request, Response, header, service::service_fn, Server}; -use futures::{future, Future, stream::Stream}; +use hyper::{Body, Request, Response, header, service::service_fn, Server, Chunk}; +use futures::{FutureExt, StreamExt, future::select}; use chrono::{Duration, Utc}; +use futures_util::stream::TryStreamExt; +use futures_timer::Delay; use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; -type GenericError = Box; -type ResponseFuture = Box, Error=GenericError> + Send>; +#[derive(Debug, derive_more::Display)] +enum Error { + Hyper(hyper::Error), + Serde(serde_json::Error), + Http(hyper::http::Error) +} + +impl std::error::Error for Error {} -fn api_response(req: Request) -> ResponseFuture { +async fn api_response(req: Request) -> Result, Error> { match req.uri().path() { - "/" => Box::new(future::ok(Response::new(Body::empty()))), - "/search" => map_request_to_response(req, |target: Target| { - // Filter and return metrics relating to the target - METRICS.read() - .keys() - .filter(|key| key.starts_with(&target.target)) - .cloned() - .collect::>() - }), + "/search" => { + map_request_to_response(req, |target: Target| { + // Filter and return metrics relating to the target + METRICS.read() + .keys() + .filter(|key| key.starts_with(&target.target)) + .cloned() + .collect::>() + }).await + }, "/query" => { map_request_to_response(req, |query: Query| { let metrics = METRICS.read(); @@ -57,69 +66,72 @@ fn api_response(req: Request) -> ResponseFuture { } }) .collect::>() - }) + }).await }, - _ => Box::new(future::ok(Response::new(Body::empty()))), + _ => Ok(Response::new(Body::empty())), } } -fn map_request_to_response(req: Request, transformation: T) -> ResponseFuture +async fn map_request_to_response(req: Request, transformation: T) -> Result, Error> where Req: DeserializeOwned, Res: Serialize, T: Fn(Req) -> Res + Send + Sync + 'static { - Box::new(req.into_body() - .concat2() - .from_err() - .and_then(move |entire_body| { - let req = serde_json::from_slice(entire_body.as_ref())?; - let res = transformation(req); - - let string = serde_json::to_string(&res)?; - - Response::builder() - .header(header::CONTENT_TYPE, "application/json") - .body(Body::from(string)) - .map_err(|e| e.into()) - }) - ) + let body = req.into_body() + .try_concat() + .await + .map_err(Error::Hyper)?; + + let req = serde_json::from_slice(body.as_ref()).map_err(Error::Serde)?; + let res = transformation(req); + let string = serde_json::to_string(&res).map_err(Error::Serde)?; + + Response::builder() + .header(header::CONTENT_TYPE, "application/json") + .body(Body::from(string)) + .map_err(Error::Http) } /// Start the data source server. -/// -/// The server shuts down cleanly when `shutdown` resolves. -pub fn run_server(address: &std::net::SocketAddr, shutdown: F) -> impl Future - where F: Future -{ - Server::bind(address) - .serve(|| service_fn(api_response)) - .with_graceful_shutdown(shutdown) - .map_err(|_| ()) - // Clean up week-old metrics once a day - .select(clean_up(Duration::days(1), Duration::weeks(1))) - .map(|_| ()) - .map_err(|_| ()) +pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Error> { + let service = hyper::service::make_service_fn(|_| { + async { + Ok::<_, Error>(service_fn(api_response)) + } + }); + + let server = Server::bind(&address) + .serve(service) + .boxed(); + + let clean = clean_up() + .boxed(); + + select(server, clean).await; + + Ok(()) } -// Remove all metrics before a certain duration every so often. -fn clean_up(every: Duration, before: Duration) -> impl Future { - tokio_timer::Interval::new_interval(every.to_std().unwrap()) - .for_each(move |_| { - let oldest_allowed = (Utc::now() - before).timestamp_millis(); +/// Periodically remove old metrics. +async fn clean_up() { + let every = Duration::days(1); + let before = Duration::weeks(1); - let mut metrics = METRICS.write(); + loop { + Delay::new(every.to_std().unwrap()).await; - for metric in metrics.values_mut() { - // Find the index of the oldest allowed timestamp and cut out all those before it. - let index = util::find_index(&metric, oldest_allowed); + let oldest_allowed = (Utc::now() - before).timestamp_millis(); - if index > 0 { - *metric = metric[index..].to_vec(); - } - } + let mut metrics = METRICS.write(); - futures::future::ok(()) - }) - .map_err(|_| ()) + for metric in metrics.values_mut() { + // Find the index of the oldest allowed timestamp and cut out all those before it. + let index = util::find_index(&metric, oldest_allowed); + + if index > 0 { + *metric = metric[index..].to_vec(); + } + } + } } diff --git a/core/grafana-data-source/test/Cargo.toml b/core/grafana-data-source/test/Cargo.toml index 3747385342453..9e23bc446948c 100644 --- a/core/grafana-data-source/test/Cargo.toml +++ b/core/grafana-data-source/test/Cargo.toml @@ -7,10 +7,8 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -hyper = "0.12" grafana-data-source = { path = ".." } +futures = "0.3" +tokio = "0.2.0-alpha.6" rand = "0.7" -futures = "0.1" ctrlc = "3.1" -tokio = "0.1" -stream-cancel = "0.4" diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index ad083bc0c732b..7c2ef914ebbb7 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -15,34 +15,49 @@ // along with Substrate. If not, see . use grafana_data_source::{run_server, record_metrics}; -use std::{time::Duration, sync::atomic::{AtomicBool, Ordering}}; +use std::{ + time::Duration, sync::atomic::{AtomicBool, Ordering}, task::{Context, Poll}, future::Future, + pin::Pin +}; use rand::Rng; -use futures::{Async, Future, Stream}; -use stream_cancel::StreamExt; -use tokio::{runtime::Runtime, timer::Interval}; +use futures::{FutureExt, future::select}; +use tokio::timer::delay_for; static EXIT: AtomicBool = AtomicBool::new(false); struct ExitFuture; -impl futures::Future for ExitFuture { - type Item = (); - type Error = (); +impl Future for ExitFuture { + type Output = (); - fn poll(&mut self) -> futures::Poll<(), ()> { - let value = EXIT.load(Ordering::Relaxed); + fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll { + let exit = EXIT.load(Ordering::Relaxed); - println!("Polling, got: {}", value); + println!("Polling, got: {}", exit); - if value { - Ok(Async::Ready(())) + if exit { + Poll::Ready(()) } else { - Ok(Async::NotReady) + Poll::Pending } } } -fn main() { +async fn randomness() { + loop { + delay_for(Duration::from_secs(1)).await; + + let random = rand::thread_rng().gen_range(0.0, 1000.0); + + record_metrics!( + "random data" => random, + "random^2" => random * random + ); + } +} + +#[tokio::main] +async fn main() -> Result<(), Box> { ctrlc::set_handler(|| { println!(" - Ctrl-C received"); EXIT.store(true, Ordering::Relaxed); @@ -50,26 +65,14 @@ fn main() { let address = "127.0.0.1:9955".parse().unwrap(); - let randomness_future = Interval::new_interval(Duration::from_secs(1)) - .take_until(ExitFuture) - .for_each(move |_| { - let random = rand::thread_rng().gen_range(0.0, 1000.0); - record_metrics!( - "random data" => random, - "random^2" => random * random - ); - futures::future::ok(()) - }) - .map_err(|_| ()) - .map(|_| println!("Shutting down randomness future")); - - let server_future = run_server(&address, ExitFuture) - .map(|_| println!("Shutting down server future")); + let server_future = run_server(address).boxed(); - let mut rt = Runtime::new().unwrap(); + let randomness_future = randomness().boxed(); - rt.spawn(randomness_future); - rt.spawn(server_future); + select( + select(randomness_future, server_future), + ExitFuture + ).await; - rt.shutdown_on_idle().wait().unwrap(); + Ok(()) } diff --git a/core/service/src/builder.rs b/core/service/src/builder.rs index b210387c367b2..9fedcaa31f5cd 100644 --- a/core/service/src/builder.rs +++ b/core/service/src/builder.rs @@ -1138,7 +1138,7 @@ ServiceBuilder< // Grafana data source if let Some(port) = config.grafana_port { let _ = to_spawn_tx.unbounded_send(Box::new( - grafana_data_source::run_server(&port, exit.clone()) + grafana_data_source::run_server(port).map_err(|_| ()).boxed().compat() )); } From 483c8946506594c3a10e6de064378ddfff9c4765 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 8 Nov 2019 15:39:46 +1300 Subject: [PATCH 21/29] Use the same futures version as hyper for now --- Cargo.lock | 57 +---------------------- core/grafana-data-source/Cargo.toml | 3 +- core/grafana-data-source/src/server.rs | 14 ++---- core/grafana-data-source/test/Cargo.toml | 2 +- core/grafana-data-source/test/src/main.rs | 2 +- 5 files changed, 10 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3478e07e89c4e..404b87bc4a181 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1202,29 +1202,6 @@ name = "futures" version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "futures" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "futures-channel" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "futures-channel-preview" version = "0.3.0-alpha.19" @@ -1253,16 +1230,6 @@ dependencies = [ "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-executor" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "futures-executor-preview" version = "0.3.0-alpha.19" @@ -1273,11 +1240,6 @@ dependencies = [ "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-io" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "futures-io-preview" version = "0.3.0-alpha.19" @@ -1307,11 +1269,6 @@ dependencies = [ "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-sink" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "futures-sink-preview" version = "0.3.0-alpha.19" @@ -1346,13 +1303,9 @@ name = "futures-util" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures-macro 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-hack 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1468,9 +1421,8 @@ version = "2.0.0" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.13.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1483,7 +1435,7 @@ name = "grafana-data-source-test" version = "2.0.0" dependencies = [ "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "grafana-data-source 2.0.0", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -7782,19 +7734,14 @@ dependencies = [ "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" -"checksum futures 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "98fcd817da24593c8e88e1be8a8d7371d87f777285b9324634e4f05d2c1dc266" -"checksum futures-channel 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f9d78ee44e3067fa297c8c2c2313b98d014be8a3783387c500b50d7b769603" "checksum futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e5f4df964fa9c1c2f8bddeb5c3611631cacd93baf810fc8bb2fb4b495c263a" "checksum futures-core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30f0ab78f035d7ed5d52689f4b05a56c15ad80097f1d860e644bdc9dba3831f2" "checksum futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" -"checksum futures-executor 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e36969e0468b1725a2db2930039be052459f40a8aa00070c02de8ceb3673c100" "checksum futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "75236e88bd9fe88e5e8bfcd175b665d0528fe03ca4c5207fabc028c8f9d93e98" -"checksum futures-io 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3376fa54783931f5d59e44ff3b95ff9762ba191674bf23c0e16cdcf1faf49b99" "checksum futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "f4914ae450db1921a56c91bde97a27846287d062087d4a652efc09bb3a01ebda" "checksum futures-macro 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7c97ef88dd44b07643c0667d3cfdac3bb6d8ca96940df755934e0c94047d1ac" "checksum futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3b1dce2a0267ada5c6ff75a8ba864b4e679a9e2aa44262af7a3b5516d530d76e" -"checksum futures-sink 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "346db18b3daf3e81f94023cd628230a01f34b1e64c5849f2a8308e678e1a21de" "checksum futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "86f148ef6b69f75bb610d4f9a2336d4fc88c4b5b67129d1a340dd0fd362efeec" "checksum futures-task 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4ace133f7db73ad31e358cf07b495e45dd767c552f321602b8158da059359a2" "checksum futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33" diff --git a/core/grafana-data-source/Cargo.toml b/core/grafana-data-source/Cargo.toml index b5f77c44ba9af..da1a6ce345353 100644 --- a/core/grafana-data-source/Cargo.toml +++ b/core/grafana-data-source/Cargo.toml @@ -8,8 +8,7 @@ edition = "2018" [dependencies] hyper = { version = "0.13.0-alpha.4", features = ["unstable-stream"] } -futures = "0.3" -futures-util = "0.3" +futures-util-preview = "=0.3.0-alpha.19" serde_json = "1" serde = { version = "1", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 542ee25deb19b..0c16ffd7c1bb0 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -15,10 +15,9 @@ // along with Substrate. If not, see . use serde::{Serialize, de::DeserializeOwned}; -use hyper::{Body, Request, Response, header, service::service_fn, Server, Chunk}; -use futures::{FutureExt, StreamExt, future::select}; +use hyper::{Body, Request, Response, header, service::{service_fn, make_service_fn}, Server}; use chrono::{Duration, Utc}; -use futures_util::stream::TryStreamExt; +use futures_util::{TryStreamExt, FutureExt, future::select}; use futures_timer::Delay; use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; @@ -95,7 +94,7 @@ async fn map_request_to_response(req: Request, transformation /// Start the data source server. pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Error> { - let service = hyper::service::make_service_fn(|_| { + let service = make_service_fn(|_| { async { Ok::<_, Error>(service_fn(api_response)) } @@ -105,7 +104,7 @@ pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Erro .serve(service) .boxed(); - let clean = clean_up() + let clean = clean_up(Duration::days(1), Duration::weeks(1)) .boxed(); select(server, clean).await; @@ -114,10 +113,7 @@ pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Erro } /// Periodically remove old metrics. -async fn clean_up() { - let every = Duration::days(1); - let before = Duration::weeks(1); - +async fn clean_up(every: Duration, before: Duration) { loop { Delay::new(every.to_std().unwrap()).await; diff --git a/core/grafana-data-source/test/Cargo.toml b/core/grafana-data-source/test/Cargo.toml index 9e23bc446948c..6dafc181455b0 100644 --- a/core/grafana-data-source/test/Cargo.toml +++ b/core/grafana-data-source/test/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] grafana-data-source = { path = ".." } -futures = "0.3" +futures-util = "0.3" tokio = "0.2.0-alpha.6" rand = "0.7" ctrlc = "3.1" diff --git a/core/grafana-data-source/test/src/main.rs b/core/grafana-data-source/test/src/main.rs index 7c2ef914ebbb7..7c5e6a1226c20 100644 --- a/core/grafana-data-source/test/src/main.rs +++ b/core/grafana-data-source/test/src/main.rs @@ -20,7 +20,7 @@ use std::{ pin::Pin }; use rand::Rng; -use futures::{FutureExt, future::select}; +use futures_util::{FutureExt, future::select}; use tokio::timer::delay_for; static EXIT: AtomicBool = AtomicBool::new(false); From 4e963850a6e7c3d95ee1b4ca4daa304f548fe0c4 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 8 Nov 2019 21:17:50 +1300 Subject: [PATCH 22/29] Error handling --- core/grafana-data-source/src/server.rs | 9 +++++---- core/service/src/builder.rs | 15 +++++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/grafana-data-source/src/server.rs b/core/grafana-data-source/src/server.rs index 0c16ffd7c1bb0..ed7cae7aa3974 100644 --- a/core/grafana-data-source/src/server.rs +++ b/core/grafana-data-source/src/server.rs @@ -17,7 +17,7 @@ use serde::{Serialize, de::DeserializeOwned}; use hyper::{Body, Request, Response, header, service::{service_fn, make_service_fn}, Server}; use chrono::{Duration, Utc}; -use futures_util::{TryStreamExt, FutureExt, future::select}; +use futures_util::{TryStreamExt, FutureExt, future::{select, Either}}; use futures_timer::Delay; use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; @@ -107,9 +107,10 @@ pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Erro let clean = clean_up(Duration::days(1), Duration::weeks(1)) .boxed(); - select(server, clean).await; - - Ok(()) + match select(server, clean).await { + Either::Left((result, _)) => result, + Either::Right(_) => Ok(()) + } } /// Periodically remove old metrics. diff --git a/core/service/src/builder.rs b/core/service/src/builder.rs index 9fedcaa31f5cd..037cb724f3179 100644 --- a/core/service/src/builder.rs +++ b/core/service/src/builder.rs @@ -27,10 +27,11 @@ use codec::{Decode, Encode, IoReader}; use consensus_common::import_queue::ImportQueue; use futures::{prelude::*, sync::mpsc}; use futures03::{ - compat::Compat, + compat::*, future::ready, FutureExt as _, TryFutureExt as _, StreamExt as _, TryStreamExt as _, + future::{select, Either} }; use keystore::{Store as Keystore}; use log::{info, warn}; @@ -1137,9 +1138,15 @@ ServiceBuilder< // Grafana data source if let Some(port) = config.grafana_port { - let _ = to_spawn_tx.unbounded_send(Box::new( - grafana_data_source::run_server(port).map_err(|_| ()).boxed().compat() - )); + let future = select( + grafana_data_source::run_server(port).boxed(), + exit.clone().compat() + ).map(|either| match either { + Either::Left((result, _)) => result.map_err(|_| ()), + Either::Right(_) => Ok(()) + }).compat(); + + let _ = to_spawn_tx.unbounded_send(Box::new(future)); } Ok(Service { From 9605717fea759a184e198900c3494d5756f6d3e1 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 20 Nov 2019 15:54:55 +0100 Subject: [PATCH 23/29] Remove dependence on hyper's tokio feature --- Cargo.lock | 89 +++++++++++++++++++- client/grafana-data-source/Cargo.toml | 8 +- client/grafana-data-source/src/lib.rs | 1 + client/grafana-data-source/src/networking.rs | 66 +++++++++++++++ client/grafana-data-source/src/server.rs | 32 +++++-- 5 files changed, 185 insertions(+), 11 deletions(-) create mode 100644 client/grafana-data-source/src/networking.rs diff --git a/Cargo.lock b/Cargo.lock index bff17be752de1..685dd854853c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,6 +138,49 @@ name = "assert_matches" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "async-macros" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "async-std" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "async-macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "async-task 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "broadcaster 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "kv-log-macro 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "async-task" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.13" @@ -297,6 +340,19 @@ dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "broadcaster" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bs58" version = "0.3.0" @@ -1490,15 +1546,19 @@ dependencies = [ name = "grafana-data-source" version = "2.0.0" dependencies = [ + "async-std 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.13.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1756,15 +1816,11 @@ dependencies = [ "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-net 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.3.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "tower-make 0.3.0-alpha.2a (registry+https://github.com/rust-lang/crates.io-index)", "tower-service 0.3.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", "want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2041,6 +2097,14 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "kv-log-macro" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "kvdb" version = "0.1.0" @@ -3156,6 +3220,11 @@ name = "once_cell" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "once_cell" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -4207,6 +4276,11 @@ dependencies = [ "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pin-project-lite" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pin-utils" version = "0.1.0-alpha.4" @@ -7960,6 +8034,9 @@ dependencies = [ "checksum asn1_der 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6fce6b6a0ffdafebd82c87e79e3f40e8d2c523e5fea5566ff6b90509bf98d638" "checksum asn1_der_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d0864d84b8e07b145449be9a8537db86bf9de5ce03b913214694643b4743502" "checksum assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7deb0a829ca7bcfaf5da70b073a8d128619259a7be8216a355e23f00763059e5" +"checksum async-macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e421d59b24c1feea2496e409b3e0a8de23e5fc130a2ddc0b012e551f3b272bba" +"checksum async-std 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f6ee33a6cfdd96bfde032d14b29905244a70868bd8dda1f3b13504d6cbc3b7bc" +"checksum async-task 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de6bd58f7b9cc49032559422595c81cbfcf04db2f2133592f70af19e258a1ced" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" @@ -7978,6 +8055,7 @@ dependencies = [ "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +"checksum broadcaster 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "07a1446420a56f1030271649ba0da46d23239b3a68c73591cea5247f15a788a0" "checksum bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b170cd256a3f9fa6b9edae3e44a7dfdfc77e8124dbc3e2612d75f9c3e2396dae" "checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" "checksum build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdce191bf3fa4995ce948c8c83b4640a1745457a149e73c6db75b4ffe36aad5f" @@ -8159,6 +8237,7 @@ dependencies = [ "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum keccak-hasher 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3468207deea1359a0e921591ae9b4c928733d94eb9d6a2eeda994cfd59f42cf8" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum kv-log-macro 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c54d9f465d530a752e6ebdc217e081a7a614b48cb200f6f0aee21ba6bc9aabb" "checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum kvdb-rocksdb 0.1.4 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" @@ -8230,6 +8309,7 @@ dependencies = [ "checksum ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c" "checksum once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" "checksum once_cell 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d584f08c2d717d5c23a6414fc2822b71c651560713e54fa7eace675f758a355e" +"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2f372b2b53ce10fb823a337aaa674e3a7d072b957c6264d0f4ff0bd86e657449" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" @@ -8264,6 +8344,7 @@ dependencies = [ "checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f" "checksum pin-project 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c5fce7042b4e4338a3f868e563fff394709c3ff62cf6908d407dd9e2caff96ed" "checksum pin-project-internal 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7644b4721cc27235f667e735da8732f5b781c442157315674c0cb7f28b4cabf3" +"checksum pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" diff --git a/client/grafana-data-source/Cargo.toml b/client/grafana-data-source/Cargo.toml index da1a6ce345353..171fd2c60ea8c 100644 --- a/client/grafana-data-source/Cargo.toml +++ b/client/grafana-data-source/Cargo.toml @@ -7,8 +7,12 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -hyper = { version = "0.13.0-alpha.4", features = ["unstable-stream"] } -futures-util-preview = "=0.3.0-alpha.19" +hyper = { version = "0.13.0-alpha.4", default-features = false, features = ["unstable-stream"] } +async-std = { version = "1.0.1", features = ["unstable"] } +tokio-io = "0.2.0-alpha.6" +tokio-executor = "0.2.0-alpha.6" +futures-util = { version = "0.3.1", default-features = false, features = ["io"] } +futures-util-alpha = { package = "futures-util-preview", default-features = false, version = "0.3.0-alpha.19" } serde_json = "1" serde = { version = "1", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } diff --git a/client/grafana-data-source/src/lib.rs b/client/grafana-data-source/src/lib.rs index f1bdb9e373464..771dbbdd8bc87 100644 --- a/client/grafana-data-source/src/lib.rs +++ b/client/grafana-data-source/src/lib.rs @@ -30,6 +30,7 @@ use parking_lot::RwLock; mod types; mod server; mod util; +mod networking; pub use server::run_server; pub use util::now_millis; diff --git a/client/grafana-data-source/src/networking.rs b/client/grafana-data-source/src/networking.rs new file mode 100644 index 0000000000000..66362e4e68145 --- /dev/null +++ b/client/grafana-data-source/src/networking.rs @@ -0,0 +1,66 @@ +// Copyright 2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +use async_std::pin::Pin; +use std::task::{Poll, Context}; +use futures_util::{stream::Stream, io::{AsyncRead, AsyncWrite}}; + +pub struct Incoming<'a>(pub async_std::net::Incoming<'a>); + +impl hyper::server::accept::Accept for Incoming<'_> { + type Conn = TcpStream; + type Error = async_std::io::Error; + + fn poll_accept(self: Pin<&mut Self>, cx: &mut Context) -> Poll>> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_next(cx) + .map(|opt| opt.map(|res| res.map(TcpStream))) + } +} + +pub struct TcpStream(pub async_std::net::TcpStream); + +impl tokio_io::AsyncRead for TcpStream { + fn poll_read( + self: Pin<&mut Self>, + cx: &mut Context, + buf: &mut [u8] + ) -> Poll> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_read(cx, buf) + } +} + +impl tokio_io::AsyncWrite for TcpStream { + fn poll_write( + self: Pin<&mut Self>, + cx: &mut Context, + buf: &[u8] + ) -> Poll> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_write(cx, buf) + } + + fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_flush(cx) + } + + fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_close(cx) + } +} diff --git a/client/grafana-data-source/src/server.rs b/client/grafana-data-source/src/server.rs index ed7cae7aa3974..8aa5f8c84b587 100644 --- a/client/grafana-data-source/src/server.rs +++ b/client/grafana-data-source/src/server.rs @@ -17,9 +17,9 @@ use serde::{Serialize, de::DeserializeOwned}; use hyper::{Body, Request, Response, header, service::{service_fn, make_service_fn}, Server}; use chrono::{Duration, Utc}; -use futures_util::{TryStreamExt, FutureExt, future::{select, Either}}; +use futures_util::{FutureExt, future::{Future, select, Either}}; use futures_timer::Delay; -use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; +use crate::{METRICS, util, types::{Target, Query, TimeseriesData}, networking::Incoming}; #[derive(Debug, derive_more::Display)] enum Error { @@ -77,6 +77,8 @@ async fn map_request_to_response(req: Request, transformation Res: Serialize, T: Fn(Req) -> Res + Send + Sync + 'static { + use futures_util_alpha::TryStreamExt; + let body = req.into_body() .try_concat() .await @@ -92,25 +94,45 @@ async fn map_request_to_response(req: Request, transformation .map_err(Error::Http) } +/// Given that we're not using hyper's tokio feature, we need to define out own executor. +#[derive(Clone)] +pub struct Executor; + +impl tokio_executor::TypedExecutor for Executor + where + T: Future + Send + 'static, + T::Output: Send + 'static, +{ + fn spawn(&mut self, future: T) -> Result<(), tokio_executor::SpawnError> { + async_std::task::spawn(future); + Ok(()) + } +} + /// Start the data source server. pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Error> { + let listener = async_std::net::TcpListener::bind(&address).await.unwrap(); + let service = make_service_fn(|_| { async { Ok::<_, Error>(service_fn(api_response)) } }); - let server = Server::bind(&address) + let server = Server::builder(Incoming(listener.incoming())) + .executor(Executor) .serve(service) .boxed(); let clean = clean_up(Duration::days(1), Duration::weeks(1)) .boxed(); - match select(server, clean).await { + let result = match select(server, clean).await { Either::Left((result, _)) => result, Either::Right(_) => Ok(()) - } + }; + + result } /// Periodically remove old metrics. From b48dae01c730fee5e381e6251e2d24d928435fc2 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 20 Nov 2019 16:40:32 +0100 Subject: [PATCH 24/29] Added target_os flag --- client/grafana-data-source/Cargo.toml | 4 +++- client/grafana-data-source/src/lib.rs | 1 + client/grafana-data-source/src/server.rs | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/grafana-data-source/Cargo.toml b/client/grafana-data-source/Cargo.toml index 171fd2c60ea8c..dcb5a8894dab0 100644 --- a/client/grafana-data-source/Cargo.toml +++ b/client/grafana-data-source/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" [dependencies] hyper = { version = "0.13.0-alpha.4", default-features = false, features = ["unstable-stream"] } -async-std = { version = "1.0.1", features = ["unstable"] } tokio-io = "0.2.0-alpha.6" tokio-executor = "0.2.0-alpha.6" futures-util = { version = "0.3.1", default-features = false, features = ["io"] } @@ -20,3 +19,6 @@ lazy_static = "1.4" parking_lot = "0.9" futures-timer = "1.0" derive_more = "0.15" + +[target.'cfg(not(target_os = "unknown"))'.dependencies] +async-std = { version = "1.0.1", features = ["unstable"] } diff --git a/client/grafana-data-source/src/lib.rs b/client/grafana-data-source/src/lib.rs index 771dbbdd8bc87..7373f62705606 100644 --- a/client/grafana-data-source/src/lib.rs +++ b/client/grafana-data-source/src/lib.rs @@ -30,6 +30,7 @@ use parking_lot::RwLock; mod types; mod server; mod util; +#[cfg(not(target_os = "unknown"))] mod networking; pub use server::run_server; diff --git a/client/grafana-data-source/src/server.rs b/client/grafana-data-source/src/server.rs index 8aa5f8c84b587..0213e9ff25514 100644 --- a/client/grafana-data-source/src/server.rs +++ b/client/grafana-data-source/src/server.rs @@ -19,7 +19,7 @@ use hyper::{Body, Request, Response, header, service::{service_fn, make_service_ use chrono::{Duration, Utc}; use futures_util::{FutureExt, future::{Future, select, Either}}; use futures_timer::Delay; -use crate::{METRICS, util, types::{Target, Query, TimeseriesData}, networking::Incoming}; +use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; #[derive(Debug, derive_more::Display)] enum Error { @@ -98,6 +98,7 @@ async fn map_request_to_response(req: Request, transformation #[derive(Clone)] pub struct Executor; +#[cfg(not(target_os = "unknown"))] impl tokio_executor::TypedExecutor for Executor where T: Future + Send + 'static, @@ -110,7 +111,10 @@ impl tokio_executor::TypedExecutor for Executor } /// Start the data source server. +#[cfg(not(target_os = "unknown"))] pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Error> { + use crate::networking::Incoming; + let listener = async_std::net::TcpListener::bind(&address).await.unwrap(); let service = make_service_fn(|_| { @@ -135,6 +139,11 @@ pub async fn run_server(address: std::net::SocketAddr) -> Result<(), hyper::Erro result } +#[cfg(target_os = "unknown")] +pub async fn run_server(_: std::net::SocketAddr) -> Result<(), hyper::Error> { + Ok(()) +} + /// Periodically remove old metrics. async fn clean_up(every: Duration, before: Duration) { loop { From a7b590010025f6c87f9ff7a195b193fc5d7321a1 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 20 Nov 2019 17:41:38 +0100 Subject: [PATCH 25/29] Update Cargo.toml Co-Authored-By: Pierre Krieger --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ff437a9ed2829..805d7501a45ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ members = [ "client/transaction-pool/graph", "client/utils/wasm-builder-runner", "client/grafana-data-source", - "client/grafana-data-source/test", + "client/grafana-data-source/test", "paint/assets", "paint/aura", "paint/authority-discovery", From a3b2298b7744e9a8ed736d184b4fc0e45f8ed71d Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 20 Nov 2019 17:54:33 +0100 Subject: [PATCH 26/29] Simplify example --- Cargo.lock | 146 ++------------------ client/grafana-data-source/Cargo.toml | 2 +- client/grafana-data-source/test/Cargo.toml | 5 +- client/grafana-data-source/test/src/main.rs | 54 ++------ core/service/Cargo.toml | 62 --------- 5 files changed, 20 insertions(+), 249 deletions(-) delete mode 100644 core/service/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index 685dd854853c3..6af67f8175ed9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1420,6 +1420,11 @@ dependencies = [ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-timer" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-util" version = "0.3.1" @@ -1549,7 +1554,7 @@ dependencies = [ "async-std 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.13.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1565,11 +1570,10 @@ dependencies = [ name = "grafana-data-source-test" version = "2.0.0" dependencies = [ - "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "grafana-data-source 2.0.0", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2148,9 +2152,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "lazycell" @@ -6895,27 +6896,6 @@ dependencies = [ "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-fs 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-macros 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-net 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.3.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-buf" version = "0.1.1" @@ -6982,17 +6962,7 @@ name = "tokio-executor" version = "0.2.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -7005,19 +6975,6 @@ dependencies = [ "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio-fs" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-io" version = "0.1.12" @@ -7040,40 +6997,6 @@ dependencies = [ "pin-project 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio-macros" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tokio-net" -version = "0.2.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-reactor" version = "0.1.10" @@ -7121,7 +7044,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7165,19 +7087,6 @@ dependencies = [ "tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "tokio-timer" -version = "0.3.0-alpha.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "tokio-tls" version = "0.2.1" @@ -7241,36 +7150,6 @@ name = "tower-service" version = "0.3.0-alpha.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "tracing" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-attributes 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tracing-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tracing-core" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "traitobject" version = "0.1.0" @@ -8174,6 +8053,7 @@ dependencies = [ "checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" "checksum futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33" "checksum futures-timer 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7946248e9429ff093345d3e8fdf4eb0f9b2d79091611c9c14f744971a6f8be45" +"checksum futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6" "checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" "checksum futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce968633c17e5f97936bd2797b6e38fb56cf16a7422319f7ec2e30d3c470e8d" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" @@ -8480,7 +8360,6 @@ dependencies = [ "checksum tiny-keccak 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2953ca5148619bc99695c1274cb54c5275bbb913c6adad87e72eaf8db9787f69" "checksum tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4574b75faccaacddb9b284faecdf0b544b80b6b294f3d062d325c5726a209c20" "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" -"checksum tokio 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1f17f5d6ab0f35c1506678b28fb1798bdf74fcb737e9843c7b17b73e426eba38" "checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" "checksum tokio-codec 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9f5d22fd1e84bd4045d28813491cb7d7caae34d45c80517c2213f09a85e8787a" @@ -8489,11 +8368,8 @@ dependencies = [ "checksum tokio-executor 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f27ee0e6db01c5f0b2973824547ce7e637b2ed79b891a9677b0de9bd532b6ac" "checksum tokio-executor 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9ee9ceecf69145923834ea73f32ba40c790fd877b74a7817dd0b089f1eb9c7c8" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" -"checksum tokio-fs 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bf85e16971e06e680c622e0c1b455be94b086275c5ddcd6d4a83a2bfbb83cda" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-io 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "112784d5543df30660b04a72ca423bfbd90e8bb32f94dcf610f15401218b22c5" -"checksum tokio-macros 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "86b616374bcdadd95974e1f0dfca07dc913f1163c53840c0d664aca35114964e" -"checksum tokio-net 0.2.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a441682cd32f3559383112c4a7f372f5c9fa1950c5cf8c8dd05274a2ce8c2654" "checksum tokio-reactor 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "c56391be9805bc80163151c0b9e5164ee64f4b0200962c346fea12773158f22d" "checksum tokio-rustls 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1df2fa53ac211c136832f530ccb081af9af891af22d685a9493e232c7a359bc2" "checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" @@ -8501,16 +8377,12 @@ dependencies = [ "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" -"checksum tokio-timer 0.3.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b97c1587fe71018eb245a4a9daa13a5a3b681bbc1f7fdadfe24720e141472c13" "checksum tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c" "checksum tokio-udp 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f02298505547f73e60f568359ef0d016d5acd6e830ab9bc7c4a5b3403440121b" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" "checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" "checksum tower-make 0.3.0-alpha.2a (registry+https://github.com/rust-lang/crates.io-index)" = "316d47dd40cde4ac5d88110eaf9a10a4e2a68612d9c056cd2aa24e37dcb484cd" "checksum tower-service 0.3.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)" = "63ff37396cd966ce43bea418bfa339f802857495f797dafa00bea5b7221ebdfa" -"checksum tracing 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ff4e4f59e752cb3beb5b61c6d5e11191c7946231ba84faec2902c9efdd8691c5" -"checksum tracing-attributes 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a4263b12c3d3c403274493eb805966093b53214124796552d674ca1dd5d27c2b" -"checksum tracing-core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bc913647c520c959b6d21e35ed8fa6984971deca9f0a2fcb8c51207e0c56af1d" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum trie-bench 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3073600c543ed001319d7e092c46dfd8c245af1a218ec5c75eb01582660a2b3e" "checksum trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0b62d27e8aa1c07414549ac872480ac82380bab39e730242ab08d82d7cc098a" diff --git a/client/grafana-data-source/Cargo.toml b/client/grafana-data-source/Cargo.toml index dcb5a8894dab0..597d036c58ae3 100644 --- a/client/grafana-data-source/Cargo.toml +++ b/client/grafana-data-source/Cargo.toml @@ -17,7 +17,7 @@ serde = { version = "1", features = ["derive"] } chrono = { version = "0.4", features = ["serde"] } lazy_static = "1.4" parking_lot = "0.9" -futures-timer = "1.0" +futures-timer = "2.0" derive_more = "0.15" [target.'cfg(not(target_os = "unknown"))'.dependencies] diff --git a/client/grafana-data-source/test/Cargo.toml b/client/grafana-data-source/test/Cargo.toml index 6dafc181455b0..2ee376be8d212 100644 --- a/client/grafana-data-source/test/Cargo.toml +++ b/client/grafana-data-source/test/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" [dependencies] grafana-data-source = { path = ".." } -futures-util = "0.3" -tokio = "0.2.0-alpha.6" +futures = "0.3" +futures-timer = "2.0" rand = "0.7" -ctrlc = "3.1" diff --git a/client/grafana-data-source/test/src/main.rs b/client/grafana-data-source/test/src/main.rs index 7c5e6a1226c20..bb2b317a6c41c 100644 --- a/client/grafana-data-source/test/src/main.rs +++ b/client/grafana-data-source/test/src/main.rs @@ -15,37 +15,13 @@ // along with Substrate. If not, see . use grafana_data_source::{run_server, record_metrics}; -use std::{ - time::Duration, sync::atomic::{AtomicBool, Ordering}, task::{Context, Poll}, future::Future, - pin::Pin -}; +use std::time::Duration; use rand::Rng; -use futures_util::{FutureExt, future::select}; -use tokio::timer::delay_for; - -static EXIT: AtomicBool = AtomicBool::new(false); - -struct ExitFuture; - -impl Future for ExitFuture { - type Output = (); - - fn poll(self: Pin<&mut Self>, _: &mut Context) -> Poll { - let exit = EXIT.load(Ordering::Relaxed); - - println!("Polling, got: {}", exit); - - if exit { - Poll::Ready(()) - } else { - Poll::Pending - } - } -} +use futures::{future::join, executor}; async fn randomness() { loop { - delay_for(Duration::from_secs(1)).await; + futures_timer::Delay::new(Duration::from_secs(1)).await; let random = rand::thread_rng().gen_range(0.0, 1000.0); @@ -56,23 +32,9 @@ async fn randomness() { } } -#[tokio::main] -async fn main() -> Result<(), Box> { - ctrlc::set_handler(|| { - println!(" - Ctrl-C received"); - EXIT.store(true, Ordering::Relaxed); - }).unwrap(); - - let address = "127.0.0.1:9955".parse().unwrap(); - - let server_future = run_server(address).boxed(); - - let randomness_future = randomness().boxed(); - - select( - select(randomness_future, server_future), - ExitFuture - ).await; - - Ok(()) +fn main() { + executor::block_on(join( + run_server("127.0.0.1:9955".parse().unwrap()), + randomness() + )).0.unwrap(); } diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml deleted file mode 100644 index 858b68422302f..0000000000000 --- a/core/service/Cargo.toml +++ /dev/null @@ -1,62 +0,0 @@ -[package] -name = "substrate-service" -version = "2.0.0" -authors = ["Parity Technologies "] -edition = "2018" - -[features] -default = ["rocksdb"] -# The RocksDB feature activates the RocksDB database backend. If it is not activated, and you pass -# a path to a database, an error will be produced at runtime. -rocksdb = ["client_db/kvdb-rocksdb"] -wasmtime = [ - "substrate-executor/wasmtime", -] - -[dependencies] -derive_more = "0.15.0" -futures = "0.1.29" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } -parking_lot = "0.9.0" -lazy_static = "1.4.0" -log = "0.4.8" -slog = { version = "2.5.2", features = ["nested-values"] } -tokio-executor = "0.1.8" -tokio-timer = "0.2.11" -exit-future = "0.1.4" -serde = "1.0.101" -serde_json = "1.0.41" -sysinfo = "0.9.5" -target_info = "0.1.0" -keystore = { package = "substrate-keystore", path = "../../core/keystore" } -sr-io = { path = "../../core/sr-io" } -sr-primitives = { path = "../../core/sr-primitives" } -primitives = { package = "substrate-primitives", path = "../primitives" } -session = { package = "substrate-session", path = "../session" } -app-crypto = { package = "substrate-application-crypto", path = "../application-crypto" } -consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } -network = { package = "substrate-network", path = "../../core/network" } -chain-spec = { package = "substrate-chain-spec", path = "../chain-spec" } -client = { package = "substrate-client", path = "../../core/client" } -sr-api = { path = "../sr-api" } -tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../transaction-pool/runtime-api" } -client_db = { package = "substrate-client-db", path = "../../core/client/db" } -codec = { package = "parity-scale-codec", version = "1.0.0" } -substrate-executor = { path = "../../core/executor" } -transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" } -rpc-servers = { package = "substrate-rpc-servers", path = "../../core/rpc-servers" } -rpc = { package = "substrate-rpc", path = "../../core/rpc" } -tel = { package = "substrate-telemetry", path = "../../core/telemetry" } -offchain = { package = "substrate-offchain", path = "../../core/offchain" } -parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } -grafana-data-source = { path = "../grafana-data-source" } - -[dev-dependencies] -substrate-test-runtime-client = { path = "../test-runtime/client" } -node-executor = { path = "../../node/executor" } -node-primitives = { path = "../../node/primitives" } -node-runtime = { path = "../../node/runtime" } -babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../core/consensus/babe/primitives" } -grandpa = { package = "substrate-finality-grandpa", path = "../../core/finality-grandpa" } -grandpa-primitives = { package = "substrate-finality-grandpa-primitives", path = "../../core/finality-grandpa/primitives" } -tokio = "0.1" From 0adbb926e7c64f106227b77b739d6b0e32f95869 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 20 Nov 2019 17:58:00 +0100 Subject: [PATCH 27/29] Remove compat wildcard --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index cfd30046ae7bf..11355720bf05e 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -29,7 +29,7 @@ use codec::{Decode, Encode, IoReader}; use consensus_common::import_queue::ImportQueue; use futures::{prelude::*, sync::mpsc}; use futures03::{ - compat::*, + compat::{Compat, Future01CompatExt}, future::ready, FutureExt as _, TryFutureExt as _, StreamExt as _, TryStreamExt as _, From 7adac1bd7fbffca5df6148f8e8b62b2eefa5c9d1 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 22 Nov 2019 14:23:35 +0100 Subject: [PATCH 28/29] Updated lock file --- Cargo.lock | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 02c5ba99e4e36..a281c3c9de8d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1330,6 +1330,15 @@ dependencies = [ "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-channel-preview" +version = "0.3.0-alpha.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-core" version = "0.3.1" @@ -1381,6 +1390,11 @@ name = "futures-sink" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-sink-preview" +version = "0.3.0-alpha.19" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-task" version = "0.3.1" @@ -1425,7 +1439,9 @@ name = "futures-util-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -6407,8 +6423,9 @@ version = "2.0.0" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "grafana-data-source 2.0.0", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "node-executor 2.0.0", @@ -8065,6 +8082,7 @@ dependencies = [ "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" "checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987" "checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86" +"checksum futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e5f4df964fa9c1c2f8bddeb5c3611631cacd93baf810fc8bb2fb4b495c263a" "checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" "checksum futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" @@ -8072,6 +8090,7 @@ dependencies = [ "checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff" "checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764" "checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16" +"checksum futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "86f148ef6b69f75bb610d4f9a2336d4fc88c4b5b67129d1a340dd0fd362efeec" "checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" "checksum futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33" "checksum futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6" From e7adcfb5182017066eb500406930aca3a82b3c5b Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 22 Nov 2019 15:30:17 +0100 Subject: [PATCH 29/29] =?UTF-8?q?Fix=20indentation=20=F0=9F=98=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/service/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 2112105b1bbce..f48bcb77ad95d 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -1143,7 +1143,7 @@ ServiceBuilder< telemetry }); - // Grafana data source + // Grafana data source if let Some(port) = config.grafana_port { let future = select( grafana_data_source::run_server(port).boxed(),