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

CV2-4952: ClassyCat Error Handling and Metrics #104

Merged
merged 12 commits into from
Aug 13, 2024
Merged

CV2-4952: ClassyCat Error Handling and Metrics #104

merged 12 commits into from
Aug 13, 2024

Conversation

ashkankzme
Copy link
Contributor

@ashkankzme ashkankzme commented Aug 5, 2024

Description

Error handling for ClassyCat using new error handling / exception mechanisms in Presto
ClassyCat modules now raise unhandled "PrestoBaseException" objects that include an http error code to properly respond to consumer requests.

Reference: CV2-4952

How has this been tested?

Has been tested locally and in unit tests

Are there any external dependencies?

No

Have you considered secure coding practices when writing this code?

We return stack traces included in error messages, which raises security concerns.

Copy link
Contributor

@skyemeedan skyemeedan left a comment

Choose a reason for hiding this comment

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

This looks awesome to me! I do think we should still logger.exception() when handling the errors at the top level

lib/model/classycat_classify.py Show resolved Hide resolved
@@ -64,7 +68,10 @@ def get_response(self, message: schemas.Message) -> schemas.GenericItem:
result = self.process(message)
Cache.set_cached_result(message.body.content_hash, result)
except Exception as e:
return self.handle_fingerprinting_error(e)
if isinstance(e, PrestoBaseException):
Copy link
Contributor

Choose a reason for hiding this comment

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

since we are (I think) nicely bubbling up errors to this level, should logger.exception() here so that it will still get logged to Sentry from the presto side?

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 think this exists on line 58, no?

Copy link
Contributor

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 is what capture_custom_messages does. In Presto we are explicitly capturing message so it will go to Sentry only and not normal python logs? If so maybe that capture message argument should be 'error' instead of 'info'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! (changed info to error)

overall, I also think it's better to log errors when they happen. makes debugging easier, and we also won't lose the line number on which the error logging happens. for all of classycat errors, I made sure we log the errors where they happen.


self.assertEqual(result.responseMessage, "Error classifying items: list index out of range")
try:
result = self.classycat_model.process(classify_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

side comment: there is an assertRaises pattern in the unitTest framework that can be helpful for these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great idea, updated

@ashkankzme ashkankzme changed the title Cv2 4952 Cv2 4952: ClassyCat Error Handling and Metrics Aug 5, 2024
@ashkankzme ashkankzme marked this pull request as draft August 5, 2024 22:14
@ashkankzme ashkankzme marked this pull request as ready for review August 6, 2024 16:42
@ashkankzme ashkankzme marked this pull request as draft August 6, 2024 16:42
# Conflicts:
#	lib/model/classycat_classify.py
@ashkankzme ashkankzme marked this pull request as ready for review August 6, 2024 22:15
@ashkankzme ashkankzme changed the title Cv2 4952: ClassyCat Error Handling and Metrics CV2-4952: ClassyCat Error Handling and Metrics Aug 9, 2024
Copy link
Collaborator

@DGaffney DGaffney left a comment

Choose a reason for hiding this comment

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

:shipit:

@ashkankzme ashkankzme merged commit 7cf0f34 into master Aug 13, 2024
2 checks passed
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.

3 participants