Skip to content

Commit 8df3fe9

Browse files
tests fixed
1 parent c4bbc75 commit 8df3fe9

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

src/connection_string.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ export function parseOptions(
523523
MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY,
524524
MONGODB_LOG_SERVER_SELECTION: process.env.MONGODB_LOG_SERVER_SELECTION,
525525
MONGODB_LOG_CONNECTION: process.env.MONGODB_LOG_CONNECTION,
526+
MONGODB_LOG_CLIENT: process.env.MONGODB_LOG_CLIENT,
526527
MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,
527528
MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,
528529
MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH,

src/mongo_client.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -373,41 +373,36 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
373373
const documentDBHostnames = this[kOptions].hosts.filter(
374374
(hostAddress: HostAddress) =>
375375
hostAddress.host &&
376-
(hostAddress.host.endsWith('.docdb.amazonaws.com') ||
377-
hostAddress.host.endsWith('.docdb-elastic.amazonaws.com'))
376+
(hostAddress.host.toLowerCase().endsWith('.docdb.amazonaws.com') ||
377+
hostAddress.host.toLowerCase().endsWith('.docdb-elastic.amazonaws.com'))
378378
);
379379

380380
const srvHostIsDocumentDB =
381381
this[kOptions].srvHost &&
382-
(this[kOptions].srvHost.endsWith('.docdb.amazonaws.com') ||
383-
this[kOptions].srvHost.endsWith('.docdb-elastic.amazonaws.com'));
382+
(this[kOptions].srvHost.toLowerCase().endsWith('.docdb.amazonaws.com') ||
383+
this[kOptions].srvHost.toLowerCase().endsWith('.docdb-elastic.amazonaws.com'));
384384

385385
if (documentDBHostnames.length !== 0 || srvHostIsDocumentDB) {
386-
this.mongoLogger.logDestination.write({
387-
t: new Date(),
388-
c: 'topology',
389-
s: 'info',
390-
message:
391-
'You appear to be connected to a DocumentDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/documentdb'
392-
});
386+
this.mongoLogger.info(
387+
'client',
388+
'You appear to be connected to a DocumentDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/documentdb'
389+
);
393390
}
394391

395392
const cosmosDBHostnames = this[kOptions].hosts.filter(
396393
(hostAddress: HostAddress) =>
397-
hostAddress.host && hostAddress.host.endsWith('.cosmos.azure.com')
394+
hostAddress.host && hostAddress.host.toLowerCase().endsWith('.cosmos.azure.com')
398395
);
399396

400397
const srvHostIsCosmosDB =
401-
this[kOptions].srvHost && this[kOptions].srvHost.endsWith('.cosmos.azure.com');
398+
this[kOptions].srvHost &&
399+
this[kOptions].srvHost.toLowerCase().endsWith('.cosmos.azure.com');
402400

403401
if (cosmosDBHostnames.length !== 0 || srvHostIsCosmosDB) {
404-
this.mongoLogger.logDestination.write({
405-
t: new Date(),
406-
c: 'topology',
407-
s: 'info',
408-
message:
409-
'You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb'
410-
});
402+
this.mongoLogger.info(
403+
'client',
404+
'You appear to be connected to a CosmosDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/cosmosdb'
405+
);
411406
}
412407
}
413408
}

src/mongo_logger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export const MongoLoggableComponent = Object.freeze({
9898
COMMAND: 'command',
9999
TOPOLOGY: 'topology',
100100
SERVER_SELECTION: 'serverSelection',
101-
CONNECTION: 'connection'
101+
CONNECTION: 'connection',
102+
CLIENT: 'client'
102103
} as const);
103104

104105
/** @internal */
@@ -115,6 +116,8 @@ export interface MongoLoggerEnvOptions {
115116
MONGODB_LOG_SERVER_SELECTION?: string;
116117
/** Severity level for CMAP */
117118
MONGODB_LOG_CONNECTION?: string;
119+
/** Severity level for client */
120+
MONGODB_LOG_CLIENT?: string;
118121
/** Default severity level to be if any of the above are unset */
119122
MONGODB_LOG_ALL?: string;
120123
/** Max length of embedded EJSON docs. Setting to 0 disables truncation. Defaults to 1000. */
@@ -140,6 +143,8 @@ export interface MongoLoggerOptions {
140143
serverSelection: SeverityLevel;
141144
/** Severity level for connection component */
142145
connection: SeverityLevel;
146+
/** Severity level for client component */
147+
client: SeverityLevel;
143148
/** Default severity level to be used if any of the above are unset */
144149
default: SeverityLevel;
145150
};
@@ -528,6 +533,7 @@ export class MongoLogger {
528533
parseSeverityFromString(combinedOptions.MONGODB_LOG_SERVER_SELECTION) ?? defaultSeverity,
529534
connection:
530535
parseSeverityFromString(combinedOptions.MONGODB_LOG_CONNECTION) ?? defaultSeverity,
536+
client: parseSeverityFromString(combinedOptions.MONGODB_LOG_CLIENT) ?? defaultSeverity,
531537
default: defaultSeverity
532538
},
533539
maxDocumentLength:

test/unit/connection_string.test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,14 @@ describe('Connection String', function () {
885885
});
886886

887887
describe('non-genuine hosts', () => {
888+
beforeEach(() => {
889+
process.env.MONGODB_LOG_CLIENT = 'info';
890+
});
891+
892+
afterEach(() => {
893+
process.env.MONGODB_LOG_CLIENT = undefined;
894+
});
895+
888896
const loggerFeatureFlag = Symbol.for('@@mdb.enableMongoLogger');
889897
const docDBmsg =
890898
'You appear to be connected to a DocumentDB cluster. For more information regarding feature compatibility and support please visit https://www.mongodb.com/supportability/documentdb';
@@ -895,12 +903,13 @@ describe('Connection String', function () {
895903
['non-SRV default uri', 'mongodb://a.mongodb.net:27017', ''],
896904
['SRV example uri', 'mongodb+srv://a.example.com/', ''],
897905
['SRV default uri', 'mongodb+srv://a.mongodb.net/', ''],
898-
['non-SRV cosmosDB uri', 'mongodb://a.mongo.cosmos.azure.com:19555/', cosmosDBmsg],
899-
['non-SRV documentDB uri', 'mongodb://a.docdb.amazonaws.com:27017/', docDBmsg],
900-
['non-SRV documentDB uri ', 'mongodb://a.docdb-elastic.amazonaws.com:27017/', docDBmsg],
901-
['SRV cosmosDB uri', 'mongodb+srv://a.mongo.cosmos.azure.com/', cosmosDBmsg],
902-
['SRV documentDB uri', 'mongodb+srv://a.docdb.amazonaws.com/', docDBmsg],
903-
['SRV documentDB uri 2', 'mongodb+srv://a.docdb-elastic.amazonaws.com/', docDBmsg]
906+
// ensure case insensitity
907+
['non-SRV cosmosDB uri', 'mongodb://a.mongo.COSmos.aZure.com:19555/', cosmosDBmsg],
908+
['non-SRV documentDB uri', 'mongodb://a.docDB.AmazonAws.com:27017/', docDBmsg],
909+
['non-SRV documentDB uri ', 'mongodb://a.docdB-eLasTic.amazonaws.com:27017/', docDBmsg],
910+
['SRV cosmosDB uri', 'mongodb+srv://a.mongo.COSmos.aZure.com/', cosmosDBmsg],
911+
['SRV documentDB uri', 'mongodb+srv://a.docDB.AmazonAws.com/', docDBmsg],
912+
['SRV documentDB uri 2', 'mongodb+srv://a.docdB-eLastic.amazonaws.com/', docDBmsg]
904913
];
905914

906915
context('when logging is turned on', () => {
@@ -919,6 +928,7 @@ describe('Connection String', function () {
919928

920929
if (message.length > 0) {
921930
expect(stream.buffer).to.have.lengthOf(1);
931+
expect(stream.buffer[0]).to.have.property('c', 'client');
922932
expect(stream.buffer[0]).to.have.property('message', message);
923933
} else {
924934
expect(stream.buffer).to.have.lengthOf(0);

test/unit/mongo_logger.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ describe('class MongoLogger', function () {
116116
['MONGODB_LOG_COMMAND', 'command'],
117117
['MONGODB_LOG_TOPOLOGY', 'topology'],
118118
['MONGODB_LOG_SERVER_SELECTION', 'serverSelection'],
119-
['MONGODB_LOG_CONNECTION', 'connection']
119+
['MONGODB_LOG_CONNECTION', 'connection'],
120+
['MONGODB_LOG_CLIENT', 'client']
120121
]);
121122

122123
function* makeValidOptions(): Generator<[string, string]> {

0 commit comments

Comments
 (0)