feat: Added grpc based health check (#6441)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sarthak Soni
2024-11-26 18:54:55 +05:30
committed by GitHub
parent 8fbb766308
commit e922f96cee
13 changed files with 285 additions and 17 deletions

View File

@ -1,5 +1,7 @@
#[cfg(feature = "olap")]
use analytics::health_check::HealthCheck;
#[cfg(feature = "dynamic_routing")]
use api_models::health_check::HealthCheckMap;
use api_models::health_check::HealthState;
use error_stack::ResultExt;
use router_env::logger;
@ -28,6 +30,11 @@ pub trait HealthCheckInterface {
async fn health_check_opensearch(
&self,
) -> CustomResult<HealthState, errors::HealthCheckDBError>;
#[cfg(feature = "dynamic_routing")]
async fn health_check_grpc(
&self,
) -> CustomResult<HealthCheckMap, errors::HealthCheckGRPCServiceError>;
}
#[async_trait::async_trait]
@ -158,4 +165,20 @@ impl HealthCheckInterface for app::SessionState {
logger::debug!("Outgoing request successful");
Ok(HealthState::Running)
}
#[cfg(feature = "dynamic_routing")]
async fn health_check_grpc(
&self,
) -> CustomResult<HealthCheckMap, errors::HealthCheckGRPCServiceError> {
let health_client = &self.grpc_client.health_client;
let grpc_config = &self.conf.grpc_client;
let health_check_map = health_client
.perform_health_check(grpc_config)
.await
.change_context(errors::HealthCheckGRPCServiceError::FailedToCallService)?;
logger::debug!("Health check successful");
Ok(health_check_map)
}
}

View File

@ -95,6 +95,19 @@ async fn deep_health_check_func(
logger::debug!("Analytics health check end");
logger::debug!("gRPC health check begin");
#[cfg(feature = "dynamic_routing")]
let grpc_health_check = state.health_check_grpc().await.map_err(|error| {
let message = error.to_string();
error.change_context(errors::ApiErrorResponse::HealthCheckError {
component: "gRPC services",
message,
})
})?;
logger::debug!("gRPC health check end");
logger::debug!("Opensearch health check begin");
#[cfg(feature = "olap")]
@ -129,6 +142,8 @@ async fn deep_health_check_func(
#[cfg(feature = "olap")]
opensearch: opensearch_status.into(),
outgoing_request: outgoing_check.into(),
#[cfg(feature = "dynamic_routing")]
grpc_health_check,
};
Ok(api::ApplicationResponse::Json(response))