Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): add key_value to locker metrics #2995

Merged
merged 8 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,21 @@ 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"),
router_env::opentelemetry::KeyValue::new("operation", "add"),
],
);
error
})
},
&metrics::CARD_ADD_TIME,
&[],
&[router_env::opentelemetry::KeyValue::new(
"locker", "basilisk",
)],
)
.await?;
logger::debug!("card added to basilisk locker");
Expand All @@ -248,22 +257,45 @@ 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"),
router_env::opentelemetry::KeyValue::new("operation", "add"),
],
);
error
})
},
&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");
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");
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)
}
}
Expand All @@ -290,12 +322,19 @@ 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"),
router_env::opentelemetry::KeyValue::new("operation", "get"),
],
);
ShankarSinghC marked this conversation as resolved.
Show resolved Hide resolved
error
})
},
&metrics::CARD_GET_TIME,
&[],
&[router_env::opentelemetry::KeyValue::new("locker", "rust")],
)
.await;

Expand All @@ -313,20 +352,45 @@ 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"),
router_env::opentelemetry::KeyValue::new("operation", "get"),
],
);
error
})
},
&metrics::CARD_GET_TIME,
&[],
&[router_env::opentelemetry::KeyValue::new(
"locker", "basilisk",
)],
)
.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", "get"),
],
);
get_card_from_rs_locker_resp
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/routes/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading