diff --git a/packages/check-http/src/checking.rs b/packages/check-http/src/checking.rs index c85d52f70e4..ca27002a68a 100644 --- a/packages/check-http/src/checking.rs +++ b/packages/check-http/src/checking.rs @@ -19,13 +19,13 @@ use crate::http::ProcessedResponse; // So we're modelling exactly this. pub struct UpperLevels { - warn: T, - crit: Option, + pub warn: T, + pub crit: Option, } impl UpperLevels where - T: Ord + PartialOrd, + T: PartialOrd, { pub fn warn(warn: T) -> Self { Self { warn, crit: None } @@ -57,7 +57,7 @@ pub struct Bounds { impl Bounds where - T: Ord + PartialOrd, + T: PartialOrd, { pub fn lower(lower: T) -> Self { Self { lower, upper: None } @@ -178,8 +178,8 @@ pub enum CheckResult { pub struct CheckParameters { pub onredirect: OnRedirect, pub page_size: Option>, - pub response_time_levels: Option>, - pub document_age_levels: Option>, + pub response_time_levels: Option>, + pub document_age_levels: Option>, } pub fn collect_response_checks( @@ -248,10 +248,10 @@ fn check_page_size(page_size: usize, page_size_limits: Option>) -> fn check_response_time( response_time: Duration, - response_time_levels: Option>, + response_time_levels: Option>, ) -> Option { let state = response_time_levels - .and_then(|levels| levels.evaluate(&response_time)) + .and_then(|levels| levels.evaluate(&response_time.as_secs_f64())) .unwrap_or(State::Ok); Some(CheckItem { @@ -266,7 +266,7 @@ fn check_response_time( fn check_document_age( headers: &HeaderMap, - document_age_levels: Option>, + document_age_levels: Option>, ) -> Option { let document_age_levels = document_age_levels?; @@ -295,7 +295,7 @@ fn check_document_age( return cr_document_age_error; }; - let state = document_age_levels.evaluate(&age)?; + let state = document_age_levels.evaluate(&age.as_secs())?; //TODO(au): Specify "too old" in Output Some(CheckItem { @@ -375,12 +375,9 @@ mod test_check_response_time { #[test] fn test_warn_within_bounds() { assert_eq!( - check_response_time( - Duration::new(5, 0), - Some(UpperLevels::warn(Duration::new(6, 0))) - ) - .unwrap() - .state, + check_response_time(Duration::new(5, 0), Some(UpperLevels::warn(6.))) + .unwrap() + .state, State::Ok ); } @@ -388,12 +385,9 @@ mod test_check_response_time { #[test] fn test_warn_is_warn() { assert_eq!( - check_response_time( - Duration::new(5, 0), - Some(UpperLevels::warn(Duration::new(4, 0))) - ) - .unwrap() - .state, + check_response_time(Duration::new(5, 0), Some(UpperLevels::warn(4.))) + .unwrap() + .state, State::Warn ); } @@ -401,15 +395,9 @@ mod test_check_response_time { #[test] fn test_warncrit_within_bounds() { assert_eq!( - check_response_time( - Duration::new(5, 0), - Some(UpperLevels::warn_crit( - Duration::new(6, 0), - Duration::new(7, 0) - )) - ) - .unwrap() - .state, + check_response_time(Duration::new(5, 0), Some(UpperLevels::warn_crit(6., 7.))) + .unwrap() + .state, State::Ok ); } @@ -417,15 +405,9 @@ mod test_check_response_time { #[test] fn test_warncrit_is_warn() { assert_eq!( - check_response_time( - Duration::new(5, 0), - Some(UpperLevels::warn_crit( - Duration::new(4, 0), - Duration::new(6, 0) - )) - ) - .unwrap() - .state, + check_response_time(Duration::new(5, 0), Some(UpperLevels::warn_crit(4., 6.))) + .unwrap() + .state, State::Warn ); } @@ -433,15 +415,9 @@ mod test_check_response_time { #[test] fn test_warncrit_is_crit() { assert_eq!( - check_response_time( - Duration::new(5, 0), - Some(UpperLevels::warn_crit( - Duration::new(2, 0), - Duration::new(3, 0) - )) - ) - .unwrap() - .state, + check_response_time(Duration::new(5, 0), Some(UpperLevels::warn_crit(2., 3.))) + .unwrap() + .state, State::Crit ); } diff --git a/packages/check-http/src/main.rs b/packages/check-http/src/main.rs index a6d6d94cb3c..d60af12dec2 100644 --- a/packages/check-http/src/main.rs +++ b/packages/check-http/src/main.rs @@ -9,7 +9,6 @@ use check_http::output::Output; use check_http::runner::collect_checks; use clap::Parser; use cli::Cli; -use std::time::Duration; mod cli; mod pwstore; @@ -76,14 +75,10 @@ fn make_configs( (x, Some(y)) => Bounds::lower_upper(x, y), }), response_time_levels: args.response_time_levels.map(|val| match val { - (x, None) => UpperLevels::warn(Duration::from_secs_f64(x)), - (x, Some(y)) => { - UpperLevels::warn_crit(Duration::from_secs_f64(x), Duration::from_secs_f64(y)) - } + (x, None) => UpperLevels::warn(x), + (x, Some(y)) => UpperLevels::warn_crit(x, y), }), - document_age_levels: args - .document_age_levels - .map(|val| UpperLevels::warn(Duration::from_secs(val))), + document_age_levels: args.document_age_levels.map(UpperLevels::warn), }, ) }