Skip to content

Commit

Permalink
feat(routing): Routing prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak1799 committed Nov 14, 2023
1 parent d2968c9 commit b191363
Show file tree
Hide file tree
Showing 2 changed files with 21 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 @@ -44,3 +44,13 @@ counter_metric!(
WEBHOOK_EVENT_TYPE_IDENTIFICATION_FAILURE_COUNT,
GLOBAL_METER
);

counter_metric!(ROUTING_CREATE_REQUEST_RECEIVED, GLOBAL_METER);
counter_metric!(ROUTING_MERCHANT_DICTIONARY_RETRIEVE, GLOBAL_METER);
counter_metric!(ROUTING_LINK_CONFIG, GLOBAL_METER);
counter_metric!(ROUTING_RETRIEVE_CONFIG, GLOBAL_METER);
counter_metric!(ROUTING_RETRIEVE_LINK_CONFIG, GLOBAL_METER);
counter_metric!(ROUTING_UNLINK_CONFIG, GLOBAL_METER);
counter_metric!(ROUTING_UPDATE_CONFIG, GLOBAL_METER);
counter_metric!(ROUTING_UPDATE_CONFIG_FOR_PROFILE, GLOBAL_METER);
counter_metric!(ROUTING_RETRIEVE_CONFIG_FOR_PROFILE, GLOBAL_METER);
12 changes: 11 additions & 1 deletion crates/router/src/core/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
consts,
core::{
errors::{RouterResponse, StorageErrorExt},
utils as core_utils,
metrics, utils as core_utils,
},
routes::AppState,
types::domain,
Expand All @@ -35,6 +35,7 @@ pub async fn retrieve_merchant_routing_dictionary(
merchant_account: domain::MerchantAccount,
#[cfg(feature = "business_profile_routing")] query_params: RoutingRetrieveQuery,
) -> RouterResponse<routing_types::RoutingKind> {
metrics::ROUTING_MERCHANT_DICTIONARY_RETRIEVE.add(&metrics::CONTEXT, 1, &[]);
#[cfg(feature = "business_profile_routing")]
{
let routing_metadata = state
Expand Down Expand Up @@ -73,6 +74,7 @@ pub async fn create_routing_config(
key_store: domain::MerchantKeyStore,
request: routing_types::RoutingConfigRequest,
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
metrics::ROUTING_CREATE_REQUEST_RECEIVED.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();

let name = request
Expand Down Expand Up @@ -223,6 +225,7 @@ pub async fn link_routing_config(
#[cfg(not(feature = "business_profile_routing"))] key_store: domain::MerchantKeyStore,
algorithm_id: String,
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
metrics::ROUTING_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
#[cfg(feature = "business_profile_routing")]
{
Expand Down Expand Up @@ -326,6 +329,7 @@ pub async fn retrieve_routing_config(
merchant_account: domain::MerchantAccount,
algorithm_id: RoutingAlgorithmId,
) -> RouterResponse<routing_types::MerchantRoutingAlgorithm> {
metrics::ROUTING_RETRIEVE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
#[cfg(feature = "business_profile_routing")]
{
Expand Down Expand Up @@ -396,6 +400,7 @@ pub async fn unlink_routing_config(
#[cfg(not(feature = "business_profile_routing"))] key_store: domain::MerchantKeyStore,
#[cfg(feature = "business_profile_routing")] request: routing_types::RoutingConfigRequest,
) -> RouterResponse<routing_types::RoutingDictionaryRecord> {
metrics::ROUTING_UNLINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
#[cfg(feature = "business_profile_routing")]
{
Expand Down Expand Up @@ -568,6 +573,7 @@ pub async fn update_default_routing_config(
merchant_account: domain::MerchantAccount,
updated_config: Vec<routing_types::RoutableConnectorChoice>,
) -> RouterResponse<Vec<routing_types::RoutableConnectorChoice>> {
metrics::ROUTING_UPDATE_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();
let default_config =
helpers::get_merchant_default_config(db, &merchant_account.merchant_id).await?;
Expand Down Expand Up @@ -613,6 +619,7 @@ 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, &[]);
let db = state.store.as_ref();

helpers::get_merchant_default_config(db, &merchant_account.merchant_id)
Expand All @@ -625,6 +632,7 @@ pub async fn retrieve_linked_routing_config(
merchant_account: domain::MerchantAccount,
#[cfg(feature = "business_profile_routing")] query_params: RoutingRetrieveLinkQuery,
) -> RouterResponse<routing_types::LinkedRoutingConfigRetrieveResponse> {
metrics::ROUTING_RETRIEVE_LINK_CONFIG.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();

#[cfg(feature = "business_profile_routing")]
Expand Down Expand Up @@ -726,6 +734,7 @@ pub async fn retrieve_default_routing_config_for_profiles(
state: AppState,
merchant_account: domain::MerchantAccount,
) -> RouterResponse<Vec<routing_types::ProfileDefaultRoutingConfig>> {
metrics::ROUTING_RETRIEVE_CONFIG_FOR_PROFILE.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();

let all_profiles = db
Expand Down Expand Up @@ -764,6 +773,7 @@ pub async fn update_default_routing_config_for_profile(
updated_config: Vec<routing_types::RoutableConnectorChoice>,
profile_id: String,
) -> RouterResponse<routing_types::ProfileDefaultRoutingConfig> {
metrics::ROUTING_UPDATE_CONFIG_FOR_PROFILE.add(&metrics::CONTEXT, 1, &[]);
let db = state.store.as_ref();

let business_profile = core_utils::validate_and_get_business_profile(
Expand Down

0 comments on commit b191363

Please sign in to comment.