-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix configure_onto when redis instance is early initialized #3278
Conversation
06eb7d6
to
294e11a
Compare
👋 Thanks @Drowze . I can reproduced the issue reported, it seems like Redis 3 and 4 are impacted. The fix seems feasible and I would like to move forward with test provided. 😄 Let me know how I can help. |
Hey @TonyCTHsu thank you very much for taking a look at the issue and even providing a test-case for it! (I wasn't sure about testing it as it was related to the patch lifecycle - looks like adding a new rake task was the way to go!) Looking forward to v1.18.0 now 😄 |
require 'ddtrace' | ||
|
||
# The regression task must be a standalone task due to the life cycle of patcher | ||
RSpec.describe 'Regression', skip: Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5') ? 'Not supported' : false do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a regression, or just a test to ensure that Redis < 5 can be patched if initialized before Datadog?
require 'ddtrace' | ||
|
||
# The regression task must be a standalone task due to the life cycle of patcher | ||
RSpec.describe 'Regression', skip: Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5') ? 'Not supported' : false do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in Rails > 5 that makes this test not necessary anymore? Did Redis fix something internally that makes it work?
If so, this knowledge should be captured in a comment in either lib/datadog/tracing/contrib/redis/patcher.rb
or lib/datadog/tracing/contrib/redis/integration.rb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @marcotc 👋
Thank you for your comment! It made me realize that my changes were NOT actually working for configure_onto
for Redis >=5. Ops!
(please note: no Rails involved here!)
Added a couple commits:
@marcotc @TonyCTHsu can you have another look please? EDIT: just rebased with latest master as I saw some failed tests on ruby 3.3 (non related to this PR) |
c6a7dd2
to
292ad54
Compare
5153b58
to
e4e2838
Compare
|
||
Datadog.configuration.tracing[:redis, redis_config.server_url].to_h.merge(custom) | ||
def resolve(config) | ||
# support both: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! @Drowze to make this work for Redis 5+. However, I was not entirely sure about supporting it because we want to encourage user to leverage the Redis 5+ public interface with
Redis.new(..., custom: { datadog: { ... } })
Furthermore, there is another concern: We have made our redis patcher to detect different scenarios because the target, client instance, was harboured within the redis gem and extracted redis-client
after version 5. Which means redis-client
could be installed without redis
( an example would be Sidekiq
7) . In such scenario, this line from patcher would be broken because of missing Redis
constant.
Things get a bit tricky when using standalone redis-client
, because the client instance can be interacted with directly.
require 'redis_client'
redis_client = RedisClient.new
redis_client.call("PING")
They might want to pin the client instance directly like this (which currently is not supported):
require 'redis_client'
redis_client = RedisClient.new
Datadog.configure_onto(redis_client, ...)
redis_client.call("PING")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @TonyCTHsu 👋
Based on your reply, I understand that when using Redis 5+, the following no longer works (and is no longer supported):
redis = Redis.new
Datadog.configure_onto(redis, service_name: 'my-redis')
I'm updating now the PR based on that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, would we event want to support the following? (just wondering - I prefer to keep that out of the scope of this PR)
require 'redis_client'
redis_client = RedisClient.new
Datadog.configure_onto(redis_client, ...)
redis_client.call("PING")
My feeling is that, since configure_onto
is not supported on redis 5+, it would be confusing to have it working with redis-client. Also because I believe redis-client can be initialized with custom options... i.e.:
require 'redis_client'
redis_client = RedisClient.new(custom_options: { datadog: { ... } })
redis_client.call("PING")
e4e2838
to
c25be38
Compare
c25be38
to
28f89fc
Compare
28f89fc
to
9da9405
Compare
Also add multiple tests for custom tracing options at instance level: - tests for custom tracing options with Datadog.configure_onto (for redis < 5) - add tests for custom tracing options with redis-client's `custom` options (for redis >= 5)
e93d1b2
to
21fcf15
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #3278 +/- ##
==========================================
- Coverage 98.25% 98.24% -0.01%
==========================================
Files 1262 1263 +1
Lines 73606 73699 +93
Branches 3445 3455 +10
==========================================
+ Hits 72319 72409 +90
- Misses 1287 1290 +3 ☔ View full report in Codecov by Sentry. |
Hey! 👋 Sorry for the long wait to come back here - just updated this PR by:
I think the changes in this PR should make the differences between Redis 4 and Redis 5 tracing at instance level a bit more clear :) |
👋 Thanks @Drowze , I have carried on with the implementation, with some changes (I also merged
I wonder if you could remind me if I am missing anything? Would you be able to validate this change on your project to confirm the issue being fixed? If yes, I would ask @marcotc for another round of review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of small suggestions!
Co-authored-by: May Lee <mayl@alumni.cmu.edu>
👋 @Drowze , |
What does this PR do?
Should fix #3277
Motivation:
Datadog.configure_onto doesn't work if the Redis instance was initialized before Datadog redis tracing is configured.
Additional Notes:
None.
How to test the change?
It is hard to automatically test this, but to manually test, simply use
Datadog.configure_onto
in a Redis instance that was initialized before the Redis patch is applied (i.e. before the Datadog Redis tracing is configured).For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance
.