Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/bb 632 bump mongo db driver 6 #2599

Draft
wants to merge 11 commits into
base: development/9.0
Choose a base branch
from
15 changes: 15 additions & 0 deletions .github/actions/debug-wait/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: "Debug wait"
description: "If debugging is enabled, wait"

runs:
using: composite
steps:
- name: "Debug: SSH to runner"
uses: scality/actions/[email protected]
continue-on-error: true
with:
tmate-server-host: ${{ env.TMATE_SERVER_HOST }}
tmate-server-port: ${{ env.TMATE_SERVER_PORT }}
tmate-server-rsa-fingerprint: ${{ env.TMATE_SERVER_RSA_FINGERPRINT }}
tmate-server-ed25519-fingerprint: ${{ env.TMATE_SERVER_ED25519_FINGERPRINT }}
11 changes: 11 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: tests

env:
GINKGO_VERSION: v1.15.2
# DEBUG WAIT
TMATE_SERVER_HOST: ${{ secrets.TMATE_SERVER_HOST }}
TMATE_SERVER_PORT: ${{ secrets.TMATE_SERVER_PORT }}
TMATE_SERVER_RSA_FINGERPRINT: ${{ secrets.TMATE_SERVER_RSA_FINGERPRINT }}
TMATE_SERVER_ED25519_FINGERPRINT: ${{ secrets.TMATE_SERVER_ED25519_FINGERPRINT }}

on:
push:
Expand Down Expand Up @@ -192,3 +197,9 @@ jobs:
# will crash if they end up in memory all at the same time (circuit breaking
# ineffective) while waiting to be committed to the kafka topic.
NODE_OPTIONS: '--max-old-space-size=150'

- name: Debug wait
uses: ./.github/actions/debug-wait
timeout-minutes: 60
if: failure() && runner.debug == '1'

21 changes: 11 additions & 10 deletions extensions/notification/configManager/MongoConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,13 @@ class MongoConfigManager extends BaseConfigManager {
*/
_setupMongoClient(cb) {
const mongoUrl = constructConnectionString(this._mongoConfig);
MongoClient.connect(mongoUrl, {
const client = new MongoClient(mongoUrl, {
replicaSet: this._mongoConfig.replicaSet,
useNewUrlParser: true,
},
(err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
method: 'MongoConfigManager._setupMongoClient',
error: err.message,
});
return cb(err);
}
readPreference: this._mongoConfig.readPreference,
});

return client.connect().then(client => {
this._logger.debug('Connected to MongoDB', {
method: 'MongoConfigManager._setupMongoClient',
});
Expand All @@ -133,6 +128,12 @@ class MongoConfigManager extends BaseConfigManager {
} catch (error) {
return cb(error);
}
}).catch(err => {
this._logger.error('Could not connect to MongoDB', {
method: 'MongoConfigManager._setupMongoClient',
error: err.message,
});
return cb(err);
});
}

Expand Down
4 changes: 3 additions & 1 deletion extensions/oplogPopulator/OplogPopulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ class OplogPopulator {
*/
async _setupMongoClient() {
try {
const client = await MongoClient.connect(this._mongoUrl, {
let client = new MongoClient(this._mongoUrl, {
replicaSet: this._replicaSet,
useNewUrlParser: true,
useUnifiedTopology: true,
readPreference: this._mongoConfig.readPreference,
});
client = await client.connect();
// connect to metadata DB
this._mongoClient = client.db(this._database, {
ignoreUndefined: true,
Expand Down
2 changes: 1 addition & 1 deletion extensions/replication/tasks/ReplicateObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class ReplicateObject extends BackbeatTask {
};
return this.backbeatSource.getMetadata(params, (err, blob) => {
if (err) {
err.origin = 'source';
err.origin = 'source'; // eslint-disable-line no-param-reassign
log.error('error getting metadata blob from S3', {
method: 'ReplicateObject._refreshSourceEntry',
error: err,
Expand Down
47 changes: 24 additions & 23 deletions extensions/utils/LocationStatusStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,12 @@
*/
_setupMongoClient(cb) {
const mongoUrl = constructConnectionString(this._mongoConfig);
MongoClient.connect(mongoUrl, {
const client = new MongoClient(mongoUrl, {
replicaSet: this._mongoConfig.replicaSet,
useNewUrlParser: true,
useUnifiedTopology: true,
}, (err, client) => {
if (err) {
this._log.error('Could not connect to MongoDB', {
method: 'ServiceStatusManager._setupMongoClient',
error: err.message,
});
return cb(err);
}
});
return client.connect().then(client => {
// connect to metadata DB
this._mongoClient = client.db(this._mongoConfig.database, {
ignoreUndefined: true,
Expand All @@ -96,6 +90,12 @@
return cb();
});
return undefined;
}).catch(err => {
this._log.error('Could not connect to MongoDB', {

Check warning on line 94 in extensions/utils/LocationStatusStream.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/utils/LocationStatusStream.js#L94

Added line #L94 was not covered by tests
method: 'ServiceStatusManager._setupMongoClient',
error: err.message,
});
return cb(err);

Check warning on line 98 in extensions/utils/LocationStatusStream.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/utils/LocationStatusStream.js#L98

Added line #L98 was not covered by tests
});
}

Expand All @@ -106,22 +106,23 @@
*/
_initializeLocationStatuses(cb) {
this._locationStatusColl.find({})
.toArray((err, locations) => {
if (err) {
this._log.error('Could not fetch location statuses from mongo', {
method: 'ServiceStatusManager._initializeLocationStatuses',
error: err.message,
});
return cb(err);
.toArray()
.then(locations => {
locations.forEach(location => {
const isPaused = location.value[this._serviceName].paused;
if (isPaused) {
this._pauseServiceForLocation(location._id);
}
locations.forEach(location => {
const isPaused = location.value[this._serviceName].paused;
if (isPaused) {
this._pauseServiceForLocation(location._id);
}
});
return cb();
});
return cb();
})
.catch(err => {
this._log.error('Could not fetch location statuses from mongo', {
method: 'ServiceStatusManager._initializeLocationStatuses',
error: err.message,
});
return cb(err);
});
}

/**
Expand Down
21 changes: 10 additions & 11 deletions lib/api/BackbeatAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -1335,21 +1335,14 @@ class BackbeatAPI {
});
return cb();
} else {
// To be removed once the mongodb drivers are bumped
// BB-585
const mongoUrl = constructConnectionString(mongoConfig);
return MongoClient.connect(mongoUrl, {
const client = new MongoClient(mongoUrl, {
replicaSet: mongoConfig.replicaSet,
useNewUrlParser: true,
useUnifiedTopology: true,
}, (err, client) => {
if (err) {
this._logger.error('Could not connect to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
error: err.message,
});
return cb(err);
}
});

return client.connect().then(client => {
// connect to metadata DB
this._mongoClient = client.db(mongoConfig.database, {
ignoreUndefined: true,
Expand All @@ -1358,6 +1351,12 @@ class BackbeatAPI {
method: 'BackbeatAPI._setupMongoClient',
});
return cb();
}).catch(err => {
this._logger.error('Could not connect to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
error: err.message,
});
return cb(err);
});
}
}
Expand Down
62 changes: 33 additions & 29 deletions lib/util/LocationStatusManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,23 @@
* @return {undefined}
*/
_initCollection(cb) {
this._mongoClient.createCollection(locationStatusCollection, err => {
// in case the collection already exists, we ignore the error
if (err && err.codeName !== 'NamespaceExists') {
this._logger.error('Could not create mongo collection', {
method: 'LocationStatusManager._initCollection',
collection: locationStatusCollection,
error: err.message,
});
return cb(err);
}
this._locationStatusColl = this._mongoClient.collection(locationStatusCollection);
return cb();
});
return this._mongoClient.createCollection(locationStatusCollection)
.then(() => {
this._locationStatusColl = this._mongoClient.collection(locationStatusCollection);
return cb();
})
.catch(err => {
if (err.codeName !== 'NamespaceExists') {
this._logger.error('Could not create mongo collection', {

Check warning on line 78 in lib/util/LocationStatusManager.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

lib/util/LocationStatusManager.js#L78

Added line #L78 was not covered by tests
method: 'LocationStatusManager._initCollection',
collection: locationStatusCollection,
error: err.message,
});
return cb(err);

Check warning on line 83 in lib/util/LocationStatusManager.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

lib/util/LocationStatusManager.js#L83

Added line #L83 was not covered by tests
}
this._locationStatusColl = this._mongoClient.collection(locationStatusCollection);
return cb();
});
}

/**
Expand All @@ -89,16 +93,17 @@
* @returns {undefined}}
*/
_listCollectionDocuments(cb) {
this._locationStatusColl.find({}, (err, cursor) => {
if (err) {
this._locationStatusColl.find({})
.toArray()
.then(docs => cb(null, docs))
.catch(err => {
this._logger.error('Could not list documents', {
method: 'LocationStatusManager._listCollectionDocuments',
collection: locationStatusCollection,
error: err.message,
});
}
return cursor.toArray(cb);
});
cb(err);

Check warning on line 105 in lib/util/LocationStatusManager.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

lib/util/LocationStatusManager.js#L105

Added line #L105 was not covered by tests
});
}

/**
Expand Down Expand Up @@ -139,15 +144,14 @@
_id: {
$in: invalidLocations
}
}, err => {
if (err) {
this._logger.error('Could not delete invalid locations', {
method: 'LocationStatusManager._deleteInvalidLocations',
error: err.message,
});
return cb(err);
}
return cb(null, locations);
})
.then(() => cb(null, locations))
.catch(err => {
this._logger.error('Could not delete invalid locations', {

Check warning on line 150 in lib/util/LocationStatusManager.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

lib/util/LocationStatusManager.js#L150

Added line #L150 was not covered by tests
method: 'LocationStatusManager._deleteInvalidLocations',
error: err.message,
});
cb(err);

Check warning on line 154 in lib/util/LocationStatusManager.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

lib/util/LocationStatusManager.js#L154

Added line #L154 was not covered by tests
});
}

Expand All @@ -166,10 +170,10 @@
async.eachLimit(newLocations, 10, (location, next) => {
const locationConfig = new LocationStatus(this._supportedServices);
this._locationStatusStore[location] = locationConfig;
this._locationStatusColl.insert({
this._locationStatusColl.insertOne({
_id: location,
value: locationConfig.getValue(),
}, next);
}).finally(next);
}, err => {
if (err) {
this._logger.error('Could not add new locations', {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"oplog_populator": "node extensions/oplogPopulator/OplogPopulatorTask.js",
"mongo_queue_processor": "node extensions/mongoProcessor/mongoProcessorTask.js",
"garbage_collector": "node extensions/gc/service.js",
"test": "mocha --recursive tests/unit/oplogPopulator --timeout 30000",
"test": "mocha --recursive tests/unit --timeout 30000",
"cover:test": "nyc --clean --silent yarn run test && nyc report --report-dir ./coverage/test --reporter=lcov",
"ft_test": "mocha --recursive $(find tests/functional -name '*.js') --timeout 30000",
"ft_test:notification": "mocha --recursive $(find tests/functional/notification -name '*.js') --timeout 30000",
Expand Down Expand Up @@ -59,7 +59,7 @@
"ioredis": "^4.9.5",
"joi": "^17.6.0",
"minimatch": "^3.0.4",
"mongodb": "^3.1.13",
"mongodb": "^6.11.0",
"node-forge": "^0.7.6",
"node-rdkafka": "^2.12.0",
"node-rdkafka-prometheus": "^1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion tests/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"mongo": {
"logName": "s3-recordlog",
"replicaSetHosts": "localhost:27018"
"replicaSetHosts": "localhost:27018",
"readPreference": "primary"
},
"probeServer": {
"bindAddress": "localhost",
Expand Down
Loading
Loading