Skip to content
Open
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
60 changes: 30 additions & 30 deletions src/euclid/handlers/routing_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn config_sr_dimentions(

if !invalid_dimensions.is_empty() {
metrics::API_REQUEST_COUNTER
.with_label_values(&["config_sr_dimentions", "failure"])
.with_label_values(&["config_sr_dimentions", "failure", "400"])
.inc();
timer.observe_duration();

Expand Down Expand Up @@ -107,7 +107,7 @@ pub async fn config_sr_dimentions(

if let Err(_) = result {
metrics::API_REQUEST_COUNTER
.with_label_values(&["config_sr_dimentions", "failure"])
.with_label_values(&["config_sr_dimentions", "failure", "500"])
.inc();
timer.observe_duration();
logger::error!(
Expand All @@ -117,7 +117,7 @@ pub async fn config_sr_dimentions(
return Err(ContainerError::from(EuclidErrors::StorageError));
}
metrics::API_REQUEST_COUNTER
.with_label_values(&["config_sr_dimentions", "success"])
.with_label_values(&["config_sr_dimentions", "success", "200"])
.inc();
timer.observe_duration();
logger::info!(
Expand Down Expand Up @@ -154,7 +154,7 @@ pub async fn routing_create(
logger::error!("Routing rule validation failed with errors: {detailed_error}");

metrics::API_REQUEST_COUNTER
.with_label_values(&["routing_create", "failure"])
.with_label_values(&["routing_create", "failure", "400"])
.inc();
timer.observe_duration();
return Err(ContainerError::new_with_status_code_and_payload(
Expand All @@ -169,7 +169,7 @@ pub async fn routing_create(
}
}
metrics::API_REQUEST_COUNTER
.with_label_values(&["routing_create", "failure"])
.with_label_values(&["routing_create", "failure", "400"])
.inc();
timer.observe_duration();
return Err(err.into());
Expand Down Expand Up @@ -218,7 +218,7 @@ pub async fn routing_create(
logger::info!("Response: {response:?}");

metrics::API_REQUEST_COUNTER
.with_label_values(&["routing_create", "success"])
.with_label_values(&["routing_create", "success", "200"])
.inc();
timer.observe_duration();
Ok(Json(response))
Expand Down Expand Up @@ -269,7 +269,7 @@ pub async fn routing_evaluate(
Ok(mapper) => mapper.routing_algorithm_id,
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "404"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -287,7 +287,7 @@ pub async fn routing_evaluate(
Ok(config) => config,
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -299,7 +299,7 @@ pub async fn routing_evaluate(
&& value.as_ref().is_some_and(|val| !val.is_metadata())
{
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "400"])
.inc();
timer.observe_duration();
return Err(EuclidErrors::InvalidRequestParameter(key.clone()).into());
Expand All @@ -310,7 +310,7 @@ pub async fn routing_evaluate(
if let Some(Some(ValueType::EnumVariant(value))) = parameters.get(key) {
if !is_valid_enum_value(routing_config, key, value) {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "400"])
.inc();
timer.observe_duration();
return Err(EuclidErrors::InvalidRequest(format!(
Expand All @@ -321,7 +321,7 @@ pub async fn routing_evaluate(
}
} else {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "400"])
.inc();
timer.observe_duration();
return Err(EuclidErrors::InvalidRequest(format!(
Expand Down Expand Up @@ -353,7 +353,7 @@ pub async fn routing_evaluate(
Ok(algo) => algo,
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -373,7 +373,7 @@ pub async fn routing_evaluate(
Ok(data) => data,
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "400"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -393,7 +393,7 @@ pub async fn routing_evaluate(
Ok((_, eval)) => (out_enum, eval, Some("straight_through_rule".into())),
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -412,7 +412,7 @@ pub async fn routing_evaluate(
Ok((_, eval)) => (out_enum, eval, Some("priority_rule".into())),
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -431,7 +431,7 @@ pub async fn routing_evaluate(
Ok((_, eval)) => (out_enum, eval, Some("volume_split_rule".into())),
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand Down Expand Up @@ -465,7 +465,7 @@ pub async fn routing_evaluate(
}
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "failure"])
.with_label_values(&["routing_evaluate", "failure", "400"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand Down Expand Up @@ -495,7 +495,7 @@ pub async fn routing_evaluate(
logger::info!("Response: {response:?}");

API_REQUEST_COUNTER
.with_label_values(&["routing_evaluate", "success"])
.with_label_values(&["routing_evaluate", "success", "200"])
.inc();
timer.observe_duration();
Ok(Json(response))
Expand Down Expand Up @@ -526,7 +526,7 @@ pub async fn activate_routing_rule(
Ok(connection) => connection,
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "failure"])
.with_label_values(&["activate_routing_rule", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -546,7 +546,7 @@ pub async fn activate_routing_rule(
Ok(algorithm) => algorithm.algorithm_for,
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "failure"])
.with_label_values(&["activate_routing_rule", "failure", "404"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand Down Expand Up @@ -589,22 +589,22 @@ pub async fn activate_routing_rule(
{
Ok(_) => {
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "success"])
.with_label_values(&["activate_routing_rule", "success", "200"])
.inc();
timer.observe_duration();
return Ok(());
}
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "failure"])
.with_label_values(&["activate_routing_rule", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
}
}
}
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "success"])
.with_label_values(&["activate_routing_rule", "success", "200"])
.inc();
timer.observe_duration();
return Ok(());
Expand All @@ -623,14 +623,14 @@ pub async fn activate_routing_rule(
{
Ok(_) => {
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "success"])
.with_label_values(&["activate_routing_rule", "success", "200"])
.inc();
timer.observe_duration();
Ok(())
}
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["activate_routing_rule", "failure"])
.with_label_values(&["activate_routing_rule", "failure", "500"])
.inc();
timer.observe_duration();
Err(e.into())
Expand Down Expand Up @@ -660,14 +660,14 @@ pub async fn list_all_routing_algorithm_id(
{
Ok(algorithms) => {
API_REQUEST_COUNTER
.with_label_values(&["list_all_routing_algorithm_id", "success"])
.with_label_values(&["list_all_routing_algorithm_id", "success", "200"])
.inc();
timer.observe_duration();
Ok(Json(algorithms.into_iter().map(Into::into).collect()))
}
Err(e) => {
API_REQUEST_COUNTER
.with_label_values(&["list_all_routing_algorithm_id", "failure"])
.with_label_values(&["list_all_routing_algorithm_id", "failure", "500"])
.inc();
timer.observe_duration();
Err(e.into())
Expand Down Expand Up @@ -699,7 +699,7 @@ pub async fn list_active_routing_algorithm(
Ok(mappings) => mappings,
Err(e) => {
metrics::API_REQUEST_COUNTER
.with_label_values(&["list_active_routing_algorithm", "failure"])
.with_label_values(&["list_active_routing_algorithm", "failure", "404"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -722,7 +722,7 @@ pub async fn list_active_routing_algorithm(
Ok(algos) => algos,
Err(e) => {
metrics::API_REQUEST_COUNTER
.with_label_values(&["list_active_routing_algorithm", "failure"])
.with_label_values(&["list_active_routing_algorithm", "failure", "500"])
.inc();
timer.observe_duration();
return Err(e.into());
Expand All @@ -734,7 +734,7 @@ pub async fn list_active_routing_algorithm(
.collect();

API_REQUEST_COUNTER
.with_label_values(&["list_active_routing_algorithm", "success"])
.with_label_values(&["list_active_routing_algorithm", "success", "200"])
.inc();
timer.observe_duration();

Expand Down
2 changes: 1 addition & 1 deletion src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy_static! {
pub static ref API_REQUEST_COUNTER: IntCounterVec = register_int_counter_vec!(
"api_requests_by_status",
"Count of API requests grouped by endpoint and result",
&["endpoint", "status"]
&["endpoint", "status", "status_code"]
).unwrap();

/// Latency of API calls grouped by endpoint
Expand Down
8 changes: 4 additions & 4 deletions src/routes/decide_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn decide_gateway(
Err(e) => {
logger::debug!(tag = "DecideGateway", "Error: {:?}", e);
metrics::API_REQUEST_COUNTER
.with_label_values(&["decide_gateway", "failure"])
.with_label_values(&["decide_gateway", "failure", "400"])
.inc();
timer.observe_duration();
return Err(ErrorResponse {
Expand All @@ -80,22 +80,22 @@ pub async fn decide_gateway(
Ok(payload) => match deciderFullPayloadHSFunction(payload).await {
Ok(decided_gateway) => {
metrics::API_REQUEST_COUNTER
.with_label_values(&["decide_gateway", "success"])
.with_label_values(&["decide_gateway", "success", "200"])
.inc();
Ok(decided_gateway)
}
Err(e) => {
logger::debug!(tag = "DecideGateway", "Error: {:?}", e);
metrics::API_REQUEST_COUNTER
.with_label_values(&["decide_gateway", "failure"])
.with_label_values(&["decide_gateway", "failure", "400"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.with_label_values(&["decide_gateway", "failure", "400"])
.with_label_values(&["decide_gateway", "failure", "500"])

isn't it 500?

.inc();
Err(e)
}
},
Err(e) => {
logger::debug!(tag = "DecideGateway", "Error: {:?}", e);
metrics::API_REQUEST_COUNTER
.with_label_values(&["decide_gateway", "failure"])
.with_label_values(&["decide_gateway", "failure", "400"])
.inc();
Err(ErrorResponse {
status: "400".to_string(),
Expand Down
10 changes: 5 additions & 5 deletions src/routes/decision_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ where
);

API_REQUEST_COUNTER
.with_label_values(&["decision_gateway", "failure"])
.with_label_values(&["decision_gateway", "failure", "400"])
.inc();
timer.observe_duration();

Expand Down Expand Up @@ -176,7 +176,7 @@ where
);

API_REQUEST_COUNTER
.with_label_values(&["decision_gateway", "success"])
.with_label_values(&["decision_gateway", "success", "200"])
.inc();
Ok(response)
}
Expand Down Expand Up @@ -205,9 +205,9 @@ where
category = "INCOMING_API",
"Error occurred while processing decider function"
);

let status_code = e.status.clone();
API_REQUEST_COUNTER
.with_label_values(&["decision_gateway", "failure"])
.with_label_values(&["decision_gateway", "failure", &status_code])
Comment on lines +208 to +210
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clone() operation on e.status is unnecessary since it's being used immediately as a string reference. Consider using &e.status instead of cloning.

Copilot uses AI. Check for mistakes.
.inc();
Err(e)
}
Expand Down Expand Up @@ -260,7 +260,7 @@ where
);

API_REQUEST_COUNTER
.with_label_values(&["decision_gateway", "failure"])
.with_label_values(&["decision_gateway", "failure", "400"])
.inc();
timer.observe_duration();
Err(error_response)
Expand Down
Loading
Loading