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-1675 Add log messages and tests to CMAP spec #1324

Merged
merged 12 commits into from
Nov 8, 2022

Conversation

kmahar
Copy link
Contributor

@kmahar kmahar commented Oct 18, 2022

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).

This PR includes the following:

  • Add log messages to CMAP which match the events defined in CMAP.
  • Adds JSON/YAML tests for the log messages, utilizing unified format changes made in DRIVERS-1677, DRIVERS-1673: Add general logging specification and command logging #1303.
    • As part of this, I rearranged the existing CMAP tests. Those in the proprietary CMAP format have been moved into a new tests/cmap-format directory, and the logging tests live in a tests/logging directory. Additionally, I moved all the content on the CMAP format tests into a new README in tests/cmap-format and edited the top-level README to discuss the different types of CMAP tests. I don't have strong feelings on the naming or particular organization here, so if anyone prefers something else, let me know. This just seemed like a logical enough way to do it.
  • Adds a description of a client close operation to the unified test format. This is required to be able to test pool close messages. Per a recent conversation with @jmikola I don't believe this warrants a new minor schema version: "Drivers are supposed to raise errors for unsupported operations so I'm not at all concerned about bumping a schema version for it. The reasoning behind schema changes is that drivers might silently ignore new syntax."

The new tests pass in the Rust driver, but there are a few of them I had to skip from connection-pool-options.yml due to options we don't support. So if another driver is able to test these and let me know if they work for you, please let me know:

  • "maxConnecting should be included in connection pool created message when specified"
  • "waitQueueTimeoutMS should be included in connection pool created message when specified"
  • "waitQueueSize should be included in connection pool created message when specified"
  • "waitQueueMultiple should be included in connection pool created message when specified"

For the latter two I wasn't sure if they were worth including given that the options are deprecated, but at least the .NET driver still supports those options so it seemed they would provide value to them. (cc @BorisDog)

I will leave some comments inline.


The YAML and JSON files in this directory are platform-independent tests that
Copy link
Contributor Author

@kmahar kmahar Oct 18, 2022

Choose a reason for hiding this comment

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

this content has been moved unchanged into /tests/cmap-format/README.rst


runOnRequirements:
- topologies:
- single # The number of log messages is different for each topology since there is a connection pool per host.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered writing per-topology versions of these tests but it didn't seem like the extra coverage would have a ton of value assuming drivers have well-abstracted connection pools that don't care about what topology type they live in. it looks like the existing CMAP integration tests also only instruct drivers to only run them against a single host in whatever topology they are connected to.

@kmahar kmahar marked this pull request as ready for review October 18, 2022 23:06
@kmahar kmahar requested review from a team as code owners October 18, 2022 23:06
@kmahar kmahar requested review from jmikola, BorisDog, patrickfreed and jyemin and removed request for a team October 18, 2022 23:06
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Unified changes LGTM although I have one question. Not going to review the CMAP stuff.

@@ -1634,6 +1634,18 @@ specifications:
Client operations that require special handling or are not documented by an
existing specification are described below.

close
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm: is this the first PR introducing spec tests with a client.close operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, from a search through the specs repo the only other occurrences of the close operation I can find are for cursors and change streams. All of those occurrences are in the load balancer tests.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, that operation is already documented in Cursor Operations. Thanks for confirming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI @jmikola I made a small addition to the paragraph here to clarify that entities descended from a closed client should also not be used after a close.

subscriber if it is convenient to do so.

The types used in the structured message definitions below are demonstrative, and drivers MAY use similar types instead so long as the information
is present (e.g. a double instead of an integer, or a string instead of an integer if the structured logging framework does not support numeric types.)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: period at the end of the sentence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved period out of the parentheses

message: "Connection checkout failed"
serverHost: { $$type: string }
serverPort: { $$type: [int, long] }
reason: "An error occurred while trying to establish a connection"
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably should be "An error occurred while trying to establish a new connection" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes good catch, I accidentally omitted the "new" here and in Rust impl. fixed.

@kmahar
Copy link
Contributor Author

kmahar commented Nov 1, 2022

FYI: It came up in driver-devs that Ruby does not close the connection pool when a client is closed. I was thinking about how these tests would work (or not work) for Ruby and I noticed all of the connection-pool-options tests were unnecessarily closing the client and expecting a corresponding log message so I have removed those. I think Ruby will just have to skip the one test that does need the close and write some prose test to cover that log message.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM (minor comment)

serverHost: { $$type: string }
serverPort: { $$type: [int, long] }

# This test exists to probide coverage of checkout failed and pool cleared events.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: provide

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, fixed.


The unstructured form SHOULD be as follows, using the values defined in the structured format above to fill in placeholders as appropriate:

Connection checked out with driver-generated ID {{driverConnectionId}} to {{serverHost}}:{{serverPort}}
Copy link
Contributor

@patrickfreed patrickfreed Nov 1, 2022

Choose a reason for hiding this comment

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

This is kind of a grammar nit, but I think this message reads a bit easier if the "with id" and "to <address>" phrases came before the verb here, since they're describing "Connection". If you drop the "with" part, the issue is a bit more obvious (e.g. "Connection checked out to a:12345" doesn't quite make sense).

Something like "Connection to a:12345 with driver-generated ID checked out" reads a bit better to me. The drawback with that is "Connection" and "checked out" are now separate, though I'm not sure if that's an issue or not. A more dramatic shift that doesn't have either problem could be something like "Connection checked out (driver-generated ID=1, destination=a:12345)".

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I was having a hard time figuring out how to write the english for some of these and it shows here 😅

re-reading this I had a couple thoughts:

  1. I feel like the host/port should come before the ID as it feels more important given that IDs are only unique per-pool/endpoint
  2. maybe "for" would be a better word than to?

I do think keeping the "Connection checked out" part together and at the start of the message is useful so that if you are skimming you can easily see what the message is about from the start of it.

given these WDYT of either of the following:

  1. Connection checked out for endpoint a:12345 with driver-generated ID 123
  2. Connection checked out: endpoint=a:12345, driver-generated ID=123.

(borrowing "endpoint" terminology from elsewhere in CMAP)

Copy link
Contributor

Choose a reason for hiding this comment

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

I kinda like 2. It's consistent and pretty easy to parse visually (and programatically in case a given language can't do structured logs).

"endpoint" is spec language-y though, I'm not sure if it ends up in our API or docs that often. What about just using "address" like the events do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, I updated to the second one (but with address instead of endpoint) and updated some of the other log messages to make the format/phrasing more consistent

@kmahar kmahar requested a review from BorisDog November 3, 2022 21:25
@jyemin jyemin removed their request for review November 7, 2022 17:35
Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM

@kmahar kmahar merged commit d268119 into master Nov 8, 2022
@kmahar kmahar deleted the DRIVERS-1675/cmap-logging branch November 8, 2022 20:32
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.

4 participants