Skip to content

Conversation

@klochek
Copy link
Contributor

@klochek klochek commented Nov 20, 2025

No description provided.

@klochek klochek requested a review from a team as a code owner November 20, 2025 15:28
@klochek klochek force-pushed the christopherklochek/web_server_checks branch from eabbdae to 3d51390 Compare November 20, 2025 15:56
Copy link
Member

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?

Copy link
Contributor Author

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!)

Copy link
Member

@evanpurkhiser evanpurkhiser left a 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?

@klochek klochek changed the title feat(uptime): add assertion checks to check_executor; add endpoint check feat(uptime): add assertion checks to check_executor Nov 24, 2025
@klochek
Copy link
Contributor Author

klochek commented Nov 24, 2025

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.

Comment on lines 54 to 60
{
let rl = self.compiled.read().expect("not poisoned");

if let Some(entry) = rl.get(key) {
return Ok(entry.assertion.clone());
}
}
Copy link
Member

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?

Comment on lines 54 to 60
{
let rl = self.compiled.read().expect("not poisoned");

if let Some(entry) = rl.get(key) {
return Ok(entry.assertion.clone());
}
}
Copy link
Member

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

Suggested change
{
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());
}

Comment on lines 379 to 389
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,
};
Copy link
Member

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.

Comment on lines 275 to 331
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(),
}),
)
}
}
Copy link
Member

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

@klochek klochek merged commit 208519e into main Dec 1, 2025
13 checks passed
@klochek klochek deleted the christopherklochek/web_server_checks branch December 1, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants