Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(analytics): add `smart_retries` only metrics for analytics v2 dashboard (#6575)
Uzair Khanf3897dd6b573
diff --git a/crates/analytics/src/payments/accumulator.rs b/crates/analytics/src/payments/accumulator.rsindex 5ca9fdf751..291d736407 100644--- a/crates/analytics/src/payments/accumulator.rs+++ b/crates/analytics/src/payments/accumulator.rs@@ -76,8 +76,11 @@ pub struct PaymentsDistributionAccumulator {pub failed: u32,pub total: u32,pub success_without_retries: u32,+ pub success_with_only_retries: u32,pub failed_without_retries: u32,+ pub failed_with_only_retries: u32,pub total_without_retries: u32,+ pub total_with_only_retries: u32,}pub trait PaymentMetricAccumulator {@@ -181,7 +184,14 @@ impl PaymentMetricAccumulator for SuccessRateAccumulator {}impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {- type MetricOutput = (Option<f64>, Option<f64>, Option<f64>, Option<f64>);+ type MetricOutput = (+ Option<f64>,+ Option<f64>,+ Option<f64>,+ Option<f64>,+ Option<f64>,+ Option<f64>,+ );fn add_metrics_bucket(&mut self, metrics: &PaymentMetricRow) {if let Some(ref status) = metrics.status {@@ -193,6 +203,8 @@ impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {self.success += success;if metrics.first_attempt.unwrap_or(false) {self.success_without_retries += success;+ } else {+ self.success_with_only_retries += success;}}}@@ -201,6 +213,8 @@ impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {self.failed += failed;if metrics.first_attempt.unwrap_or(false) {self.failed_without_retries += failed;+ } else {+ self.failed_with_only_retries += failed;}}}@@ -208,6 +222,8 @@ impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {self.total += total;if metrics.first_attempt.unwrap_or(false) {self.total_without_retries += total;+ } else {+ self.total_with_only_retries += total;}}}@@ -215,14 +231,17 @@ impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {fn collect(self) -> Self::MetricOutput {if self.total == 0 {- (None, None, None, None)+ (None, None, None, None, None, None)} else {let success = Some(self.success);let success_without_retries = Some(self.success_without_retries);+ let success_with_only_retries = Some(self.success_with_only_retries);let failed = Some(self.failed);+ let failed_with_only_retries = Some(self.failed_with_only_retries);let failed_without_retries = Some(self.failed_without_retries);let total = Some(self.total);let total_without_retries = Some(self.total_without_retries);+ let total_with_only_retries = Some(self.total_with_only_retries);let success_rate = match (success, total) {(Some(s), Some(t)) if t > 0 => Some(f64::from(s) * 100.0 / f64::from(t)),@@ -235,6 +254,12 @@ impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {_ => None,};+ let success_rate_with_only_retries =+ match (success_with_only_retries, total_with_only_retries) {+ (Some(s), Some(t)) if t > 0 => Some(f64::from(s) * 100.0 / f64::from(t)),+ _ => None,+ };+let failed_rate = match (failed, total) {(Some(s), Some(t)) if t > 0 => Some(f64::from(s) * 100.0 / f64::from(t)),_ => None,@@ -245,11 +270,19 @@ impl PaymentMetricAccumulator for PaymentsDistributionAccumulator {(Some(s), Some(t)) if t > 0 => Some(f64::from(s) * 100.0 / f64::from(t)),_ => None,};++ let failed_rate_with_only_retries =+ match (failed_with_only_retries, total_with_only_retries) {+ (Some(s), Some(t)) if t > 0 => Some(f64::from(s) * 100.0 / f64::from(t)),+ _ => None,+ };(success_rate,success_rate_without_retries,+ success_rate_with_only_retries,failed_rate,failed_rate_without_retries,+ failed_rate_with_only_retries,)}}@@ -393,8 +426,10 @@ impl PaymentMetricsAccumulator {let (payments_success_rate_distribution,payments_success_rate_distribution_without_smart_retries,+ payments_success_rate_distribution_with_only_retries,payments_failure_rate_distribution,payments_failure_rate_distribution_without_smart_retries,+ payments_failure_rate_distribution_with_only_retries,) = self.payments_distribution.collect();let (failure_reason_count, failure_reason_count_without_smart_retries) =self.failure_reasons_distribution.collect();@@ -413,8 +448,10 @@ impl PaymentMetricsAccumulator {connector_success_rate: self.connector_success_rate.collect(),payments_success_rate_distribution,payments_success_rate_distribution_without_smart_retries,+ payments_success_rate_distribution_with_only_retries,payments_failure_rate_distribution,payments_failure_rate_distribution_without_smart_retries,+ payments_failure_rate_distribution_with_only_retries,failure_reason_count,failure_reason_count_without_smart_retries,payment_processed_amount_in_usd,diff --git a/crates/api_models/src/analytics/payments.rs b/crates/api_models/src/analytics/payments.rsindex b34f8c9293..1bade6b5ec 100644--- a/crates/api_models/src/analytics/payments.rs+++ b/crates/api_models/src/analytics/payments.rs@@ -283,8 +283,10 @@ pub struct PaymentMetricsBucketValue {pub connector_success_rate: Option<f64>,pub payments_success_rate_distribution: Option<f64>,pub payments_success_rate_distribution_without_smart_retries: Option<f64>,+ pub payments_success_rate_distribution_with_only_retries: Option<f64>,pub payments_failure_rate_distribution: Option<f64>,pub payments_failure_rate_distribution_without_smart_retries: Option<f64>,+ pub payments_failure_rate_distribution_with_only_retries: Option<f64>,pub failure_reason_count: Option<u64>,pub failure_reason_count_without_smart_retries: Option<u64>,}