-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from tursodatabase/lucio/sim-test-metrics
sim-tests: add asserts for metrics
- Loading branch information
Showing
8 changed files
with
146 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,83 @@ | ||
#![allow(dead_code)] | ||
|
||
use std::collections::HashMap; | ||
|
||
use metrics::{SharedString, Unit}; | ||
use metrics_util::{ | ||
debugging::{DebugValue, Snapshotter}, | ||
CompositeKey, MetricKind, | ||
}; | ||
|
||
pub mod http; | ||
pub mod net; | ||
|
||
pub fn print_metrics() { | ||
let snapshot = MetricsSnapshot::current(); | ||
|
||
eprintln!("{:?}", snapshot); | ||
} | ||
|
||
#[track_caller] | ||
pub fn snapshot_metrics() -> MetricsSnapshot { | ||
MetricsSnapshot::current() | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct MetricsSnapshot { | ||
snapshot: HashMap<CompositeKey, (Option<Unit>, Option<SharedString>, DebugValue)>, | ||
} | ||
|
||
impl MetricsSnapshot { | ||
#[track_caller] | ||
pub fn current() -> Self { | ||
let snapshot = Snapshotter::current_thread_snapshot() | ||
.expect("No snapshot available") | ||
.into_hashmap(); | ||
|
||
MetricsSnapshot { snapshot } | ||
} | ||
|
||
pub fn get_counter(&self, metric_name: &str) -> Option<u64> { | ||
for (key, (_, _, val)) in &self.snapshot { | ||
if key.kind() == MetricKind::Counter && key.key().name() == metric_name { | ||
match val { | ||
DebugValue::Counter(v) => return Some(*v), | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
|
||
None | ||
} | ||
|
||
pub fn get_gauge(&self, metric_name: &str) -> Option<f64> { | ||
for (key, (_, _, val)) in &self.snapshot { | ||
if key.kind() == MetricKind::Gauge && key.key().name() == metric_name { | ||
match val { | ||
DebugValue::Gauge(v) => return Some(v.0), | ||
_ => unreachable!(), | ||
} | ||
} | ||
} | ||
|
||
None | ||
} | ||
|
||
#[track_caller] | ||
pub fn assert_gauge(&self, metric_name: &str, value: f64) -> &Self { | ||
let val = self.get_gauge(metric_name).expect("metric does not exist"); | ||
|
||
assert_eq!(val, value); | ||
self | ||
} | ||
|
||
#[track_caller] | ||
pub fn assert_counter(&self, metric_name: &str, value: u64) -> &Self { | ||
let val = self | ||
.get_counter(metric_name) | ||
.expect("metric does not exist"); | ||
|
||
assert_eq!(val, value); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#![allow(clippy::disallowed_names)] | ||
|
||
mod cluster; | ||
#[macro_use] | ||
mod common; | ||
|
||
mod cluster; | ||
mod embedded_replica; | ||
mod namespaces; | ||
mod standalone; |