mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-04 16:09:05 +00:00
fix: fix middleware check (#8986)
There were few issues with the middleware, this attempts to fix it. --------- Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com> Co-authored-by: Yashodhan Joshi <yjdoc2@gmail.com>
This commit is contained in:
co-authored by
Yashodhan Joshi
parent
12aedbf858
commit
a5ea45bd54
@@ -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]
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user