-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom metrics and dht sync lag scenario
- Loading branch information
1 parent
7448012
commit dfd9c25
Showing
17 changed files
with
383 additions
and
17 deletions.
There are no files selected for viewing
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,12 +1,77 @@ | ||
mod metrics_report; | ||
mod summary_report; | ||
|
||
use std::ops::Deref; | ||
use influxive_core::{Metric, StringType}; | ||
use crate::OperationRecord; | ||
|
||
pub use metrics_report::MetricsReportCollector; | ||
pub use summary_report::SummaryReportCollector; | ||
|
||
/// A simple, opinionated, newtype for the influxive_core::Metric type. | ||
/// | ||
/// The reported timestamp for the metric will be the current time when the metric is created. | ||
/// The name you choose will be transformed into `ws.instruments.custom.<name>`. | ||
pub struct ReportMetric(Metric); | ||
|
||
impl ReportMetric { | ||
pub fn new(name: &str) -> Self { | ||
Self(Metric::new( | ||
std::time::SystemTime::now(), | ||
format!("wt.custom.{}", name), | ||
)) | ||
} | ||
|
||
pub fn with_field<N, V>(mut self, name: N, value: V) -> Self | ||
where | ||
N: Into<StringType>, | ||
V: Into<influxive_core::DataType>, | ||
{ | ||
self.0 = self.0.with_field(name, value); | ||
self | ||
} | ||
|
||
pub fn with_tag<N, V>(mut self, name: N, value: V) -> Self | ||
where | ||
N: Into<StringType>, | ||
V: Into<influxive_core::DataType>, | ||
{ | ||
self.0 = self.0.with_tag(name, value); | ||
self | ||
} | ||
|
||
pub(crate) fn into_inner(self) -> Metric { | ||
self.0 | ||
} | ||
} | ||
|
||
// TODO temporary, prefer to do without multiple reporter implementations | ||
impl Clone for ReportMetric { | ||
fn clone(&self) -> Self { | ||
let mut new_inner = Metric::new(self.timestamp, self.name.clone()); | ||
for (k, v) in &self.fields { | ||
new_inner = new_inner.with_field(k.clone(), v.clone()); | ||
} | ||
for (k, v) in &self.tags { | ||
new_inner = new_inner.with_tag(k.clone(), v.clone()); | ||
} | ||
Self(new_inner) | ||
} | ||
} | ||
|
||
impl Deref for ReportMetric { | ||
type Target = Metric; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
pub trait ReportCollector { | ||
fn add_operation(&mut self, operation_record: &OperationRecord); | ||
|
||
/// Record a custom metric that | ||
fn add_custom(&mut self, metric: ReportMetric); | ||
|
||
fn finalize(&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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"apiVersion":"influxdata.com/v2alpha1","kind":"Dashboard","metadata":{"name":"victorious-kapitsa-bf8001"},"spec":{"charts":[{"axes":[{"base":"10","name":"x","scale":"linear"},{"base":"10","name":"y","scale":"linear","suffix":"s"}],"colorizeRows":true,"colors":[{"id":"EeycwCWfyw0YSbHfK-_bg","name":"Color Blind Friendly - Light","type":"scale","hex":"#FFFFFF"},{"id":"reCGKSBa8F4FXQG3VYe_B","name":"Color Blind Friendly - Light","type":"scale","hex":"#E69F00"},{"id":"LwHjuuBTah-Q6Kv31XbMb","name":"Color Blind Friendly - Light","type":"scale","hex":"#56B4E9"},{"id":"UYJNhccStV1szRDzc5ZS8","name":"Color Blind Friendly - Light","type":"scale","hex":"#009E73"},{"id":"ZaGqV7BaVmHtlZZ7QiBR9","name":"Color Blind Friendly - Light","type":"scale","hex":"#F0E442"},{"id":"MLJ4MzW3SBtxs8E6jW8FB","name":"Color Blind Friendly - Light","type":"scale","hex":"#0072B2"},{"id":"XQFWzHtO8a6lHXL2D1mHH","name":"Color Blind Friendly - Light","type":"scale","hex":"#D55E00"},{"id":"mwVE20owCu-EGZVTQ7aca","name":"Color Blind Friendly - Light","type":"scale","hex":"#CC79A7"}],"geom":"line","height":4,"hoverDimension":"auto","kind":"Xy","legendColorizeRows":true,"legendOpacity":1,"legendOrientationThreshold":100000000,"name":"Sync Lag (mean)","opacity":1,"orientationThreshold":100000000,"position":"overlaid","queries":[{"query":"from(bucket: \"windtunnel\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"wt.custom.dht_sync_lag\")\n |> filter(fn: (r) => r[\"_field\"] == \"value\")\n |> map(fn: (r) => ({ r with _value: r._value / 1000.0 })) \n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")"}],"shade":true,"staticLegend":{"colorizeRows":true,"opacity":1,"orientationThreshold":100000000,"widthRatio":1},"width":6,"widthRatio":1,"xCol":"_time","yCol":"_value"},{"axes":[{"base":"10","name":"x","scale":"linear"},{"base":"10","name":"y","scale":"linear"}],"colorizeRows":true,"colors":[{"id":"2VIaJgN6zA7q-7pJxjW6R","name":"Color Blind Friendly - Light","type":"scale","hex":"#FFFFFF"},{"id":"54Pm1akf7W1i6Qu-haF2O","name":"Color Blind Friendly - Light","type":"scale","hex":"#E69F00"},{"id":"ka2GpKDmGeoX3CkjCsVB9","name":"Color Blind Friendly - Light","type":"scale","hex":"#56B4E9"},{"id":"p2jDtNTUfRNUXEDkHLo3_","name":"Color Blind Friendly - Light","type":"scale","hex":"#009E73"},{"id":"v1bMU4KDeOO9f-cKvLwcz","name":"Color Blind Friendly - Light","type":"scale","hex":"#F0E442"},{"id":"fKPuvSYrt7IdU29E-Lu4G","name":"Color Blind Friendly - Light","type":"scale","hex":"#0072B2"},{"id":"meYBhHM7mf6ZaNQiQy8vb","name":"Color Blind Friendly - Light","type":"scale","hex":"#D55E00"},{"id":"nu4Wev2n_a_Zu712_arTE","name":"Color Blind Friendly - Light","type":"scale","hex":"#CC79A7"}],"geom":"line","height":4,"hoverDimension":"auto","kind":"Xy","legendColorizeRows":true,"legendOpacity":1,"legendOrientationThreshold":100000000,"name":"Send count","opacity":1,"orientationThreshold":100000000,"position":"overlaid","queries":[{"query":"from(bucket: \"windtunnel\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"wt.custom.dht_sync_sent_count\")\n |> filter(fn: (r) => r[\"_field\"] == \"value\")\n |> increase()\n |> yield(name: \"increase\")"}],"shade":true,"staticLegend":{"colorizeRows":true,"opacity":1,"orientationThreshold":100000000,"widthRatio":1},"width":6,"widthRatio":1,"xCol":"_time","yCol":"_value","yPos":4},{"axes":[{"base":"10","name":"x","scale":"linear"},{"base":"10","name":"y","scale":"linear","suffix":"s"}],"colorizeRows":true,"colors":[{"id":"EeycwCWfyw0YSbHfK-_bg","name":"Color Blind Friendly - Light","type":"scale","hex":"#FFFFFF"},{"id":"reCGKSBa8F4FXQG3VYe_B","name":"Color Blind Friendly - Light","type":"scale","hex":"#E69F00"},{"id":"LwHjuuBTah-Q6Kv31XbMb","name":"Color Blind Friendly - Light","type":"scale","hex":"#56B4E9"},{"id":"UYJNhccStV1szRDzc5ZS8","name":"Color Blind Friendly - Light","type":"scale","hex":"#009E73"},{"id":"ZaGqV7BaVmHtlZZ7QiBR9","name":"Color Blind Friendly - Light","type":"scale","hex":"#F0E442"},{"id":"MLJ4MzW3SBtxs8E6jW8FB","name":"Color Blind Friendly - Light","type":"scale","hex":"#0072B2"},{"id":"XQFWzHtO8a6lHXL2D1mHH","name":"Color Blind Friendly - Light","type":"scale","hex":"#D55E00"},{"id":"mwVE20owCu-EGZVTQ7aca","name":"Color Blind Friendly - Light","type":"scale","hex":"#CC79A7"}],"geom":"line","height":4,"hoverDimension":"auto","kind":"Xy","legendColorizeRows":true,"legendOpacity":1,"legendOrientationThreshold":100000000,"name":"Sync Lag (max)","opacity":1,"orientationThreshold":100000000,"position":"overlaid","queries":[{"query":"from(bucket: \"windtunnel\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"wt.custom.dht_sync_lag\")\n |> filter(fn: (r) => r[\"_field\"] == \"value\")\n |> map(fn: (r) => ({ r with _value: r._value / 1000.0 })) \n |> aggregateWindow(every: v.windowPeriod, fn: max, createEmpty: false)\n |> yield(name: \"max\")"}],"shade":true,"staticLegend":{"colorizeRows":true,"opacity":1,"orientationThreshold":100000000,"widthRatio":1},"width":6,"widthRatio":1,"xCol":"_time","xPos":6,"yCol":"_value"},{"axes":[{"base":"10","name":"x","scale":"linear"},{"base":"10","name":"y","scale":"linear"}],"colorizeRows":true,"colors":[{"id":"2VIaJgN6zA7q-7pJxjW6R","name":"Color Blind Friendly - Light","type":"scale","hex":"#FFFFFF"},{"id":"54Pm1akf7W1i6Qu-haF2O","name":"Color Blind Friendly - Light","type":"scale","hex":"#E69F00"},{"id":"ka2GpKDmGeoX3CkjCsVB9","name":"Color Blind Friendly - Light","type":"scale","hex":"#56B4E9"},{"id":"p2jDtNTUfRNUXEDkHLo3_","name":"Color Blind Friendly - Light","type":"scale","hex":"#009E73"},{"id":"v1bMU4KDeOO9f-cKvLwcz","name":"Color Blind Friendly - Light","type":"scale","hex":"#F0E442"},{"id":"fKPuvSYrt7IdU29E-Lu4G","name":"Color Blind Friendly - Light","type":"scale","hex":"#0072B2"},{"id":"meYBhHM7mf6ZaNQiQy8vb","name":"Color Blind Friendly - Light","type":"scale","hex":"#D55E00"},{"id":"nu4Wev2n_a_Zu712_arTE","name":"Color Blind Friendly - Light","type":"scale","hex":"#CC79A7"}],"geom":"line","height":4,"hoverDimension":"auto","kind":"Xy","legendColorizeRows":true,"legendOpacity":1,"legendOrientationThreshold":100000000,"name":"Recieved count","opacity":1,"orientationThreshold":100000000,"position":"overlaid","queries":[{"query":"from(bucket: \"windtunnel\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"wt.custom.dht_sync_recv_count\")\n |> filter(fn: (r) => r[\"_field\"] == \"value\")\n |> increase()\n |> yield(name: \"increase\")"}],"shade":true,"staticLegend":{"colorizeRows":true,"opacity":1,"orientationThreshold":100000000,"widthRatio":1},"width":6,"widthRatio":1,"xCol":"_time","xPos":6,"yCol":"_value","yPos":4}],"name":"DHT Sync Lag"}}] |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "dht_sync_lag" | ||
version = "0.1.0" | ||
edition = "2021" | ||
build = "../scenario_build.rs" | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
holochain_types = { workspace = true } | ||
holochain_wind_tunnel_runner = { workspace = true } | ||
timed_integrity = { workspace = true } | ||
|
||
[build-dependencies] | ||
toml = { workspace = true } | ||
anyhow = { workspace = true } | ||
holochain_types = { workspace = true } | ||
serde_yaml = { workspace = true } | ||
walkdir = { workspace = true } | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[package.metadata.required-dna] | ||
name = "timed" | ||
zomes = ["timed"] | ||
|
||
[package.metadata.required-happ] | ||
name = "timed" | ||
dnas = ["timed"] |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## dht_sync_lag | ||
|
||
### Description | ||
|
||
This scenario has two roles: | ||
- _write_: A simple job that just creates entries with a timestamp field. Those entries are linked to a known base hash. | ||
- _record_lag_: A job that repeatedly queries for links from the known base hash. It keeps track of records that it has seen | ||
and when a new record is found, it calculates the time difference between the timestamp of the new record and the current time. | ||
That time difference is then recorded as a custom metric called `wt.custom.dht_sync_lag`. | ||
|
||
### Suggested command | ||
|
||
You can run the scenario locally with the following command: | ||
|
||
```bash | ||
RUST_LOG=info cargo run --package dht_sync_lag -- --connection-string ws://localhost:8888 --agents 2 --behaviour write:1 --behaviour record_lag:1 --duration 900 | ||
``` | ||
|
||
However, doing so is not that meaningful because data is all local so the lag should be minimal. | ||
|
||
Running the scenario distributed is suggested to be done by partitioning your nodes. The first group run the command: | ||
|
||
```bash | ||
RUST_LOG=info cargo run --package dht_sync_lag -- --connection-string ws://localhost:8888 --behaviour write --duration 300 | ||
``` | ||
|
||
Then the second group run command: | ||
|
||
```bash | ||
RUST_LOG=info cargo run --package dht_sync_lag -- --connection-string ws://localhost:8888 --behaviour record_lag --duration 900 | ||
``` |
Oops, something went wrong.