Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat: add healthcheck for outgoing request (#3519)

Kartikeya Hegde54fb61eeebec
diff --git a/crates/api_models/src/health_check.rs b/crates/api_models/src/health_check.rs
index eab971b5fe..e4611f43bc 100644
--- a/crates/api_models/src/health_check.rs
+++ b/crates/api_models/src/health_check.rs
@@ -5,6 +5,7 @@ pub struct RouterHealthCheckResponse {
pub locker: bool,
#[cfg(feature = "olap")]
pub analytics: bool,
+ pub outgoing_request: bool,
}
impl common_utils::events::ApiEventMetric for RouterHealthCheckResponse {}
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 12b688e3d3..3c3f01dc5f 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -91,3 +91,6 @@ pub const MAX_SESSION_EXPIRY: u32 = 7890000;
pub const MIN_SESSION_EXPIRY: u32 = 60;
pub const LOCKER_HEALTH_CALL_PATH: &str = "/health";
+
+// URL for checking the outgoing call
+pub const OUTGOING_CALL_URL: &str = "https://api.stripe.com/healthcheck";
diff --git a/crates/router/src/core/errors.rs b/crates/router/src/core/errors.rs
index cbc4290f63..9052893d4a 100644
--- a/crates/router/src/core/errors.rs
+++ b/crates/router/src/core/errors.rs
@@ -186,6 +186,12 @@ pub enum ConnectorError {
InvalidConnectorConfig { config: &'static str },
}
+#[derive(Debug, thiserror::Error)]
+pub enum HealthCheckOutGoing {
+ #[error("Outgoing call failed with error: {message}")]
+ OutGoingFailed { message: String },
+}
+
#[derive(Debug, thiserror::Error)]
pub enum VaultError {
#[error("Failed to save card in card vault")]
diff --git a/crates/router/src/core/health_check.rs b/crates/router/src/core/health_check.rs
index 6fc038b82e..bc523b4fba 100644
--- a/crates/router/src/core/health_check.rs
+++ b/crates/router/src/core/health_check.rs
@@ -4,7 +4,7 @@ use error_stack::ResultExt;
use router_env::logger;
use crate::{
- consts::LOCKER_HEALTH_CALL_PATH,
+ consts,
core::errors::{self, CustomResult},
routes::app,
services::api as services,
@@ -15,6 +15,7 @@ pub trait HealthCheckInterface {
async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError>;
async fn health_check_redis(&self) -> CustomResult<(), errors::HealthCheckRedisError>;
async fn health_check_locker(&self) -> CustomResult<(), errors::HealthCheckLockerError>;
+ async fn health_check_outgoing(&self) -> CustomResult<(), errors::HealthCheckOutGoing>;
#[cfg(feature = "olap")]
async fn health_check_analytics(&self) -> CustomResult<(), errors::HealthCheckDBError>;
}
@@ -61,7 +62,7 @@ impl HealthCheckInterface for app::AppState {
let locker = &self.conf.locker;
if !locker.mock_locker {
let mut url = locker.host_rs.to_owned();
- url.push_str(LOCKER_HEALTH_CALL_PATH);
+ url.push_str(consts::LOCKER_HEALTH_CALL_PATH);
let request = services::Request::new(services::Method::Get, &url);
services::call_connector_api(self, request)
.await
@@ -108,4 +109,22 @@ impl HealthCheckInterface for app::AppState {
}
}
}
+
+ async fn health_check_outgoing(&self) -> CustomResult<(), errors::HealthCheckOutGoing> {
+ let request = services::Request::new(services::Method::Get, consts::OUTGOING_CALL_URL);
+ services::call_connector_api(self, request)
+ .await
+ .map_err(|err| errors::HealthCheckOutGoing::OutGoingFailed {
+ message: err.to_string(),
+ })?
+ .map_err(|err| errors::HealthCheckOutGoing::OutGoingFailed {
+ message: format!(
+ "Got a non 200 status while making outgoing request. Error {:?}",
+ err.response
+ ),
+ })?;
+
+ logger::debug!("Outgoing request successful");
+ Ok(())
+ }
}
diff --git a/crates/router/src/routes/health.rs b/crates/router/src/routes/health.rs
index 89132c3319..2183ab07fe 100644
--- a/crates/router/src/routes/health.rs
+++ b/crates/router/src/routes/health.rs
@@ -94,6 +94,17 @@ async fn deep_health_check_func(state: app::AppState) -> RouterResponse<RouterHe
})
})?;
+ let outgoing_check = state
+ .health_check_outgoing()
+ .await
+ .map(|_| true)
+ .map_err(|err| {
+ error_stack::report!(errors::ApiErrorResponse::HealthCheckError {
+ component: "Outgoing Request",
+ message: err.to_string()
+ })
+ })?;
+
logger::debug!("Locker health check end");
let response = RouterHealthCheckResponse {
@@ -102,6 +113,7 @@ async fn deep_health_check_func(state: app::AppState) -> RouterResponse<RouterHe
locker: locker_status,
#[cfg(feature = "olap")]
analytics: analytics_status,
+ outgoing_request: outgoing_check,
};
Ok(api::ApplicationResponse::Json(response))