Skip to content

Commit

Permalink
Develop redis addons (#888)
Browse files Browse the repository at this point in the history
* 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>

* Redis asyncio testing (#881)

* Add/modify redis asyncio tests

* Change to psubscribe

* Tweak redis async tests/instrumentation

* [Mega-Linter] Apply linters fixes

* Push empty commit

* Exclude older instrumentation from coverage

* Resolve requested testing changes

* Tweak async pubsub test

* Fix pubsub test

---------

Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>

* Remove aioredis and aredis from tox (#891)

* Remove aioredis and aredis from tox

* Add aredis and aioredis to coverage ignore

* Push empty commit

* Fix codecov ignore file

---------

Co-authored-by: Ahmed <ahmedhropewala@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: lrafeei <lrafeei@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 10, 2023
1 parent 4b3768b commit 17f8937
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 82 deletions.
24 changes: 13 additions & 11 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
ignore:
- "newrelic/packages/**/*"
- "newrelic/packages/*"
- "newreilc/hooks/component_sentry.py"
- "newrelic/hooks/adapter_meinheld.py"
- "newrelic/admin/*"
- "newrelic/console.py"
- "newrelic/hooks/adapter_flup.py"
- "newrelic/hooks/adapter_meinheld.py"
- "newrelic/hooks/adapter_paste.py"
- "newrelic/hooks/component_piston.py"
- "newrelic/hooks/database_oursql.py"
- "newrelic/hooks/database_psycopg2ct.py"
- "newrelic/hooks/datastore_aioredis.py"
- "newrelic/hooks/datastore_aredis.py"
- "newrelic/hooks/datastore_motor.py"
- "newrelic/hooks/datastore_pyelasticsearch.py"
- "newrelic/hooks/external_pywapi.py"
- "newrelic/hooks/datastore_umemcache.py"
- "newrelic/hooks/external_dropbox.py"
- "newrelic/hooks/external_facepy.py"
- "newrelic/hooks/external_pywapi.py"
- "newrelic/hooks/external_xmlrpclib.py"
- "newrelic/hooks/framework_pylons.py"
- "newrelic/hooks/framework_web2py.py"
- "newrelic/hooks/middleware_weberror.py"
- "newrelic/hooks/framework_webpy.py"
- "newrelic/hooks/datastore_motor.py"
- "newrelic/hooks/database_oursql.py"
- "newrelic/hooks/database_psycopg2ct.py"
- "newrelic/hooks/datastore_umemcache.py"
- "newrelic/admin/*"
- "newrelic/console.py"
- "newrelic/hooks/middleware_weberror.py"
- "newrelic/packages/*"
- "newrelic/packages/**/*"
6 changes: 4 additions & 2 deletions newrelic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2674,12 +2674,14 @@ def _process_module_builtin_defaults():
"aioredis.connection", "newrelic.hooks.datastore_aioredis", "instrument_aioredis_connection"
)

# Redis v4.2+
_process_module_definition(
"redis.asyncio.client", "newrelic.hooks.datastore_aioredis", "instrument_aioredis_client"
"redis.asyncio.client", "newrelic.hooks.datastore_redis", "instrument_asyncio_redis_client"
)

# Redis v4.2+
_process_module_definition(
"redis.asyncio.commands", "newrelic.hooks.datastore_aioredis", "instrument_aioredis_client"
"redis.asyncio.commands", "newrelic.hooks.datastore_redis", "instrument_asyncio_redis_client"
)

_process_module_definition(
Expand Down
23 changes: 18 additions & 5 deletions newrelic/hooks/datastore_aioredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ def _nr_wrapper_AioRedis_method_(wrapped, instance, args, kwargs):
# Method will return synchronously without executing,
# it will be added to the command stack and run later.
aioredis_version = get_package_version_tuple("aioredis")
if aioredis_version and aioredis_version < (2,):
# This conditional is for versions of aioredis that are outside
# New Relic's supportability window but will still work. New
# Relic does not provide testing/support for this. In order to
# keep functionality without affecting coverage metrics, this
# segment is excluded from coverage analysis.
if aioredis_version and aioredis_version < (2,): # pragma: no cover
# AioRedis v1 uses a RedisBuffer instead of a real connection for queueing up pipeline commands
from aioredis.commands.transaction import _RedisBuffer

Expand All @@ -72,8 +77,6 @@ def _nr_wrapper_AioRedis_method_(wrapped, instance, args, kwargs):
# AioRedis v2 uses a Pipeline object for a client and internally queues up pipeline commands
if aioredis_version:
from aioredis.client import Pipeline
else:
from redis.asyncio.client import Pipeline
if isinstance(instance, Pipeline):
return wrapped(*args, **kwargs)

Expand Down Expand Up @@ -137,7 +140,12 @@ async def wrap_Connection_send_command(wrapped, instance, args, kwargs):
return await wrapped(*args, **kwargs)


def wrap_RedisConnection_execute(wrapped, instance, args, kwargs):
# This wrapper is for versions of aioredis that are outside
# New Relic's supportability window but will still work. New
# Relic does not provide testing/support for this. In order to
# keep functionality without affecting coverage metrics, this
# segment is excluded from coverage analysis.
def wrap_RedisConnection_execute(wrapped, instance, args, kwargs): # pragma: no cover
# RedisConnection in aioredis v1 returns a future instead of using coroutines
transaction = current_transaction()
if not transaction:
Expand Down Expand Up @@ -205,6 +213,11 @@ def instrument_aioredis_connection(module):
if hasattr(module.Connection, "send_command"):
wrap_function_wrapper(module, "Connection.send_command", wrap_Connection_send_command)

if hasattr(module, "RedisConnection"):
# This conditional is for versions of aioredis that are outside
# New Relic's supportability window but will still work. New
# Relic does not provide testing/support for this. In order to
# keep functionality without affecting coverage metrics, this
# segment is excluded from coverage analysis.
if hasattr(module, "RedisConnection"): # pragma: no cover
if hasattr(module.RedisConnection, "execute"):
wrap_function_wrapper(module, "RedisConnection.execute", wrap_RedisConnection_execute)
Loading

0 comments on commit 17f8937

Please sign in to comment.