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

Improve elastic adapter exception handling #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JSCU-CNI
Copy link
Contributor

This PR improves exception handling of the Elastic adapter. Currently when an Elasticsearch endpoint is unreachable rdump will stay stuck in a thread. We have added a threading.excepthook to make sure rdump exists with a non-zero status code. Let us know if you prefer a different method of propagating exceptions in rdump. Currently the stdout is a bit noisey, but at least rdump is no longer stuck.

Steps to reproduce:

rdump foo.rec -w elastic+https://invalid-hostname?index=foo

Copy link

codecov bot commented Oct 31, 2024

Codecov Report

Attention: Patch coverage is 70.58824% with 5 lines in your changes missing coverage. Please review.

Project coverage is 83.84%. Comparing base (c17dc6b) to head (c91c594).

Files with missing lines Patch % Lines
flow/record/adapter/elastic.py 64.28% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #150      +/-   ##
==========================================
- Coverage   83.92%   83.84%   -0.09%     
==========================================
  Files          34       34              
  Lines        3466     3478      +12     
==========================================
+ Hits         2909     2916       +7     
- Misses        557      562       +5     
Flag Coverage Δ
unittests 83.84% <70.58%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +152 to +153
self.queue.put(StopIteration)
self.event.wait()
Copy link
Member

Choose a reason for hiding this comment

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

note that self.queue and self.event here might not exist yet if our __init__ raises an exception, which results that this close() method is called due to a finally block and causing an AttributeError as they are not initialised yet.

That was the reason why we added if hasattr(self, "es") guard, which in hindsight is not very clean.

I think it would be safe to move self.queue = ... and self.event = ... higher up (before self.es = ...) in the __init__ and it would be OK.

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