feat(router_env): making metric flow as a trait for extensibility (#797)

This commit is contained in:
Nishant Joshi
2023-03-23 14:52:57 +05:30
committed by GitHub
parent 699ca4f6f8
commit da5a89bc3d
3 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,9 @@
use super::utils as metric_utils; use super::utils as metric_utils;
pub async fn record_request_time_metric<F, R>(future: F, flow: router_env::Flow) -> R pub async fn record_request_time_metric<F, R>(
future: F,
flow: impl router_env::types::FlowMetric,
) -> R
where where
F: futures::Future<Output = R>, F: futures::Future<Output = R>,
{ {

View File

@ -522,7 +522,7 @@ where
fields(request_method, request_url_path) fields(request_method, request_url_path)
)] )]
pub async fn server_wrap<'a, 'b, A, T, U, Q, F, Fut, E>( pub async fn server_wrap<'a, 'b, A, T, U, Q, F, Fut, E>(
flow: router_env::Flow, flow: impl router_env::types::FlowMetric,
state: &'b A, state: &'b A,
request: &'a HttpRequest, request: &'a HttpRequest,
payload: T, payload: T,

View File

@ -164,6 +164,12 @@ pub enum Flow {
ApiKeyList, ApiKeyList,
} }
///
/// Trait for providing generic behaviour to flow metric
///
pub trait FlowMetric: ToString + std::fmt::Debug {}
impl FlowMetric for Flow {}
/// Category of log event. /// Category of log event.
#[derive(Debug)] #[derive(Debug)]
pub enum Category { pub enum Category {