From 83e76addca9ff611a948feec39b072e408858e75 Mon Sep 17 00:00:00 2001 From: Joshua Ferge Date: Mon, 24 Feb 2025 17:45:30 -0500 Subject: [PATCH 1/3] feat(uptime): add redirect errors --- src/check_executor.rs | 1 + src/checker/http_checker.rs | 5 +++++ src/types/result.rs | 1 + 3 files changed, 7 insertions(+) diff --git a/src/check_executor.rs b/src/check_executor.rs index 1eed6dc..c70bb47 100644 --- a/src/check_executor.rs +++ b/src/check_executor.rs @@ -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) { diff --git a/src/checker/http_checker.rs b/src/checker/http_checker.rs index 75ceab1..e47af04 100644 --- a/src/checker/http_checker.rs +++ b/src/checker/http_checker.rs @@ -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, diff --git a/src/types/result.rs b/src/types/result.rs index 56fb42e..8ddfb96 100644 --- a/src/types/result.rs +++ b/src/types/result.rs @@ -31,6 +31,7 @@ pub enum CheckStatusReasonType { DnsError, TlsError, ConnectionError, + RedirectError, Failure, } From da28cb8f167ee695abeee674c566c353a342e6cf Mon Sep 17 00:00:00 2001 From: Joshua Ferge Date: Mon, 24 Feb 2025 22:06:37 -0500 Subject: [PATCH 2/3] add test for redirects --- src/checker/http_checker.rs | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/checker/http_checker.rs b/src/checker/http_checker.rs index e47af04..3414a1e 100644 --- a/src/checker/http_checker.rs +++ b/src/checker/http_checker.rs @@ -749,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() { From c14852f071acc9dc9db4c92e25a0cdb177601d67 Mon Sep 17 00:00:00 2001 From: Joshua Ferge Date: Tue, 25 Feb 2025 12:50:30 -0500 Subject: [PATCH 3/3] bump sentry kafka schemas --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18fa6e2..94895c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1536,7 +1536,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.7", "tokio", "tower-service", "tracing", @@ -1993,7 +1993,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -3323,9 +3323,9 @@ dependencies = [ [[package]] name = "sentry-kafka-schemas" -version = "1.0.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775426b2478f7dd0002f533db77aaaea575966057d39a8b3f1cf58e68d7f2b8b" +checksum = "e947a81fe9a146f9f7a8a2544afe0f950b03022f6a99426f527c728f527fffea" dependencies = [ "jsonschema", "prettyplease", diff --git a/Cargo.toml b/Cargo.toml index 4d5aeeb..ad43142 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"