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

fix: do not expose auth params with Redis 5 #1370

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zvkemp
Copy link
Contributor

@zvkemp zvkemp commented Jan 27, 2025

Redis 5 is a wrapper around RedisClient, so the middleware-based instrumentation (intended for RedisClient) applies here.

  • The largest issue this fixes is that AUTH params are exposed as span attributes at runtime when using Redis 5. Redis commands are not case sensitive, so making the matcher insensitive corrects the issue.
  • Other changes are test-only:
    • the expectations found in instrumentation/redis/test/opentelemetry/instrumentation/redis/patches/client_test.rb largely apply to Redis v4 and Redis v5 equally, though technically the patches are not the thing under test for Redis v5. It's possible this file should be renamed; it may be more clear to group the tests based on their API rather than which patch/middleware applies.
    • The expectations that do not apply equally have been branched using a redis_gte_5? helper method.
    • queue method invocations (deprecated in v4, removed in v5) have been replaced with pipelined
    • Several of the middleware tests (i.e. instrumentation/redis/test/opentelemetry/instrumentation/redis_client_test.rb) were not being run with the correct RedisClient api (when using Redis v4, Redis.new does not use RedisClient internally).

@@ -297,7 +338,7 @@ def redis_with_auth(redis_options = {})
_(exporter.finished_spans.size).must_equal 3

set_span = exporter.finished_spans[0]
_(set_span.name).must_equal 'AUTH'
_(set_span.name).must_equal(redis_gte_5? ? 'PIPELINED' : 'AUTH')
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may want to look into splitting these tests up. I know it will lead to duplication but conditional logic in tests that go beyond using skip become difficult to reason about IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to individually duplicate the tests that should be forked, or duplicate the file entirely for v5?

redis_options[:host] = redis_host
redis_options[:port] = redis_port
RedisClient.new(**redis_options)
redis_options[:password] ||= password
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are these lazily initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seemed appropriate not to clobber the options from the argument if they are given — the redis_with_auth(host: 'example.com' ... test fails without this.


skip('FIXME: what is this intended to test?')
Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed this skip during my last review.

I think what the intent was was to ensure the span had the net.peer.* attributes where captured during a network failure to execute the auth command.

Are there changes in how the driver works that would make this impossible to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, forgot to follow up on that one. RedisClient tries to do the connect before any of the middlewares are invoked, so we don't get a span here under that implementation. I don't think it's within the scope of the PR to change that behavior (previously, the test was erroneously running the RedisV4 client instrumentation), but I didn't want to complete clobber the expectations (these still exist in the other test file). I can clarify the comment so that if that span is ever added for RedisClient, it should have those attributes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. In that case then I think it's fine to delete the test since we won't be able to get a span generated from it.

Additionally:
- Add a redis 5 appraisal
- use RedisClient in RedisClient tests
@zvkemp
Copy link
Contributor Author

zvkemp commented Jan 29, 2025

@arielvalentin thanks for your feedback; I clarified some of the test changes.

@kaylareopelle kaylareopelle linked an issue Jan 29, 2025 that may be closed by this pull request
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this, @zvkemp!

it may be more clear to group the tests based on their API rather than which patch/middleware applies.

I like this idea. I don't think refactoring the tests needs to be accomplished in this PR. What do you think about opening an issue to save this work for a future date?

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.

Redis Gem 5.x Support
3 participants