Skip to content

Commit edaf326

Browse files
authored
fix(mongobi-driver): Invalid configuration for mysql2 connection (#6352) Thanks @loremaps!
* fix(mongobi-driver): invalid configuration for mysql2 connection Stop passing invalid configuration for mysql2 connection Closes #5527 * test(mongobi-driver): add smoke test * test(mongobi-driver): add to the integration matrix
1 parent 2384564 commit edaf326

File tree

11 files changed

+175
-6
lines changed

11 files changed

+175
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# Debug log for test containers
5+
export DEBUG=testcontainers
6+
7+
export TEST_MONGO_TAG=6.0
8+
export TEST_MONGOBI_VERSION=mongodb-bi-linux-x86_64-ubuntu2004-v2.14.8
9+
10+
echo "::group::MongoBI"
11+
yarn lerna run --concurrency 1 --stream --no-prefix integration:mongobi
12+
echo "::endgroup::"

.github/actions/smoke.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ echo "::endgroup::"
5252
echo "::group::MS SQL"
5353
yarn lerna run --concurrency 1 --stream --no-prefix smoke:mssql
5454
echo "::endgroup::"
55+
56+
echo "::group::MongoBI"
57+
yarn lerna run --concurrency 1 --stream --no-prefix smoke:mongobi
58+
echo "::endgroup::"

.github/workflows/push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ jobs:
383383
node-version: [16.x]
384384
db: [
385385
'clickhouse', 'druid', 'elasticsearch', 'mssql', 'mysql', 'postgres', 'prestodb',
386-
'mysql-aurora-serverless', 'crate'
386+
'mysql-aurora-serverless', 'crate', 'mongobi'
387387
]
388388
fail-fast: false
389389

packages/cubejs-mongobi-driver/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"tsc": "tsc",
2323
"watch": "tsc -w",
2424
"lint": "eslint src/* --ext .ts",
25-
"lint:fix": "eslint --fix src/* --ext .ts"
25+
"lint:fix": "eslint --fix src/* --ext .ts",
26+
"integration": "jest dist/test",
27+
"integration:mongobi": "jest dist/test"
2628
},
2729
"dependencies": {
2830
"@cubejs-backend/base-driver": "^0.33.43",
@@ -39,6 +41,7 @@
3941
"devDependencies": {
4042
"@cubejs-backend/linter": "^0.33.0",
4143
"@types/generic-pool": "^3.1.9",
44+
"testcontainers": "^9.8.0",
4245
"typescript": "~4.9.5"
4346
},
4447
"eslintConfig": {

packages/cubejs-mongobi-driver/src/MongoBIDriver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export class MongoBIDriver extends BaseDriver implements DriverInterface {
6565
testConnectionTimeout: config.testConnectionTimeout,
6666
});
6767

68-
const dataSource =
69-
config.dataSource ||
70-
assertDataSource('default');
68+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
69+
const { dataSource: configDataSource, maxPoolSize, testConnectionTimeout, ...mongoBIDriverConfiguration } = config;
70+
const dataSource = configDataSource || assertDataSource('default');
7171

7272
this.config = {
7373
host: getEnv('dbHost', { dataSource }),
@@ -97,7 +97,7 @@ export class MongoBIDriver extends BaseDriver implements DriverInterface {
9797

9898
return next();
9999
},
100-
...config
100+
...mongoBIDriverConfiguration
101101
};
102102
this.pool = genericPool.createPool({
103103
create: async () => {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:20.04
2+
WORKDIR /home/mongobi
3+
4+
ARG MONGOBI=mongodb-bi-linux-x86_64-ubuntu2004-v2.14.3
5+
6+
RUN apt update \
7+
&& apt install -y libssl-dev libgssapi-krb5-2 wget \
8+
&& wget -qO- https://info-mongodb-com.s3.amazonaws.com/mongodb-bi/v2/${MONGOBI}.tgz | tar -xvz -C /home/mongobi \
9+
&& install -m755 ${MONGOBI}/bin/mongo* /usr/local/bin/ \
10+
&& mkdir /logs
11+
12+
COPY config.yaml config.yaml
13+
14+
EXPOSE 3307
15+
CMD ["mongosqld", "--config=config.yaml"]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import { Wait, DockerComposeEnvironment, StartedDockerComposeEnvironment } from 'testcontainers';
3+
import { MongoBIDriver, } from '../src';
4+
5+
describe('MongoBiDriver', () => {
6+
let driver: MongoBIDriver;
7+
let environment: StartedDockerComposeEnvironment;
8+
9+
jest.setTimeout(2 * 60 * 1000);
10+
11+
beforeAll(async () => {
12+
const MONGO_TAG = process.env.TEST_MONGO_TAG || '6.0';
13+
const MONGOBI_VERSION = process.env.TEST_MONGOBI_VERSION || 'mongodb-bi-linux-x86_64-ubuntu2004-v2.14.8';
14+
15+
environment = await new DockerComposeEnvironment('./test', 'docker-compose.yml')
16+
.withEnvironment({ MONGO_TAG, MONGOBI_VERSION })
17+
.withWaitStrategy('mongosqld', Wait.forLogMessage('obtained initial schema'))
18+
.up();
19+
20+
const container = environment.getContainer('mongosqld');
21+
22+
driver = new MongoBIDriver({
23+
host: container.getHost(),
24+
port: container.getMappedPort(3307),
25+
waitForConnections: true,
26+
database: 'test',
27+
dataSource: 'default',
28+
maxPoolSize: 1,
29+
testConnectionTimeout: 10,
30+
});
31+
});
32+
33+
afterAll(async () => {
34+
await driver.release();
35+
await environment.down();
36+
});
37+
38+
test('should test connection', async () => {
39+
await driver.testConnection();
40+
});
41+
42+
test('should select raw sql', async () => {
43+
const result = await driver.query(`
44+
SELECT number
45+
FROM mycol
46+
LIMIT 1
47+
`, []);
48+
expect(result).toEqual([{ number: 1 }]);
49+
});
50+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
net:
2+
bindIp: '0.0.0.0' # To bind to multiple IP addresses
3+
port: 3307
4+
ssl:
5+
mode: 'disabled'
6+
7+
mongodb:
8+
net:
9+
uri: 'mongodb://mongo:27017'
10+
ssl:
11+
enabled: false
12+
13+
systemLog:
14+
quiet: false
15+
verbosity: 1
16+
logRotate: 'rename' # "rename"|"reopen"
17+
18+
schema:
19+
refreshIntervalSecs: 60
20+
stored:
21+
mode: 'auto' # "auto"|"custom"
22+
source: 'mongosqld_data' # the database where schemas are stored in stored-schema modes
23+
name: 'mySchema' # the named schema to read/write to in stored-schema modes
24+
sample:
25+
size: 1000 # The amount of random documents we sample from each collection.
26+
namespaces: ['*.*']
27+
28+
processManagement:
29+
service:
30+
name: 'mongosql'
31+
displayName: 'MongoSQL Service'
32+
description: 'MongoSQL accesses MongoDB data with SQL'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
3+
services:
4+
mongo:
5+
image: mongo:${MONGO_TAG}
6+
ports:
7+
- 27017:27017
8+
volumes:
9+
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
10+
11+
mongosqld:
12+
container_name: mongosqld
13+
build:
14+
context: ./
15+
args:
16+
MONGOBI: ${MONGOBI_VERSION}
17+
ports:
18+
- 3307:3307
19+
depends_on:
20+
- mongo
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
db = db.getSiblingDB('test');
2+
3+
db.createCollection('mycol');
4+
5+
db.mycol.insertMany([{ number: 1 }]);

0 commit comments

Comments
 (0)