Skip to content

Commit d8202eb

Browse files
Sarthak1799hyperswitch-bot[bot]
authored andcommitted
feat(health): Health check for Decision engine (#8243)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent f99e9b7 commit d8202eb

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

crates/api_models/src/health_check.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub struct RouterHealthCheckResponse {
1212
pub outgoing_request: bool,
1313
#[cfg(feature = "dynamic_routing")]
1414
pub grpc_health_check: HealthCheckMap,
15+
#[cfg(feature = "dynamic_routing")]
16+
pub decision_engine: bool,
1517
}
1618

1719
impl common_utils::events::ApiEventMetric for RouterHealthCheckResponse {}

crates/router/src/core/health_check.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ pub trait HealthCheckInterface {
3535
async fn health_check_grpc(
3636
&self,
3737
) -> CustomResult<HealthCheckMap, errors::HealthCheckGRPCServiceError>;
38+
39+
#[cfg(feature = "dynamic_routing")]
40+
async fn health_check_decision_engine(
41+
&self,
42+
) -> CustomResult<HealthState, errors::HealthCheckDecisionEngineError>;
3843
}
3944

4045
#[async_trait::async_trait]
@@ -184,4 +189,25 @@ impl HealthCheckInterface for app::SessionState {
184189
logger::debug!("Health check successful");
185190
Ok(health_check_map)
186191
}
192+
193+
#[cfg(feature = "dynamic_routing")]
194+
async fn health_check_decision_engine(
195+
&self,
196+
) -> CustomResult<HealthState, errors::HealthCheckDecisionEngineError> {
197+
if self.conf.open_router.enabled {
198+
let url = format!("{}/{}", &self.conf.open_router.url, "health");
199+
let request = services::Request::new(services::Method::Get, &url);
200+
let _ = services::call_connector_api(self, request, "health_check_for_decision_engine")
201+
.await
202+
.change_context(
203+
errors::HealthCheckDecisionEngineError::FailedToCallDecisionEngineService,
204+
)?;
205+
206+
logger::debug!("Decision engine health check successful");
207+
Ok(HealthState::Running)
208+
} else {
209+
logger::debug!("Decision engine health check not applicable");
210+
Ok(HealthState::NotApplicable)
211+
}
212+
}
187213
}

crates/router/src/routes/health.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ async fn deep_health_check_func(
108108

109109
logger::debug!("gRPC health check end");
110110

111+
logger::debug!("Decision Engine health check begin");
112+
113+
#[cfg(feature = "dynamic_routing")]
114+
let decision_engine_health_check =
115+
state
116+
.health_check_decision_engine()
117+
.await
118+
.map_err(|error| {
119+
let message = error.to_string();
120+
error.change_context(errors::ApiErrorResponse::HealthCheckError {
121+
component: "Decision Engine service",
122+
message,
123+
})
124+
})?;
125+
126+
logger::debug!("Decision Engine health check end");
127+
111128
logger::debug!("Opensearch health check begin");
112129

113130
#[cfg(feature = "olap")]
@@ -144,6 +161,8 @@ async fn deep_health_check_func(
144161
outgoing_request: outgoing_check.into(),
145162
#[cfg(feature = "dynamic_routing")]
146163
grpc_health_check,
164+
#[cfg(feature = "dynamic_routing")]
165+
decision_engine: decision_engine_health_check.into(),
147166
};
148167

149168
Ok(api::ApplicationResponse::Json(response))

crates/storage_impl/src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,9 @@ pub enum RecoveryError {
280280
#[error("Failed to fetch billing connector account id")]
281281
BillingMerchantConnectorAccountIdNotFound,
282282
}
283+
284+
#[derive(Debug, Clone, thiserror::Error)]
285+
pub enum HealthCheckDecisionEngineError {
286+
#[error("Failed to establish Decision Engine connection")]
287+
FailedToCallDecisionEngineService,
288+
}

0 commit comments

Comments
 (0)