mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
refactor(dynamic_routing): add info logs to log the grpc request and response (#6962)
This commit is contained in:
@ -128,3 +128,13 @@ impl<T> AddHeaders for tonic::Request<T> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "dynamic_routing")]
|
||||
pub(crate) fn create_grpc_request<T: Debug>(message: T, headers: GrpcHeaders) -> tonic::Request<T> {
|
||||
let mut request = tonic::Request::new(message);
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
|
||||
logger::info!(dynamic_routing_request=?request);
|
||||
|
||||
request
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ pub use elimination_rate::{
|
||||
LabelWithBucketName, UpdateEliminationBucketRequest, UpdateEliminationBucketResponse,
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
use router_env::{instrument, logger, tracing};
|
||||
#[allow(
|
||||
missing_docs,
|
||||
unused_qualifications,
|
||||
@ -21,7 +22,7 @@ pub mod elimination_rate {
|
||||
}
|
||||
|
||||
use super::{Client, DynamicRoutingError, DynamicRoutingResult};
|
||||
use crate::grpc_client::{AddHeaders, GrpcHeaders};
|
||||
use crate::grpc_client::{self, GrpcHeaders};
|
||||
|
||||
/// The trait Elimination Based Routing would have the functions required to support performance, calculation and invalidation bucket
|
||||
#[async_trait::async_trait]
|
||||
@ -54,6 +55,7 @@ pub trait EliminationBasedRouting: dyn_clone::DynClone + Send + Sync {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
|
||||
#[instrument(skip_all)]
|
||||
async fn perform_elimination_routing(
|
||||
&self,
|
||||
id: String,
|
||||
@ -69,14 +71,15 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
|
||||
|
||||
let config = configs.map(ForeignTryFrom::foreign_try_from).transpose()?;
|
||||
|
||||
let mut request = tonic::Request::new(EliminationRequest {
|
||||
id,
|
||||
params,
|
||||
labels,
|
||||
config,
|
||||
});
|
||||
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
let request = grpc_client::create_grpc_request(
|
||||
EliminationRequest {
|
||||
id,
|
||||
params,
|
||||
labels,
|
||||
config,
|
||||
},
|
||||
headers,
|
||||
);
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
@ -87,9 +90,12 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
|
||||
))?
|
||||
.into_inner();
|
||||
|
||||
logger::info!(dynamic_routing_response=?response);
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn update_elimination_bucket_config(
|
||||
&self,
|
||||
id: String,
|
||||
@ -110,14 +116,15 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut request = tonic::Request::new(UpdateEliminationBucketRequest {
|
||||
id,
|
||||
params,
|
||||
labels_with_bucket_name,
|
||||
config,
|
||||
});
|
||||
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
let request = grpc_client::create_grpc_request(
|
||||
UpdateEliminationBucketRequest {
|
||||
id,
|
||||
params,
|
||||
labels_with_bucket_name,
|
||||
config,
|
||||
},
|
||||
headers,
|
||||
);
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
@ -127,16 +134,19 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
|
||||
"Failed to update the elimination bucket".to_string(),
|
||||
))?
|
||||
.into_inner();
|
||||
|
||||
logger::info!(dynamic_routing_response=?response);
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn invalidate_elimination_bucket(
|
||||
&self,
|
||||
id: String,
|
||||
headers: GrpcHeaders,
|
||||
) -> DynamicRoutingResult<InvalidateBucketResponse> {
|
||||
let mut request = tonic::Request::new(InvalidateBucketRequest { id });
|
||||
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
let request = grpc_client::create_grpc_request(InvalidateBucketRequest { id }, headers);
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
@ -146,6 +156,9 @@ impl EliminationBasedRouting for EliminationAnalyserClient<Client> {
|
||||
"Failed to invalidate the elimination bucket".to_string(),
|
||||
))?
|
||||
.into_inner();
|
||||
|
||||
logger::info!(dynamic_routing_response=?response);
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ use api_models::routing::{
|
||||
};
|
||||
use common_utils::{ext_traits::OptionExt, transformers::ForeignTryFrom};
|
||||
use error_stack::ResultExt;
|
||||
use router_env::{instrument, logger, tracing};
|
||||
pub use success_rate::{
|
||||
success_rate_calculator_client::SuccessRateCalculatorClient, CalSuccessRateConfig,
|
||||
CalSuccessRateRequest, CalSuccessRateResponse,
|
||||
@ -15,13 +16,14 @@ pub use success_rate::{
|
||||
missing_docs,
|
||||
unused_qualifications,
|
||||
clippy::unwrap_used,
|
||||
clippy::as_conversions
|
||||
clippy::as_conversions,
|
||||
clippy::use_self
|
||||
)]
|
||||
pub mod success_rate {
|
||||
tonic::include_proto!("success_rate");
|
||||
}
|
||||
use super::{Client, DynamicRoutingError, DynamicRoutingResult};
|
||||
use crate::grpc_client::{AddHeaders, GrpcHeaders};
|
||||
use crate::grpc_client::{self, GrpcHeaders};
|
||||
/// The trait Success Based Dynamic Routing would have the functions required to support the calculation and updation window
|
||||
#[async_trait::async_trait]
|
||||
pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
|
||||
@ -53,6 +55,7 @@ pub trait SuccessBasedDynamicRouting: dyn_clone::DynClone + Send + Sync {
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
#[instrument(skip_all)]
|
||||
async fn calculate_success_rate(
|
||||
&self,
|
||||
id: String,
|
||||
@ -71,14 +74,15 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
.map(ForeignTryFrom::foreign_try_from)
|
||||
.transpose()?;
|
||||
|
||||
let mut request = tonic::Request::new(CalSuccessRateRequest {
|
||||
id,
|
||||
params,
|
||||
labels,
|
||||
config,
|
||||
});
|
||||
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
let request = grpc_client::create_grpc_request(
|
||||
CalSuccessRateRequest {
|
||||
id,
|
||||
params,
|
||||
labels,
|
||||
config,
|
||||
},
|
||||
headers,
|
||||
);
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
@ -89,9 +93,12 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
))?
|
||||
.into_inner();
|
||||
|
||||
logger::info!(dynamic_routing_response=?response);
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn update_success_rate(
|
||||
&self,
|
||||
id: String,
|
||||
@ -113,14 +120,15 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut request = tonic::Request::new(UpdateSuccessRateWindowRequest {
|
||||
id,
|
||||
params,
|
||||
labels_with_status,
|
||||
config,
|
||||
});
|
||||
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
let request = grpc_client::create_grpc_request(
|
||||
UpdateSuccessRateWindowRequest {
|
||||
id,
|
||||
params,
|
||||
labels_with_status,
|
||||
config,
|
||||
},
|
||||
headers,
|
||||
);
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
@ -131,16 +139,18 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
))?
|
||||
.into_inner();
|
||||
|
||||
logger::info!(dynamic_routing_response=?response);
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn invalidate_success_rate_routing_keys(
|
||||
&self,
|
||||
id: String,
|
||||
headers: GrpcHeaders,
|
||||
) -> DynamicRoutingResult<InvalidateWindowsResponse> {
|
||||
let mut request = tonic::Request::new(InvalidateWindowsRequest { id });
|
||||
|
||||
request.add_headers_to_grpc_request(headers);
|
||||
let request = grpc_client::create_grpc_request(InvalidateWindowsRequest { id }, headers);
|
||||
|
||||
let response = self
|
||||
.clone()
|
||||
@ -150,6 +160,9 @@ impl SuccessBasedDynamicRouting for SuccessRateCalculatorClient<Client> {
|
||||
"Failed to invalidate the success rate routing keys".to_string(),
|
||||
))?
|
||||
.into_inner();
|
||||
|
||||
logger::info!(dynamic_routing_response=?response);
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user