Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/service-provider-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@mongosh/shell-bson": "1.0.2",
"bson": "^6.10.4",
"mongodb": "^6.19.0",
"mongodb-build-info": "^1.7.2",
"mongodb-build-info": "^1.8.1",
"mongodb-connection-string-url": "^3.0.2"
},
"devDependencies": {
Expand Down
19 changes: 12 additions & 7 deletions packages/service-provider-core/src/connect-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('getConnectInfo', function () {
auth_type: 'PLAIN',
is_data_federation: false,
is_stream: false,
dl_version: null,
dl_version: undefined,
atlas_version: '20210330.0.0.1617063608',
is_genuine: true,
non_genuine_server_name: 'mongodb',
Expand All @@ -81,6 +81,7 @@ describe('getConnectInfo', function () {
atlasVersion: ATLAS_VERSION,
resolvedHostname: 'test-data-sets-00-02-a011bb.mongodb.net',
isLocalAtlas: false,
serverName: 'mongodb',
})
).to.deep.equal(output);
});
Expand All @@ -96,7 +97,7 @@ describe('getConnectInfo', function () {
auth_type: undefined,
is_data_federation: false,
is_stream: false,
dl_version: null,
dl_version: undefined,
atlas_version: '20210330.0.0.1617063608',
is_genuine: true,
non_genuine_server_name: 'mongodb',
Expand All @@ -113,6 +114,7 @@ describe('getConnectInfo', function () {
atlasVersion: ATLAS_VERSION,
resolvedHostname: 'test-data-sets-00-02-a011bb.mongodb.net',
isLocalAtlas: false,
serverName: 'mongodb',
})
).to.deep.equal(output);
});
Expand All @@ -130,7 +132,7 @@ describe('getConnectInfo', function () {
auth_type: undefined,
is_data_federation: false,
is_stream: true,
dl_version: null,
dl_version: undefined,
atlas_version: null,
is_genuine: true,
is_local_atlas: false,
Expand All @@ -148,6 +150,7 @@ describe('getConnectInfo', function () {
resolvedHostname:
'atlas-stream-67b8e1cd6d60357be377be7b-1dekw.virginia-usa.a.query.mongodb-dev.net',
isLocalAtlas: false,
serverName: 'mongodb',
})
).to.deep.equal(output);
});
Expand All @@ -163,7 +166,7 @@ describe('getConnectInfo', function () {
auth_type: undefined,
is_data_federation: false,
is_stream: false,
dl_version: null,
dl_version: undefined,
atlas_version: null,
is_genuine: true,
non_genuine_server_name: 'mongodb',
Expand All @@ -179,6 +182,7 @@ describe('getConnectInfo', function () {
atlasVersion: null,
resolvedHostname: 'localhost',
isLocalAtlas: true,
serverName: 'mongodb',
})
).to.deep.equal(output);
});
Expand All @@ -194,13 +198,13 @@ describe('getConnectInfo', function () {
auth_type: undefined,
is_data_federation: false,
is_stream: false,
dl_version: null,
dl_version: undefined,
atlas_version: null,
is_genuine: true,
non_genuine_server_name: 'mongodb',
server_arch: null,
node_version: process.version,
server_os: null,
server_os: undefined,
server_arch: undefined,
uri: '',
is_local_atlas: false,
};
Expand All @@ -209,6 +213,7 @@ describe('getConnectInfo', function () {
buildInfo: null,
atlasVersion: null,
isLocalAtlas: false,
serverName: 'mongodb',
})
).to.deep.equal(output);
});
Expand Down
21 changes: 10 additions & 11 deletions packages/service-provider-core/src/connect-info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ^ segment data is in snake_case: forgive me javascript, for i have sinned.

import getBuildInfo from 'mongodb-build-info';
import * as getBuildInfo from 'mongodb-build-info';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the 💙 for moving towards correct imports!

import type { ConnectionString } from 'mongodb-connection-string-url';

export type ConnectionExtraInfo = {
Expand Down Expand Up @@ -65,44 +65,43 @@ export default function getConnectExtraInfo({
atlasVersion,
resolvedHostname,
isLocalAtlas,
serverName = 'unknown',
}: {
connectionString?: ConnectionString;
buildInfo: any;
atlasVersion: any;
resolvedHostname?: string;
isLocalAtlas: boolean;
serverName?: string;
}): ConnectionExtraInfo {
const auth_type =
connectionString?.searchParams.get('authMechanism') ?? undefined;
const uri = connectionString?.toString() ?? '';

buildInfo ??= {}; // We're currently not getting buildInfo with --apiStrict.
const { isGenuine: is_genuine, serverName: non_genuine_server_name } =
getBuildInfo.getGenuineMongoDB(uri);
// Atlas Data Lake has been renamed to Atlas Data Federation
const { isDataLake: is_data_federation, dlVersion: dl_version } =
const { isDataLake: is_data_federation, dlVersion } =
getBuildInfo.getDataLake(buildInfo);

const { serverOs: server_os, serverArch: server_arch } =
getBuildInfo.getBuildEnv(buildInfo);
const { serverOs, serverArch } = getBuildInfo.getBuildEnv(buildInfo);
const isAtlas = !!atlasVersion?.atlasVersion || getBuildInfo.isAtlas(uri);

return {
...getHostInformation(resolvedHostname || uri),
is_atlas: isAtlas,
server_version: buildInfo.version,
node_version: process.version,
server_os,
server_os: serverOs || undefined,
uri,
server_arch,
server_arch: serverArch || undefined,
is_enterprise: getBuildInfo.isEnterprise(buildInfo),
auth_type,
is_data_federation,
is_stream: getBuildInfo.isAtlasStream(uri),
dl_version,
dl_version: dlVersion || undefined,
atlas_version: atlasVersion?.atlasVersion ?? null,
is_genuine,
non_genuine_server_name,
is_genuine: serverName === 'mongodb' || serverName === 'unknown',
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The logic for determining is_genuine treats 'unknown' as genuine, which may be misleading. If server identification fails and returns 'unknown', it's unclear whether the server is genuine or not. Consider documenting this behavior or adjusting the logic to handle the 'unknown' case more explicitly.

Suggested change
is_genuine: serverName === 'mongodb' || serverName === 'unknown',
is_genuine: serverName === 'unknown' ? undefined : serverName === 'mongodb',

Copilot uses AI. Check for mistakes.
non_genuine_server_name: serverName,
is_local_atlas: isLocalAtlas,
};
}
1 change: 1 addition & 0 deletions packages/service-provider-node-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@mongosh/types": "^3.14.0",
"aws4": "^1.12.0",
"mongodb": "^6.19.0",
"mongodb-build-info": "^1.8.1",
"mongodb-connection-string-url": "^3.0.2",
"socks": "^2.8.3",
"mongodb-client-encryption": "^6.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ describe('NodeDriverServiceProvider', function () {
expect(info.extraInfo?.is_local_atlas).to.equal(false);
expect(info.extraInfo?.is_localhost).to.equal(true);
expect(info.extraInfo?.fcv).to.equal(undefined);
expect(dbStub.command).to.have.callCount(3);
expect(dbStub.command).to.have.callCount(4);
expect(
dbStub.collection,
'calls countDocument on collection to check local atlas cli support'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import {
ClientEncryption,
} from 'mongodb';
import { connectMongoClient } from '@mongodb-js/devtools-connect';
import { identifyServerName } from 'mongodb-build-info';

const bsonlib = () => {
const {
Expand Down Expand Up @@ -472,27 +473,47 @@ export class NodeDriverServiceProvider
}

async getConnectionInfo(): Promise<ConnectionInfo> {
const [buildInfo = null, atlasVersion = null, fcv = null, atlascliInfo] =
await Promise.all([
this.runCommandWithCheck(
'admin',
{ buildInfo: 1 },
this.baseCmdOptions
).catch(() => {}),
this.runCommandWithCheck(
'admin',
{ atlasVersion: 1 },
this.baseCmdOptions
).catch(() => {}),
this.runCommandWithCheck(
'admin',
{ getParameter: 1, featureCompatibilityVersion: 1 },
this.baseCmdOptions
).catch(() => {}),
this.countDocuments('admin', 'atlascli', {
managedClusterType: 'atlasCliLocalDevCluster',
}).catch(() => 0),
]);
const buildInfoPromise = this.runCommandWithCheck(
'admin',
{ buildInfo: 1 },
this.baseCmdOptions
).catch(() => ({}));

const [
buildInfo,
atlasVersion = null,
fcv = null,
atlascliInfo,
serverName,
] = await Promise.all([
Comment on lines +482 to +488
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buildInfo destructured from the Promise.all result has no default value, but buildInfoPromise can resolve to an empty object {} when the catch handler executes. This inconsistency means buildInfo could be {} instead of the expected buildInfo response structure. Consider adding a default value of {} to match the catch handler's return value.

Copilot uses AI. Check for mistakes.
buildInfoPromise,
this.runCommandWithCheck(
'admin',
{ atlasVersion: 1 },
this.baseCmdOptions
).catch(() => {}),
this.runCommandWithCheck(
'admin',
{ getParameter: 1, featureCompatibilityVersion: 1 },
this.baseCmdOptions
).catch(() => {}),
this.countDocuments('admin', 'atlascli', {
managedClusterType: 'atlasCliLocalDevCluster',
}).catch(() => 0),
identifyServerName({
connectionString: this.uri?.toString() ?? '',
adminCommand: (command) => {
if (command.buildInfo) {
return buildInfoPromise;
}
return this.runCommandWithCheck(
'admin',
command,
this.baseCmdOptions
);
},
}),
]);

const resolvedHostname = this._getHostnameForConnection(
this._lastSeenTopology
Expand All @@ -504,6 +525,7 @@ export class NodeDriverServiceProvider
atlasVersion,
resolvedHostname,
isLocalAtlas: !!atlascliInfo,
serverName,
});

return {
Expand Down
Loading