-
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.
- Loading branch information
1 parent
84a5576
commit 9365e09
Showing
14 changed files
with
241 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,4 @@ logs/**/*.log | |
*.key | ||
/data | ||
scenarios/*/logs | ||
run_summary.jsonl |
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
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,18 @@ | ||
[package] | ||
name = "wind_tunnel_summary_model" | ||
version = "0.3.0-alpha.1" | ||
description = "The Wind Tunnel summary model" | ||
license = "MIT" | ||
authors = ["ThetaSinner"] | ||
edition = "2021" | ||
categories = ["development-tools::testing", "development-tools::profiling"] | ||
homepage = "https://github.com/holochain/wind-tunnel" | ||
repository = "https://github.com/holochain/wind-tunnel" | ||
|
||
[dependencies] | ||
serde = { workspace = true, features = ["derive"] } | ||
serde_json = { workspace = true } | ||
anyhow = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
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,119 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use std::collections::HashMap; | ||
use std::io::{BufRead, Write}; | ||
use std::path::PathBuf; | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
/// Summary of a run | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct RunSummary { | ||
/// The unique run id | ||
/// | ||
/// Chosen by the runner. Unique for each run. | ||
pub run_id: String, | ||
/// The name of the scenario that was run | ||
pub scenario_name: String, | ||
/// The time the run started | ||
/// | ||
/// This is a Unix timestamp in seconds. | ||
pub started_at: u64, | ||
/// The duration that the run was configured with, in seconds | ||
/// | ||
/// If the run was configured for soak testing, then this will not be set. | ||
/// | ||
/// It is possible that the run finished sooner than `started_at + run_duration` if all | ||
/// behaviours failed. As long as [RunSummary::peer_end_count] is greater than 0 then that | ||
/// number of agents will have run for the full duration. | ||
pub run_duration: Option<u64>, | ||
/// The number of peers configured | ||
/// | ||
/// This is the number of peers that were either configured or required by the behaviour | ||
/// configuration. | ||
pub peer_count: usize, | ||
/// The number of peers at the end of the test | ||
/// | ||
/// If some peers exit early, for example due to a fatal error during a behaviour run or an | ||
/// unavailable conductor, then this will be less than [RunSummary::peer_count]. | ||
pub peer_end_count: usize, | ||
/// The behaviour configuration | ||
/// | ||
/// This is the number of agents that were assigned to each behaviour. | ||
pub behaviours: HashMap<String, usize>, | ||
/// Environment variables set for the run | ||
/// | ||
/// This won't capture all environment variables. Just the ones that the runner is aware of or | ||
/// that are included by the scenario itself. | ||
pub env: HashMap<String, String>, | ||
} | ||
|
||
impl RunSummary { | ||
/// Create a new run summary | ||
pub fn new( | ||
run_id: String, | ||
scenario_name: String, | ||
started_at: SystemTime, | ||
run_duration: Option<u64>, | ||
peer_count: usize, | ||
behaviours: HashMap<String, usize>, | ||
) -> Self { | ||
Self { | ||
run_id, | ||
scenario_name, | ||
started_at: started_at | ||
.duration_since(UNIX_EPOCH) | ||
.expect("Time went backwards") | ||
.as_secs(), | ||
run_duration, | ||
peer_count, | ||
peer_end_count: 0, | ||
behaviours, | ||
env: HashMap::with_capacity(0), | ||
} | ||
} | ||
|
||
/// Set the peer end count | ||
pub fn set_peer_end_count(&mut self, peer_end_count: usize) { | ||
self.peer_end_count = peer_end_count; | ||
} | ||
|
||
/// Add an environment variable | ||
pub fn add_env(&mut self, key: String, value: String) { | ||
self.env.insert(key, value); | ||
} | ||
} | ||
|
||
/// Append the run summary to a file | ||
/// | ||
/// The summary will be serialized to JSON and output as a single line followed by a newline. The | ||
/// recommended file extension is `.jsonl`. | ||
pub fn append_run_summary(run_summary: RunSummary, path: PathBuf) -> anyhow::Result<()> { | ||
let mut file = std::fs::OpenOptions::new() | ||
.append(true) | ||
.create(true) | ||
.open(path)?; | ||
store_run_summary(run_summary, &mut file)?; | ||
file.write("\n".as_bytes())?; | ||
Ok(()) | ||
} | ||
|
||
/// Serialize the run summary to a writer | ||
pub fn store_run_summary<W: Write>(run_summary: RunSummary, writer: &mut W) -> anyhow::Result<()> { | ||
serde_json::to_writer(writer, &run_summary)?; | ||
Ok(()) | ||
} | ||
|
||
/// Load run summaries from a file | ||
/// | ||
/// The file should contain one JSON object per line. This is the format produced by | ||
/// [append_run_summary]. | ||
pub fn load_summary_runs(path: PathBuf) -> anyhow::Result<Vec<RunSummary>> { | ||
let file = std::fs::File::open(path)?; | ||
let reader = std::io::BufReader::new(file); | ||
let mut runs = Vec::new(); | ||
for line in reader.lines() { | ||
let line = line?; | ||
let run: RunSummary = serde_json::from_str(&line)?; | ||
runs.push(run); | ||
} | ||
Ok(runs) | ||
} |
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,13 @@ | ||
[package] | ||
name = "holochain_summariser" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
influxdb = { workspace = true } | ||
itertools = { workspace = true } | ||
|
||
wind_tunnel_summary_model = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
Oops, something went wrong.