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

Add queue overflow handler in asyncsender. #156

Merged
merged 4 commits into from
Jun 24, 2020
Merged

Add queue overflow handler in asyncsender. #156

merged 4 commits into from
Jun 24, 2020

Conversation

pguz
Copy link
Contributor

@pguz pguz commented Jan 29, 2020

Hi,

In order to guarantee that the logging process won't block under any circumstance the app, queue_circular flag can be used. In that case it can cause loss of events if the queue fills up completely.

However sometimes there is a need to handle such cases in some way. That's why I propose adding queue_overflow_handler parameter to asyncsender.

Please consider my pull request.

Cheers!

@coveralls
Copy link

coveralls commented Jan 29, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 478bd02 on pguz:queue_overflow_handler into eb68481 on fluent:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.7%) to 99.191% when pulling 50119c5 on pguz:queue_overflow_handler into a37f313 on fluent:master.

@pguz pguz requested a review from arcivanov January 29, 2020 13:03
Copy link
Member

@arcivanov arcivanov left a comment

Choose a reason for hiding this comment

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

Please add tests to cover and see comments inline.

@@ -132,5 +135,13 @@ def _send_loop(self):
finally:
self._close()

def _call_queue_overflow_handler(self, discarded_bytes):
try:
if self._queue_overflow_handler:
Copy link
Member

Choose a reason for hiding this comment

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

I don't like checks like that in the critical paths, as it's going to be repeated every call.
Can we push it up into the constructor like we do here https://github.com/fluent/fluent-logger-python/blob/master/fluent/handler.py#L86?

Copy link
Member

@arcivanov arcivanov left a comment

Choose a reason for hiding this comment

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

We don't support Python 2 anymore, there is no need for these changes.

UPD: Nevermind, we still do. :)

@pguz
Copy link
Contributor Author

pguz commented Jan 30, 2020

I have just added improved test.

@pguz pguz requested a review from arcivanov February 5, 2020 13:01
@arcivanov
Copy link
Member

I'm travelling and will try to get to this tonight.

@pguz
Copy link
Contributor Author

pguz commented Feb 20, 2020

up

@@ -109,7 +114,8 @@ def _send(self, bytes_):
if self._queue_circular and self._queue.full():
# discard oldest
try:
self._queue.get(block=False)
discarded_bytes = self._queue.get(block=False)
self._queue_overflow_handler(discarded_bytes)
Copy link
Member

Choose a reason for hiding this comment

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

This particular line concerns me a bit. If self._queue_overflow_handler raises an Empty, it's going to go into pass too.

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 have just resolved it. I hope it does a job.

@arcivanov
Copy link
Member

@pguz sorry, it was Pending review for two weeks now, because I always forget to actually submit the review :(

@pguz
Copy link
Contributor Author

pguz commented Feb 24, 2020

Locally I am not receiving these errors. Is it testing environment issue?

@arcivanov
Copy link
Member

Nope, that's a dependency issue, i.e. your local testing environment issue :)

Paweł Guz added 3 commits February 24, 2020 12:23
Signed-off-by: Paweł Guz <pawel.guz@socialwifi.com>
Signed-off-by: Paweł Guz <pawel.guz@socialwifi.com>
Signed-off-by: Paweł Guz <pawel.guz@socialwifi.com>
@jgoclawski
Copy link

Hi @arcivanov, this PR looks like a nice addition. Would you have any hints as to why one test fails only o Python 2.7 on Travis? What can be done to move this forward?

FAIL: test_simple (tests.test_asynchandler.TestHandlerWithCircularQueueHandler)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/fluent/fluent-logger-python/tests/test_asynchandler.py", line 371, in test_simple
    log.info({'cnt': 2, 'from': 'userA', 'to': 'userB'})
AssertionError: QueueOverflowException not raised

Signed-off-by: pguz <pawelguz@gmail.com>
@pguz
Copy link
Contributor Author

pguz commented May 25, 2020

Hi, I fixed this issue writing more defensive test. QueueOverflowException not raised error was not caused by python2.7 itself, but rather multithreading issues. We cannot be sure that QueueOverflowException is always thrown, that's why in the last commit I assumed that this exception may not be thrown, however I wrapped in print statement number of times this exception is excepted to be thrown.

print('Exception raised: {} (expected 3)'.format(exc_counter))

We can see that in newer series of tests for python 2.7 tests are passing and even the condition which was not passed last time is passing now. However this time the problematic condition would not pass pypy3.6-7.1.1 test. However due to defensive nature of tests pypy3.6-7.1.1 tests are passing. I am sure that running tests one more time for pypy3.6-7.1.1 tests would pass the problematic condition. It is all about multithreading.

@pguz
Copy link
Contributor Author

pguz commented Jun 22, 2020

up

@arcivanov arcivanov merged commit d1b81ba into fluent:master Jun 24, 2020
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.

4 participants