Skip to content

Commit 33c6292

Browse files
authored
feat: Introduce single unified CUBEJS_DB_QUERY_TIMEOUT env variable to set all various variables that control database query timeouts (cube-js#3864)
* feat: Introduce single unified CUBEJS_DB_QUERY_TIMEOUT env variable to control all various variables that control database query timeouts * chore: Introduce single unified CUBEJS_DB_QUERY_TIMEOUT env variable to control all various variables that control database query timeouts -- test fixes
1 parent a52be2f commit 33c6292

File tree

11 files changed

+25
-13
lines changed

11 files changed

+25
-13
lines changed

packages/cubejs-athena-driver/driver/AthenaDriver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AthenaDriver extends BaseDriver {
1818
S3OutputLocation: process.env.CUBEJS_AWS_S3_OUTPUT_LOCATION,
1919
workGroup: process.env.CUBEJS_AWS_ATHENA_WORKGROUP || 'primary',
2020
...config,
21-
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout')) * 1000,
21+
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout') || getEnv('dbQueryTimeout')) * 1000,
2222
pollMaxInterval: (config.pollMaxInterval || getEnv('dbPollMaxInterval')) * 1000,
2323
};
2424

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class InvalidConfiguration extends Error {
1111
export function convertTimeStrToMs(
1212
input: string,
1313
envName: string,
14-
description: string = 'Must be number (in seconds) or string in time format (1s, 1m, 1h).',
14+
description: string = 'Must be a number in seconds or duration string (1s, 1m, 1h).',
1515
) {
1616
if (/^\d+$/.test(input)) {
1717
return parseInt(input, 10);
@@ -126,8 +126,16 @@ const variables: Record<string, (...args: any) => any> = {
126126
preAggregationsSchema: () => get('CUBEJS_PRE_AGGREGATIONS_SCHEMA')
127127
.asString(),
128128
dbPollTimeout: () => {
129-
const value = process.env.CUBEJS_DB_POLL_TIMEOUT || '15m';
130-
return convertTimeStrToMs(value, 'CUBEJS_DB_POLL_TIMEOUT');
129+
const value = process.env.CUBEJS_DB_POLL_TIMEOUT;
130+
if (value) {
131+
return convertTimeStrToMs(value, 'CUBEJS_DB_POLL_TIMEOUT');
132+
} else {
133+
return null;
134+
}
135+
},
136+
dbQueryTimeout: () => {
137+
const value = process.env.CUBEJS_DB_QUERY_TIMEOUT || '10m';
138+
return convertTimeStrToMs(value, 'CUBEJS_DB_QUERY_TIMEOUT');
131139
},
132140
dbPollMaxInterval: () => {
133141
const value = process.env.CUBEJS_DB_POLL_MAX_INTERVAL || '5s';

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test('convertTimeStrToMs', () => {
1212

1313
test('convertTimeStrToMs(exception)', () => {
1414
expect(() => convertTimeStrToMs('', 'VARIABLE_ENV')).toThrowError(
15-
`Value "" is not valid for VARIABLE_ENV. Must be number (in seconds) or string in time format (1s, 1m, 1h).`
15+
`Value "" is not valid for VARIABLE_ENV. Must be a number in seconds or duration string (1s, 1m, 1h).`
1616
);
1717
});
1818

@@ -68,8 +68,6 @@ describe('getEnv', () => {
6868
});
6969

7070
test('dbPollTimeout', () => {
71-
expect(getEnv('dbPollTimeout')).toBe(15 * 60);
72-
7371
process.env.CUBEJS_DB_POLL_TIMEOUT = '1m';
7472
expect(getEnv('dbPollTimeout')).toBe(60);
7573
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class BigQueryDriver extends BaseDriver implements DriverInterface {
4545
exportBucket: getEnv('dbExportBucket') || process.env.CUBEJS_DB_BQ_EXPORT_BUCKET,
4646
location: getEnv('bigQueryLocation'),
4747
...config,
48-
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout')) * 1000,
48+
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout') || getEnv('dbQueryTimeout')) * 1000,
4949
pollMaxInterval: (config.pollMaxInterval || getEnv('dbPollMaxInterval')) * 1000,
5050
};
5151

packages/cubejs-dremio-driver/driver/DremioDriver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DremioDriver extends BaseDriver {
2727
database: config.database || process.env.CUBEJS_DB_NAME,
2828
ssl: config.ssl || process.env.CUBEJS_DB_SSL,
2929
...config,
30-
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout')) * 1000,
30+
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout') || getEnv('dbQueryTimeout')) * 1000,
3131
pollMaxInterval: (config.pollMaxInterval || getEnv('dbPollMaxInterval')) * 1000,
3232
};
3333

packages/cubejs-postgres-driver/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
},
2929
"dependencies": {
3030
"@cubejs-backend/query-orchestrator": "^0.29.12",
31+
"@cubejs-backend/shared": "^0.29.12",
3132
"@types/pg": "^8.6.0",
3233
"@types/pg-query-stream": "^1.0.3",
3334
"moment": "^2.24.0",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { types, Pool, PoolConfig, PoolClient, FieldDef } from 'pg';
22
// eslint-disable-next-line import/no-extraneous-dependencies
33
import { TypeId, TypeFormat } from 'pg-types';
4+
import { getEnv } from '@cubejs-backend/shared';
45
import * as moment from 'moment';
56
import {
67
BaseDriver,
@@ -80,6 +81,7 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
8081

8182
this.config = {
8283
...this.getInitialConfiguration(),
84+
executionTimeout: getEnv('dbQueryTimeout'),
8385
...config,
8486
};
8587
}

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ export class PreAggregations {
13641364

13651365
this.externalDriverFactory = options.externalDriverFactory;
13661366
this.structureVersionPersistTime = options.structureVersionPersistTime || 60 * 60 * 24 * 30;
1367-
this.usedTablePersistTime = options.usedTablePersistTime || 600;
1367+
this.usedTablePersistTime = options.usedTablePersistTime || getEnv('dbQueryTimeout');
13681368
this.externalRefresh = options.externalRefresh;
13691369
this.getQueueEventsBus = options.getQueueEventsBus;
13701370
}

packages/cubejs-query-orchestrator/src/orchestrator/QueryQueue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import R from 'ramda';
2+
import { getEnv } from '@cubejs-backend/shared';
23

34
import { TimeoutError } from './TimeoutError';
45
import { ContinueWaitError } from './ContinueWaitError';
@@ -10,7 +11,7 @@ export class QueryQueue {
1011
this.redisQueuePrefix = redisQueuePrefix;
1112
this.concurrency = options.concurrency || 2;
1213
this.continueWaitTimeout = options.continueWaitTimeout || 5;
13-
this.executionTimeout = options.executionTimeout || 600;
14+
this.executionTimeout = options.executionTimeout || getEnv('dbQueryTimeout');
1415
this.orphanedTimeout = options.orphanedTimeout || 120;
1516
this.heartBeatInterval = options.heartBeatInterval || 30;
1617
this.sendProcessMessageFn = options.sendProcessMessageFn || ((queryKey) => { this.processQuery(queryKey); });

packages/cubejs-redshift-driver/src/RedshiftDriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
100100
.join(' ');
101101

102102
await this.prepareConnection(conn, {
103-
executionTimeout: 600000,
103+
executionTimeout: this.config.executionTimeout ? this.config.executionTimeout * 1000 : 600000,
104104
});
105105

106106
let unloadTotalRows: number | null = null;

0 commit comments

Comments
 (0)