Skip to content

Commit 0429a49

Browse files
committed
feat(base-driver): add an option to skip connection test probes
feat(bigquery-driver): add an option to skip connection test probes feat(aurora-serverless-driver): add an option to skip connection test probes feat(postgres-driver): add an option to skip connection test probes
1 parent 9346f21 commit 0429a49

File tree

5 files changed

+58
-20
lines changed

5 files changed

+58
-20
lines changed

packages/cubejs-backend-shared/src/env.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,17 @@ const variables: Record<string, (...args: any) => any> = {
479479
return val;
480480
},
481481

482+
/**
483+
* Flag to disable driver's test connection probes
484+
*/
485+
dbDisableTestConnection: ({
486+
dataSource
487+
}: {
488+
dataSource: string,
489+
}) => (
490+
!!process.env[keyByDataSource('CUBEJS_DB_DISABLE_TEST_CONNECTION', dataSource)]
491+
),
492+
482493
/**
483494
* Database max pool size.
484495
*/
@@ -500,7 +511,7 @@ const variables: Record<string, (...args: any) => any> = {
500511
),
501512

502513
/**
503-
* Max polling interval. Currenly used in BigQuery and Databricks.
514+
* Max polling interval. Currently used in BigQuery and Databricks.
504515
* TODO: clarify this env.
505516
*/
506517
dbPollMaxInterval: ({
@@ -514,7 +525,7 @@ const variables: Record<string, (...args: any) => any> = {
514525
},
515526

516527
/**
517-
* Polling timeout. Currenly used in BigQuery, Dremio and Athena.
528+
* Polling timeout. Currently used in BigQuery, Dremio and Athena.
518529
* TODO: clarify this env.
519530
*/
520531
dbPollTimeout: ({
@@ -532,7 +543,7 @@ const variables: Record<string, (...args: any) => any> = {
532543
},
533544

534545
/**
535-
* Query timeout. Currenly used in BigQuery, Dremio, Postgres, Snowflake
546+
* Query timeout. Currently used in BigQuery, Dremio, Postgres, Snowflake
536547
* and Athena drivers and the orchestrator (queues, pre-aggs). For the
537548
* orchestrator this variable did not split by the datasource.
538549
*

packages/cubejs-base-driver/src/BaseDriver.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ const DbTypeValueMatcher: Record<string, ((v: any) => boolean)> = {
171171
* Base driver class.
172172
*/
173173
export abstract class BaseDriver implements DriverInterface {
174-
private testConnectionTimeoutValue = 10000;
174+
private readonly testConnectionTimeoutValue: number = 10000;
175175

176176
protected logger: any;
177177

178+
protected isTestConnectionDisabledFlag: boolean = false;
179+
178180
/**
179181
* Class constructor.
180182
*/
@@ -184,8 +186,14 @@ export abstract class BaseDriver implements DriverInterface {
184186
* request before determining it as not valid. Default - 10000 ms.
185187
*/
186188
testConnectionTimeout?: number,
189+
190+
/**
191+
* Flag for serverless DWHs to omit test connection probes.
192+
*/
193+
isTestConnectionDisabled?: boolean,
187194
} = {}) {
188195
this.testConnectionTimeoutValue = _options.testConnectionTimeout || 10000;
196+
this.isTestConnectionDisabledFlag = _options.isTestConnectionDisabled || false;
189197
}
190198

191199
protected informationSchemaQuery() {
@@ -680,6 +688,10 @@ export abstract class BaseDriver implements DriverInterface {
680688
query.query = `SELECT * FROM (${query.query}) AS t LIMIT ${query.limit}`;
681689
}
682690

691+
public isTestConnectionDisabled(): boolean {
692+
return !!this.isTestConnectionDisabledFlag;
693+
}
694+
683695
/**
684696
* Returns an array of signed AWS S3 URLs of the unloaded csv files.
685697
*/

packages/cubejs-bigquery-driver/src/BigQueryDriver.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ export class BigQueryDriver extends BaseDriver implements DriverInterface {
9393
testConnectionTimeout?: number,
9494
} = {}
9595
) {
96-
super({
97-
testConnectionTimeout: config.testConnectionTimeout,
98-
});
99-
10096
const dataSource =
10197
config.dataSource ||
10298
assertDataSource('default');
10399

100+
super({
101+
testConnectionTimeout: config.testConnectionTimeout,
102+
isTestConnectionDisabled: getEnv('dbDisableTestConnection', { dataSource }),
103+
});
104+
104105
this.options = {
105106
scopes: [
106107
'https://www.googleapis.com/auth/bigquery',
@@ -155,6 +156,10 @@ export class BigQueryDriver extends BaseDriver implements DriverInterface {
155156
}
156157

157158
public async testConnection() {
159+
if (this.isTestConnectionDisabled()) {
160+
return;
161+
}
162+
158163
await this.bigquery.query({
159164
query: 'SELECT ? AS number',
160165
params: ['1'],

packages/cubejs-mysql-aurora-serverless-driver/driver/AuroraServerlessMySqlDriver.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ class AuroraServerlessMySqlDriver extends BaseDriver {
3333
* Class constructor.
3434
*/
3535
constructor(config = {}) {
36-
super({
37-
testConnectionTimeout: config.testConnectionTimeout,
38-
});
39-
4036
const dataSource =
4137
config.dataSource ||
4238
assertDataSource('default');
43-
39+
40+
super({
41+
testConnectionTimeout: config.testConnectionTimeout,
42+
isTestConnectionDisabled: getEnv('dbDisableTestConnection', { dataSource }),
43+
});
44+
4445
this.config = {
4546
secretArn:
4647
config.secretArn ||
@@ -66,7 +67,11 @@ class AuroraServerlessMySqlDriver extends BaseDriver {
6667
}
6768

6869
async testConnection() {
69-
return this.dataApi.query('SELECT 1');
70+
if (this.isTestConnectionDisabled()) {
71+
return;
72+
}
73+
74+
await this.dataApi.query('SELECT 1');
7075
}
7176

7277
positionBindings(sql) {

packages/cubejs-postgres-driver/src/PostgresDriver.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
111111
testConnectionTimeout?: number,
112112
} = {}
113113
) {
114+
const dataSource =
115+
config.dataSource ||
116+
assertDataSource('default');
117+
114118
super({
115119
testConnectionTimeout: config.testConnectionTimeout,
120+
isTestConnectionDisabled: getEnv('dbDisableTestConnection', { dataSource }),
116121
});
117122

118-
const dataSource =
119-
config.dataSource ||
120-
assertDataSource('default');
121-
122123
this.pool = new Pool({
123124
idleTimeoutMillis: 30000,
124125
max:
@@ -146,9 +147,9 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
146147
}
147148

148149
protected primaryKeysQuery(conditionString?: string): string | null {
149-
return `SELECT
150+
return `SELECT
150151
columns.table_schema as ${this.quoteIdentifier('table_schema')},
151-
columns.table_name as ${this.quoteIdentifier('table_name')},
152+
columns.table_name as ${this.quoteIdentifier('table_name')},
152153
columns.column_name as ${this.quoteIdentifier('column_name')}
153154
FROM information_schema.table_constraints tc
154155
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
@@ -225,6 +226,10 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
225226
}
226227

227228
public async testConnection(): Promise<void> {
229+
if (this.isTestConnectionDisabled()) {
230+
return;
231+
}
232+
228233
try {
229234
await this.pool.query('SELECT $1::int AS number', ['1']);
230235
} catch (e) {

0 commit comments

Comments
 (0)