-
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.
Merge remote-tracking branch 'origin/main' into payment_charges
- Loading branch information
Showing
91 changed files
with
3,147 additions
and
2,391 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
94 changes: 94 additions & 0 deletions
94
crates/analytics/src/auth_events/metrics/frictionless_success_count.rs
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,94 @@ | ||
use api_models::analytics::{ | ||
auth_events::{AuthEventFlows, AuthEventMetricsBucketIdentifier}, | ||
Granularity, TimeRange, | ||
}; | ||
use common_utils::errors::ReportSwitchExt; | ||
use error_stack::ResultExt; | ||
use time::PrimitiveDateTime; | ||
|
||
use super::AuthEventMetricRow; | ||
use crate::{ | ||
query::{Aggregate, GroupByClause, QueryBuilder, QueryFilter, ToSql, Window}, | ||
types::{AnalyticsCollection, AnalyticsDataSource, MetricsError, MetricsResult}, | ||
}; | ||
|
||
#[derive(Default)] | ||
pub(super) struct FrictionlessSuccessCount; | ||
|
||
#[async_trait::async_trait] | ||
impl<T> super::AuthEventMetric<T> for FrictionlessSuccessCount | ||
where | ||
T: AnalyticsDataSource + super::AuthEventMetricAnalytics, | ||
PrimitiveDateTime: ToSql<T>, | ||
AnalyticsCollection: ToSql<T>, | ||
Granularity: GroupByClause<T>, | ||
Aggregate<&'static str>: ToSql<T>, | ||
Window<&'static str>: ToSql<T>, | ||
{ | ||
async fn load_metrics( | ||
&self, | ||
merchant_id: &str, | ||
_publishable_key: &str, | ||
granularity: &Option<Granularity>, | ||
time_range: &TimeRange, | ||
pool: &T, | ||
) -> MetricsResult<Vec<(AuthEventMetricsBucketIdentifier, AuthEventMetricRow)>> { | ||
let mut query_builder: QueryBuilder<T> = | ||
QueryBuilder::new(AnalyticsCollection::ApiEventsAnalytics); | ||
|
||
query_builder | ||
.add_select_column(Aggregate::Count { | ||
field: None, | ||
alias: Some("count"), | ||
}) | ||
.switch()?; | ||
|
||
if let Some(granularity) = granularity.as_ref() { | ||
query_builder | ||
.add_granularity_in_mins(granularity) | ||
.switch()?; | ||
} | ||
|
||
query_builder | ||
.add_filter_clause("merchant_id", merchant_id) | ||
.switch()?; | ||
|
||
query_builder | ||
.add_filter_clause("api_flow", AuthEventFlows::PaymentsExternalAuthentication) | ||
.switch()?; | ||
|
||
query_builder | ||
.add_filter_clause("visitParamExtractRaw(response, 'transStatus')", "\"Y\"") | ||
.switch()?; | ||
|
||
time_range | ||
.set_filter_clause(&mut query_builder) | ||
.attach_printable("Error filtering time range") | ||
.switch()?; | ||
|
||
if let Some(_granularity) = granularity.as_ref() { | ||
query_builder | ||
.add_group_by_clause("time_bucket") | ||
.attach_printable("Error adding granularity") | ||
.switch()?; | ||
} | ||
|
||
query_builder | ||
.execute_query::<AuthEventMetricRow, _>(pool) | ||
.await | ||
.change_context(MetricsError::QueryBuildingError)? | ||
.change_context(MetricsError::QueryExecutionFailure)? | ||
.into_iter() | ||
.map(|i| { | ||
Ok(( | ||
AuthEventMetricsBucketIdentifier::new(i.time_bucket.clone()), | ||
i, | ||
)) | ||
}) | ||
.collect::<error_stack::Result< | ||
Vec<(AuthEventMetricsBucketIdentifier, AuthEventMetricRow)>, | ||
crate::query::PostProcessingError, | ||
>>() | ||
.change_context(MetricsError::PostProcessingFailure) | ||
} | ||
} |
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
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.