Fix redis.asyncio sync operations wrapper#782
Merged
lrafeei merged 26 commits intonewrelic:develop-swap-redis-asyncio-commitsfrom Aug 26, 2023
Merged
Conversation
|
|
…s-wrapper' into fix-redis-asyncio-sync-operations-wrapper
* Added separate instrumentation for redis.asyncio.client Merge main branch updates Add tests for newrelic/config.py (newrelic#860) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Modify redis tests * removed redis.asyncio from aioredis instrumentation removed aioredis instrumentation in redis asyncio client removed redis.asyncio from aioredis instrumentation --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com> Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## develop-swap-redis-asyncio-commits #782 +/- ##
=====================================================================
Coverage ? 81.69%
=====================================================================
Files ? 185
Lines ? 18638
Branches ? 3265
=====================================================================
Hits ? 15226
Misses ? 2496
Partials ? 916 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Contributor
lrafeei
reviewed
Jul 25, 2023
lrafeei
approved these changes
Jul 25, 2023
Merged
Contributor
Author
|
@lrafeei |
Contributor
|
@bc291 No worries--I'll reopen this and if you sign the CLA we can get this one merged |
…cio-sync-operations-wrapper
lrafeei
added a commit
that referenced
this pull request
Aug 28, 2023
* Revert "Redis asyncio testing (#881)" (#911) * Revert "Redis asyncio testing (#881)" This reverts commit 05cff1b. * Add spublish to list of commands * Fix redis.asyncio sync operations wrapper (#782) * Fix redis.asyncio sync operations wrapper * Add clean ups * Fixes: - `loop` -> noqa - catch `TimeoutError` on `asyncio.timeout` * Added separate instrumentation for redis.asyncio.client (#808) * Added separate instrumentation for redis.asyncio.client Merge main branch updates Add tests for newrelic/config.py (#860) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Modify redis tests * removed redis.asyncio from aioredis instrumentation removed aioredis instrumentation in redis asyncio client removed redis.asyncio from aioredis instrumentation --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com> Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com> * Modify tests * Tweak tests and instrumentation * Tweak tests to separate aioredis and redis.asyncio * Correctly separate commands to sync/async --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Ahmed <ahmedhropewala@gmail.com> Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com> Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com> * Remove formatting in import --------- Co-authored-by: Błażej Cyrzon <36710760+bc291@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Ahmed <ahmedhropewala@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
redis.asyncio: Fix synchronous methods wrapped in coroutines
Related Github Issue
#623
Testing
Few tests added - I'm not quite sure if put in the right place
Bug reproduction
To reproduce this behaviour sync method of async redis may be used.
As example
redis.pubsub()could be invoked, followed by pattern subscription:This results in
AttributeError: 'coroutine' object has no attribute 'psubscribe':Culprit
Bug perhaps lays here
Logic assumes that every
redis.*interaction is an asynchronous operation and it breaks usage of e.g.pubsub(),monitor(),client()and many more (see solution no 3 below).Solution
inspect.iscoroutinefunction - rejected
inspect.iscoroutinefunctionmay be problematic here because -> coroutine happens after invocation:So we can invoke method prematurely, but I think that's going to break DatastoreTrace
inspect.signature - rejected
Another solution would be to
inspect.signature()of wrapped function, e.g.:but after some investigation this is not reliable across python versions.
predefined sync methods list - imlemented in this PR
Using
_redis_client_methodsand someinspect.signature(wrapped).return_annotationwe can compile sync method list:and simply use that in wrapping function decision.