Skip to content

PHPLIB-516: Append PHPLIB version information to handshake data #731

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

Merged
merged 1 commit into from
Mar 25, 2020

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Mar 24, 2020

@alcaeus alcaeus requested a review from jmikola March 24, 2020 12:28
@alcaeus alcaeus self-assigned this Mar 24, 2020
Copy link
Member Author

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

A short note on testing: the only way to test this would be to enable the MongoDB debug log and check the handshake data. Even then, we can only check if ext-mongodb gets the additional data for the handshake, as it can't be changed after the first connection due to a limitation in libmongoc. If there are any suggestions on how to efficiently test this, please let me know.

@@ -13,7 +13,8 @@
"php": "^7.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.8"
"ext-mongodb": "^1.8",
"jean85/pretty-package-versions": "^1.2"
Copy link
Member Author

Choose a reason for hiding this comment

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

This provides a better interface around version strings returned by ocramius/package-versions. It is used to provide the current version of this library without having to maintain it in a version constant.

{
if (self::$version === null) {
try {
self::$version = PrettyVersions::getVersion('mongodb/mongodb')->getPrettyVersion();
Copy link
Member Author

Choose a reason for hiding this comment

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

While the package-versions package caches package information when they are installed, I thought it would be best to still cache this data to ensure we're not unnecessarily causing delays on connecting.

}

foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['driver' => ['version' => $value]];
Copy link
Member

Choose a reason for hiding this comment

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

Should we also test platform here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added, but requires a little extra work since we only pass platform information through to the driver.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't realize that when I left my first comment. I see now that PHPLIB is only throwing its own InvalidArgumentException for the two options it merges. Thanks for adding this just the same.

try {
self::$version = PrettyVersions::getVersion('mongodb/mongodb')->getPrettyVersion();
} catch (OutOfBoundsException $e) {
return 'unknown';
Copy link
Member

Choose a reason for hiding this comment

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

I took a look through PrettyVersions and it seems that it doesn't throw anything on its own, so I assume this comes from Ocramius' library. If so, I think there's also a case where UnexpectedValueException could be thrown. Would it be safer to just catch any RuntimeException?

Also, I'm totally on board with not exposing the original exception. I don't think "fix your shit" would go over well with users, especially when it might not be clear which library is generating that message 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to catch any throwable. That exception message (along with not wanting to break a connection to MongoDB because we couldn't determine the version) was the main reason for adding a try-catch block.

'version' => '1.2.3-dev',
'platform' => 'some-platform',
]
.. versionadded:: 1.7
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a note that this is best used for things like wrapping libraries and ODMs rather than applications?

}

foreach ($this->getInvalidStringValues() as $value) {
$options[][] = ['driver' => ['version' => $value]];
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't realize that when I left my first comment. I see now that PHPLIB is only throwing its own InvalidArgumentException for the two options it merges. Thanks for adding this just the same.

@alcaeus alcaeus merged commit 9fa37e7 into mongodb:master Mar 25, 2020
@alcaeus alcaeus deleted the phplib-516 branch March 25, 2020 16:22
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.

2 participants