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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat: add deep health check for analytics (#3438)
Kartikeya Hegde7597f3b69212
diff --git a/crates/analytics/src/clickhouse.rs b/crates/analytics/src/clickhouse.rsindex 00ae3b6e31..27d4235050 100644--- a/crates/analytics/src/clickhouse.rs+++ b/crates/analytics/src/clickhouse.rs@@ -7,6 +7,7 @@ use router_env::logger;use time::PrimitiveDateTime;use super::{+ health_check::HealthCheck,payments::{distribution::PaymentDistributionRow, filters::FilterRow, metrics::PaymentMetricRow,},@@ -93,6 +94,18 @@ impl ClickhouseClient {}}+#[async_trait::async_trait]+impl HealthCheck for ClickhouseClient {+ async fn deep_health_check(+ &self,+ ) -> common_utils::errors::CustomResult<(), QueryExecutionError> {+ self.execute_query("SELECT 1")+ .await+ .map(|_| ())+ .change_context(QueryExecutionError::DatabaseError)+ }+}+#[async_trait::async_trait]impl AnalyticsDataSource for ClickhouseClient {type Row = serde_json::Value;diff --git a/crates/analytics/src/health_check.rs b/crates/analytics/src/health_check.rsnew file mode 100644index 0000000000..f566aecf10--- /dev/null+++ b/crates/analytics/src/health_check.rs@@ -0,0 +1,8 @@+use common_utils::errors::CustomResult;++use crate::types::QueryExecutionError;++#[async_trait::async_trait]+pub trait HealthCheck {+ async fn deep_health_check(&self) -> CustomResult<(), QueryExecutionError>;+}diff --git a/crates/analytics/src/lib.rs b/crates/analytics/src/lib.rsindex 501bd58527..a4e925519c 100644--- a/crates/analytics/src/lib.rs+++ b/crates/analytics/src/lib.rs@@ -8,6 +8,7 @@ pub mod refunds;pub mod api_event;pub mod connector_events;+pub mod health_check;pub mod outgoing_webhook_event;pub mod sdk_events;mod sqlx;diff --git a/crates/analytics/src/sqlx.rs b/crates/analytics/src/sqlx.rsindex 7ab8a2aa4b..562a3a1f64 100644--- a/crates/analytics/src/sqlx.rs+++ b/crates/analytics/src/sqlx.rs@@ -17,6 +17,7 @@ use storage_impl::config::Database;use time::PrimitiveDateTime;use super::{+ health_check::HealthCheck,query::{Aggregate, ToSql, Window},types::{AnalyticsCollection, AnalyticsDataSource, DBEnumWrapper, LoadRow, QueryExecutionError,@@ -164,6 +165,17 @@ impl AnalyticsDataSource for SqlxClient {.change_context(QueryExecutionError::RowExtractionFailure)}}+#[async_trait::async_trait]+impl HealthCheck for SqlxClient {+ async fn deep_health_check(&self) -> CustomResult<(), QueryExecutionError> {+ sqlx::query("SELECT 1")+ .fetch_all(&self.pool)+ .await+ .map(|_| ())+ .into_report()+ .change_context(QueryExecutionError::DatabaseError)+ }+}impl<'a> FromRow<'a, PgRow> for super::refunds::metrics::RefundMetricRow {fn from_row(row: &'a PgRow) -> sqlx::Result<Self> {diff --git a/crates/api_models/Cargo.toml b/crates/api_models/Cargo.tomlindex 8cd3ee53f2..1e8e0f47eb 100644--- a/crates/api_models/Cargo.toml+++ b/crates/api_models/Cargo.toml@@ -18,6 +18,7 @@ dummy_connector = ["euclid/dummy_connector", "common_enums/dummy_connector"]detailed_errors = []payouts = []frm = []+olap = []openapi = ["common_enums/openapi"]recon = []diff --git a/crates/api_models/src/health_check.rs b/crates/api_models/src/health_check.rsindex d7bb120d01..8323f13513 100644--- a/crates/api_models/src/health_check.rs+++ b/crates/api_models/src/health_check.rs@@ -1,6 +1,10 @@#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]pub struct RouterHealthCheckResponse {- pub database: String,- pub redis: String,- pub locker: String,+ pub database: bool,+ pub redis: bool,+ pub locker: bool,+ #[cfg(feature = "olap")]+ pub analytics: bool,}++impl common_utils::events::ApiEventMetric for RouterHealthCheckResponse {}diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.tomlindex 3d129edfe3..f60b0c25e9 100644--- a/crates/router/Cargo.toml+++ b/crates/router/Cargo.toml@@ -17,7 +17,7 @@ email = ["external_services/email", "olap"]frm = []stripe = ["dep:serde_qs"]release = ["kms", "stripe", "aws_s3", "email", "backwards_compatibility", "business_profile_routing", "accounts_cache", "kv_store", "connector_choice_mca_id", "profile_specific_fallback_routing", "vergen", "recon"]-olap = ["data_models/olap", "storage_impl/olap", "scheduler/olap", "dep:analytics"]+olap = ["data_models/olap", "storage_impl/olap", "scheduler/olap","api_models/olap","dep:analytics"]oltp = ["storage_impl/oltp"]kv_store = ["scheduler/kv_store"]accounts_cache = []diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rsindex 63205ea68c..759e968125 100644--- a/crates/router/src/compatibility/stripe/errors.rs+++ b/crates/router/src/compatibility/stripe/errors.rs@@ -468,7 +468,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {errors::ApiErrorResponse::MandateUpdateFailed| errors::ApiErrorResponse::MandateSerializationFailed| errors::ApiErrorResponse::MandateDeserializationFailed- | errors::ApiErrorResponse::InternalServerError => Self::InternalServerError, // not a stripe code+ | errors::ApiErrorResponse::InternalServerError+ | errors::ApiErrorResponse::HealthCheckError { .. } => Self::InternalServerError, // not a stripe codeerrors::ApiErrorResponse::ExternalConnectorError {code,message,diff --git a/crates/router/src/core.rs b/crates/router/src/core.rsindex 5ae4b0be33..9bdc493e07 100644--- a/crates/router/src/core.rs+++ b/crates/router/src/core.rs@@ -17,6 +17,7 @@ pub mod files;#[cfg(feature = "frm")]pub mod fraud_check;pub mod gsm;+pub mod health_check;pub mod locker_migration;pub mod mandate;pub mod metrics;diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rsindex 54ec4ec1e2..023e1f4b7f 100644--- a/crates/router/src/core/errors/api_error_response.rs+++ b/crates/router/src/core/errors/api_error_response.rs@@ -238,6 +238,11 @@ pub enum ApiErrorResponse {WebhookInvalidMerchantSecret,#[error(error_type = ErrorType::InvalidRequestError, code = "IR_19", message = "{message}")]CurrencyNotSupported { message: String },+ #[error(error_type = ErrorType::ServerNotAvailable, code= "HE_00", message = "{component} health check is failiing with error: {message}")]+ HealthCheckError {+ component: &'static str,+ message: String,+ },#[error(error_type = ErrorType::InvalidRequestError, code = "IR_24", message = "Merchant connector account is configured with invalid {config}")]InvalidConnectorConfiguration { config: String },#[error(error_type = ErrorType::ValidationError, code = "HE_01", message = "Failed to convert currency to minor unit")]diff --git a/crates/router/src/core/errors/transformers.rs b/crates/router/src/core/errors/transformers.rsindex ff764cafed..0119335b7c 100644--- a/crates/router/src/core/errors/transformers.rs+++ b/crates/router/src/core/errors/transformers.rs@@ -123,7 +123,10 @@ impl ErrorSwitch<api_models::errors::types::ApiErrorResponse> for ApiErrorRespon},Self::MandateUpdateFailed | Self::MandateSerializationFailed | Self::MandateDeserializationFailed | Self::InternalServerError => {AER::InternalServerError(ApiError::new("HE", 0, "Something went wrong", None))- }+ },+ Self::HealthCheckError { message,component } => {+ AER::InternalServerError(ApiError::new("HE",0,format!("{} health check failed with error: {}",component,message),None))+ },Self::PayoutFailed { data } => {AER::BadRequest(ApiError::new("CE", 4, "Payout failed while processing with connector.", Some(Extra { data: data.clone(), ..Default::default()})))},diff --git a/crates/router/src/core/health_check.rs b/crates/router/src/core/health_check.rsnew file mode 100644index 0000000000..6fc038b82e--- /dev/null+++ b/crates/router/src/core/health_check.rs@@ -0,0 +1,111 @@+#[cfg(feature = "olap")]+use analytics::health_check::HealthCheck;+use error_stack::ResultExt;+use router_env::logger;++use crate::{+ consts::LOCKER_HEALTH_CALL_PATH,+ core::errors::{self, CustomResult},+ routes::app,+ services::api as services,+};++#[async_trait::async_trait]+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>;+ #[cfg(feature = "olap")]+ async fn health_check_analytics(&self) -> CustomResult<(), errors::HealthCheckDBError>;+}++#[async_trait::async_trait]+impl HealthCheckInterface for app::AppState {+ async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> {+ let db = &*self.store;+ db.health_check_db().await?;+ Ok(())+ }++ async fn health_check_redis(&self) -> CustomResult<(), errors::HealthCheckRedisError> {+ let db = &*self.store;+ let redis_conn = db+ .get_redis_conn()+ .change_context(errors::HealthCheckRedisError::RedisConnectionError)?;++ redis_conn+ .serialize_and_set_key_with_expiry("test_key", "test_value", 30)+ .await+ .change_context(errors::HealthCheckRedisError::SetFailed)?;++ logger::debug!("Redis set_key was successful");++ redis_conn+ .get_key("test_key")+ .await+ .change_context(errors::HealthCheckRedisError::GetFailed)?;++ logger::debug!("Redis get_key was successful");++ redis_conn+ .delete_key("test_key")+ .await+ .change_context(errors::HealthCheckRedisError::DeleteFailed)?;++ logger::debug!("Redis delete_key was successful");++ Ok(())+ }++ async fn health_check_locker(&self) -> CustomResult<(), errors::HealthCheckLockerError> {+ let locker = &self.conf.locker;+ if !locker.mock_locker {+ let mut url = locker.host_rs.to_owned();+ url.push_str(LOCKER_HEALTH_CALL_PATH);+ let request = services::Request::new(services::Method::Get, &url);+ services::call_connector_api(self, request)+ .await+ .change_context(errors::HealthCheckLockerError::FailedToCallLocker)?+ .ok();+ }++ logger::debug!("Locker call was successful");++ Ok(())+ }++ #[cfg(feature = "olap")]+ async fn health_check_analytics(&self) -> CustomResult<(), errors::HealthCheckDBError> {+ let analytics = &self.pool;+ match analytics {+ analytics::AnalyticsProvider::Sqlx(client) => client+ .deep_health_check()+ .await+ .change_context(errors::HealthCheckDBError::SqlxAnalyticsError),+ analytics::AnalyticsProvider::Clickhouse(client) => client+ .deep_health_check()+ .await+ .change_context(errors::HealthCheckDBError::ClickhouseAnalyticsError),+ analytics::AnalyticsProvider::CombinedCkh(sqlx_client, ckh_client) => {+ sqlx_client+ .deep_health_check()+ .await+ .change_context(errors::HealthCheckDBError::SqlxAnalyticsError)?;+ ckh_client+ .deep_health_check()+ .await+ .change_context(errors::HealthCheckDBError::ClickhouseAnalyticsError)+ }+ analytics::AnalyticsProvider::CombinedSqlx(sqlx_client, ckh_client) => {+ sqlx_client+ .deep_health_check()+ .await+ .change_context(errors::HealthCheckDBError::SqlxAnalyticsError)?;+ ckh_client+ .deep_health_check()+ .await+ .change_context(errors::HealthCheckDBError::ClickhouseAnalyticsError)+ }+ }+ }+}diff --git a/crates/router/src/core/pm_auth.rs b/crates/router/src/core/pm_auth.rsindex d805925f31..9f70cc6bae 100644--- a/crates/router/src/core/pm_auth.rs+++ b/crates/router/src/core/pm_auth.rs@@ -375,9 +375,6 @@ async fn store_bank_details_in_payment_methods(.await.change_context(ApiErrorResponse::InternalServerError)?;- #[cfg(not(feature = "kms"))]- let pm_auth_key = pm_auth_key;-let mut update_entries: Vec<(storage::PaymentMethod, storage::PaymentMethodUpdate)> =Vec::new();let mut new_entries: Vec<storage::PaymentMethodNew> = Vec::new();diff --git a/crates/router/src/db.rs b/crates/router/src/db.rsindex b9d346b7a7..5490017724 100644--- a/crates/router/src/db.rs+++ b/crates/router/src/db.rs@@ -110,7 +110,7 @@ pub trait StorageInterface:+ user_role::UserRoleInterface+ authorization::AuthorizationInterface+ user::sample_data::BatchSampleDataInterface- + health_check::HealthCheckInterface+ + health_check::HealthCheckDbInterface+ 'static{fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface>;diff --git a/crates/router/src/db/health_check.rs b/crates/router/src/db/health_check.rsindex 73bc2a4321..6ebc9dfff5 100644--- a/crates/router/src/db/health_check.rs+++ b/crates/router/src/db/health_check.rs@@ -3,145 +3,66 @@ use diesel_models::ConfigNew;use error_stack::ResultExt;use router_env::logger;-use super::{MockDb, StorageInterface, Store};+use super::{MockDb, Store};use crate::{connection,- consts::LOCKER_HEALTH_CALL_PATH,core::errors::{self, CustomResult},- routes,- services::api as services,types::storage,};#[async_trait::async_trait]-pub trait HealthCheckInterface {+pub trait HealthCheckDbInterface {async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError>;- async fn health_check_redis(- &self,- db: &dyn StorageInterface,- ) -> CustomResult<(), errors::HealthCheckRedisError>;- async fn health_check_locker(- &self,- state: &routes::AppState,- ) -> CustomResult<(), errors::HealthCheckLockerError>;}#[async_trait::async_trait]-impl HealthCheckInterface for Store {+impl HealthCheckDbInterface for Store {async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> {let conn = connection::pg_connection_write(self).await.change_context(errors::HealthCheckDBError::DBError)?;- let _data = conn- .transaction_async(|conn| {- Box::pin(async move {- let query =- diesel::select(diesel::dsl::sql::<diesel::sql_types::Integer>("1 + 1"));- let _x: i32 = query.get_result_async(&conn).await.map_err(|err| {- logger::error!(read_err=?err,"Error while reading element in the database");- errors::HealthCheckDBError::DBReadError- })?;+ conn.transaction_async(|conn| async move {+ let query = diesel::select(diesel::dsl::sql::<diesel::sql_types::Integer>("1 + 1"));+ let _x: i32 = query.get_result_async(&conn).await.map_err(|err| {+ logger::error!(read_err=?err,"Error while reading element in the database");+ errors::HealthCheckDBError::DBReadError+ })?;- logger::debug!("Database read was successful");+ logger::debug!("Database read was successful");- let config = ConfigNew {- key: "test_key".to_string(),- config: "test_value".to_string(),- };+ let config = ConfigNew {+ key: "test_key".to_string(),+ config: "test_value".to_string(),+ };- config.insert(&conn).await.map_err(|err| {- logger::error!(write_err=?err,"Error while writing to database");- errors::HealthCheckDBError::DBWriteError- })?;+ config.insert(&conn).await.map_err(|err| {+ logger::error!(write_err=?err,"Error while writing to database");+ errors::HealthCheckDBError::DBWriteError+ })?;- logger::debug!("Database write was successful");+ logger::debug!("Database write was successful");- storage::Config::delete_by_key(&conn, "test_key").await.map_err(|err| {- logger::error!(delete_err=?err,"Error while deleting element in the database");- errors::HealthCheckDBError::DBDeleteError- })?;-- logger::debug!("Database delete was successful");-- Ok::<_, errors::HealthCheckDBError>(())- })- })- .await?;-- Ok(())- }-- async fn health_check_redis(- &self,- db: &dyn StorageInterface,- ) -> CustomResult<(), errors::HealthCheckRedisError> {- let redis_conn = db- .get_redis_conn()- .change_context(errors::HealthCheckRedisError::RedisConnectionError)?;-- redis_conn- .serialize_and_set_key_with_expiry("test_key", "test_value", 30)- .await- .change_context(errors::HealthCheckRedisError::SetFailed)?;-- logger::debug!("Redis set_key was successful");-- redis_conn- .get_key("test_key")- .await- .change_context(errors::HealthCheckRedisError::GetFailed)?;-- logger::debug!("Redis get_key was successful");-- redis_conn- .delete_key("test_key")- .await- .change_context(errors::HealthCheckRedisError::DeleteFailed)?;-- logger::debug!("Redis delete_key was successful");-- Ok(())- }-- async fn health_check_locker(- &self,- state: &routes::AppState,- ) -> CustomResult<(), errors::HealthCheckLockerError> {- let locker = &state.conf.locker;- if !locker.mock_locker {- let mut url = locker.host_rs.to_owned();- url.push_str(LOCKER_HEALTH_CALL_PATH);- let request = services::Request::new(services::Method::Get, &url);- services::call_connector_api(state, request)+ storage::Config::delete_by_key(&conn, "test_key").await- .change_context(errors::HealthCheckLockerError::FailedToCallLocker)?- .ok();- }+ .map_err(|err| {+ logger::error!(delete_err=?err,"Error while deleting element in the database");+ errors::HealthCheckDBError::DBDeleteError+ })?;++ logger::debug!("Database delete was successful");- logger::debug!("Locker call was successful");+ Ok::<_, errors::HealthCheckDBError>(())+ })+ .await?;Ok(())}}#[async_trait::async_trait]-impl HealthCheckInterface for MockDb {+impl HealthCheckDbInterface for MockDb {async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> {Ok(())}-- async fn health_check_redis(- &self,- _: &dyn StorageInterface,- ) -> CustomResult<(), errors::HealthCheckRedisError> {- Ok(())- }-- async fn health_check_locker(- &self,- _: &routes::AppState,- ) -> CustomResult<(), errors::HealthCheckLockerError> {- Ok(())- }}diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex e88d59ea9f..665a920bca 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -43,7 +43,7 @@ use crate::{events::EventInterface,file::FileMetadataInterface,gsm::GsmInterface,- health_check::HealthCheckInterface,+ health_check::HealthCheckDbInterface,locker_mock_up::LockerMockUpInterface,mandate::MandateInterface,merchant_account::MerchantAccountInterface,@@ -58,7 +58,6 @@ use crate::{routing_algorithm::RoutingAlgorithmInterface,MasterKeyInterface, StorageInterface,},- routes,services::{authentication, kafka::KafkaProducer, Store},types::{domain,@@ -2185,22 +2184,8 @@ impl AuthorizationInterface for KafkaStore {}#[async_trait::async_trait]-impl HealthCheckInterface for KafkaStore {+impl HealthCheckDbInterface for KafkaStore {async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> {self.diesel_store.health_check_db().await}-- async fn health_check_redis(- &self,- db: &dyn StorageInterface,- ) -> CustomResult<(), errors::HealthCheckRedisError> {- self.diesel_store.health_check_redis(db).await- }-- async fn health_check_locker(- &self,- state: &routes::AppState,- ) -> CustomResult<(), errors::HealthCheckLockerError> {- self.diesel_store.health_check_locker(state).await- }}diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex a69220231f..9e8bee73c2 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -311,7 +311,7 @@ impl Health {web::scope("health").app_data(web::Data::new(state)).service(web::resource("").route(web::get().to(health)))- .service(web::resource("/deep_check").route(web::post().to(deep_health_check)))+ .service(web::resource("/ready").route(web::get().to(deep_health_check)))}}diff --git a/crates/router/src/routes/health.rs b/crates/router/src/routes/health.rsindex f07b744f7f..89132c3319 100644--- a/crates/router/src/routes/health.rs+++ b/crates/router/src/routes/health.rs@@ -1,9 +1,14 @@-use actix_web::web;+use actix_web::{web, HttpRequest};use api_models::health_check::RouterHealthCheckResponse;-use router_env::{instrument, logger, tracing};+use router_env::{instrument, logger, tracing, Flow};use super::app;-use crate::{routes::metrics, services};+use crate::{+ core::{api_locking, health_check::HealthCheckInterface},+ errors::{self, RouterResponse},+ routes::metrics,+ services::{api, authentication as auth},+};/// .// #[logger::instrument(skip_all, name = "name1", level = "warn", fields( key1 = "val1" ))]#[instrument(skip_all)]@@ -14,58 +19,90 @@ pub async fn health() -> impl actix_web::Responder {actix_web::HttpResponse::Ok().body("health is good")}-#[instrument(skip_all)]-pub async fn deep_health_check(state: web::Data<app::AppState>) -> impl actix_web::Responder {+#[instrument(skip_all, fields(flow = ?Flow::DeepHealthCheck))]+pub async fn deep_health_check(+ state: web::Data<app::AppState>,+ request: HttpRequest,+) -> impl actix_web::Responder {metrics::HEALTH_METRIC.add(&metrics::CONTEXT, 1, &[]);- let db = &*state.store;- let mut status_code = 200;++ let flow = Flow::DeepHealthCheck;++ Box::pin(api::server_wrap(+ flow,+ state,+ &request,+ (),+ |state, _, _| deep_health_check_func(state),+ &auth::NoAuth,+ api_locking::LockAction::NotApplicable,+ ))+ .await+}++async fn deep_health_check_func(state: app::AppState) -> RouterResponse<RouterHealthCheckResponse> {logger::info!("Deep health check was called");logger::debug!("Database health check begin");- let db_status = match db.health_check_db().await {- Ok(_) => "Health is good".to_string(),- Err(err) => {- status_code = 500;- err.to_string()- }- };+ let db_status = state.health_check_db().await.map(|_| true).map_err(|err| {+ error_stack::report!(errors::ApiErrorResponse::HealthCheckError {+ component: "Database",+ message: err.to_string()+ })+ })?;+logger::debug!("Database health check end");logger::debug!("Redis health check begin");- let redis_status = match db.health_check_redis(db).await {- Ok(_) => "Health is good".to_string(),- Err(err) => {- status_code = 500;- err.to_string()- }- };+ let redis_status = state+ .health_check_redis()+ .await+ .map(|_| true)+ .map_err(|err| {+ error_stack::report!(errors::ApiErrorResponse::HealthCheckError {+ component: "Redis",+ message: err.to_string()+ })+ })?;logger::debug!("Redis health check end");logger::debug!("Locker health check begin");- let locker_status = match db.health_check_locker(&state).await {- Ok(_) => "Health is good".to_string(),- Err(err) => {- status_code = 500;- err.to_string()- }- };+ let locker_status = state+ .health_check_locker()+ .await+ .map(|_| true)+ .map_err(|err| {+ error_stack::report!(errors::ApiErrorResponse::HealthCheckError {+ component: "Locker",+ message: err.to_string()+ })+ })?;++ #[cfg(feature = "olap")]+ let analytics_status = state+ .health_check_analytics()+ .await+ .map(|_| true)+ .map_err(|err| {+ error_stack::report!(errors::ApiErrorResponse::HealthCheckError {+ component: "Analytics",+ message: err.to_string()+ })+ })?;logger::debug!("Locker health check end");- let response = serde_json::to_string(&RouterHealthCheckResponse {+ let response = RouterHealthCheckResponse {database: db_status,redis: redis_status,locker: locker_status,- })- .unwrap_or_default();-- if status_code == 200 {- services::http_response_json(response)- } else {- services::http_server_error_json_response(response)- }+ #[cfg(feature = "olap")]+ analytics: analytics_status,+ };++ Ok(api::ApplicationResponse::Json(response))}diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rsindex b726c64f0e..0dfc3b1b33 100644--- a/crates/router/src/routes/lock_utils.rs+++ b/crates/router/src/routes/lock_utils.rs@@ -11,6 +11,7 @@ pub enum ApiIdentifier {Configs,Customers,Ephemeral,+ Health,Mandates,PaymentMethods,PaymentMethodAuth,@@ -83,6 +84,7 @@ impl From<Flow> for ApiIdentifier {Flow::EphemeralKeyCreate | Flow::EphemeralKeyDelete => Self::Ephemeral,+ Flow::DeepHealthCheck => Self::Health,Flow::MandatesRetrieve | Flow::MandatesRevoke | Flow::MandatesList => Self::Mandates,Flow::PaymentMethodsCreatediff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rsindex a395235ca8..55e7bafd8e 100644--- a/crates/router_env/src/logger/types.rs+++ b/crates/router_env/src/logger/types.rs@@ -54,6 +54,8 @@ pub enum Tag {/// API Flow#[derive(Debug, Display, Clone, PartialEq, Eq)]pub enum Flow {+ /// Deep health Check+ DeepHealthCheck,/// Merchants account create flow.MerchantsAccountCreate,/// Merchants account retrieve flow.diff --git a/crates/storage_impl/src/errors.rs b/crates/storage_impl/src/errors.rsindex ac3a04e85b..2adcdcf8d2 100644--- a/crates/storage_impl/src/errors.rs+++ b/crates/storage_impl/src/errors.rs@@ -394,6 +394,10 @@ pub enum HealthCheckDBError {UnknownError,#[error("Error in database transaction")]TransactionError,+ #[error("Error while executing query in Sqlx Analytics")]+ SqlxAnalyticsError,+ #[error("Error while executing query in Clickhouse Analytics")]+ ClickhouseAnalyticsError,}impl From<diesel::result::Error> for HealthCheckDBError {