Skip to content
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

feat(NODE-4687): Add logging to server selection #3946

Merged
merged 20 commits into from
Jan 8, 2024

Conversation

aditi-khare-mongoDB
Copy link
Contributor

@aditi-khare-mongoDB aditi-khare-mongoDB commented Dec 11, 2023

Description

Add logging to server selection.

What is changing?

When logging is enabled at the debug level, users will be able to see "server selection started, succeeded and failed events". When logging is enabled at the info level, users will be able to see "waiting for suitable server events".

Is there new documentation needed for these changes?

Not until logging is released (NODE-5672)

What is the motivation for this change?

To help users see their server selection events, depending on their logging level enabled.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken changed the title feat(4687): Add logging to server selection feat(NODE-4687): Add logging to server selection Dec 11, 2023
@aditi-khare-mongoDB aditi-khare-mongoDB marked this pull request as ready for review December 12, 2023 14:59
@aditi-khare-mongoDB
Copy link
Contributor Author

Reference to the failing tests: there are two spec tests with the same description 'server-selection-logging', which cause a MochaError. Anyone know a work around?

@alenakhineika
Copy link
Contributor

Reference to the failing tests: there are two spec tests with the same description 'server-selection-logging', which cause a MochaError. Anyone know a work around?

@dariakp I am wondering if this should be changed in the spec itself?

@durran
Copy link
Member

durran commented Dec 13, 2023

Reference to the failing tests: there are two spec tests with the same description 'server-selection-logging', which cause a MochaError. Anyone know a work around?

@dariakp I am wondering if this should be changed in the spec itself?

We shouldn't be duplicating all the unified tests here. I'd update the name of one of the duplicates here in this PR, open a DRIVERS ticket to change the name, and point to this PR as the reference implementation for the change.

@aditi-khare-mongoDB
Copy link
Contributor Author

I found a related ticket in the logging epic filed recently about potentially removing Load Balancer mode in server selection logging, this would also mean removing one of the duplicate test descriptions. I messaged in the drivers-1204-logging channel for more information:
https://mongodb.slack.com/archives/G015EB3QHED/p1702492490091139

@alenakhineika alenakhineika self-assigned this Dec 14, 2023
@alenakhineika alenakhineika added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Dec 14, 2023
src/change_stream.ts Outdated Show resolved Hide resolved
src/mongo_logger.ts Outdated Show resolved Hide resolved
src/sdam/topology.ts Outdated Show resolved Hide resolved
@alenakhineika alenakhineika added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Dec 20, 2023
@aditi-khare-mongoDB aditi-khare-mongoDB force-pushed the NODE-4687/log-server-selection-with-operation branch 2 times, most recently from a5da0d6 to 82a5e60 Compare December 21, 2023 19:58
@aditi-khare-mongoDB aditi-khare-mongoDB force-pushed the NODE-4687/log-server-selection-with-operation branch from 82a5e60 to fc5bca0 Compare December 21, 2023 20:44
@W-A-James W-A-James self-requested a review December 28, 2023 15:36
@@ -369,11 +383,17 @@ export function stringifyWithMaxLen(
maxDocumentLength: number,
options: EJSONOptions = {}
): string {
const ejson = EJSON.stringify(value, options);
maxDocumentLength = 20;
Copy link
Contributor

@W-A-James W-A-James Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we overwriting maxDocumentLength here? This would make us non-compliant with the spec that states that our default maxDocumentLength should be 1000 (characters in our case) and also override the value passed in to defaultLogTransform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was part of debugging and I forgot to remove it before pushing. It's removed now.

log: Record<string, any>,
event: ConnectionPoolMonitoringEvent | ServerOpeningEvent | ServerClosedEvent
) {
function attachConnectionFields(log: Record<string, any>, event: any) {
Copy link
Contributor

@W-A-James W-A-James Dec 28, 2023

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?

Copy link
Contributor Author

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 and serverPort were defined directly on the loggable server selection event classes.

@@ -251,7 +254,10 @@ async function retryOperation<
}

// select a new server, and attempt to retry the operation
const server = await topology.selectServerAsync(selector, { session });
const server = await topology.selectServerAsync(selector, {
session: session,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
session: session,
session,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't catch that, should be changed now.

@aditi-khare-mongoDB aditi-khare-mongoDB force-pushed the NODE-4687/log-server-selection-with-operation branch from 4617695 to 5322cf6 Compare January 3, 2024 20:20
@durran durran self-assigned this Jan 5, 2024
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are failures in the unit tests now around max staleness. These tests are using the server selection test helper here so I suspect the changes in this PR are directly related.

@aditi-khare-mongoDB
Copy link
Contributor Author

Ah, I see, I'll be more mindful of running unit tests before I push in the future.

@aditi-khare-mongoDB
Copy link
Contributor Author

aditi-khare-mongoDB commented Jan 5, 2024

Current CI Failures are flaky tests:

@durran durran merged commit 7f3ce0b into main Jan 8, 2024
20 of 23 checks passed
@durran durran deleted the NODE-4687/log-server-selection-with-operation branch January 8, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
4 participants