From a395e3f0e432b10d670a8cef4a488c125bb177d0 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Mon, 24 Jun 2024 21:07:23 -0700 Subject: [PATCH] fix(cloud): add clean timeout for matchmaker logs (#942) Fixes RVTEE-134 --- infra/tf/vector/vector.tf | 3 ++- lib/util/core/src/lib.rs | 7 +++++++ lib/util/macros/src/lib.rs | 7 +------ svc/api/cloud/src/route/games/matchmaker.rs | 5 +++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/infra/tf/vector/vector.tf b/infra/tf/vector/vector.tf index 8f12b5497..b0d5acf1d 100644 --- a/infra/tf/vector/vector.tf +++ b/infra/tf/vector/vector.tf @@ -137,7 +137,8 @@ resource "helm_release" "vector" { ca_file = "/usr/local/share/ca-certificates/clickhouse-ca.crt" } : {} batch = { - timeout_secs = 5.0 + # Speed up for realtime-ish logs + timeout_secs = 1.0 } } diff --git a/lib/util/core/src/lib.rs b/lib/util/core/src/lib.rs index 28cb9cf52..1b512de33 100644 --- a/lib/util/core/src/lib.rs +++ b/lib/util/core/src/lib.rs @@ -22,6 +22,13 @@ pub mod sort; pub mod timestamp; pub mod uuid; +pub mod watch { + /// Represented in seconds. + /// + /// See docs/infrastructure/TIMEOUTS.md for reasoning. + pub const DEFAULT_TIMEOUT: u64 = 40 * 1000; +} + #[cfg(feature = "serde")] pub mod serde { use aws_smithy_types::Document; diff --git a/lib/util/macros/src/lib.rs b/lib/util/macros/src/lib.rs index 571ffb6c4..4528b8814 100644 --- a/lib/util/macros/src/lib.rs +++ b/lib/util/macros/src/lib.rs @@ -10,11 +10,6 @@ use syn::{ Expr, Ident, Result, Token, }; -/// Represented in seconds. -/// -/// See docs/infrastructure/TIMEOUTS.md for reasoning. -const DEFAULT_TIMEOUT: u64 = 40 * 1000; - mod kw { syn::custom_keyword!(JITTER); } @@ -172,7 +167,7 @@ pub fn select_with_timeout(item: TokenStream) -> TokenStream { let (timeout, timeout_scale) = data .timeout .map(|(timeout, timeout_scale)| (timeout.to_token_stream(), timeout_scale)) - .unwrap_or((quote! { #DEFAULT_TIMEOUT }, 1)); + .unwrap_or((quote! { util::watch::DEFAULT_TIMEOUT }, 1)); let returning = data.returning.map_or_else( || { quote! {Default::default()} diff --git a/svc/api/cloud/src/route/games/matchmaker.rs b/svc/api/cloud/src/route/games/matchmaker.rs index 737716d2b..f3658a48d 100644 --- a/svc/api/cloud/src/route/games/matchmaker.rs +++ b/svc/api/cloud/src/route/games/matchmaker.rs @@ -204,6 +204,11 @@ pub async fn get_lobby_logs( break logs_res; } + // Timeout cleanly + if query_start.elapsed().as_millis() > util::watch::DEFAULT_TIMEOUT as u128 { + break job_log::read::Response { entries: Vec::new() }; + } + // Throttle request // // We don't use `tokio::time::interval` because if the request takes longer than 500