mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
feat(multitenancy): add tenant_id as a field for data pipeline and support individual database for clickhouse (#4867)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Arun Raj M <jarnura47@gmail.com> Co-authored-by: Sampras Lopes <sampras.lopes@juspay.in>
This commit is contained in:
@ -35,6 +35,7 @@ pub type ClickhouseResult<T> = error_stack::Result<T, ClickhouseError>;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ClickhouseClient {
|
||||
pub config: Arc<ClickhouseConfig>,
|
||||
pub database: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
@ -42,7 +43,6 @@ pub struct ClickhouseConfig {
|
||||
username: String,
|
||||
password: Option<String>,
|
||||
host: String,
|
||||
database_name: String,
|
||||
}
|
||||
|
||||
impl Default for ClickhouseConfig {
|
||||
@ -51,7 +51,6 @@ impl Default for ClickhouseConfig {
|
||||
username: "default".to_string(),
|
||||
password: None,
|
||||
host: "http://localhost:8123".to_string(),
|
||||
database_name: "default".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,7 +62,7 @@ impl ClickhouseClient {
|
||||
let params = CkhQuery {
|
||||
date_time_output_format: String::from("iso"),
|
||||
output_format_json_quote_64bit_integers: 0,
|
||||
database: self.config.database_name.clone(),
|
||||
database: self.database.clone(),
|
||||
};
|
||||
let response = client
|
||||
.post(&self.config.host)
|
||||
|
||||
@ -601,22 +601,30 @@ impl AnalyticsProvider {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn from_conf(config: &AnalyticsConfig, tenant: &str) -> Self {
|
||||
pub async fn from_conf(
|
||||
config: &AnalyticsConfig,
|
||||
tenant: &dyn storage_impl::config::ClickHouseConfig,
|
||||
) -> Self {
|
||||
match config {
|
||||
AnalyticsConfig::Sqlx { sqlx } => Self::Sqlx(SqlxClient::from_conf(sqlx, tenant).await),
|
||||
AnalyticsConfig::Sqlx { sqlx } => {
|
||||
Self::Sqlx(SqlxClient::from_conf(sqlx, tenant.get_schema()).await)
|
||||
}
|
||||
AnalyticsConfig::Clickhouse { clickhouse } => Self::Clickhouse(ClickhouseClient {
|
||||
config: Arc::new(clickhouse.clone()),
|
||||
database: tenant.get_clickhouse_database().to_string(),
|
||||
}),
|
||||
AnalyticsConfig::CombinedCkh { sqlx, clickhouse } => Self::CombinedCkh(
|
||||
SqlxClient::from_conf(sqlx, tenant).await,
|
||||
SqlxClient::from_conf(sqlx, tenant.get_schema()).await,
|
||||
ClickhouseClient {
|
||||
config: Arc::new(clickhouse.clone()),
|
||||
database: tenant.get_clickhouse_database().to_string(),
|
||||
},
|
||||
),
|
||||
AnalyticsConfig::CombinedSqlx { sqlx, clickhouse } => Self::CombinedSqlx(
|
||||
SqlxClient::from_conf(sqlx, tenant).await,
|
||||
SqlxClient::from_conf(sqlx, tenant.get_schema()).await,
|
||||
ClickhouseClient {
|
||||
config: Arc::new(clickhouse.clone()),
|
||||
database: tenant.get_clickhouse_database().to_string(),
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user