Skip to content
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

feat(uptime): add redirect errors #267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["json"] }
tracing-test = "0.2.5"
console = "0.15.8"
sentry-kafka-schemas = "1.0.5"
sentry-kafka-schemas = "1.1.0"
serde_with = { version = "3.8.1", features = ["chrono"] }
rmp-serde = "1.3.0"
serde_repr = "0.1.19"
Expand Down
1 change: 1 addition & 0 deletions src/check_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ fn record_result_metrics(result: &CheckResult, is_retry: bool, will_retry: bool)
Some(CheckStatusReasonType::Timeout) => Some("timeout"),
Some(CheckStatusReasonType::TlsError) => Some("tls_error"),
Some(CheckStatusReasonType::ConnectionError) => Some("connection_error"),
Some(CheckStatusReasonType::RedirectError) => Some("redirect_error"),
None => None,
};
let status_code = match request_info.as_ref().and_then(|a| a.http_status_code) {
Expand Down
46 changes: 46 additions & 0 deletions src/checker/http_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ impl Checker for HttpChecker {
status_type: CheckStatusReasonType::Timeout,
description: "Request timed out".to_string(),
}
} else if e.is_redirect() {
CheckStatusReason {
status_type: CheckStatusReasonType::RedirectError,
description: "Too many redirects".to_string(),
}
} else if let Some(message) = dns_error(&e) {
CheckStatusReason {
status_type: CheckStatusReasonType::DnsError,
Expand Down Expand Up @@ -744,6 +749,47 @@ mod tests {
);
}

#[tokio::test]
async fn test_too_many_redirects() {
let server = MockServer::start();
let checker = HttpChecker::new_internal(Options {
validate_url: false,
disable_connection_reuse: true,
});

// Create a redirect loop where each request redirects back to itself
let redirect_mock = server.mock(|when, then| {
when.method(Method::GET)
.path("/redirect")
.header_exists("sentry-trace");
then.status(302)
.header("Location", server.url("/redirect").as_str());
});

let config = CheckConfig {
url: server.url("/redirect").to_string(),
..Default::default()
};

let tick = make_tick();
let result = checker.check_url(&config, &tick, "us-west").await;

assert_eq!(result.status, CheckStatus::Failure);
assert_eq!(result.request_info.and_then(|i| i.http_status_code), None);
assert_eq!(
result.status_reason.as_ref().map(|r| r.status_type),
Some(CheckStatusReasonType::RedirectError)
);
assert_eq!(
result.status_reason.map(|r| r.description),
Some("Too many redirects".to_string())
);

// Verify that the mock was called at least once
// The reqwest client follows redirects multiple times before giving up
redirect_mock.assert_hits(10);
}

#[tokio::test]
#[cfg(target_os = "linux")]
async fn test_connection_reset() {
Expand Down
1 change: 1 addition & 0 deletions src/types/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum CheckStatusReasonType {
DnsError,
TlsError,
ConnectionError,
RedirectError,
Failure,
}

Expand Down