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

DRIVERS-2875: add support for TopologyDescriptionChangedEvent to expectEvents #1556

Conversation

W-A-James
Copy link
Contributor

@W-A-James W-A-James commented Mar 25, 2024

  • Updated unified test format spec to detail how assertions on topologyDescriptionChangedEvents should be done
  • Updated schema to support this spec change
  • Added valid pass test for addition to schema
  • Bumped schema version in makefile for unified test runner

Please complete the following before merging:

  • Update changelog.
  • Make sure there are generated JSON files from the YAML test files.
  • Test changes in at least one language driver.
  • Test these changes against all server versions and topologies (including standalone, replica set, sharded
    clusters, and serverless).

@W-A-James
Copy link
Contributor Author

See changes made to the test runner implementation in this PR

@W-A-James W-A-James marked this pull request as ready for review March 26, 2024 01:35
@W-A-James W-A-James requested a review from a team as a code owner March 26, 2024 01:35
@W-A-James W-A-James requested review from jmikola and removed request for a team March 26, 2024 01:35
@W-A-James W-A-James changed the title add support for TopologyDescriptionChangedEvent to expectEvents DRIVERS-2875: add support for TopologyDescriptionChangedEvent to expectEvents Mar 26, 2024
- topologyDescriptionChangedEvent: {} # unknown -> replset no primary
- topologyDescriptionChangedEvent: {} # server connected
- topologyDescriptionChangedEvent: {} # server connected
- topologyDescriptionChangedEvent: {} # server connected
Copy link
Member

Choose a reason for hiding this comment

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

Is this an implicit assumption that the replica set has exactly three members? If so, that should probably be clearly called out in a comment.

I'm not familiar with any of the CMAP and SDAM tests, so if this assumption is blindly made elsewhere then feel free to take no action here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the way we set up our replica-sets for testing via drivers-evergreen-tools, yes this is the assumption we generally make. See also the replica set sdam logging tests.

ignoreExtraEvents: false
events:
- topologyOpeningEvent: {}
- topologyDescriptionChangedEvent: {} # unknown -> replset no primary
Copy link
Member

@jmikola jmikola Mar 27, 2024

Choose a reason for hiding this comment

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

Why doesn't this assert that the description goes from "Unknown" to "ReplicaSetWithPrimary"? If that's possible to assert, then you can potentially stop the entire test after the waitForEvent operation. Add ignoreExtraEvents: true and avoid closing the client entity.

In that case, you could avoid any assumptions about replica set size and subsequent event assertions. That might also make the test more resilient to variations in SDAM monitoring (not every driver uses awaitable hello).


I was initially curious why the TopologyDescription starts as "Unknown", but verified that locally with the PHP driver.

I think it'd also be helpful to call out why the TopologyDescription starts as "Unknown".

Initial TopologyType in the SDAM spec suggests that it would start as "ReplicaSetNoPrimary" (if we assume the URI includes replicaSet).

When I ran this locally with PHP, I did observe an initial "Unknown" state for the previous TopologyDescription; however, I don't see where that's mandated in the spec. Initial ServerDescription in the SDAM Logging/Monitoring spec notes why ServerDescription is initialized to "Unknown" (to avoid a null value in the previous description). I assume that same applies to TopologyDescription. Is that specified anywhere? If not, I'd propose reporting a ticket to get that clarified -- or working it into this ticket and having an SDAM spec owner review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch here on the Initial Topology type. I think the wording of the spec here is pretty clear as it relates to the Initial Topology type, I just happened to miss it when working on this, so I don't think we should assume it always starts as UNKNOWN.
The part that's not entirely clear is whether or not the replicaSet option should be required in the URI when running unified tests against replica sets. It seems that it should be when doing these kinds of spec tests given that, to my knowledge, pretty much all drivers make use of drivers-evergreen-tools scripts for their cluster setups in CI, but that's not specified anywhere. Do you think that's a change I should make here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That being said, I'm in favour of changing that spec test here to expect this replica set to start with ReplicaSetNoPrimary.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced that Initial TopologyType applies to SDAM monitoring events. If it does, then there is evidently an issue with libmongoc.

What did you observe in your driver?

...but that's not specified anywhere. Do you think that's a change I should make here?

I don't see much benefit in doing so, as it'd likely be ignored. There's presently nothing in the unified test format spec that talks about a well-formed URI, and that's not really in the scope of the test format anyway since it'd mainly impact other spec tests (excluding the "valid" test you're cooking up here).

I think it's more reasonable to just document the assumption in the test file here, such that it'd be easier for someone to diagnose a potential failure down the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our driver has the previousDescription hardcoded to UNKNOWN on the first TopologyDescriptionChangedEvent to be emitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why wouldn't the initial TopologyType apply to SDAM monitoring events though? Aren't the monitoring events supposed to give a view of the internal view of the Topology? If so, then it would make sense for them to set the previousDescription field of the first TopologyDescriptionChangedEvent to the internal view of the topology that we get from the connection string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmikola Talked to Shane about it and seems it's just something we left off of the sdam monitoring spec. Will add that clarification in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Why wouldn't the initial TopologyType apply to SDAM monitoring events though?

Closing the loop here. My point was that Initial TopologyType specifies what the initial topology should be but makes no mention of the "Unknown" state that is used for the previousDescription field of the first emitted TopologyDescriptionChangedEvent. The rules for previousDescription seems to exist entirely within the SDAM Monitoring spec.

I wasn't debating whether that's correct or not; merely pointing out that the main SDAM spec doesn't address this.

W-A-James and others added 4 commits March 27, 2024 13:29
…lient-topologyDescriptionChangedEvent.yml

Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
…f github.com:W-A-James/specifications into support-topology-description-changed-in-expectEvents
@W-A-James W-A-James requested a review from a team as a code owner March 29, 2024 19:30
@W-A-James W-A-James requested review from tom-selander and ShaneHarvey and removed request for a team and tom-selander March 29, 2024 19:30
@W-A-James W-A-James requested a review from jmikola April 3, 2024 15:07
eventType: sdam
ignoreExtraEvents: true
events:
- topologyOpeningEvent: {}
Copy link
Member

Choose a reason for hiding this comment

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

The test sets observeEvents: [topologyDescriptionChangedEvent] so this topologyOpeningEvent should be omitted.

previousDescription:
type: "Unknown"
newDescription:
type: "ReplicaSetWithPrimary"
Copy link
Member

Choose a reason for hiding this comment

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

When I run this test in Python, this first event is ReplicaSetNoPrimary, not ReplicaSetWithPrimary:

<TopologyDescriptionChangedEvent topology_id: 66104eba924530e675e287ae changed from:
  <TopologyDescription id: 66104eba924530e675e287ae, topology_type: Unknown, servers: []>, to:
  <TopologyDescription id: 66104eba924530e675e287ae, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('localhost', 27019) server_type: Unknown, rtt: None>]>>

We do this when creating the client because in this case we know ahead of time we are connecting to a replica set (because our test suite adds the replicaSet option.

Copy link
Member

Choose a reason for hiding this comment

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

How about we add "directConnection": true to the client and use type: Single?

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

- client:
id: &client client
uriOptions:
directConnection: true
Copy link
Member

Choose a reason for hiding this comment

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

Assuming the cluster is launched with mongo-orchestration, wouldn't we expect the connection string to include multiple seeds and a replicaSet option?

I expect the multiple seeds would conflict with directConnection, as mentioned in directConnection URI option with multiple seeds or SRV URI.

@ShaneHarvey how did this pass in Python?

Copy link
Member

Choose a reason for hiding this comment

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

The python test suite helper to create a MongoClient always connects with a single seed and only adds the replicaSet option if directConnection is not given (or False):
https://github.com/mongodb/mongo-python-driver/blob/e37394d4029d61f72a02dc465fbfc9afe35a5701/test/utils.py#L570-L579

Copy link
Member

Choose a reason for hiding this comment

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

always connects with a single seed and only adds the replicaSet option if directConnection is not given (or False)

This sounds like something that needs to be clarified in the Unified Test Format spec, when we talk about feeding the test runner with a connection string. I imagine these may be the first unified tests with directConnection, so this hasn't come up before.

…nitoring-logging-and-monitoring.rst

Co-authored-by: Jeremy Mikola <jmikola@gmail.com>
@W-A-James W-A-James requested a review from jmikola April 15, 2024 19:01
@@ -415,6 +415,11 @@ The structure of this object is as follows:
notable exception: if `readPreferenceTags` is specified in this object, the key will map to an array of strings,
each representing a tag set, since it is not feasible to define multiple `readPreferenceTags` keys in the object.

Note also that when specifying `directConnection` as true, the connection string used to
instantiate a client MUST only have a single seed and MUST NOT specify the `replicaSet` option.
See the [`directConnection` specification](../uri-options/uri-options.rst#directconnection-uri-option-with-multiple-seeds-or-srv-uri)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
See the [`directConnection` specification](../uri-options/uri-options.rst#directconnection-uri-option-with-multiple-seeds-or-srv-uri)
See the [URI Options spec](../uri-options/uri-options.rst#directconnection-uri-option-with-multiple-seeds-or-srv-uri)

@jmikola
Copy link
Member

jmikola commented Apr 16, 2024

Feel free to merge with @ShaneHarvey's review. I'd just like to see the spec link text changed.

@W-A-James W-A-James merged commit 688b369 into mongodb:master Apr 17, 2024
4 checks passed
@W-A-James W-A-James deleted the support-topology-description-changed-in-expectEvents branch April 17, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants