-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(NODE-4685): unified spec runner to support logging tests #3578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nbbeeken
merged 57 commits into
main
from
NODE-4685/Easier_debugging_with_standardized_logging
Mar 21, 2023
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
80f183b
ci(NODE-4685): WIP test runner changes
W-A-James 1837eb4
ci(NODE-4685): Start implementign new operators
W-A-James f86a280
ci(NODE-4685): Start adding log capture facilities to ClientEntity
W-A-James 55e9eb3
ci(NODE-4685): continue progress on unified spec runnner
W-A-James 52ed51d
ci(NODE-4685): Implement failureIsRedactedHandling
W-A-James c714020
ci(NODE-4685): Change field names
W-A-James 53b4d39
style(NODE-4685): Remove todo
W-A-James 6c135e9
fix(NODE-4685): TO BE REVERTED
W-A-James 4321391
test(NODE-4685): Add unit tests for new functionality
W-A-James cb57476
ci(NODE-4685): Changes to fit 1088matchAsDocument and 1088matchAsRoot…
W-A-James 75dd3ae
Merge branch 'main' into NODE-4685/Easier_debugging_with_standardized…
W-A-James bc0b66c
test(NODE-4685): Update tests
W-A-James 420481f
ci(NODE-4685): Change type of Logs
W-A-James a76868b
ci(NODE-4685): run command logging spec tests
W-A-James a83ae0b
ci(NODE-4685): remove extraneous test file
W-A-James 1cf7a99
ci(NODE-4685): Update LogCollector
W-A-James abd5be9
style(NODE-4685): remove todo comment
W-A-James fedaeb8
style(NODE-4685): remove todo comment
W-A-James 94ba6c0
ci(NODE-4685): fix log capture
W-A-James c291584
ci(NODE-4685): Update conditional
W-A-James 7b9e7f5
ci(NODE-4685): remove unneeded field
W-A-James 48ac7ce
ci(NODE-4685): Fix up log collection
W-A-James c7a36a8
ci(NODE-4685): Remove unneeded conditon
W-A-James b0796cf
style(NODE-4685): remove todo
W-A-James 24321f8
ci(NODE-4685): fix condition
W-A-James a264ba9
Merge branch 'main' into NODE-4685/Easier_debugging_with_standardized…
W-A-James 3428f0c
style(NODE-4685): Remove todo comment
W-A-James 6234beb
style(NODE-4685): eslint
W-A-James f1d80ac
test(NODE-4685): Add regex check to Error assertion
W-A-James 9950d12
test(NODE-4685): Add regex
W-A-James 4ed6731
ci(NODE-4685): Update assertions
W-A-James ccd05a9
test(NODE-4685): Update test name
W-A-James 9369b42
ci(NODE-4685): change field name
W-A-James 16adbcf
fix(NODE-4685): remove call to entries()
W-A-James 6fa85e5
style(NODE-4685): eslint
W-A-James 5065ca7
ci(NODE-4685): Update log collector
W-A-James 0537cd5
Merge branch 'main' into NODE-4685/Easier_debugging_with_standardized…
W-A-James 5253a66
test(NODE-4685): skip command logging tests
W-A-James a7279ec
ci(NODE-4685): Add callback to write method and eslint fixes
W-A-James 4d4d1a3
style(NODE-4685): eslint
W-A-James b526b8e
test(NODE-4685): Add review fixes
W-A-James 36efc36
ci(NODE-4685): Fix field access
W-A-James bb4b944
test(NODE-4685): Fix resultCheckSpy
W-A-James 1ce04b4
test(NODE-4685): Move commmand monitoring and command logging spec te…
W-A-James 1be583c
style(NODE-4685): ADd todo comment
W-A-James a9c1f1d
test(NODE-4685): addressing review comments
W-A-James f0ee322
refactor(NODE-4685): restore bang operator
W-A-James 0af5a86
refactor(NODE-4685): Add internal symbol property to be able to progr…
W-A-James b71217a
style(NODE-4685): Rename variable
W-A-James 37277ac
style(NODE-4685): rename variable
W-A-James efd1c02
refactor(NODE-4685): remove duplicate types
W-A-James 7a21fac
style(NODE-4685): rename symbol property
W-A-James 993958c
Merge branch 'main' into NODE-4685/Easier_debugging_with_standardized…
W-A-James 6f8999c
refactor(NODE-4685): override logger environment variables in Unified…
W-A-James 8ea8ce8
Merge branch 'NODE-4685/Easier_debugging_with_standardized_logging' o…
W-A-James a61b8cd
refactor(NODE-4685): hardcode component to env var mapping
W-A-James f60f3bb
test(NODE-4685): Fix test failures
W-A-James File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { expect } from 'chai'; | ||
import { EventEmitter } from 'events'; | ||
import { Writable } from 'stream'; | ||
|
||
import { | ||
AbstractCursor, | ||
|
@@ -37,7 +38,12 @@ import { | |
import { ejson, getEnvironmentalOptions } from '../../tools/utils'; | ||
import type { TestConfiguration } from '../runner/config'; | ||
import { trace } from './runner'; | ||
import type { ClientEncryption, ClientEntity, EntityDescription } from './schema'; | ||
import type { | ||
ClientEncryption, | ||
ClientEntity, | ||
EntityDescription, | ||
ExpectedLogMessage | ||
} from './schema'; | ||
import { | ||
createClientEncryption, | ||
makeConnectionString, | ||
|
@@ -95,16 +101,40 @@ export type CmapEvent = | |
| ConnectionCheckedInEvent | ||
| ConnectionPoolClearedEvent; | ||
export type SdamEvent = ServerDescriptionChangedEvent; | ||
export type LogMessage = Omit<ExpectedLogMessage, 'failureIsRedacted'>; | ||
|
||
function getClient(address) { | ||
return new MongoClient(`mongodb://${address}`, getEnvironmentalOptions()); | ||
} | ||
|
||
// TODO(NODE-4813): Remove this class in favour of a simple object with a write method | ||
/* TODO(NODE-4813): Ensure that the object that we replace this with has logic to convert the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this TODO instead of adding the logic here since we are still solidifying what the shape of the logs will be |
||
* collected log into the format require by the unified spec runner | ||
* (see ExpectedLogMessage type in schema.ts) */ | ||
export class UnifiedLogCollector extends Writable { | ||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
collectedLogs: LogMessage[] = []; | ||
|
||
constructor() { | ||
super({ objectMode: true }); | ||
} | ||
|
||
_write( | ||
log: LogMessage, | ||
_: string, | ||
callback: (e: Error | null, l: LogMessage | undefined) => void | ||
) { | ||
this.collectedLogs.push(log); | ||
callback(null, log); | ||
} | ||
} | ||
|
||
export class UnifiedMongoClient extends MongoClient { | ||
commandEvents: CommandEvent[] = []; | ||
cmapEvents: CmapEvent[] = []; | ||
sdamEvents: SdamEvent[] = []; | ||
failPoints: Document[] = []; | ||
logCollector: UnifiedLogCollector; | ||
|
||
ignoredEvents: string[]; | ||
observedCommandEvents: ('commandStarted' | 'commandSucceeded' | 'commandFailed')[]; | ||
observedCmapEvents: ( | ||
|
@@ -148,13 +178,35 @@ export class UnifiedMongoClient extends MongoClient { | |
serverDescriptionChangedEvent: 'serverDescriptionChanged' | ||
} as const; | ||
|
||
static LOGGING_COMPONENT_TO_ENV_VAR_NAME = { | ||
command: 'MONGODB_LOG_COMMAND', | ||
serverSelection: 'MONGODB_LOG_SERVER_SELECTION', | ||
connection: 'MONGODB_LOG_CONNECTION', | ||
topology: 'MONGODB_LOG_TOPOLOGY' | ||
} as const; | ||
|
||
constructor(uri: string, description: ClientEntity) { | ||
const logCollector = new UnifiedLogCollector(); | ||
const componentSeverities = { | ||
MONGODB_LOG_ALL: 'off' | ||
}; | ||
|
||
// NOTE: this is done to override the logger environment variables | ||
for (const key in description.observeLogMessages) { | ||
componentSeverities[UnifiedMongoClient.LOGGING_COMPONENT_TO_ENV_VAR_NAME[key]] = | ||
description.observeLogMessages[key]; | ||
} | ||
|
||
super(uri, { | ||
monitorCommands: true, | ||
[Symbol.for('@@mdb.skipPingOnConnect')]: true, | ||
[Symbol.for('@@mdb.enableMongoLogger')]: true, | ||
[Symbol.for('@@mdb.internalMongoLoggerConfig')]: componentSeverities, | ||
mongodbLogPath: logCollector, | ||
...getEnvironmentalOptions(), | ||
...(description.serverApi ? { serverApi: description.serverApi } : {}) | ||
}); | ||
this.logCollector = logCollector; | ||
|
||
this.ignoredEvents = [ | ||
...(description.ignoreCommandMonitoringEvents ?? []), | ||
|
@@ -242,6 +294,10 @@ export class UnifiedMongoClient extends MongoClient { | |
this.off(eventName, this.pushSdamEvent); | ||
} | ||
} | ||
|
||
get collectedLogs(): LogMessage[] { | ||
return this.logCollector.collectedLogs; | ||
} | ||
} | ||
|
||
export class FailPointMap extends Map<string, Document> { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.