-
Notifications
You must be signed in to change notification settings - Fork 4
Add ability to configure explain command options #49
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
Add ability to configure explain command options #49
Conversation
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!
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.
Are there any docs or changelog that should go along with this change?
test/test_collection.py
Outdated
self.collection.watch(pipeline=[{"$project": {"tags": 1}}], | ||
batch_size=10, full_document="updateLookup") | ||
last_logger_payload = self.logger.cmd_payload | ||
res = self.explain.watch(pipeline=[{"$project": {"tags": 1}}], | ||
batch_size=10, full_document="updateLookup") | ||
self.assertIn("queryPlanner", res["stages"][0]["$cursor"]) | ||
self.assertTrue(self._recursiveIn("queryPlanner", res)) |
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 actually prefer the previous behavior here because res["stages"][0]["$cursor"]
helps us understand the structure of the explain response. _recursiveIn
makes the command response more of a black box. Can you revert these changes?
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.
self.assertTrue(self._recursiveIn("executionStats", res)) | ||
self.assertTrue(self._recursiveIn("allPlansExecution", res)) | ||
|
||
def test_comment(self): |
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.
Instead of checking the explain result, this test should probably assert that we sent the comment field with the explain comment using a CommandListener.
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.
|
||
def _explain_command(self, command): | ||
command_son = command.get_SON() | ||
explain_command = SON([("explain", command_son)]) | ||
explain_command["verbosity"] = "queryPlanner" | ||
explain_command["verbosity"] = self.verbosity or "queryPlanner" |
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 suggest setting the default verbosity in __init__
.
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.
self.last_cmd_payload = command_son | ||
return self.collection.database.command(explain_command) | ||
|
||
def update_settings(self, verbosity=None, comment=None): |
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.
In PyMongo the Collection object is immutable (the internal settings are configured once at creation and never changed). ExplainableCollection should probably be immutable too to match pymongo.
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.
test/test_collection.py
Outdated
@@ -114,14 +114,15 @@ def test_delete_many(self): | |||
last_cmd_payload = self.explain.last_cmd_payload | |||
self._compare_command_dicts(last_cmd_payload, last_logger_payload) | |||
|
|||
@unittest.skip("Travis does not have replica sets set up yet") |
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 is no longer 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.
Done.
|
||
explain = ExplainableCollection(collection, verbosity="queryPlanner", | ||
comment="I'm a comment") | ||
For more information see the documentation for the explain_ command. |
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 believe there needs to be a blank line after the code block.
test/test_collection.py
Outdated
@@ -118,10 +119,10 @@ def test_watch(self): | |||
res = self.explain.watch() | |||
self.assertIn("queryPlanner", res["stages"][0]["$cursor"]) | |||
self.collection.watch(pipeline=[{"$project": {"tags": 1}}], | |||
batch_size=10, full_document="updateLookup") | |||
batch_size=10, full_document="updateLookup") |
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 change seems off batch_size should align with pipeline.
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.
test/test_collection.py
Outdated
last_logger_payload = self.logger.cmd_payload | ||
res = self.explain.watch(pipeline=[{"$project": {"tags": 1}}], | ||
batch_size=10, full_document="updateLookup") | ||
batch_size=10, full_document="updateLookup") |
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.
Same 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.
Done.
test/test_collection.py
Outdated
self.assertNotIn("comment", self.logger.cmd_payload) | ||
self.explain = ExplainCollection(self.collection, comment="hey, " | ||
"I'm a " | ||
"comment") |
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.
Please fix the string format here. 3 short strings on new lines makes this harder to read. How about:
self.explain = ExplainCollection(self.collection, comment="comment")
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.
No description provided.