From 654044a11192fdc822156c560d152df0cb55a086 Mon Sep 17 00:00:00 2001 From: Sarthak Soni Date: Thu, 16 Nov 2023 20:25:52 +0530 Subject: [PATCH] fix(routing): Added response metrics as well --- crates/router/src/core/metrics.rs | 10 ++++++++++ crates/router/src/core/routing.rs | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/router/src/core/metrics.rs b/crates/router/src/core/metrics.rs index 6ce9893f8377..9e021987b64e 100644 --- a/crates/router/src/core/metrics.rs +++ b/crates/router/src/core/metrics.rs @@ -46,11 +46,21 @@ counter_metric!( ); counter_metric!(ROUTING_CREATE_REQUEST_RECEIVED, GLOBAL_METER); +counter_metric!(ROUTING_CREATE_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_MERCHANT_DICTIONARY_RETRIEVE, GLOBAL_METER); +counter_metric!(ROUTING_MERCHANT_DICTIONARY_RETRIEVE_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_LINK_CONFIG, GLOBAL_METER); +counter_metric!(ROUTING_LINK_CONFIG_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_RETRIEVE_CONFIG, GLOBAL_METER); +counter_metric!(ROUTING_RETRIEVE_CONFIG_RESPONSE, GLOBAL_METER); +counter_metric!(ROUTING_RETRIEVE_DEFAULT_CONFIG, GLOBAL_METER); counter_metric!(ROUTING_RETRIEVE_LINK_CONFIG, GLOBAL_METER); +counter_metric!(ROUTING_RETRIEVE_LINK_CONFIG_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_UNLINK_CONFIG, GLOBAL_METER); +counter_metric!(ROUTING_UNLINK_CONFIG_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_UPDATE_CONFIG, GLOBAL_METER); +counter_metric!(ROUTING_UPDATE_CONFIG_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_UPDATE_CONFIG_FOR_PROFILE, GLOBAL_METER); +counter_metric!(ROUTING_UPDATE_CONFIG_FOR_PROFILE_RESPONSE, GLOBAL_METER); counter_metric!(ROUTING_RETRIEVE_CONFIG_FOR_PROFILE, GLOBAL_METER); +counter_metric!(ROUTING_RETRIEVE_CONFIG_FOR_PROFILE_RESPONSE, GLOBAL_METER); diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs index 2616e8ffd8a6..d3efefe24f5d 100644 --- a/crates/router/src/core/routing.rs +++ b/crates/router/src/core/routing.rs @@ -52,11 +52,13 @@ pub async fn retrieve_merchant_routing_dictionary( .map(ForeignInto::foreign_into) .collect::>(); + metrics::ROUTING_MERCHANT_DICTIONARY_RETRIEVE_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json( routing_types::RoutingKind::RoutingAlgorithm(result), )) } #[cfg(not(feature = "business_profile_routing"))] + metrics::ROUTING_MERCHANT_DICTIONARY_RETRIEVE_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json( routing_types::RoutingKind::Config( helpers::get_merchant_routing_dictionary( @@ -149,6 +151,7 @@ pub async fn create_routing_config( let new_record = record.foreign_into(); + metrics::ROUTING_CREATE_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(new_record)) } @@ -215,6 +218,7 @@ pub async fn create_routing_config( ) .await?; + metrics::ROUTING_CREATE_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(new_record)) } } @@ -271,6 +275,7 @@ pub async fn link_routing_config( helpers::update_business_profile_active_algorithm_ref(db, business_profile, routing_ref) .await?; + metrics::ROUTING_LINK_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json( routing_algorithm.foreign_into(), )) @@ -320,6 +325,7 @@ pub async fn link_routing_config( .await?; helpers::update_merchant_active_algorithm_ref(db, &key_store, routing_ref).await?; + metrics::ROUTING_LINK_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(response)) } } @@ -354,6 +360,8 @@ pub async fn retrieve_routing_config( .foreign_try_into() .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("unable to parse routing algorithm")?; + + metrics::ROUTING_RETRIEVE_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(response)) } @@ -391,6 +399,7 @@ pub async fn retrieve_routing_config( modified_at: record.modified_at, }; + metrics::ROUTING_RETRIEVE_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(response)) } } @@ -456,6 +465,8 @@ pub async fn unlink_routing_config( routing_algorithm, ) .await?; + + metrics::ROUTING_UNLINK_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(response)) } None => Err(errors::ApiErrorResponse::PreconditionFailed { @@ -564,6 +575,7 @@ pub async fn unlink_routing_config( .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update routing algorithm ref in merchant account")?; + metrics::ROUTING_UNLINK_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(response)) } } @@ -612,6 +624,7 @@ pub async fn update_default_routing_config( ) .await?; + metrics::ROUTING_UPDATE_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(updated_config)) } @@ -619,7 +632,7 @@ pub async fn retrieve_default_routing_config( state: AppState, merchant_account: domain::MerchantAccount, ) -> RouterResponse> { - metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]); + metrics::ROUTING_RETRIEVE_DEFAULT_CONFIG.add(&metrics::CONTEXT, 1, &[]); let db = state.store.as_ref(); helpers::get_merchant_default_config(db, &merchant_account.merchant_id) @@ -680,6 +693,7 @@ pub async fn retrieve_linked_routing_config( } } + metrics::ROUTING_RETRIEVE_LINK_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json( routing_types::LinkedRoutingConfigRetrieveResponse::ProfileBased(active_algorithms), )) @@ -726,6 +740,7 @@ pub async fn retrieve_linked_routing_config( routing_types::RoutingRetrieveResponse { algorithm }, ); + metrics::ROUTING_RETRIEVE_LINK_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(response)) } } @@ -764,6 +779,7 @@ pub async fn retrieve_default_routing_config_for_profiles( ) .collect::>(); + metrics::ROUTING_RETRIEVE_CONFIG_FOR_PROFILE_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json(default_configs)) } @@ -839,6 +855,7 @@ pub async fn update_default_routing_config_for_profile( ) .await?; + metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE_RESPONSE.add(&metrics::CONTEXT, 1, &[]); Ok(service_api::ApplicationResponse::Json( routing_types::ProfileDefaultRoutingConfig { profile_id: business_profile.profile_id,