Skip to content

Commit

Permalink
fix(routing): Added response metrics as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Nov 16, 2023
1 parent b191363 commit 654044a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions crates/router/src/core/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
19 changes: 18 additions & 1 deletion crates/router/src/core/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ pub async fn retrieve_merchant_routing_dictionary(
.map(ForeignInto::foreign_into)
.collect::<Vec<_>>();

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(
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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(),
))
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -612,14 +624,15 @@ pub async fn update_default_routing_config(
)
.await?;

metrics::ROUTING_UPDATE_CONFIG_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
Ok(service_api::ApplicationResponse::Json(updated_config))
}

pub async fn retrieve_default_routing_config(
state: AppState,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
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)
Expand Down Expand Up @@ -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),
))
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -764,6 +779,7 @@ pub async fn retrieve_default_routing_config_for_profiles(
)
.collect::<Vec<_>>();

metrics::ROUTING_RETRIEVE_CONFIG_FOR_PROFILE_RESPONSE.add(&metrics::CONTEXT, 1, &[]);
Ok(service_api::ApplicationResponse::Json(default_configs))
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 654044a

Please sign in to comment.