Bug: [FIX] dont return true in case health check is not done on the component



Whenever a component is disabled we don't have to check for it's health so return false in case if we didn't check it
diff --git a/crates/api_models/src/health_check.rs b/crates/api_models/src/health_check.rs
index 6b0297b655f..29a59df397e 100644
--- a/crates/api_models/src/health_check.rs
+++ b/crates/api_models/src/health_check.rs
@@ -2,7 +2,8 @@
 pub struct RouterHealthCheckResponse {
     pub database: bool,
     pub redis: bool,
-    pub locker: bool,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub vault: Option<bool>,
     #[cfg(feature = "olap")]
     pub analytics: bool,
     pub outgoing_request: bool,
@@ -17,4 +18,28 @@ pub struct SchedulerHealthCheckResponse {
     pub outgoing_request: bool,
 }
 
+pub enum HealthState {
+    Running,
+    Error,
+    NotApplicable,
+}
+
+impl From<HealthState> for bool {
+    fn from(value: HealthState) -> Self {
+        match value {
+            HealthState::Running => true,
+            HealthState::Error | HealthState::NotApplicable => false,
+        }
+    }
+}
+impl From<HealthState> for Option<bool> {
+    fn from(value: HealthState) -> Self {
+        match value {
+            HealthState::Running => Some(true),
+            HealthState::Error => Some(false),
+            HealthState::NotApplicable => None,
+        }
+    }
+}
+
 impl common_utils::events::ApiEventMetric for SchedulerHealthCheckResponse {}
diff --git a/crates/router/src/core/health_check.rs b/crates/router/src/core/health_check.rs
index bc523b4fba6..3be764ef66b 100644
--- a/crates/router/src/core/health_check.rs
+++ b/crates/router/src/core/health_check.rs
@@ -1,5 +1,6 @@
 #[cfg(feature = "olap")]
 use analytics::health_check::HealthCheck;
+use api_models::health_check::HealthState;
 use error_stack::ResultExt;
 use router_env::logger;
 
@@ -12,23 +13,27 @@ use crate::{
 
 #[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>;
-    async fn health_check_outgoing(&self) -> CustomResult<(), errors::HealthCheckOutGoing>;
+    async fn health_check_db(&self) -> CustomResult<HealthState, errors::HealthCheckDBError>;
+    async fn health_check_redis(&self) -> CustomResult<HealthState, errors::HealthCheckRedisError>;
+    async fn health_check_locker(
+        &self,
+    ) -> CustomResult<HealthState, errors::HealthCheckLockerError>;
+    async fn health_check_outgoing(&self)
+        -> CustomResult<HealthState, errors::HealthCheckOutGoing>;
     #[cfg(feature = "olap")]
-    async fn health_check_analytics(&self) -> CustomResult<(), errors::HealthCheckDBError>;
+    async fn health_check_analytics(&self)
+        -> CustomResult<HealthState, errors::HealthCheckDBError>;
 }
 
 #[async_trait::async_trait]
 impl HealthCheckInterface for app::AppState {
-    async fn health_check_db(&self) -> CustomResult<(), errors::HealthCheckDBError> {
+    async fn health_check_db(&self) -> CustomResult<HealthState, errors::HealthCheckDBError> {
         let db = &*self.store;
         db.health_check_db().await?;
-        Ok(())
+        Ok(HealthState::Running)
     }
 
-    async fn health_check_redis(&self) -> CustomResult<(), errors::HealthCheckRedisError> {
+    async fn health_check_redis(&self) -> CustomResult<HealthState, errors::HealthCheckRedisError> {
         let db = &*self.store;
         let redis_conn = db
             .get_redis_conn()
@@ -55,10 +60,12 @@ impl HealthCheckInterface for app::AppState {
 
         logger::debug!("Redis delete_key was successful");
 
-        Ok(())
+        Ok(HealthState::Running)
     }
 
-    async fn health_check_locker(&self) -> CustomResult<(), errors::HealthCheckLockerError> {
+    async fn health_check_locker(
+        &self,
+    ) -> CustomResult<HealthState, errors::HealthCheckLockerError> {
         let locker = &self.conf.locker;
         if !locker.mock_locker {
             let mut url = locker.host_rs.to_owned();
@@ -67,16 +74,19 @@ impl HealthCheckInterface for app::AppState {
             services::call_connector_api(self, request)
                 .await
                 .change_context(errors::HealthCheckLockerError::FailedToCallLocker)?
-                .ok();
+                .map_err(|_| {
+                    error_stack::report!(errors::HealthCheckLockerError::FailedToCallLocker)
+                })?;
+            Ok(HealthState::Running)
+        } else {
+            Ok(HealthState::NotApplicable)
         }
-
-        logger::debug!("Locker call was successful");
-
-        Ok(())
     }
 
     #[cfg(feature = "olap")]
-    async fn health_check_analytics(&self) -> CustomResult<(), errors::HealthCheckDBError> {
+    async fn health_check_analytics(
+        &self,
+    ) -> CustomResult<HealthState, errors::HealthCheckDBError> {
         let analytics = &self.pool;
         match analytics {
             analytics::AnalyticsProvider::Sqlx(client) => client
@@ -107,10 +117,14 @@ impl HealthCheckInterface for app::AppState {
                     .await
                     .change_context(errors::HealthCheckDBError::ClickhouseAnalyticsError)
             }
-        }
+        }?;
+
+        Ok(HealthState::Running)
     }
 
-    async fn health_check_outgoing(&self) -> CustomResult<(), errors::HealthCheckOutGoing> {
+    async fn health_check_outgoing(
+        &self,
+    ) -> CustomResult<HealthState, errors::HealthCheckOutGoing> {
         let request = services::Request::new(services::Method::Get, consts::OUTGOING_CALL_URL);
         services::call_connector_api(self, request)
             .await
@@ -125,6 +139,6 @@ impl HealthCheckInterface for app::AppState {
             })?;
 
         logger::debug!("Outgoing request successful");
-        Ok(())
+        Ok(HealthState::Running)
     }
 }
diff --git a/crates/router/src/routes/health.rs b/crates/router/src/routes/health.rs
index 2183ab07fed..a00ba011bff 100644
--- a/crates/router/src/routes/health.rs
+++ b/crates/router/src/routes/health.rs
@@ -45,7 +45,7 @@ async fn deep_health_check_func(state: app::AppState) -> RouterResponse<RouterHe
 
     logger::debug!("Database health check begin");
 
-    let db_status = state.health_check_db().await.map(|_| true).map_err(|err| {
+    let db_status = state.health_check_db().await.map_err(|err| {
         error_stack::report!(errors::ApiErrorResponse::HealthCheckError {
             component: "Database",
             message: err.to_string()
@@ -56,64 +56,48 @@ async fn deep_health_check_func(state: app::AppState) -> RouterResponse<RouterHe
 
     logger::debug!("Redis health check begin");
 
-    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()
-            })
-        })?;
+    let redis_status = state.health_check_redis().await.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 = state
-        .health_check_locker()
-        .await
-        .map(|_| true)
-        .map_err(|err| {
-            error_stack::report!(errors::ApiErrorResponse::HealthCheckError {
-                component: "Locker",
-                message: err.to_string()
-            })
-        })?;
+    let locker_status = state.health_check_locker().await.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()
-            })
-        })?;
-
-    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()
-            })
-        })?;
+    let analytics_status = state.health_check_analytics().await.map_err(|err| {
+        error_stack::report!(errors::ApiErrorResponse::HealthCheckError {
+            component: "Analytics",
+            message: err.to_string()
+        })
+    })?;
+
+    let outgoing_check = state.health_check_outgoing().await.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 {
-        database: db_status,
-        redis: redis_status,
-        locker: locker_status,
+        database: db_status.into(),
+        redis: redis_status.into(),
+        vault: locker_status.into(),
         #[cfg(feature = "olap")]
-        analytics: analytics_status,
-        outgoing_request: outgoing_check,
+        analytics: analytics_status.into(),
+        outgoing_request: outgoing_check.into(),
     };
 
     Ok(api::ApplicationResponse::Json(response))

## Type of Change
<!-- Put an `x` in the boxes that apply -->
- [x] Bugfix

## Description
<!-- Describe your changes in detail -->
Don't return true on the places where checks or not applicable

## Motivation and Context
<!--
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.

If you don't have an issue, we'd recommend starting with one first so the PR
can focus on the implementation (unless it is an obvious bug or documentation fix
that will have little conversation).
-->
This fixes misconception in health check where it would return true even in case if the case is not checked.

## How did you test it?
<!--
Did you write an integration/unit/API test to verify the code changes?
Or did you test this change manually (provide relevant screenshots)?
-->
- Disable locker in config
```bash
curl --location 'http://localhost:8080/health/ready'
```
<img width="1305" alt="Screenshot 2024-02-07 at 2 55 21 PM" src="https://github.com/juspay/hyperswitch/assets/43412619/27a2a956-a57a-4a1b-a6cf-d2b0e602017d">


**THIS CANNOT BE TESTED IN SANDBOX**

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code