-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
2,192 additions
and
460 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod core; | ||
pub mod events; | ||
pub trait ConnectorEventAnalytics: events::ConnectorEventLogAnalytics {} | ||
|
||
pub use self::core::connector_events_core; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use api_models::analytics::connector_events::ConnectorEventsRequest; | ||
use common_utils::errors::ReportSwitchExt; | ||
use error_stack::{IntoReport, ResultExt}; | ||
|
||
use super::events::{get_connector_events, ConnectorEventsResult}; | ||
use crate::{errors::AnalyticsResult, types::FiltersError, AnalyticsProvider}; | ||
|
||
pub async fn connector_events_core( | ||
pool: &AnalyticsProvider, | ||
req: ConnectorEventsRequest, | ||
merchant_id: String, | ||
) -> AnalyticsResult<Vec<ConnectorEventsResult>> { | ||
let data = match pool { | ||
AnalyticsProvider::Sqlx(_) => Err(FiltersError::NotImplemented( | ||
"Connector Events not implemented for SQLX", | ||
)) | ||
.into_report() | ||
.attach_printable("SQL Analytics is not implemented for Connector Events"), | ||
AnalyticsProvider::Clickhouse(ckh_pool) | ||
| AnalyticsProvider::CombinedSqlx(_, ckh_pool) | ||
| AnalyticsProvider::CombinedCkh(_, ckh_pool) => { | ||
get_connector_events(&merchant_id, req, ckh_pool).await | ||
} | ||
} | ||
.switch()?; | ||
Ok(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use api_models::analytics::{ | ||
connector_events::{ConnectorEventsRequest, QueryType}, | ||
Granularity, | ||
}; | ||
use common_utils::errors::ReportSwitchExt; | ||
use error_stack::ResultExt; | ||
use time::PrimitiveDateTime; | ||
|
||
use crate::{ | ||
query::{Aggregate, GroupByClause, QueryBuilder, ToSql, Window}, | ||
types::{AnalyticsCollection, AnalyticsDataSource, FiltersError, FiltersResult, LoadRow}, | ||
}; | ||
pub trait ConnectorEventLogAnalytics: LoadRow<ConnectorEventsResult> {} | ||
|
||
pub async fn get_connector_events<T>( | ||
merchant_id: &String, | ||
query_param: ConnectorEventsRequest, | ||
pool: &T, | ||
) -> FiltersResult<Vec<ConnectorEventsResult>> | ||
where | ||
T: AnalyticsDataSource + ConnectorEventLogAnalytics, | ||
PrimitiveDateTime: ToSql<T>, | ||
AnalyticsCollection: ToSql<T>, | ||
Granularity: GroupByClause<T>, | ||
Aggregate<&'static str>: ToSql<T>, | ||
Window<&'static str>: ToSql<T>, | ||
{ | ||
let mut query_builder: QueryBuilder<T> = | ||
QueryBuilder::new(AnalyticsCollection::ConnectorEvents); | ||
query_builder.add_select_column("*").switch()?; | ||
|
||
query_builder | ||
.add_filter_clause("merchant_id", merchant_id) | ||
.switch()?; | ||
match query_param.query_param { | ||
QueryType::Payment { payment_id } => query_builder | ||
.add_filter_clause("payment_id", payment_id) | ||
.switch()?, | ||
} | ||
//TODO!: update the execute_query function to return reports instead of plain errors... | ||
query_builder | ||
.execute_query::<ConnectorEventsResult, _>(pool) | ||
.await | ||
.change_context(FiltersError::QueryBuildingError)? | ||
.change_context(FiltersError::QueryExecutionFailure) | ||
} | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize)] | ||
pub struct ConnectorEventsResult { | ||
pub merchant_id: String, | ||
pub payment_id: String, | ||
pub connector_name: Option<String>, | ||
pub request_id: Option<String>, | ||
pub flow: String, | ||
pub request: String, | ||
pub response: Option<String>, | ||
pub error: Option<String>, | ||
pub status_code: u16, | ||
pub latency: Option<u128>, | ||
#[serde(with = "common_utils::custom_serde::iso8601")] | ||
pub created_at: PrimitiveDateTime, | ||
pub method: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.