Skip to content

Commit 31173a2

Browse files
authored
fix(mongodb-server-log-checker): ignore warnings from internal clients (#627)
Ignore warnings not coming from our clients, but rather from internal clients (i.e. mongos-to-mongod or mongod-to-mongod conections). Also, as a drive-by, add a `Disposable` implementation (I figured this is something we'll want to stick to in new code as a best practice).
1 parent b85e3f1 commit 31173a2

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

  • packages/mongodb-server-log-checker/src

packages/mongodb-server-log-checker/src/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type WarningFilter = number | ((entry: LogEntry) => boolean);
3131
* Monitors MongoDB server logs and validates that no unexpected warnings occur.
3232
* Modeled after the mongosh implementation in PR #2574.
3333
*/
34-
export class ServerLogsChecker {
34+
export class ServerLogsChecker implements Disposable {
3535
static defaultAllowedWarnings: WarningFilter[] = [
3636
4615610, // "Failed to check socket connectivity", generic disconnect error
3737
7012500, // "Failed to refresh query analysis configurations", normal sharding behavior
@@ -93,6 +93,7 @@ export class ServerLogsChecker {
9393
private collectedWarnings: LogEntry[] = [];
9494
private warningFilters: ((entry: LogEntry) => boolean)[] = [];
9595
private cluster: MongoLogEventEmitter;
96+
private ignoreCtx: Set<string> = new Set();
9697

9798
constructor(cluster: MongoLogEventEmitter) {
9899
this.cluster = cluster;
@@ -106,9 +107,20 @@ export class ServerLogsChecker {
106107
}
107108

108109
private listener: (serverUUID: string, entry: LogEntry) => void = (
109-
_serverUUID: string,
110+
serverUUID: string,
110111
entry: LogEntry,
111112
) => {
113+
const crossServerCtxID = `${serverUUID}\0${entry.context}`;
114+
// Ignore events coming from internal clients (e.g. replset clients)
115+
if (
116+
entry.id === 51800 &&
117+
entry.attr?.doc?.driver?.name === 'MongoDB Internal Client' &&
118+
entry.context.startsWith('conn')
119+
) {
120+
this.ignoreCtx.add(crossServerCtxID);
121+
}
122+
if (this.ignoreCtx.has(crossServerCtxID)) return;
123+
112124
// Only collect warnings (W), errors (E), and fatal (F) severity logs
113125
// Apply filters at collection time - filtered warnings are never stored
114126
if (
@@ -173,4 +185,9 @@ export class ServerLogsChecker {
173185
close(): void {
174186
this.cluster.off('mongoLog', this.listener);
175187
}
188+
189+
/** Disposable alias for close() */
190+
[Symbol.dispose](): void {
191+
this.close();
192+
}
176193
}

0 commit comments

Comments
 (0)