implemented rtt threshold i guess

This commit is contained in:
Edward Shen 2019-05-03 00:40:34 -04:00
parent 816a6daed1
commit 82b944a748
Signed by: edward
GPG key ID: F350507060ED6C90
3 changed files with 13 additions and 6 deletions

View file

@ -35,7 +35,8 @@
endpoints:[
(label: "The code doesn't match!", endpoint: "http://example.com/", code: 204),
(label: "The body doesn't match!", endpoint: "http://example.com/", body: "asdf"),
(label: "Slow reponse time", endpoint: "http://slowwly.robertomurray.co.uk/delay/2000/url/"),
(label: "Slow reponse time", endpoint: "http://slowwly.robertomurray.co.uk/delay/2000/url/", max_rtt: 1337),
(label: "Plethora of issues!", endpoint: "http://slowwly.robertomurray.co.uk/delay/1000/url/", body: "asdf", code: 418, max_rtt: 50),
(label: "Here's an error:", endpoint: "https://some-invalid-website.arpa")
]
),

View file

@ -9,6 +9,7 @@ pub struct EndpointConfig {
pub body: Option<String>,
pub body_hash: Option<String>,
pub follow_redirects: Option<bool>,
pub max_rtt: Option<i64>,
pub should_err: Option<bool>,
}

View file

@ -68,7 +68,7 @@ fn get_result(
error = append_err_msg(
error,
format!(
"Status code mismatch: {} != {}.",
"Status code mismatch: {} != {}",
res.status().as_u16(),
code
),
@ -84,12 +84,17 @@ fn get_result(
} else if !body.is_empty() && res_body != body {
error = append_err_msg(
error,
format!("Body mismatch: {} != {}.", res_body.len(), body.len()),
format!("Body mismatch: {} != {}", res_body.len(), body.len()),
);
}
if rtt.num_seconds() >= 2 {
error = append_err_msg(error, format!("RTT too long: {}", rtt_string));
if let Some(max_rtt) = endpoint.max_rtt {
if rtt.num_milliseconds() > max_rtt {
error = append_err_msg(
error,
format!("RTT too long: {} > {}s", rtt_string, max_rtt as f64 / 1000.),
);
}
}
if error.is_some() {
@ -122,7 +127,7 @@ fn get_url(base: &Option<String>, path: &String, port: Option<u16>) -> Result<St
fn append_err_msg(optional: Option<String>, to_append: String) -> Option<String> {
Some(match optional {
Some(e) => format!("{} {}", e, to_append),
Some(e) => format!("{}\n{}", e, to_append),
None => to_append,
})
}