Skip to content

Commit 83ff11d

Browse files
committed
Add call to identifyServerName in service-provider-node-driver
1 parent 02f8b80 commit 83ff11d

File tree

5 files changed

+55
-34
lines changed

5 files changed

+55
-34
lines changed

packages/service-provider-core/src/connect-info.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('getConnectInfo', function () {
6464
auth_type: 'PLAIN',
6565
is_data_federation: false,
6666
is_stream: false,
67-
dl_version: null,
67+
dl_version: undefined,
6868
atlas_version: '20210330.0.0.1617063608',
6969
is_genuine: true,
7070
non_genuine_server_name: 'mongodb',
@@ -81,6 +81,7 @@ describe('getConnectInfo', function () {
8181
atlasVersion: ATLAS_VERSION,
8282
resolvedHostname: 'test-data-sets-00-02-a011bb.mongodb.net',
8383
isLocalAtlas: false,
84+
serverName: 'mongodb',
8485
})
8586
).to.deep.equal(output);
8687
});
@@ -96,7 +97,7 @@ describe('getConnectInfo', function () {
9697
auth_type: undefined,
9798
is_data_federation: false,
9899
is_stream: false,
99-
dl_version: null,
100+
dl_version: undefined,
100101
atlas_version: '20210330.0.0.1617063608',
101102
is_genuine: true,
102103
non_genuine_server_name: 'mongodb',
@@ -113,6 +114,7 @@ describe('getConnectInfo', function () {
113114
atlasVersion: ATLAS_VERSION,
114115
resolvedHostname: 'test-data-sets-00-02-a011bb.mongodb.net',
115116
isLocalAtlas: false,
117+
serverName: 'mongodb',
116118
})
117119
).to.deep.equal(output);
118120
});
@@ -130,7 +132,7 @@ describe('getConnectInfo', function () {
130132
auth_type: undefined,
131133
is_data_federation: false,
132134
is_stream: true,
133-
dl_version: null,
135+
dl_version: undefined,
134136
atlas_version: null,
135137
is_genuine: true,
136138
is_local_atlas: false,
@@ -148,6 +150,7 @@ describe('getConnectInfo', function () {
148150
resolvedHostname:
149151
'atlas-stream-67b8e1cd6d60357be377be7b-1dekw.virginia-usa.a.query.mongodb-dev.net',
150152
isLocalAtlas: false,
153+
serverName: 'mongodb',
151154
})
152155
).to.deep.equal(output);
153156
});
@@ -163,7 +166,7 @@ describe('getConnectInfo', function () {
163166
auth_type: undefined,
164167
is_data_federation: false,
165168
is_stream: false,
166-
dl_version: null,
169+
dl_version: undefined,
167170
atlas_version: null,
168171
is_genuine: true,
169172
non_genuine_server_name: 'mongodb',
@@ -179,6 +182,7 @@ describe('getConnectInfo', function () {
179182
atlasVersion: null,
180183
resolvedHostname: 'localhost',
181184
isLocalAtlas: true,
185+
serverName: 'mongodb',
182186
})
183187
).to.deep.equal(output);
184188
});
@@ -194,13 +198,13 @@ describe('getConnectInfo', function () {
194198
auth_type: undefined,
195199
is_data_federation: false,
196200
is_stream: false,
197-
dl_version: null,
201+
dl_version: undefined,
198202
atlas_version: null,
199203
is_genuine: true,
200204
non_genuine_server_name: 'mongodb',
201-
server_arch: null,
202205
node_version: process.version,
203-
server_os: null,
206+
server_os: undefined,
207+
server_arch: undefined,
204208
uri: '',
205209
is_local_atlas: false,
206210
};
@@ -209,6 +213,7 @@ describe('getConnectInfo', function () {
209213
buildInfo: null,
210214
atlasVersion: null,
211215
isLocalAtlas: false,
216+
serverName: 'mongodb',
212217
})
213218
).to.deep.equal(output);
214219
});

packages/service-provider-core/src/connect-info.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ^ segment data is in snake_case: forgive me javascript, for i have sinned.
22

3-
import getBuildInfo from 'mongodb-build-info';
3+
import * as getBuildInfo from 'mongodb-build-info';
44
import type { ConnectionString } from 'mongodb-connection-string-url';
55

66
export type ConnectionExtraInfo = {
@@ -65,20 +65,20 @@ export default function getConnectExtraInfo({
6565
atlasVersion,
6666
resolvedHostname,
6767
isLocalAtlas,
68+
serverName = 'unknown',
6869
}: {
6970
connectionString?: ConnectionString;
7071
buildInfo: any;
7172
atlasVersion: any;
7273
resolvedHostname?: string;
7374
isLocalAtlas: boolean;
75+
serverName?: string;
7476
}): ConnectionExtraInfo {
7577
const auth_type =
7678
connectionString?.searchParams.get('authMechanism') ?? undefined;
7779
const uri = connectionString?.toString() ?? '';
7880

7981
buildInfo ??= {}; // We're currently not getting buildInfo with --apiStrict.
80-
const { isGenuine: is_genuine, serverName: non_genuine_server_name } =
81-
getBuildInfo.getGenuineMongoDB(uri);
8282
// Atlas Data Lake has been renamed to Atlas Data Federation
8383
const { isDataLake: is_data_federation, dlVersion } =
8484
getBuildInfo.getDataLake(buildInfo);
@@ -100,8 +100,8 @@ export default function getConnectExtraInfo({
100100
is_stream: getBuildInfo.isAtlasStream(uri),
101101
dl_version: dlVersion || undefined,
102102
atlas_version: atlasVersion?.atlasVersion ?? null,
103-
is_genuine,
104-
non_genuine_server_name,
103+
is_genuine: serverName === 'mongodb' || serverName === 'unknown',
104+
non_genuine_server_name: serverName,
105105
is_local_atlas: isLocalAtlas,
106106
};
107107
}

packages/service-provider-node-driver/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@mongosh/types": "^3.14.0",
5555
"aws4": "^1.12.0",
5656
"mongodb": "^6.19.0",
57+
"mongodb-build-info": "^1.8.1",
5758
"mongodb-connection-string-url": "^3.0.2",
5859
"socks": "^2.8.3",
5960
"mongodb-client-encryption": "^6.5.0",

packages/service-provider-node-driver/src/node-driver-service-provider.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ describe('NodeDriverServiceProvider', function () {
10071007
expect(info.extraInfo?.is_local_atlas).to.equal(false);
10081008
expect(info.extraInfo?.is_localhost).to.equal(true);
10091009
expect(info.extraInfo?.fcv).to.equal(undefined);
1010-
expect(dbStub.command).to.have.callCount(3);
1010+
expect(dbStub.command).to.have.callCount(4);
10111011
expect(
10121012
dbStub.collection,
10131013
'calls countDocument on collection to check local atlas cli support'

packages/service-provider-node-driver/src/node-driver-service-provider.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import {
9393
ClientEncryption,
9494
} from 'mongodb';
9595
import { connectMongoClient } from '@mongodb-js/devtools-connect';
96+
import { identifyServerName } from 'mongodb-build-info';
9697

9798
const bsonlib = () => {
9899
const {
@@ -472,27 +473,40 @@ export class NodeDriverServiceProvider
472473
}
473474

474475
async getConnectionInfo(): Promise<ConnectionInfo> {
475-
const [buildInfo = null, atlasVersion = null, fcv = null, atlascliInfo] =
476-
await Promise.all([
477-
this.runCommandWithCheck(
478-
'admin',
479-
{ buildInfo: 1 },
480-
this.baseCmdOptions
481-
).catch(() => {}),
482-
this.runCommandWithCheck(
483-
'admin',
484-
{ atlasVersion: 1 },
485-
this.baseCmdOptions
486-
).catch(() => {}),
487-
this.runCommandWithCheck(
488-
'admin',
489-
{ getParameter: 1, featureCompatibilityVersion: 1 },
490-
this.baseCmdOptions
491-
).catch(() => {}),
492-
this.countDocuments('admin', 'atlascli', {
493-
managedClusterType: 'atlasCliLocalDevCluster',
494-
}).catch(() => 0),
495-
]);
476+
const buildInfoPromise = this.runCommandWithCheck(
477+
'admin',
478+
{ buildInfo: 1 },
479+
this.baseCmdOptions
480+
).catch(() => null);
481+
482+
const [
483+
buildInfo,
484+
atlasVersion = null,
485+
fcv = null,
486+
atlascliInfo,
487+
serverName,
488+
] = await Promise.all([
489+
buildInfoPromise,
490+
this.runCommandWithCheck(
491+
'admin',
492+
{ atlasVersion: 1 },
493+
this.baseCmdOptions
494+
).catch(() => {}),
495+
this.runCommandWithCheck(
496+
'admin',
497+
{ getParameter: 1, featureCompatibilityVersion: 1 },
498+
this.baseCmdOptions
499+
).catch(() => {}),
500+
this.countDocuments('admin', 'atlascli', {
501+
managedClusterType: 'atlasCliLocalDevCluster',
502+
}).catch(() => 0),
503+
identifyServerName({
504+
connectionString: this.uri?.toString() ?? '',
505+
buildInfo: buildInfoPromise.then((bi) => bi ?? {}),
506+
adminCommand: (command) =>
507+
this.runCommandWithCheck('admin', command, this.baseCmdOptions),
508+
}),
509+
]);
496510

497511
const resolvedHostname = this._getHostnameForConnection(
498512
this._lastSeenTopology
@@ -504,6 +518,7 @@ export class NodeDriverServiceProvider
504518
atlasVersion,
505519
resolvedHostname,
506520
isLocalAtlas: !!atlascliInfo,
521+
serverName,
507522
});
508523

509524
return {

0 commit comments

Comments
 (0)