mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat(health): Health check for Decision engine (#8243)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -12,6 +12,8 @@ pub struct RouterHealthCheckResponse {
|
|||||||
pub outgoing_request: bool,
|
pub outgoing_request: bool,
|
||||||
#[cfg(feature = "dynamic_routing")]
|
#[cfg(feature = "dynamic_routing")]
|
||||||
pub grpc_health_check: HealthCheckMap,
|
pub grpc_health_check: HealthCheckMap,
|
||||||
|
#[cfg(feature = "dynamic_routing")]
|
||||||
|
pub decision_engine: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl common_utils::events::ApiEventMetric for RouterHealthCheckResponse {}
|
impl common_utils::events::ApiEventMetric for RouterHealthCheckResponse {}
|
||||||
|
|||||||
@ -35,6 +35,11 @@ pub trait HealthCheckInterface {
|
|||||||
async fn health_check_grpc(
|
async fn health_check_grpc(
|
||||||
&self,
|
&self,
|
||||||
) -> CustomResult<HealthCheckMap, errors::HealthCheckGRPCServiceError>;
|
) -> CustomResult<HealthCheckMap, errors::HealthCheckGRPCServiceError>;
|
||||||
|
|
||||||
|
#[cfg(feature = "dynamic_routing")]
|
||||||
|
async fn health_check_decision_engine(
|
||||||
|
&self,
|
||||||
|
) -> CustomResult<HealthState, errors::HealthCheckDecisionEngineError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
@ -184,4 +189,25 @@ impl HealthCheckInterface for app::SessionState {
|
|||||||
logger::debug!("Health check successful");
|
logger::debug!("Health check successful");
|
||||||
Ok(health_check_map)
|
Ok(health_check_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dynamic_routing")]
|
||||||
|
async fn health_check_decision_engine(
|
||||||
|
&self,
|
||||||
|
) -> CustomResult<HealthState, errors::HealthCheckDecisionEngineError> {
|
||||||
|
if self.conf.open_router.enabled {
|
||||||
|
let url = format!("{}/{}", &self.conf.open_router.url, "health");
|
||||||
|
let request = services::Request::new(services::Method::Get, &url);
|
||||||
|
let _ = services::call_connector_api(self, request, "health_check_for_decision_engine")
|
||||||
|
.await
|
||||||
|
.change_context(
|
||||||
|
errors::HealthCheckDecisionEngineError::FailedToCallDecisionEngineService,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
logger::debug!("Decision engine health check successful");
|
||||||
|
Ok(HealthState::Running)
|
||||||
|
} else {
|
||||||
|
logger::debug!("Decision engine health check not applicable");
|
||||||
|
Ok(HealthState::NotApplicable)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,6 +108,23 @@ async fn deep_health_check_func(
|
|||||||
|
|
||||||
logger::debug!("gRPC health check end");
|
logger::debug!("gRPC health check end");
|
||||||
|
|
||||||
|
logger::debug!("Decision Engine health check begin");
|
||||||
|
|
||||||
|
#[cfg(feature = "dynamic_routing")]
|
||||||
|
let decision_engine_health_check =
|
||||||
|
state
|
||||||
|
.health_check_decision_engine()
|
||||||
|
.await
|
||||||
|
.map_err(|error| {
|
||||||
|
let message = error.to_string();
|
||||||
|
error.change_context(errors::ApiErrorResponse::HealthCheckError {
|
||||||
|
component: "Decision Engine service",
|
||||||
|
message,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
logger::debug!("Decision Engine health check end");
|
||||||
|
|
||||||
logger::debug!("Opensearch health check begin");
|
logger::debug!("Opensearch health check begin");
|
||||||
|
|
||||||
#[cfg(feature = "olap")]
|
#[cfg(feature = "olap")]
|
||||||
@ -144,6 +161,8 @@ async fn deep_health_check_func(
|
|||||||
outgoing_request: outgoing_check.into(),
|
outgoing_request: outgoing_check.into(),
|
||||||
#[cfg(feature = "dynamic_routing")]
|
#[cfg(feature = "dynamic_routing")]
|
||||||
grpc_health_check,
|
grpc_health_check,
|
||||||
|
#[cfg(feature = "dynamic_routing")]
|
||||||
|
decision_engine: decision_engine_health_check.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(api::ApplicationResponse::Json(response))
|
Ok(api::ApplicationResponse::Json(response))
|
||||||
|
|||||||
@ -280,3 +280,9 @@ pub enum RecoveryError {
|
|||||||
#[error("Failed to fetch billing connector account id")]
|
#[error("Failed to fetch billing connector account id")]
|
||||||
BillingMerchantConnectorAccountIdNotFound,
|
BillingMerchantConnectorAccountIdNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, thiserror::Error)]
|
||||||
|
pub enum HealthCheckDecisionEngineError {
|
||||||
|
#[error("Failed to establish Decision Engine connection")]
|
||||||
|
FailedToCallDecisionEngineService,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user