-
Notifications
You must be signed in to change notification settings - Fork 244
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
DRIVERS-2875: add support for TopologyDescriptionChangedEvent to expectEvents #1556
Conversation
See changes made to the test runner implementation in this PR |
...ied-test-format/tests/valid-pass/expectedEventsForClient-topologyDescriptionChangedEvent.yml
Outdated
Show resolved
Hide resolved
- topologyDescriptionChangedEvent: {} # unknown -> replset no primary | ||
- topologyDescriptionChangedEvent: {} # server connected | ||
- topologyDescriptionChangedEvent: {} # server connected | ||
- topologyDescriptionChangedEvent: {} # server connected |
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.
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.
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.
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 |
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 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.
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.
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?
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.
That being said, I'm in favour of changing that spec test here to expect this replica set to start with ReplicaSetNoPrimary
.
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.
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.
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.
Our driver has the previousDescription
hardcoded to UNKNOWN
on the first TopologyDescriptionChangedEvent
to be emitted.
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 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.
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.
@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.
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 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.
…lient-topologyDescriptionChangedEvent.yml Co-authored-by: Jeremy Mikola <[email protected]>
…f github.com:W-A-James/specifications into support-topology-description-changed-in-expectEvents
eventType: sdam | ||
ignoreExtraEvents: true | ||
events: | ||
- topologyOpeningEvent: {} |
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.
The test sets observeEvents: [topologyDescriptionChangedEvent]
so this topologyOpeningEvent should be omitted.
previousDescription: | ||
type: "Unknown" | ||
newDescription: | ||
type: "ReplicaSetWithPrimary" |
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.
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.
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.
How about we add "directConnection": true
to the client and use type: Single
?
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.
LGTM! Python tests are passing here: https://spruce.mongodb.com/version/66107586f9da6e00077e3ff1/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC
...e/server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.rst
Show resolved
Hide resolved
- client: | ||
id: &client client | ||
uriOptions: | ||
directConnection: true |
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.
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?
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.
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
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.
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 <[email protected]>
@@ -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) |
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.
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) |
Feel free to merge with @ShaneHarvey's review. I'd just like to see the spec link text changed. |
topologyDescriptionChangedEvents
should be donePlease complete the following before merging:
clusters, and serverless).