-
Notifications
You must be signed in to change notification settings - Fork 22
fix(pymongo): extend support for more operations #394
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.
great PR ! :)
See my comments, specifically regarding the request payload collection (document/documents)
epsagon/events/pymongo.py
Outdated
@@ -19,6 +19,8 @@ class PyMongoEvent(BaseEvent): | |||
|
|||
ORIGIN = 'pymongo' | |||
RESOURCE_TYPE = 'pymongo' | |||
INSERT_OPERATIONS = ['insert_one', 'insert_many'] |
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.
great putting that in a const.
Would change it to be a tuple instead of a list
epsagon/events/pymongo.py
Outdated
[str(response.inserted_id)] | ||
|
||
if self.resource['operation'] in PyMongoEvent.INSERT_OPERATIONS: | ||
for i in range(len(self.resource['metadata'].get('items', []))): |
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 would move each logic (of insert/query operations) to a separated method to handle the response data
epsagon/events/pymongo.py
Outdated
add_data_if_needed(self.resource['metadata'], 'Items', documents) | ||
|
||
elif self.resource['operation'] in PyMongoEvent.FILTER_OPERATIONS: | ||
add_data_if_needed(self.resource['metadata'], 'Search', documents) |
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 regarding the "Search" key, consider renaming it (we can talk about it)
epsagon/events/pymongo.py
Outdated
} | ||
|
||
if self.resource['operation'] in PyMongoEvent.INSERT_OPERATIONS: | ||
add_data_if_needed(self.resource['metadata'], 'Items', documents) |
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 think there's an issue with the document/documents logic (regarding the insert one/many operations)
Also, the documents param is only relevant for specific operations. So, I think I would add some payload colelction here according to the operation (insert many > so it documents, insert one/update one > document, etc)
epsagon/events/pymongo.py
Outdated
self.resource['metadata']['Results'] = \ | ||
list(response) | ||
|
||
elif self.resource['operation'] in ['update_one']: |
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.
better check if its equal to update_one (if we will have one more similar operation, we can add the "in" check)
epsagon/events/pymongo.py
Outdated
self.resource['metadata']['modified_count'] = \ | ||
response.modified_count | ||
|
||
elif self.resource['operation'] in ['delete_many']: |
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 as update_one comment
epsagon/events/pymongo.py
Outdated
:return: None | ||
""" | ||
|
||
self.resource['metadata']['Filter'] = str( |
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.
should put it directly as str in the handle_request_payload function
epsagon/events/pymongo.py
Outdated
'Collection Name': str(instance.collection.name), | ||
} | ||
|
||
self.handle_request_payload(input_args) |
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.
perfect :)
epsagon/events/pymongo.py
Outdated
input_args = list() | ||
|
||
else: | ||
input_args = args[0] |
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 think the [0] logic should be done inside the handle_request_payload (according to the operation , you can know what to expect in args)
So basically, you would just send "args" as is to handle_request_payload. The handle_request_payload obviously should be called only if there're any args
epsagon/events/pymongo.py
Outdated
INSERT_ONE = 'insert_one' | ||
INSERT_MANY = 'insert_many' | ||
INSERT_OPERATIONS = (INSERT_ONE, INSERT_MANY) | ||
FILTER_OPERATIONS = ['find', 'update_one', 'delete_many'] |
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.
change to tuple
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.
Great :)
🎉 This PR is included in version 1.77.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
https://epsagon.atlassian.net/browse/CS-119