diff --git a/Cargo.lock b/Cargo.lock index a2c0c6904c55359b2556986daab42c1064a443f3..23c6e008aa29fd83e37b4e3cde3adf1d188d9770 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 = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core 0.3.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)", +] + +[[package]] +name = "async-std" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "async-macros 2.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.4.0 (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.7.0 (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 2.0.2 (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.1 (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" @@ -302,6 +345,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.2.5" @@ -440,6 +496,7 @@ dependencies = [ "libc 0.2.65 (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.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -713,6 +770,14 @@ dependencies = [ "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-channel" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-deque" version = "0.7.2" @@ -1265,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" @@ -1316,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" @@ -1360,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)", ] @@ -1461,6 +1542,35 @@ dependencies = [ "scroll 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "grafana-data-source" +version = "2.0.0" +dependencies = [ + "async-std 1.1.0 (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 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)", + "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]] +name = "grafana-data-source-test" +version = "2.0.0" +dependencies = [ + "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)", +] + [[package]] name = "h2" version = "0.1.26" @@ -1478,6 +1588,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.3.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" @@ -1600,6 +1730,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" @@ -1660,6 +1799,32 @@ 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)", + "pin-project 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (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)", + "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-rustls" version = "0.17.1" @@ -1931,6 +2096,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" @@ -3050,6 +3223,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" @@ -4116,6 +4294,29 @@ dependencies = [ "fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pin-project" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "pin-project-internal 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.6" +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.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" @@ -6229,6 +6430,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 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", @@ -6778,6 +6980,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" @@ -6807,6 +7021,14 @@ 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 = [ + "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-fs" version = "0.1.6" @@ -6827,6 +7049,18 @@ 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.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-reactor" version = "0.1.10" @@ -6867,6 +7101,16 @@ 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-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-tcp" version = "0.1.3" @@ -6956,6 +7200,20 @@ dependencies = [ "serde 1.0.102 (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" @@ -7270,6 +7528,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" @@ -7733,6 +8000,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 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "644a5a8de80f2085a1e7e57cd1544a2a7438f6e003c0790999bd43b92a77cdb2" +"checksum async-std 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56933da6903b273923d13f4746d829f66ff9b444173f6743d831e80f4da15446" +"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" @@ -7752,6 +8022,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.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c95ee6bba9d950218b6cc910cf62bc9e0a171d0f4537e3627b0f54d08549b188" "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" @@ -7796,6 +8067,7 @@ dependencies = [ "checksum criterion-plot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76f9212ddf2f4a9eb2d401635190600656a1f88a932ef53d06e7fa4c7e02fb8e" "checksum criterion-plot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eccdc6ce8bbe352ca89025bee672aa6d24f4eb8c53e3a8b5d1bc58011da072a2" "checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa" +"checksum crossbeam-channel 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec9a3b0b3559f15aee4f90746c4e5e293b701c0f7d3925d24e01645267b68c" "checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" "checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" @@ -7857,6 +8129,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" @@ -7864,6 +8137,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" @@ -7881,6 +8155,7 @@ dependencies = [ "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" "checksum goblin 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6040506480da04a63de51a478e8021892d65d8411f29b2a422c2648bdd8bcb" "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" @@ -7896,10 +8171,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-rustls 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "719d85c7df4a7f309a77d145340a063ea929dcb2e025bae46a80345cffec2952" "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" @@ -7928,6 +8205,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)" = "<none>" "checksum kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "<none>" "checksum kvdb-rocksdb 0.1.4 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "<none>" @@ -8000,6 +8278,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" @@ -8034,6 +8313,9 @@ 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.6 (registry+https://github.com/rust-lang/crates.io-index)" = "94b90146c7216e4cb534069fb91366de4ea0ea353105ee45ed297e2d1619e469" +"checksum pin-project-internal 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "44ca92f893f0656d3cba8158dd0f2b99b94de256a4a54e870bd6922fcc6c8355" +"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" @@ -8174,14 +8456,18 @@ dependencies = [ "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" "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-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-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" +"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" @@ -8189,6 +8475,8 @@ dependencies = [ "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" @@ -8226,6 +8514,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.55 (registry+https://github.com/rust-lang/crates.io-index)" = "29ae32af33bacd663a9a28241abecf01f2be64e6a185c6139b04f18b6385c5f2" "checksum wasm-bindgen-backend 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "1845584bd3593442dc0de6e6d9f84454a59a057722f36f005e44665d6ab19d85" diff --git a/Cargo.toml b/Cargo.toml index 785492e282b90fbe268366b1177b4243b161fe81..1ed25a994135c8be0867b818e1be3ee1449174f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,8 @@ members = [ "client/transaction-pool", "client/transaction-pool/graph", "client/utils/wasm-builder-runner", + "client/grafana-data-source", + "client/grafana-data-source/test", "palette/assets", "palette/aura", "palette/authority-discovery", diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index f841591dc9596f59132ed9cd4dbd45e825314ad8..9e908c9330559308771804df7081c5d36cedaec9 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -818,9 +818,13 @@ 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/client/cli/src/params.rs b/client/cli/src/params.rs index 5ebedf664b4ae6edb7873d3bfc5b4dbf936b1a9c..15ec2fa113c054282258135bc1db537d73187090 100644 --- a/client/cli/src/params.rs +++ b/client/cli/src/params.rs @@ -404,6 +404,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<u16>, @@ -426,6 +432,10 @@ pub struct RunCmd { #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] pub rpc_cors: Option<Cors>, + /// Specify Grafana data source server TCP Port. + #[structopt(long = "grafana-port", value_name = "PORT")] + pub grafana_port: Option<u16>, + /// 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/client/grafana-data-source/Cargo.toml b/client/grafana-data-source/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..597d036c58ae334e0bd22c0d976f8b3f7c543c84 --- /dev/null +++ b/client/grafana-data-source/Cargo.toml @@ -0,0 +1,24 @@ +[package] +description = "Grafana data source server" +name = "grafana-data-source" +version = "2.0.0" +license = "GPL-3.0" +authors = ["Parity Technologies <admin@parity.io>"] +edition = "2018" + +[dependencies] +hyper = { version = "0.13.0-alpha.4", default-features = false, features = ["unstable-stream"] } +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"] } +lazy_static = "1.4" +parking_lot = "0.9" +futures-timer = "2.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 new file mode 100644 index 0000000000000000000000000000000000000000..7373f62705606029a1fa3d468d7f1c0bfea0e10e --- /dev/null +++ b/client/grafana-data-source/src/lib.rs @@ -0,0 +1,58 @@ +// 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 <http://www.gnu.org/licenses/>. + +//! [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 std::collections::HashMap; +use parking_lot::RwLock; + +mod types; +mod server; +mod util; +#[cfg(not(target_os = "unknown"))] +mod networking; + +pub use server::run_server; +pub use util::now_millis; + +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<Metrics> = RwLock::new(Metrics::new()); +} + +/// Write metrics to `METRICS`. +#[macro_export] +macro_rules! record_metrics( + ($($key:expr => $value:expr),*) => { + use $crate::{METRICS, now_millis}; + let mut metrics = METRICS.write(); + let now = now_millis(); + $( + metrics.entry($key).or_insert_with(Vec::new).push(($value as f32, now)); + )* + } +); diff --git a/client/grafana-data-source/src/networking.rs b/client/grafana-data-source/src/networking.rs new file mode 100644 index 0000000000000000000000000000000000000000..66362e4e68145b23046d6ab7f23e13a275e3c573 --- /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 <http://www.gnu.org/licenses/>. + +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<Option<Result<Self::Conn, Self::Error>>> { + 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<Result<usize, std::io::Error>> { + 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<Result<usize, std::io::Error>> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_write(cx, buf) + } + + fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), std::io::Error>> { + Pin::new(&mut Pin::into_inner(self).0) + .poll_flush(cx) + } + + fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), std::io::Error>> { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..0213e9ff25514c6af295b24dce8ebdfa5f78345e --- /dev/null +++ b/client/grafana-data-source/src/server.rs @@ -0,0 +1,165 @@ +// 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 <http://www.gnu.org/licenses/>. + +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::{FutureExt, future::{Future, select, Either}}; +use futures_timer::Delay; +use crate::{METRICS, util, types::{Target, Query, TimeseriesData}}; + +#[derive(Debug, derive_more::Display)] +enum Error { + Hyper(hyper::Error), + Serde(serde_json::Error), + Http(hyper::http::Error) +} + +impl std::error::Error for Error {} + +async fn api_response(req: Request<Body>) -> Result<Response<Body>, Error> { + match req.uri().path() { + "/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::<Vec<_>>() + }).await + }, + "/query" => { + map_request_to_response(req, |query: Query| { + let metrics = METRICS.read(); + + // Return timeseries data related to the specified metrics + query.targets.iter() + .map(|target| { + let datapoints = metrics.get(target.target.as_str()) + .map(|metric| { + let from = util::find_index(&metric, query.range.from); + let to = util::find_index(&metric, query.range.to); + + // 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); + + TimeseriesData { + target: target.target.clone(), datapoints + } + }) + .collect::<Vec<_>>() + }).await + }, + _ => Ok(Response::new(Body::empty())), + } +} + +async fn map_request_to_response<Req, Res, T>(req: Request<Body>, transformation: T) -> Result<Response<Body>, Error> + where + Req: DeserializeOwned, + Res: Serialize, + T: Fn(Req) -> Res + Send + Sync + 'static +{ + use futures_util_alpha::TryStreamExt; + + 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) +} + +/// Given that we're not using hyper's tokio feature, we need to define out own executor. +#[derive(Clone)] +pub struct Executor; + +#[cfg(not(target_os = "unknown"))] +impl<T> tokio_executor::TypedExecutor<T> 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. +#[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(|_| { + async { + Ok::<_, Error>(service_fn(api_response)) + } + }); + + let server = Server::builder(Incoming(listener.incoming())) + .executor(Executor) + .serve(service) + .boxed(); + + let clean = clean_up(Duration::days(1), Duration::weeks(1)) + .boxed(); + + let result = match select(server, clean).await { + Either::Left((result, _)) => result, + Either::Right(_) => Ok(()) + }; + + 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 { + Delay::new(every.to_std().unwrap()).await; + + let oldest_allowed = (Utc::now() - before).timestamp_millis(); + + 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(); + } + } + } +} diff --git a/client/grafana-data-source/src/types.rs b/client/grafana-data-source/src/types.rs new file mode 100644 index 0000000000000000000000000000000000000000..773fcb652d5dcbb00516fb7e824c4d221a1ecb20 --- /dev/null +++ b/client/grafana-data-source/src/types.rs @@ -0,0 +1,50 @@ +// 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 <http://www.gnu.org/licenses/>. + +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +pub struct Target { + pub target: String, +} + +#[derive(Serialize, Deserialize)] +pub struct Query { + #[serde(rename = "maxDataPoints")] + pub max_datapoints: usize, + pub targets: Vec<Target>, + pub range: Range, +} + +#[derive(Serialize, Deserialize)] +pub struct Range { + #[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<Utc>` +fn date_to_timestamp_ms<'de, D: serde::Deserializer<'de>>(timestamp: D) -> Result<i64, D::Error> { + Deserialize::deserialize(timestamp) + .map(|date: chrono::DateTime<chrono::Utc>| date.timestamp_millis()) +} + +#[derive(Serialize, Deserialize)] +pub struct TimeseriesData { + pub target: String, + pub datapoints: Vec<(f32, i64)> +} diff --git a/client/grafana-data-source/src/util.rs b/client/grafana-data-source/src/util.rs new file mode 100644 index 0000000000000000000000000000000000000000..cd27c440f7ded406709ca24db64b530db75b3047 --- /dev/null +++ b/client/grafana-data-source/src/util.rs @@ -0,0 +1,52 @@ +// 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 <http://www.gnu.org/licenses/>. + +/// 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 up to `num_points` points from a slice +pub fn select_points<T: Copy>(slice: &[T], num_points: usize) -> Vec<T> { + 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()) + .collect() +} + +#[test] +fn test_select_points() { + let array = [1, 2, 3, 4, 5]; + assert_eq!(select_points(&array, 0), Vec::<u8>::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]); +} diff --git a/client/grafana-data-source/test/Cargo.toml b/client/grafana-data-source/test/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..2ee376be8d212e68639ab69015591f6572bb7305 --- /dev/null +++ b/client/grafana-data-source/test/Cargo.toml @@ -0,0 +1,13 @@ +[package] +description = "Grafana data source server test" +name = "grafana-data-source-test" +version = "2.0.0" +license = "GPL-3.0" +authors = ["Parity Technologies <admin@parity.io>"] +edition = "2018" + +[dependencies] +grafana-data-source = { path = ".." } +futures = "0.3" +futures-timer = "2.0" +rand = "0.7" diff --git a/client/grafana-data-source/test/src/main.rs b/client/grafana-data-source/test/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..bb2b317a6c41cfd716eb98496883d2de8fc48ff9 --- /dev/null +++ b/client/grafana-data-source/test/src/main.rs @@ -0,0 +1,40 @@ +// 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 <http://www.gnu.org/licenses/>. + +use grafana_data_source::{run_server, record_metrics}; +use std::time::Duration; +use rand::Rng; +use futures::{future::join, executor}; + +async fn randomness() { + loop { + futures_timer::Delay::new(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 + ); + } +} + +fn main() { + executor::block_on(join( + run_server("127.0.0.1:9955".parse().unwrap()), + randomness() + )).0.unwrap(); +} diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index ae04da8c26476c268674242f52ea6e6fc6f76856..81f6aabbe0bc753a28a38e8c00523b54b6e02716 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -50,6 +50,7 @@ rpc = { package = "substrate-rpc", path = "../rpc" } tel = { package = "substrate-telemetry", path = "../telemetry" } offchain = { package = "substrate-offchain", path = "../offchain" } parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } +grafana-data-source = { path = "../grafana-data-source" } substrate-tracing = { package = "substrate-tracing", path = "../tracing" } tracing = "0.1.10" diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 9f624139e1d5651ebf4e2d629d5075eeea4fa5bb..f48bcb77ad95d53cc9ad971e9401128f08ded9bb 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -29,10 +29,11 @@ use codec::{Decode, Encode, IoReader}; use consensus_common::import_queue::ImportQueue; use futures::{prelude::*, sync::mpsc}; use futures03::{ - compat::Compat, + compat::{Compat, Future01CompatExt}, future::ready, FutureExt as _, TryFutureExt as _, StreamExt as _, TryStreamExt as _, + future::{select, Either} }; use keystore::{Store as Keystore}; use log::{info, warn, error}; @@ -53,6 +54,7 @@ use std::{ 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. /// @@ -991,6 +993,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(())); @@ -1130,6 +1143,19 @@ ServiceBuilder< telemetry }); + // Grafana data source + if let Some(port) = config.grafana_port { + 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)); + } + // Instrumentation if let Some(tracing_targets) = config.tracing_targets.as_ref() { let subscriber = substrate_tracing::ProfilingSubscriber::new( diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 27f26820d105a330ed4b301a32ab72c6843b43c3..a17c0ee877de2fac436f2f225d4d58830f92694e 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -73,6 +73,8 @@ pub struct Configuration<C, G, E = NoExtension> { pub rpc_ws_max_connections: Option<usize>, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option<Vec<String>>, + /// Grafana data source http port. `None` if disabled. + pub grafana_port: Option<SocketAddr>, /// Telemetry service URL. `None` if disabled. pub telemetry_endpoints: Option<TelemetryEndpoints>, /// External WASM transport for the telemetry. If `Some`, when connection to a telemetry @@ -151,6 +153,7 @@ impl<C, G, E> Configuration<C, G, E> 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, diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 2d1517fd8e844b27e5bb7f8817156216e2939cbd..594e5bf7ed4004c3d55696e633a74bddc7fb6785 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -190,6 +190,7 @@ fn node_config<G, E: Clone> ( 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,