diff --git a/src/db/spanner/manager/deadpool.rs b/src/db/spanner/manager/deadpool.rs index ae7a6dc649..8dae9b9201 100644 --- a/src/db/spanner/manager/deadpool.rs +++ b/src/db/spanner/manager/deadpool.rs @@ -25,6 +25,7 @@ pub struct SpannerSessionManager { test_transactions: bool, max_lifespan: Option, max_idle: Option, + emulator_host: Option, } impl fmt::Debug for SpannerSessionManager { @@ -56,6 +57,7 @@ impl SpannerSessionManager { test_transactions, max_lifespan: settings.database_pool_connection_lifespan, max_idle: settings.database_pool_connection_max_idle, + emulator_host: settings.spanner_emulator_host.clone(), }) } } @@ -68,6 +70,7 @@ impl Manager for SpannerSessionManager { self.metrics.clone(), &self.database_name, self.test_transactions, + self.emulator_host.clone(), ) .await?; Ok(session) diff --git a/src/db/spanner/manager/session.rs b/src/db/spanner/manager/session.rs index 0063419666..70ff6f4a12 100644 --- a/src/db/spanner/manager/session.rs +++ b/src/db/spanner/manager/session.rs @@ -37,18 +37,26 @@ pub async fn create_spanner_session( mut metrics: Metrics, database_name: &str, use_test_transactions: bool, + emulator_host: Option, ) -> Result { // XXX: issue732: Could google_default_credentials (or // ChannelBuilder::secure_connect) block?! let chan = block(move || -> Result { metrics.start_timer("storage.pool.grpc_auth", None); - // Requires - // GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json - let creds = ChannelCredentials::google_default_credentials()?; - Ok(ChannelBuilder::new(env) - .max_send_message_len(100 << 20) - .max_receive_message_len(100 << 20) - .secure_connect(SPANNER_ADDRESS, creds)) + if let Some(spanner_emulator_address) = emulator_host { + Ok(ChannelBuilder::new(env) + .max_send_message_len(100 << 20) + .max_receive_message_len(100 << 20) + .connect(&spanner_emulator_address)) + } else { + // Requires + // GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json + let creds = ChannelCredentials::google_default_credentials()?; + Ok(ChannelBuilder::new(env) + .max_send_message_len(100 << 20) + .max_receive_message_len(100 << 20) + .secure_connect(SPANNER_ADDRESS, creds)) + } }) .await .map_err(|e| match e { diff --git a/src/settings.rs b/src/settings.rs index fef7119612..fdda77a590 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -80,6 +80,8 @@ pub struct Settings { pub enable_quota: bool, pub enforce_quota: bool, + + pub spanner_emulator_host: Option, } impl Default for Settings { @@ -109,6 +111,7 @@ impl Default for Settings { human_logs: false, enable_quota: false, enforce_quota: false, + spanner_emulator_host: None, } } }