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

fix(NODE-6067): make topology descriptions JSON stringifiable #4076

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Apr 11, 2024

Description

What is changing?

5.x backport of #4070.

Is there new documentation needed for these changes?

What is the motivation for this change?

Release Highlight

TopologyDescription now properly stringifies itself to JSON

The TopologyDescription class is exposed by the driver in server selection errors and topology monitoring events to provide insight into the driver's current representation of the server's topology and to aid in debugging. However, the TopologyDescription uses Maps internally, which get serialized to {} when JSON stringified. We recommend using Node's util.inspect() helper to print topology descriptions because inspect properly handles all JS types and all types we use in the driver. However, if JSON must be used, the TopologyDescription now provides a custom toJSON() hook:

client.on('topologyDescriptionChanged', ({ newDescription }) => {
   // recommended!
	console.log('topology description changed', inspect(newDescription, { depth: Infinity, colors: true }))

    // now properly prints the entire topology description
	console.log('topology description changed', JSON.stringify(newDescription))
});

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

baileympearson and others added 3 commits April 11, 2024 10:30
@baileympearson baileympearson changed the title fix(NODE-5530): make topology descriptions JSON stringifiable (#4070) fix(NODE-6067): make topology descriptions JSON stringifiable Apr 15, 2024
@baileympearson baileympearson marked this pull request as ready for review April 22, 2024 17:24
@W-A-James W-A-James self-requested a review April 23, 2024 21:30
@W-A-James W-A-James self-assigned this Apr 23, 2024
@W-A-James W-A-James added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 23, 2024
@W-A-James W-A-James added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Apr 24, 2024
@W-A-James W-A-James merged commit 7ae6eac into mongodb:5.x Apr 24, 2024
23 of 25 checks passed
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
Development

Successfully merging this pull request may close these issues.

2 participants