diff --git a/src/config/src/router.rs b/src/config/src/router.rs index 3bb633e912..822344b27b 100644 --- a/src/config/src/router.rs +++ b/src/config/src/router.rs @@ -52,7 +52,7 @@ const QUERIER_ROUTES_BY_BODY: [&str; 6] = [ "/prometheus/api/v1/query_exemplars", ]; const FIXED_QUERIER_ROUTES: [&str; 3] = ["/summary", "/schema", "/streams"]; -pub const INGESTER_ROUTES: [&str; 13] = [ +pub const INGESTER_ROUTES: [&str; 12] = [ "/_json", "/_bulk", "/_multi", @@ -65,7 +65,6 @@ pub const INGESTER_ROUTES: [&str; 13] = [ "/v1/metrics", "/traces", "/v1/traces", - "/traces/latest", ]; #[inline] diff --git a/src/handler/http/router/middlewares/org_blocking.rs b/src/handler/http/router/middlewares/org_blocking.rs index 19d80bd501..16160d351f 100644 --- a/src/handler/http/router/middlewares/org_blocking.rs +++ b/src/handler/http/router/middlewares/org_blocking.rs @@ -5,8 +5,9 @@ use actix_web::{ }; #[cfg(feature = "cloud")] use { - crate::service::ingestion::check_ingestion_allowed, actix_web::error::ErrorTooManyRequests, - config::get_config, config::meta::stream::StreamType, + crate::service::organization, + actix_web::error::ErrorTooManyRequests, + config::{cluster::LOCAL_NODE, get_config}, }; pub async fn blocked_orgs_middleware( @@ -30,20 +31,29 @@ pub async fn blocked_orgs_middleware( .next() .unwrap(); - if config::router::INGESTER_ROUTES - .iter() - .any(|r| path.ends_with(r)) + // in middleware, we only want to block ingestion request + // so for non ingester node, we can allow pass. + if LOCAL_NODE.is_ingester() + && config::router::INGESTER_ROUTES + .iter() + .any(|r| path.ends_with(r)) { // for all ingester routes, the first part of path is org_id let org_id = path.split("/").next().unwrap(); - // stream type doesn't matter here, as we are giving name as None - match check_ingestion_allowed(org_id, StreamType::Logs, None).await { - Ok(_) => { - log::warn!("here {org_id} is valid"); + // the function can return error if there ware any db errors or such + // in that case, we allow the request to proceed + match organization::is_org_in_free_trial_period(org_id).await { + Ok(ongoing) => { + // if the trial period is not ongoing, we will block the org here itself + if !ongoing { + log::info!("{org_id} blocked in middleware"); + return Err(ErrorTooManyRequests( + "organization has expired its trial period", + )); + } } Err(e) => { - log::warn!("here, {org_id} expired"); - return Err(ErrorTooManyRequests(e.to_string())); + log::error!("error in middleware while checking for trial period : {e}"); } } }