Skip to content

Commit d126665

Browse files
committed
fix(topology): report unified topology as nodejs
The unified topology has been incorrectly reporting itself as `nodejs-core` in client metadata. This correct that to report just `nodejs`, but to include the unified or legacy type in the platform data. NODE-2316
1 parent 0a22e3f commit d126665

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

lib/core/topologies/shared.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const os = require('os');
4-
const f = require('util').format;
54
const ReadPreference = require('./read_preference');
65
const Buffer = require('safe-buffer').Buffer;
76
const TopologyType = require('../sdam/topology_description').TopologyType;
@@ -20,20 +19,19 @@ function emitSDAMEvent(self, event, description) {
2019
}
2120

2221
// Get package.json variable
23-
var driverVersion = require('../../../package.json').version;
24-
var nodejsversion = f('Node.js %s, %s', process.version, os.endianness());
25-
var type = os.type();
26-
var name = process.platform;
27-
var architecture = process.arch;
28-
var release = os.release();
22+
const driverVersion = require('../../../package.json').version;
23+
const nodejsVersion = `'Node.js ${process.version}, ${os.endianness}`;
24+
const type = os.type();
25+
const name = process.platform;
26+
const architecture = process.arch;
27+
const release = os.release();
2928

3029
function createClientInfo(options) {
31-
// Build default client information
32-
var clientInfo = options.clientInfo
30+
const clientInfo = options.clientInfo
3331
? clone(options.clientInfo)
3432
: {
3533
driver: {
36-
name: 'nodejs-core',
34+
name: 'nodejs',
3735
version: driverVersion
3836
},
3937
os: {
@@ -44,11 +42,8 @@ function createClientInfo(options) {
4442
}
4543
};
4644

47-
// Is platform specified
48-
if (clientInfo.platform && clientInfo.platform.indexOf('mongodb-core') === -1) {
49-
clientInfo.platform = f('%s, mongodb-core: %s', clientInfo.platform, driverVersion);
50-
} else if (!clientInfo.platform) {
51-
clientInfo.platform = nodejsversion;
45+
if (options.useUnifiedTopology) {
46+
clientInfo.platform = `${nodejsVersion} (${options.useUnifiedTopology ? 'unified' : 'legacy'})`;
5247
}
5348

5449
// Do we have an application specific string

test/core/unit/connect_tests.js

+29
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,35 @@ describe('Connect Tests', function() {
100100
});
101101
});
102102

103+
it(
104+
'should report the correct metadata for unified topology',
105+
{ requires: { unifiedTopology: true, topology: ['single'] } },
106+
function(done) {
107+
let ismaster;
108+
test.server.setMessageHandler(request => {
109+
const doc = request.document;
110+
const $clusterTime = genClusterTime(Date.now());
111+
if (doc.ismaster) {
112+
ismaster = doc;
113+
request.reply(
114+
Object.assign({}, mock.DEFAULT_ISMASTER, {
115+
$clusterTime,
116+
arbiterOnly: true
117+
})
118+
);
119+
}
120+
});
121+
122+
const topology = this.configuration.newTopology(test.connectOptions);
123+
topology.connect(test.connectOptions, err => {
124+
expect(err).to.not.exist;
125+
const platform = ismaster.client.platform;
126+
expect(platform).to.match(/unified/);
127+
topology.close(done);
128+
});
129+
}
130+
);
131+
103132
describe('runCommand', function() {
104133
class MockConnection extends EventEmitter {
105134
constructor(conn) {

0 commit comments

Comments
 (0)