Skip to content

Commit f1ca75e

Browse files
authored
fix(build-info): add short-circuit on servers from Atlas / mongodb.net (#586)
* Add short-circuit on servers from Atlas / mongodb.net * Add test
1 parent fbc118c commit f1ca75e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

packages/mongodb-build-info/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ export async function identifyServerName({
158158
}: IdentifyServerNameOptions): Promise<string> {
159159
try {
160160
const hostname = getHostnameFromUrl(connectionString);
161+
if (hostname.match(ATLAS_REGEX)) {
162+
return 'mongodb';
163+
}
164+
161165
if (hostname.match(COSMOS_DB_REGEX)) {
162166
return 'cosmosdb';
163167
}

packages/mongodb-build-info/test/fixtures.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ export const CMD_LINE_OPTS = {
6969
ok: 1,
7070
};
7171

72+
export const ATLAS_URIS = [
73+
'mongodb+srv://x:y@cluster0.nxezgv0.mongodb.net/',
74+
'mongodb+srv://x:y@cluster0.nxezgv0.mongodb-qa.net/',
75+
'mongodb+srv://x:y@cluster0.nxezgv0.mongodb-dev.net/',
76+
'mongodb://x:y@atlas-stream-64ba1372b2a9f1545031f34d-gkumd.virginia-usa.a.query.mongodb.net/',
77+
];
78+
7279
export const COSMOS_DB_URI = [
7380
'mongodb://x:y@compass-serverless.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass-serverless@',
7481
'mongodb://x:y@compass.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass@',

packages/mongodb-build-info/test/index.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,16 @@ describe('mongodb-build-info', function () {
436436
return Promise.reject(new Error('Should not be called'));
437437
}
438438

439+
it('reports MongoDB (when Atlas)', async function () {
440+
for (const connectionString of fixtures.ATLAS_URIS) {
441+
const result = await identifyServerName({
442+
connectionString,
443+
adminCommand: fail,
444+
});
445+
expect(result).to.equal('mongodb');
446+
}
447+
});
448+
439449
it('reports CosmosDB', async function () {
440450
for (const connectionString of fixtures.COSMOS_DB_URI) {
441451
const result = await identifyServerName({

0 commit comments

Comments
 (0)