mirror of
https://git.ghostchain.io/proxmio/ghost-node.git
synced 2025-12-27 03:09:56 +00:00
rustfmt ghost metrics and fix typos
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use hyper::{Client, Uri};
|
||||
use ghost_test_service::{node_config, run_validator_node, test_prometheus_config};
|
||||
use hyper::{Client, Uri};
|
||||
use keyring::AccountKeyring::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -7,8 +7,13 @@ const DEFAULT_PROMETHEUS_PORT: u16 = 9616;
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn runtime_can_publish_metrics() {
|
||||
let mut alice_config =
|
||||
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
|
||||
let mut alice_config = node_config(
|
||||
|| {},
|
||||
tokio::runtime::Handle::current(),
|
||||
Alice,
|
||||
Vec::new(),
|
||||
true,
|
||||
);
|
||||
|
||||
// Enable prometheus metrics for Alice.
|
||||
alice_config.prometheus_config = Some(test_prometheus_config(DEFAULT_PROMETHEUS_PORT));
|
||||
@@ -26,8 +31,13 @@ async fn runtime_can_publish_metrics() {
|
||||
// Start validator Alice
|
||||
let alice = run_validator_node(alice_config, None);
|
||||
|
||||
let bob_config =
|
||||
node_config(|| {}, tokio::runtime::Handle::current(), Bob, vec![alice.addr.clone()], true);
|
||||
let bob_config = node_config(
|
||||
|| {},
|
||||
tokio::runtime::Handle::current(),
|
||||
Bob,
|
||||
vec![alice.addr.clone()],
|
||||
true,
|
||||
);
|
||||
|
||||
// Start validator Bob
|
||||
let _bob = run_validator_node(bob_config, None);
|
||||
@@ -48,19 +58,25 @@ async fn scrape_prometheus_metrics(metrics_uri: &str) -> HashMap<String, u64> {
|
||||
.expect("GET request failed");
|
||||
|
||||
let body = String::from_utf8(
|
||||
hyper::body::to_bytes(res).await.expect("can't get body as bytes").to_vec(),
|
||||
).expect("body is not an UTF8 string");
|
||||
hyper::body::to_bytes(res)
|
||||
.await
|
||||
.expect("can't get body as bytes")
|
||||
.to_vec(),
|
||||
)
|
||||
.expect("body is not an UTF8 string");
|
||||
|
||||
let lines: Vec<_> = body.lines().map(|s| Ok(s.to_owned())).collect();
|
||||
prometheus_parse::Scrape::parse(lines.into_iter())
|
||||
.expect("Scraper failed to parse Prometheus metrics")
|
||||
.samples
|
||||
.into_iter()
|
||||
.filter_map(|prometheus_parse::Sample { metric, value, .. }| match value {
|
||||
prometheus_parse::Value::Counter(value) => Some((metric, value as u64)),
|
||||
prometheus_parse::Value::Gauge(value) => Some((metric, value as u64)),
|
||||
prometheus_parse::Value::Untyped(value) => Some((metric, value as u64)),
|
||||
_ => None,
|
||||
})
|
||||
.filter_map(
|
||||
|prometheus_parse::Sample { metric, value, .. }| match value {
|
||||
prometheus_parse::Value::Counter(value) => Some((metric, value as u64)),
|
||||
prometheus_parse::Value::Gauge(value) => Some((metric, value as u64)),
|
||||
prometheus_parse::Value::Untyped(value) => Some((metric, value as u64)),
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
.collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user