Skip to content

Commit 55405ab

Browse files
committed
Merge branch 'feature/support_startup_grace'
2 parents 2d822c9 + cbdc25b commit 55405ab

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ clap = { version = "4.4.10", features = ["derive"] }
4343
colored = "2.1.0"
4444
ctrlc = "3.4.5"
4545
dotenvy = "0.15.7"
46+
duration-str = "0.13.0"
4647
futures-util = "0.3.30"
4748
http = "1.1.0"
4849
itertools = "0.13.0"

cardamon.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ curve = [7.627190097500079,0.07551567953624883,20.45110313049153,-1.526142275974
4848
# default: "file"
4949
# required - false
5050
#
51+
# startup_grace:
52+
# type - integer
53+
# desc - the number of milliseconds Cardamon will wait before running
54+
# scenarios
55+
# default - 2000 ms
56+
# required - false
57+
#
5158
# EXAMPLE
5259
# -------
5360
# [[process]]
@@ -57,6 +64,7 @@ curve = [7.627190097500079,0.07551567953624883,20.45110313049153,-1.526142275974
5764
# redirect.to = "file"
5865
# process.type = "docker"
5966
# process.containers = ["postgres"]
67+
# startup_grace = 4000
6068

6169
[[process]]
6270
name = "test_proc"
@@ -135,4 +143,4 @@ processes = ["test_proc"]
135143
#
136144
[[observation]]
137145
name = "test_obs"
138-
scenarios = ["sleep"]
146+
scenarios = ["sleep"]

src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize};
44
use std::{
55
collections::HashSet,
66
fs::{self, File},
7-
io::{Read, Write},
7+
io::{Read, Write}, time::Duration,
88
};
9+
use duration_str::deserialize_option_duration;
910

1011
#[cfg(not(windows))]
1112
static EXAMPLE_CONFIG: &str = include_str!("templates/cardamon.unix.toml");
@@ -215,6 +216,9 @@ pub struct Process {
215216
pub redirect: Option<Redirect>,
216217
#[serde(rename = "process")]
217218
pub process_type: ProcessType,
219+
#[serde(deserialize_with = "deserialize_option_duration")]
220+
#[serde(default)]
221+
pub startup_grace: Option<Duration>,
218222
}
219223

220224
#[derive(Debug, Deserialize, PartialEq, Serialize)]

src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,18 @@ pub async fn run<'a>(
567567
) -> anyhow::Result<DatasetRows> {
568568
let mut processes_to_observe = exec_plan.external_processes_to_observe.unwrap_or(vec![]); // external procs to observe are cloned here.
569569

570+
// Set as minimum grace period, keeping it to stay backwards compatibile
571+
let mut max_grace_millis = 2000_u64;
570572
// run the application if there is anything to run
571573
if !exec_plan.processes_to_execute.is_empty() {
572574
for proc in exec_plan.processes_to_execute {
573575
print!("> starting process {}", proc.name.green());
576+
if let Some(startup_grace) = proc.startup_grace {
577+
let millis = startup_grace.as_millis() as u64;
578+
if millis > max_grace_millis {
579+
max_grace_millis = millis;
580+
}
581+
}
574582

575583
let process_to_observe = run_process(proc)?;
576584

@@ -581,9 +589,9 @@ pub async fn run<'a>(
581589
}
582590
}
583591

584-
print!("> waiting for application to settle");
592+
print!("> waiting for application to settle: {}ms",max_grace_millis);
585593
std::io::stdout().flush()?;
586-
tokio::time::sleep(tokio::time::Duration::from_millis(2000)).await;
594+
tokio::time::sleep(tokio::time::Duration::from_millis(max_grace_millis)).await;
587595
println!(" {}", "\t✓".green());
588596

589597
let start_time = Utc::now().timestamp_millis();
@@ -810,6 +818,7 @@ pub mod tests {
810818
down: None,
811819
redirect: Some(Redirect::Null),
812820
process_type: ProcessType::BareMetal,
821+
startup_grace: None,
813822
};
814823
let proc_to_observe = run_process(&proc)?;
815824

@@ -843,6 +852,7 @@ pub mod tests {
843852
down: None,
844853
redirect: Some(Redirect::Null),
845854
process_type: ProcessType::BareMetal,
855+
startup_grace: None,
846856
};
847857
let procs_to_observe = run_process(&proc)?;
848858
let stop_handle = metrics_logger::start_logging(vec![procs_to_observe])?;

src/templates/cardamon.unix.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
# default: "file"
4545
# required - false
4646
#
47+
# startup_grace:
48+
# type - integer
49+
# desc - the number of milliseconds Cardamon will wait before running
50+
# scenarios
51+
# default - 2000 ms
52+
# required - false
53+
#
4754
# EXAMPLE
4855
# -------
4956
# [[process]]

src/templates/cardamon.win.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
# default: "file"
4545
# required - false
4646
#
47+
# startup_grace:
48+
# type - integer
49+
# desc - the number of milliseconds Cardamon will wait before running
50+
# scenarios
51+
# default - 2000 ms
52+
# required - false
53+
#
4754
# EXAMPLE
4855
# -------
4956
# [[process]]

0 commit comments

Comments
 (0)