-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat(uptime): add assertion checks to check_executor #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
eabbdae to
3d51390
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is all this robots stuff supposed to be in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it was here before, it just stands out because of the factoring I did (the check code was getting really lengthy and difficult to read; I hope this is an improvement!)
evanpurkhiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to split this up, one PR for adding actual assertion checking, and another for adding it into the endpoint?
Okay, endpoint work has been reverted; this is just the execution flow. |
src/assertions/cache.rs
Outdated
| { | ||
| let rl = self.compiled.read().expect("not poisoned"); | ||
|
|
||
| if let Some(entry) = rl.get(key) { | ||
| return Ok(entry.assertion.clone()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the block to drop the read lock right?
src/assertions/cache.rs
Outdated
| { | ||
| let rl = self.compiled.read().expect("not poisoned"); | ||
|
|
||
| if let Some(entry) = rl.get(key) { | ||
| return Ok(entry.assertion.clone()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you could avoid the block here if you wrote this as
| { | |
| let rl = self.compiled.read().expect("not poisoned"); | |
| if let Some(entry) = rl.get(key) { | |
| return Ok(entry.assertion.clone()); | |
| } | |
| } | |
| if let Some(entry) = self.compiled.read().expect("not poisoned").get(key) { | |
| return Ok(entry.assertion.clone()); | |
| } |
src/check_executor.rs
Outdated
| let failure_reason = match status_reason.as_ref().map(|r| &r.status_type) { | ||
| Some(CheckStatusReasonType::Failure) => Some("failure"), | ||
| Some(CheckStatusReasonType::DnsError) => Some("dns_error"), | ||
| Some(CheckStatusReasonType::Timeout) => Some("timeout"), | ||
| Some(CheckStatusReasonType::TlsError) => Some("tls_error"), | ||
| Some(CheckStatusReasonType::ConnectionError) => Some("connection_error"), | ||
| Some(CheckStatusReasonType::RedirectError) => Some("redirect_error"), | ||
| Some(CheckStatusReasonType::AssertionFailure) => Some("assertion_failure"), | ||
| Some(CheckStatusReasonType::AssertionError) => Some("assertion_error"), | ||
| None => None, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should put this as a AsStr impl on the CheckStatusReasonType, but not critical.
src/checker/reqwest_checker.rs
Outdated
| fn to_check_status_and_reason( | ||
| assert_cache: &assertions::cache::Cache, | ||
| response: Result<Response, reqwest::Error>, | ||
| check: &ScheduledCheck, | ||
| body_bytes: &[u8], | ||
| subscription_id: &Uuid, | ||
| ) -> (CheckStatus, Option<CheckStatusReason>) { | ||
| match response { | ||
| Ok(r) => match r.status().is_success() { | ||
| true => { | ||
| if let Some(assertion) = &check.get_config().assertion { | ||
| let comp_assert = assert_cache.get_or_compile(assertion); | ||
|
|
||
| match comp_assert { | ||
| Ok(assertion) => { | ||
| let result = | ||
| assertion.eval(r.status().as_u16(), r.headers(), body_bytes); | ||
|
|
||
| match result { | ||
| Ok(result) => { | ||
| if result { | ||
| (CheckStatus::Success, None) | ||
| } else { | ||
| ( | ||
| CheckStatus::Failure, | ||
| Some(CheckStatusReason { | ||
| status_type: | ||
| CheckStatusReasonType::AssertionFailure, | ||
| description: "Assertion failed".to_string(), | ||
| }), | ||
| ) | ||
| } | ||
| } | ||
| Err(err) => ( | ||
| CheckStatus::Failure, | ||
| Some(CheckStatusReason { | ||
| status_type: CheckStatusReasonType::AssertionError, | ||
| description: err.to_string(), | ||
| }), | ||
| ), | ||
| } | ||
| } | ||
| Err(err) => { | ||
| tracing::warn!( | ||
| "a bad assertion made it to compile from {} : {}", | ||
| subscription_id, | ||
| err.to_string(), | ||
| ); | ||
| ( | ||
| CheckStatus::Failure, | ||
| Some(CheckStatusReason { | ||
| status_type: CheckStatusReasonType::AssertionError, | ||
| description: err.to_string(), | ||
| }), | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like to see if we could reduce the pyramid of doom effect here
No description provided.