Skip to content

Commit

Permalink
fix(topology): report unified topology as nodejs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mbroadst committed Nov 11, 2019
1 parent 0a22e3f commit d126665
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/core/topologies/shared.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const os = require('os');
const f = require('util').format;
const ReadPreference = require('./read_preference');
const Buffer = require('safe-buffer').Buffer;
const TopologyType = require('../sdam/topology_description').TopologyType;
Expand All @@ -20,20 +19,19 @@ function emitSDAMEvent(self, event, description) {
}

// Get package.json variable
var driverVersion = require('../../../package.json').version;
var nodejsversion = f('Node.js %s, %s', process.version, os.endianness());
var type = os.type();
var name = process.platform;
var architecture = process.arch;
var release = os.release();
const driverVersion = require('../../../package.json').version;
const nodejsVersion = `'Node.js ${process.version}, ${os.endianness}`;
const type = os.type();
const name = process.platform;
const architecture = process.arch;
const release = os.release();

function createClientInfo(options) {
// Build default client information
var clientInfo = options.clientInfo
const clientInfo = options.clientInfo
? clone(options.clientInfo)
: {
driver: {
name: 'nodejs-core',
name: 'nodejs',
version: driverVersion
},
os: {
Expand All @@ -44,11 +42,8 @@ function createClientInfo(options) {
}
};

// Is platform specified
if (clientInfo.platform && clientInfo.platform.indexOf('mongodb-core') === -1) {
clientInfo.platform = f('%s, mongodb-core: %s', clientInfo.platform, driverVersion);
} else if (!clientInfo.platform) {
clientInfo.platform = nodejsversion;
if (options.useUnifiedTopology) {
clientInfo.platform = `${nodejsVersion} (${options.useUnifiedTopology ? 'unified' : 'legacy'})`;
}

// Do we have an application specific string
Expand Down
29 changes: 29 additions & 0 deletions test/core/unit/connect_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ describe('Connect Tests', function() {
});
});

it(
'should report the correct metadata for unified topology',
{ requires: { unifiedTopology: true, topology: ['single'] } },
function(done) {
let ismaster;
test.server.setMessageHandler(request => {
const doc = request.document;
const $clusterTime = genClusterTime(Date.now());
if (doc.ismaster) {
ismaster = doc;
request.reply(
Object.assign({}, mock.DEFAULT_ISMASTER, {
$clusterTime,
arbiterOnly: true
})
);
}
});

const topology = this.configuration.newTopology(test.connectOptions);
topology.connect(test.connectOptions, err => {
expect(err).to.not.exist;
const platform = ismaster.client.platform;
expect(platform).to.match(/unified/);
topology.close(done);
});
}
);

describe('runCommand', function() {
class MockConnection extends EventEmitter {
constructor(conn) {
Expand Down

0 comments on commit d126665

Please sign in to comment.