Skip to content

Commit

Permalink
feat(analytics): Add card network filter (#6087)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
lsampras and hyperswitch-bot[bot] authored Sep 26, 2024
1 parent 809c92b commit 8049993
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crates/analytics/src/opensearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ impl HealthCheck for OpenSearchClient {
if health.status != OpenSearchHealthStatus::Red {
Ok(())
} else {
Err(QueryExecutionError::DatabaseError.into())
Err::<(), error_stack::Report<QueryExecutionError>>(
QueryExecutionError::DatabaseError.into(),
)
.attach_printable_lazy(|| format!("Opensearch cluster health is red: {health:?}"))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/analytics/src/payments/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub async fn get_filters(
PaymentDimensions::ClientSource => fil.client_source,
PaymentDimensions::ClientVersion => fil.client_version,
PaymentDimensions::ProfileId => fil.profile_id,
PaymentDimensions::CardNetwork => fil.card_network,
})
.collect::<Vec<String>>();
res.query_data.push(FilterValue {
Expand Down
1 change: 1 addition & 0 deletions crates/analytics/src/payments/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ pub struct PaymentFilterRow {
pub client_source: Option<String>,
pub client_version: Option<String>,
pub profile_id: Option<String>,
pub card_network: Option<String>,
}
19 changes: 19 additions & 0 deletions crates/analytics/src/payments/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ where
.add_filter_in_range_clause(PaymentDimensions::ProfileId, &self.profile_id)
.attach_printable("Error adding profile id filter")?;
}
if !self.card_network.is_empty() {
let card_networks: Vec<String> = self
.card_network
.iter()
.flat_map(|cn| {
[
format!("\"{cn}\""),
cn.to_string(),
format!("\"{cn}\"").to_uppercase(),
]
})
.collect();
builder
.add_filter_in_range_clause(
PaymentDimensions::CardNetwork,
card_networks.as_slice(),
)
.attach_printable("Error adding card network filter")?;
}
Ok(())
}
}
5 changes: 5 additions & 0 deletions crates/analytics/src/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
let card_network: Option<String> = row.try_get("card_network").or_else(|e| match e {
ColumnNotFound(_) => Ok(Default::default()),
e => Err(e),
})?;
Ok(Self {
currency,
status,
Expand All @@ -499,6 +503,7 @@ impl<'a> FromRow<'a, PgRow> for super::payments::filters::PaymentFilterRow {
client_source,
client_version,
profile_id,
card_network,
})
}
}
Expand Down
6 changes: 5 additions & 1 deletion crates/api_models/src/analytics/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use common_utils::id_type;

use super::{NameDescription, TimeRange};
use crate::enums::{
AttemptStatus, AuthenticationType, Connector, Currency, PaymentMethod, PaymentMethodType,
AttemptStatus, AuthenticationType, CardNetwork, Connector, Currency, PaymentMethod,
PaymentMethodType,
};

#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
Expand All @@ -29,6 +30,8 @@ pub struct PaymentFilters {
#[serde(default)]
pub client_version: Vec<String>,
#[serde(default)]
pub card_network: Vec<CardNetwork>,
#[serde(default)]
pub profile_id: Vec<id_type::ProfileId>,
}

Expand Down Expand Up @@ -64,6 +67,7 @@ pub enum PaymentDimensions {
ClientSource,
ClientVersion,
ProfileId,
CardNetwork,
}

#[derive(
Expand Down

0 comments on commit 8049993

Please sign in to comment.