Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): add smart_retries only metrics #6575

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions crates/analytics/src/payments/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
}
Expand All @@ -201,28 +213,35 @@ 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;
}
}
}
if let Some(total) = metrics.count.and_then(|total| u32::try_from(total).ok()) {
self.total += total;
if metrics.first_attempt.unwrap_or(false) {
self.total_without_retries += total;
} else {
self.total_with_only_retries += total;
}
}
}
}

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)),
Expand All @@ -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,
Expand All @@ -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,
)
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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_usd,
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/analytics/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}
Expand Down
Loading