From e2a4f43a38e348ca2f5f675ead1699ede8c873a1 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Tue, 28 Nov 2023 15:38:08 +0530 Subject: [PATCH 1/5] enhancement(router): add key_vaule to locker metrics --- .../router/src/core/payment_methods/cards.rs | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 044e270a7ea9..258a279dac9d 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -230,7 +230,9 @@ pub async fn add_card_to_locker( }) }, &metrics::CARD_ADD_TIME, - &[], + &[router_env::opentelemetry::KeyValue::new( + "locker", "basilisk", + )], ) .await?; logger::debug!("card added to basilisk locker"); @@ -253,17 +255,17 @@ pub async fn add_card_to_locker( }) }, &metrics::CARD_ADD_TIME, - &[], + &[router_env::opentelemetry::KeyValue::new("locker", "rust")], ) .await; match add_card_to_rs_resp { value @ Ok(_) => { - logger::debug!("Card added successfully"); + logger::debug!("card added to rust locker"); value } Err(err) => { - logger::debug!(error =? err,"failed to add card"); + logger::debug!(error =? err,"failed to add card to rust locker"); Ok(add_card_to_hs_resp) } } @@ -290,12 +292,16 @@ pub async fn get_card_from_locker( .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while getting card from basilisk_hs") .map_err(|error| { - metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); + metrics::CARD_LOCKER_FAILURES.add( + &metrics::CONTEXT, + 1, + &[router_env::opentelemetry::KeyValue::new("locker", "rust")], + ); error }) }, &metrics::CARD_GET_TIME, - &[], + &[router_env::opentelemetry::KeyValue::new("locker", "rust")], ) .await; @@ -313,12 +319,20 @@ pub async fn get_card_from_locker( .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed while getting card from basilisk_hs") .map_err(|error| { - metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); + metrics::CARD_LOCKER_FAILURES.add( + &metrics::CONTEXT, + 1, + &[router_env::opentelemetry::KeyValue::new( + "locker", "basilisk", + )], + ); error }) }, &metrics::CARD_GET_TIME, - &[], + &[router_env::opentelemetry::KeyValue::new( + "locker", "basilisk", + )], ) .await .map(|inner_card| { From fd514d0b3db1fa685413449e15c726a5574b9623 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Wed, 29 Nov 2023 12:14:44 +0530 Subject: [PATCH 2/5] add that metric to get locker sucessful response count --- .../router/src/core/payment_methods/cards.rs | 46 ++++++++++++++++++- crates/router/src/routes/metrics.rs | 1 + 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 258a279dac9d..7ff75f1ceb52 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -225,7 +225,13 @@ pub async fn add_card_to_locker( ) .await .map_err(|error| { - metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); + metrics::CARD_LOCKER_FAILURES.add( + &metrics::CONTEXT, + 1, + &[router_env::opentelemetry::KeyValue::new( + "locker", "basilisk", + )], + ); error }) }, @@ -250,7 +256,11 @@ pub async fn add_card_to_locker( ) .await .map_err(|error| { - metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT, 1, &[]); + metrics::CARD_LOCKER_FAILURES.add( + &metrics::CONTEXT, + 1, + &[router_env::opentelemetry::KeyValue::new("locker", "rust")], + ); error }) }, @@ -262,10 +272,26 @@ pub async fn add_card_to_locker( match add_card_to_rs_resp { value @ Ok(_) => { logger::debug!("card added to rust locker"); + let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add( + &metrics::CONTEXT, + 1, + &[ + router_env::opentelemetry::KeyValue::new("locker", "rust"), + router_env::opentelemetry::KeyValue::new("operation", "add"), + ], + ); value } Err(err) => { logger::debug!(error =? err,"failed to add card to rust locker"); + let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add( + &metrics::CONTEXT, + 1, + &[ + router_env::opentelemetry::KeyValue::new("locker", "basilisk"), + router_env::opentelemetry::KeyValue::new("operation", "add"), + ], + ); Ok(add_card_to_hs_resp) } } @@ -337,10 +363,26 @@ pub async fn get_card_from_locker( .await .map(|inner_card| { logger::debug!("card retrieved from basilisk locker"); + let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add( + &metrics::CONTEXT, + 1, + &[ + router_env::opentelemetry::KeyValue::new("locker", "basilisk"), + router_env::opentelemetry::KeyValue::new("operation", "get"), + ], + ); inner_card }), Ok(_) => { logger::debug!("card retrieved from rust locker"); + let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add( + &metrics::CONTEXT, + 1, + &[ + router_env::opentelemetry::KeyValue::new("locker", "rust"), + router_env::opentelemetry::KeyValue::new("operation", "add"), + ], + ); get_card_from_rs_locker_resp } } diff --git a/crates/router/src/routes/metrics.rs b/crates/router/src/routes/metrics.rs index a8e6f9d2a892..192df1a09298 100644 --- a/crates/router/src/routes/metrics.rs +++ b/crates/router/src/routes/metrics.rs @@ -85,6 +85,7 @@ counter_metric!(CONNECTOR_HTTP_STATUS_CODE_5XX_COUNT, GLOBAL_METER); // Service Level counter_metric!(CARD_LOCKER_FAILURES, GLOBAL_METER); +counter_metric!(CARD_LOCKER_SUCCESSFUL_RESPONSE, GLOBAL_METER); counter_metric!(TEMP_LOCKER_FAILURES, GLOBAL_METER); histogram_metric!(CARD_ADD_TIME, GLOBAL_METER); histogram_metric!(CARD_GET_TIME, GLOBAL_METER); From 2e30b5519cec47c0858e6dbd9254d96583ee3b5a Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Wed, 29 Nov 2023 12:18:18 +0530 Subject: [PATCH 3/5] fix typo --- crates/router/src/core/payment_methods/cards.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 7ff75f1ceb52..a5ef37547aab 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -380,7 +380,7 @@ pub async fn get_card_from_locker( 1, &[ router_env::opentelemetry::KeyValue::new("locker", "rust"), - router_env::opentelemetry::KeyValue::new("operation", "add"), + router_env::opentelemetry::KeyValue::new("operation", "get"), ], ); get_card_from_rs_locker_resp From 7fef2ff59512a7d6be5ad211a14101b1de3c3262 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Wed, 29 Nov 2023 12:26:12 +0530 Subject: [PATCH 4/5] address pr comments --- .../router/src/core/payment_methods/cards.rs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index a5ef37547aab..d7013ce253ca 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -236,9 +236,10 @@ pub async fn add_card_to_locker( }) }, &metrics::CARD_ADD_TIME, - &[router_env::opentelemetry::KeyValue::new( - "locker", "basilisk", - )], + &[ + router_env::opentelemetry::KeyValue::new("locker", "basilisk"), + router_env::opentelemetry::KeyValue::new("operation", "add"), + ], ) .await?; logger::debug!("card added to basilisk locker"); @@ -259,7 +260,10 @@ pub async fn add_card_to_locker( metrics::CARD_LOCKER_FAILURES.add( &metrics::CONTEXT, 1, - &[router_env::opentelemetry::KeyValue::new("locker", "rust")], + &[ + router_env::opentelemetry::KeyValue::new("locker", "rust"), + router_env::opentelemetry::KeyValue::new("operation", "add"), + ], ); error }) @@ -321,7 +325,10 @@ pub async fn get_card_from_locker( metrics::CARD_LOCKER_FAILURES.add( &metrics::CONTEXT, 1, - &[router_env::opentelemetry::KeyValue::new("locker", "rust")], + &[ + router_env::opentelemetry::KeyValue::new("locker", "rust"), + router_env::opentelemetry::KeyValue::new("operation", "get"), + ], ); error }) @@ -348,9 +355,10 @@ pub async fn get_card_from_locker( metrics::CARD_LOCKER_FAILURES.add( &metrics::CONTEXT, 1, - &[router_env::opentelemetry::KeyValue::new( - "locker", "basilisk", - )], + &[ + router_env::opentelemetry::KeyValue::new("locker", "basilisk"), + router_env::opentelemetry::KeyValue::new("operation", "get"), + ], ); error }) From 5303dacafabe498cfb619348e9576584a0855134 Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Wed, 29 Nov 2023 12:29:03 +0530 Subject: [PATCH 5/5] address pr comments --- crates/router/src/core/payment_methods/cards.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index d7013ce253ca..545733e298ab 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -228,18 +228,18 @@ pub async fn add_card_to_locker( metrics::CARD_LOCKER_FAILURES.add( &metrics::CONTEXT, 1, - &[router_env::opentelemetry::KeyValue::new( - "locker", "basilisk", - )], + &[ + router_env::opentelemetry::KeyValue::new("locker", "basilisk"), + router_env::opentelemetry::KeyValue::new("operation", "add"), + ], ); error }) }, &metrics::CARD_ADD_TIME, - &[ - router_env::opentelemetry::KeyValue::new("locker", "basilisk"), - router_env::opentelemetry::KeyValue::new("operation", "add"), - ], + &[router_env::opentelemetry::KeyValue::new( + "locker", "basilisk", + )], ) .await?; logger::debug!("card added to basilisk locker");