mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
feat(events): adding infra level components to api-events (#8214)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1077,3 +1077,7 @@ retry_algorithm_type = "cascading" # type of retry algorithm
|
|||||||
[clone_connector_allowlist]
|
[clone_connector_allowlist]
|
||||||
merchant_ids = "merchant_ids" # Comma-separated list of allowed merchant IDs
|
merchant_ids = "merchant_ids" # Comma-separated list of allowed merchant IDs
|
||||||
connector_names = "connector_names" # Comma-separated list of allowed connector names
|
connector_names = "connector_names" # Comma-separated list of allowed connector names
|
||||||
|
|
||||||
|
[infra_values]
|
||||||
|
cluster = "CLUSTER" # value of CLUSTER from deployment
|
||||||
|
version = "HOSTNAME" # value of HOSTNAME from deployment which tells its version
|
||||||
@ -1160,3 +1160,7 @@ retry_algorithm_type = "cascading"
|
|||||||
[clone_connector_allowlist]
|
[clone_connector_allowlist]
|
||||||
merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDs
|
merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDs
|
||||||
connector_names = "stripe, adyen" # Comma-separated list of allowed connector names
|
connector_names = "stripe, adyen" # Comma-separated list of allowed connector names
|
||||||
|
|
||||||
|
[infra_values]
|
||||||
|
cluster = "CLUSTER"
|
||||||
|
version = "HOSTNAME"
|
||||||
@ -1069,3 +1069,7 @@ retry_algorithm_type = "cascading" # type of retry algorithm
|
|||||||
[clone_connector_allowlist]
|
[clone_connector_allowlist]
|
||||||
merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDs
|
merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDs
|
||||||
connector_names = "stripe, adyen" # Comma-separated list of allowed connector names
|
connector_names = "stripe, adyen" # Comma-separated list of allowed connector names
|
||||||
|
|
||||||
|
[infra_values]
|
||||||
|
cluster = "CLUSTER" # value of CLUSTER from deployment
|
||||||
|
version = "HOSTNAME" # value of HOSTNAME from deployment which tells its version
|
||||||
@ -540,5 +540,6 @@ pub(crate) async fn fetch_raw_secrets(
|
|||||||
revenue_recovery: conf.revenue_recovery,
|
revenue_recovery: conf.revenue_recovery,
|
||||||
debit_routing_config: conf.debit_routing_config,
|
debit_routing_config: conf.debit_routing_config,
|
||||||
clone_connector_allowlist: conf.clone_connector_allowlist,
|
clone_connector_allowlist: conf.clone_connector_allowlist,
|
||||||
|
infra_values: conf.infra_values,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -158,6 +158,8 @@ pub struct Settings<S: SecretState> {
|
|||||||
#[cfg(feature = "v2")]
|
#[cfg(feature = "v2")]
|
||||||
pub revenue_recovery: revenue_recovery::RevenueRecoverySettings,
|
pub revenue_recovery: revenue_recovery::RevenueRecoverySettings,
|
||||||
pub clone_connector_allowlist: Option<CloneConnectorAllowlistConfig>,
|
pub clone_connector_allowlist: Option<CloneConnectorAllowlistConfig>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub infra_values: Option<HashMap<String, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone, Default)]
|
#[derive(Debug, Deserialize, Clone, Default)]
|
||||||
|
|||||||
@ -103,7 +103,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
|
|||||||
let response_value = serde_json::to_value(&webhooks_response_tracker)
|
let response_value = serde_json::to_value(&webhooks_response_tracker)
|
||||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
.attach_printable("Could not convert webhook effect to string")?;
|
.attach_printable("Could not convert webhook effect to string")?;
|
||||||
|
let infra = state.infra_components.clone();
|
||||||
let api_event = ApiEvent::new(
|
let api_event = ApiEvent::new(
|
||||||
state.tenant.tenant_id.clone(),
|
state.tenant.tenant_id.clone(),
|
||||||
Some(merchant_context.get_merchant_account().get_id().clone()),
|
Some(merchant_context.get_merchant_account().get_id().clone()),
|
||||||
@ -119,6 +119,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
|
|||||||
api_event,
|
api_event,
|
||||||
req,
|
req,
|
||||||
req.method(),
|
req.method(),
|
||||||
|
infra,
|
||||||
);
|
);
|
||||||
state.event_handler().log_event(&api_event);
|
state.event_handler().log_event(&api_event);
|
||||||
Ok(application_response)
|
Ok(application_response)
|
||||||
|
|||||||
@ -97,6 +97,8 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
|
|||||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||||
.attach_printable("Could not convert webhook effect to string")?;
|
.attach_printable("Could not convert webhook effect to string")?;
|
||||||
|
|
||||||
|
let infra = state.infra_components.clone();
|
||||||
|
|
||||||
let api_event = ApiEvent::new(
|
let api_event = ApiEvent::new(
|
||||||
state.tenant.tenant_id.clone(),
|
state.tenant.tenant_id.clone(),
|
||||||
Some(merchant_context.get_merchant_account().get_id().clone()),
|
Some(merchant_context.get_merchant_account().get_id().clone()),
|
||||||
@ -112,6 +114,7 @@ pub async fn incoming_webhooks_wrapper<W: types::OutgoingWebhookType>(
|
|||||||
api_event,
|
api_event,
|
||||||
req,
|
req,
|
||||||
req.method(),
|
req.method(),
|
||||||
|
infra,
|
||||||
);
|
);
|
||||||
state.event_handler().log_event(&api_event);
|
state.event_handler().log_event(&api_event);
|
||||||
Ok(application_response)
|
Ok(application_response)
|
||||||
|
|||||||
@ -43,6 +43,8 @@ pub struct ApiEvent {
|
|||||||
event_type: ApiEventsType,
|
event_type: ApiEventsType,
|
||||||
hs_latency: Option<u128>,
|
hs_latency: Option<u128>,
|
||||||
http_method: String,
|
http_method: String,
|
||||||
|
#[serde(flatten)]
|
||||||
|
infra_components: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApiEvent {
|
impl ApiEvent {
|
||||||
@ -62,6 +64,7 @@ impl ApiEvent {
|
|||||||
event_type: ApiEventsType,
|
event_type: ApiEventsType,
|
||||||
http_req: &HttpRequest,
|
http_req: &HttpRequest,
|
||||||
http_method: &http::Method,
|
http_method: &http::Method,
|
||||||
|
infra_components: Option<serde_json::Value>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
tenant_id,
|
tenant_id,
|
||||||
@ -87,6 +90,7 @@ impl ApiEvent {
|
|||||||
event_type,
|
event_type,
|
||||||
hs_latency,
|
hs_latency,
|
||||||
http_method: http_method.to_string(),
|
http_method: http_method.to_string(),
|
||||||
|
infra_components,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -130,6 +130,7 @@ pub struct SessionState {
|
|||||||
pub theme_storage_client: Arc<dyn FileStorageInterface>,
|
pub theme_storage_client: Arc<dyn FileStorageInterface>,
|
||||||
pub locale: String,
|
pub locale: String,
|
||||||
pub crm_client: Arc<dyn CrmInterface>,
|
pub crm_client: Arc<dyn CrmInterface>,
|
||||||
|
pub infra_components: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
impl scheduler::SchedulerSessionState for SessionState {
|
impl scheduler::SchedulerSessionState for SessionState {
|
||||||
fn get_db(&self) -> Box<dyn SchedulerInterface> {
|
fn get_db(&self) -> Box<dyn SchedulerInterface> {
|
||||||
@ -242,6 +243,7 @@ pub struct AppState {
|
|||||||
pub grpc_client: Arc<GrpcClients>,
|
pub grpc_client: Arc<GrpcClients>,
|
||||||
pub theme_storage_client: Arc<dyn FileStorageInterface>,
|
pub theme_storage_client: Arc<dyn FileStorageInterface>,
|
||||||
pub crm_client: Arc<dyn CrmInterface>,
|
pub crm_client: Arc<dyn CrmInterface>,
|
||||||
|
pub infra_components: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
impl scheduler::SchedulerAppState for AppState {
|
impl scheduler::SchedulerAppState for AppState {
|
||||||
fn get_tenants(&self) -> Vec<id_type::TenantId> {
|
fn get_tenants(&self) -> Vec<id_type::TenantId> {
|
||||||
@ -406,7 +408,7 @@ impl AppState {
|
|||||||
let crm_client = conf.crm.get_crm_client().await;
|
let crm_client = conf.crm.get_crm_client().await;
|
||||||
|
|
||||||
let grpc_client = conf.grpc_client.get_grpc_client_interface().await;
|
let grpc_client = conf.grpc_client.get_grpc_client_interface().await;
|
||||||
|
let infra_component_values = Self::process_env_mappings(conf.infra_values.clone());
|
||||||
Self {
|
Self {
|
||||||
flow_name: String::from("default"),
|
flow_name: String::from("default"),
|
||||||
stores,
|
stores,
|
||||||
@ -427,6 +429,7 @@ impl AppState {
|
|||||||
grpc_client,
|
grpc_client,
|
||||||
theme_storage_client,
|
theme_storage_client,
|
||||||
crm_client,
|
crm_client,
|
||||||
|
infra_components: infra_component_values,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
@ -521,8 +524,29 @@ impl AppState {
|
|||||||
theme_storage_client: self.theme_storage_client.clone(),
|
theme_storage_client: self.theme_storage_client.clone(),
|
||||||
locale: locale.unwrap_or(common_utils::consts::DEFAULT_LOCALE.to_string()),
|
locale: locale.unwrap_or(common_utils::consts::DEFAULT_LOCALE.to_string()),
|
||||||
crm_client: self.crm_client.clone(),
|
crm_client: self.crm_client.clone(),
|
||||||
|
infra_components: self.infra_components.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process_env_mappings(
|
||||||
|
mappings: Option<HashMap<String, String>>,
|
||||||
|
) -> Option<serde_json::Value> {
|
||||||
|
let result: HashMap<String, String> = mappings?
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|(key, env_var)| std::env::var(&env_var).ok().map(|value| (key, value)))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if result.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(serde_json::Value::Object(
|
||||||
|
result
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, v)| (k, serde_json::Value::String(v)))
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Health;
|
pub struct Health;
|
||||||
|
|||||||
@ -602,7 +602,6 @@ where
|
|||||||
.switch(),
|
.switch(),
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let locale = utils::get_locale_from_header(&incoming_request_header.clone());
|
let locale = utils::get_locale_from_header(&incoming_request_header.clone());
|
||||||
let mut session_state =
|
let mut session_state =
|
||||||
Arc::new(app_state.clone()).get_session_state(&tenant_id, Some(locale), || {
|
Arc::new(app_state.clone()).get_session_state(&tenant_id, Some(locale), || {
|
||||||
@ -701,6 +700,8 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let infra = state.infra_components.clone();
|
||||||
|
|
||||||
let api_event = ApiEvent::new(
|
let api_event = ApiEvent::new(
|
||||||
tenant_id,
|
tenant_id,
|
||||||
Some(merchant_id.clone()),
|
Some(merchant_id.clone()),
|
||||||
@ -716,7 +717,9 @@ where
|
|||||||
event_type.unwrap_or(ApiEventsType::Miscellaneous),
|
event_type.unwrap_or(ApiEventsType::Miscellaneous),
|
||||||
request,
|
request,
|
||||||
request.method(),
|
request.method(),
|
||||||
|
infra.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
state.event_handler().log_event(&api_event);
|
state.event_handler().log_event(&api_event);
|
||||||
|
|
||||||
output
|
output
|
||||||
|
|||||||
Reference in New Issue
Block a user