-
Notifications
You must be signed in to change notification settings - Fork 67
SDAM monitoring updates #379
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
Conversation
| @@ -1,4 +1,5 @@ | |||
| --exclude Sources/MongoSwift/MongoSwiftVersion.swift,Sources/MongoSwiftSync/* | |||
| --exclude .build/* | |||
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.
not sure why this wasn't a problem for me before, maybe a linux only thing?
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.
🤔weird, I don't think I've run into this either
| @@ -1,4 +1,5 @@ | |||
| --exclude Sources/MongoSwift/MongoSwiftVersion.swift,Sources/MongoSwiftSync/* | |||
| --exclude .build/* | |||
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.
🤔weird, I don't think I've run into this either
Sources/MongoSwift/SDAM.swift
Outdated
| self.lastUpdateTime = Date(msSinceEpoch: mongoc_server_description_last_update_time(description)) | ||
| let serverType = String(cString: mongoc_server_description_type(description)) | ||
| // swiftlint:disable:next force_unwrapping | ||
| self.type = ServerType(rawValue: serverType)! // libmongoc will always give us a valid raw value. |
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 wonder if it would be worth adding a .other ServerType case 🤔
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.
A new server type would be a mega breaking change for all drivers I think. The only case I can think of that might introduce one is multi-master, but that might be handled entirely by mongos or something. @mbroadst probably has a better perspective on this.
| public struct ConnectionId: Equatable { | ||
| /// A string representing the host for this connection. | ||
| /// A struct representing a server address, consisting of a host and port. | ||
| public struct Address: Equatable { |
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.
nit: let's either call it ServerAddress or correct the comment to explain this is a generic address. Also, now that we have NIO as a dependency, is there a good reason we aren't just using their SocketAddress? It seems to serve a similar purpose.
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.
done. I added a try! when converting from a mongoc_host_list_t to a SocketAddress, since I figured libmongoc would only contain well-formatted addresses in its server descriptions. Is that a safe assumption to make?
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.
SocketAddress only works on resolved IP addresses, so things like "localhost" or a domain name won't be able to be stored in it, which I think doesn't work for us. As such, I've reverted the commits that enabled its usage in the driver.
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've updated the comment to say a "network address" instead of "server address"
| lhs.lastWriteDate == rhs.lastWriteDate && | ||
| lhs.opTime == rhs.opTime && | ||
| // As per the SDAM spec, only some fields are necessary to compare for equality. | ||
| return lhs.address == rhs.address && |
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.
This will at some point need to account for a stored error on the ServerDescription as well.
Sources/MongoSwift/SDAM.swift
Outdated
| /// Whether every server's wire protocol version range is compatible with MongoSwift's. | ||
| public var compatible: Bool { | ||
| return self.servers.allSatisfy { | ||
| $0.maxWireVersion >= MIN_SUPPORTED_WIRE_VERSION |
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.
This logic is incorrect. From the spec:
A ServerDescription which is not Unknown is incompatible if:
minWireVersion > clientMaxWireVersion, or
maxWireVersion < clientMinWireVersion
Here we are not ignoring Unknown servers, nor are we checking the minWireVersion requirements. Additionally, the reason the error itself is stored is because it will likely change based on what part of this is incompatible, its unclear you'd have that information where you eventually report the error to the user.
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.
Do you think this property is worth having around right now? I'm now starting to realize that it was probably intended to be used as part of server selection error reporting rather than SDAM monitoring.
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.
For now I've just removed it.
9670410 to
5945844
Compare
12f8477 to
f88613e
Compare
This PR introduces a number of updates to the SDAM monitoring API:
Misc. updates:
ConnectionIdrefactored toAddress. This more accurately reflects what is actually stored within the id, and the field name / object returned are flexibly specified in the SDAM monitoring spec:nilonTopologyDescriptionandServerDescriptionhave just been omitted. We can add them back once we have a pure Swift implementation of SDAM if necessary.opTimefromServerDescriptionsince it only needs to be recorded by mongos.compatibleproperty onTopoogyDescriptionas described in the SDAM spec.ServerDescriptionandTopologyDescriptionto just beInts. Rationale:SWIFT-601 changes:
MongoSDAMEventprotocol that is empty at the moment.MongoEventMongoTopologyUpdateEventprotocol:MongoSDAMEventTopologyDescriptionChangedEvent,TopologyOpeningEvent, andTopologyClosedEventMongoServerUpdateEventprotocol:MongoSDAMEventServerDescriptionChangedEvent,ServerOpeningEvent, andServerClosingEventMongoServerHeartbeatEventprotocolMongoSDAMEventServerHeartbeatStartedEvent,ServerHeartbeatSucceededEvent, andServerHeartbeatFailedEventSWIFT-288 was also completed as part of this work.