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
4 changes: 4 additions & 0 deletions packages/mongodb-build-info/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export async function identifyServerName({
}: IdentifyServerNameOptions): Promise<string> {
try {
const hostname = getHostnameFromUrl(connectionString);
if (hostname.match(ATLAS_REGEX)) {
return 'mongodb';
}

if (hostname.match(COSMOS_DB_REGEX)) {
return 'cosmosdb';
}
Expand Down
7 changes: 7 additions & 0 deletions packages/mongodb-build-info/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export const CMD_LINE_OPTS = {
ok: 1,
};

export const ATLAS_URIS = [
'mongodb+srv://x:y@cluster0.nxezgv0.mongodb.net/',
'mongodb+srv://x:y@cluster0.nxezgv0.mongodb-qa.net/',
'mongodb+srv://x:y@cluster0.nxezgv0.mongodb-dev.net/',
'mongodb://x:y@atlas-stream-64ba1372b2a9f1545031f34d-gkumd.virginia-usa.a.query.mongodb.net/',
];

export const COSMOS_DB_URI = [
'mongodb://x:y@compass-serverless.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass-serverless@',
'mongodb://x:y@compass.mongo.cosmos.azure.com:19555/?ssl=true&retrywrites=false&maxIdleTimeMS=120000&appName=@compass@',
Expand Down
10 changes: 10 additions & 0 deletions packages/mongodb-build-info/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ describe('mongodb-build-info', function () {
return Promise.reject(new Error('Should not be called'));
}

it('reports MongoDB (when Atlas)', async function () {
for (const connectionString of fixtures.ATLAS_URIS) {
const result = await identifyServerName({
connectionString,
adminCommand: fail,
});
expect(result).to.equal('mongodb');
}
});

it('reports CosmosDB', async function () {
for (const connectionString of fixtures.COSMOS_DB_URI) {
const result = await identifyServerName({
Expand Down