-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-4687): Add logging to server selection #3946
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
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7c7148b
feat(NODE-4687): Add logging to server selection
aditi-khare-mongoDB c90bb51
basic implementation completed
aditi-khare-mongoDB fd0bea6
restored spec tests
aditi-khare-mongoDB 184554d
ready for PR i think
aditi-khare-mongoDB 0df2b85
Unsynced spec test name for clarity and lack of duplication
aditi-khare-mongoDB 8bf5cd3
Updated skip reason
aditi-khare-mongoDB 0467a25
PR requested changes 0
aditi-khare-mongoDB cdb2823
replica set expected logs changes
aditi-khare-mongoDB fc5bca0
Removed failiing spec test from local folder, only in spec now
aditi-khare-mongoDB 644be77
semi-fix after rebase
aditi-khare-mongoDB 8aeb178
stop using incorrect logging component:
aditi-khare-mongoDB 60f2469
stray only
aditi-khare-mongoDB 5322cf6
requested changes
aditi-khare-mongoDB 366e337
restored package lock
aditi-khare-mongoDB f193abe
Unit test fix 0
aditi-khare-mongoDB 4541589
Failing unified test fix
aditi-khare-mongoDB b5763a5
removed stray only
aditi-khare-mongoDB 3b181eb
fixed timeout bug:
aditi-khare-mongoDB ec2cbf9
package-lock.json fix
aditi-khare-mongoDB 377a9fe
Merge branch 'main' into NODE-4687/log-server-selection-with-operation
durran 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
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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { HostAddress } from '.././utils'; | ||
import { | ||
SERVER_SELECTION_FAILED, | ||
SERVER_SELECTION_STARTED, | ||
SERVER_SELECTION_SUCCEEDED, | ||
WAITING_FOR_SUITABLE_SERVER | ||
} from '../constants'; | ||
import { type ReadPreference } from '../read_preference'; | ||
import { type ServerSelector } from './server_selection'; | ||
import type { TopologyDescription } from './topology_description'; | ||
|
||
/** | ||
* The base export class for all logs published from server selection | ||
* @internal | ||
* @category Log Type | ||
*/ | ||
export abstract class ServerSelectionEvent { | ||
durran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** String representation of the selector being used to select the server. | ||
* Defaults to 'custom selector' for application-provided custom selector case. | ||
*/ | ||
selector: string | ReadPreference | ServerSelector; | ||
/** The name of the operation for which a server is being selected. */ | ||
operation: string; | ||
/** The current topology description. */ | ||
topologyDescription: TopologyDescription; | ||
|
||
/** @internal */ | ||
abstract name: | ||
| typeof SERVER_SELECTION_STARTED | ||
| typeof SERVER_SELECTION_SUCCEEDED | ||
| typeof SERVER_SELECTION_FAILED | ||
| typeof WAITING_FOR_SUITABLE_SERVER; | ||
|
||
abstract message: string; | ||
|
||
/** @internal */ | ||
constructor( | ||
selector: string | ReadPreference | ServerSelector, | ||
topologyDescription: TopologyDescription, | ||
operation: string | ||
) { | ||
this.selector = selector; | ||
this.operation = operation; | ||
this.topologyDescription = topologyDescription; | ||
} | ||
} | ||
|
||
/** | ||
* An event published when server selection starts | ||
* @internal | ||
* @category Event | ||
*/ | ||
export class ServerSelectionStartedEvent extends ServerSelectionEvent { | ||
/** @internal */ | ||
name = SERVER_SELECTION_STARTED; | ||
message = 'Server selection started'; | ||
|
||
/** @internal */ | ||
constructor( | ||
selector: string | ReadPreference | ServerSelector, | ||
topologyDescription: TopologyDescription, | ||
operation: string | ||
) { | ||
super(selector, topologyDescription, operation); | ||
} | ||
} | ||
|
||
/** | ||
* An event published when a server selection fails | ||
* @internal | ||
* @category Event | ||
*/ | ||
export class ServerSelectionFailedEvent extends ServerSelectionEvent { | ||
/** @internal */ | ||
name = SERVER_SELECTION_FAILED; | ||
message = 'Server selection failed'; | ||
/** Representation of the error the driver will throw regarding server selection failing. */ | ||
failure: Error; | ||
|
||
/** @internal */ | ||
constructor( | ||
selector: string | ReadPreference | ServerSelector, | ||
topologyDescription: TopologyDescription, | ||
error: Error, | ||
operation: string | ||
) { | ||
super(selector, topologyDescription, operation); | ||
this.failure = error; | ||
} | ||
} | ||
|
||
/** | ||
* An event published when server selection succeeds | ||
* @internal | ||
* @category Event | ||
*/ | ||
export class ServerSelectionSucceededEvent extends ServerSelectionEvent { | ||
/** @internal */ | ||
name = SERVER_SELECTION_SUCCEEDED; | ||
message = 'Server selection succeeded'; | ||
/** The hostname, IP address, or Unix domain socket path for the selected server. */ | ||
aditi-khare-mongoDB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
serverHost: string; | ||
/** The port for the selected server. Optional; not present for Unix domain sockets. When the user does not specify a port and the default (27017) is used, the driver SHOULD include it here. */ | ||
serverPort: number | undefined; | ||
|
||
/** @internal */ | ||
constructor( | ||
selector: string | ReadPreference | ServerSelector, | ||
topologyDescription: TopologyDescription, | ||
address: string, | ||
operation: string | ||
) { | ||
super(selector, topologyDescription, operation); | ||
const { host, port } = HostAddress.fromString(address).toHostPort(); | ||
this.serverHost = host; | ||
this.serverPort = port; | ||
} | ||
} | ||
|
||
/** | ||
* An event published when server selection is waiting for a suitable server to become available | ||
* @internal | ||
* @category Event | ||
*/ | ||
export class WaitingForSuitableServerEvent extends ServerSelectionEvent { | ||
/** @internal */ | ||
name = WAITING_FOR_SUITABLE_SERVER; | ||
message = 'Waiting for suitable server to become available'; | ||
/** The remaining time left until server selection will time out. */ | ||
remainingTimeMS: number; | ||
|
||
/** @internal */ | ||
constructor( | ||
selector: string | ReadPreference | ServerSelector, | ||
topologyDescription: TopologyDescription, | ||
remainingTimeMS: number, | ||
operation: string | ||
) { | ||
super(selector, topologyDescription, operation); | ||
this.remainingTimeMS = remainingTimeMS; | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we broaden the type of the
event
parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use this function for all SDAM Events, too. We used to use it for server selection events as well before
serverHost
andserverPort
were defined directly on the loggable server selection event classes.