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 frozen input for Redis #2370

Merged
merged 4 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ For a list of available integrations, and their configuration options, please re
| Rack | `rack` | `>= 1.1` | `>= 1.1` | *[Link](#rack)* | *[Link](https://github.com/rack/rack)* |
| Rails | `rails` | `>= 3.2` | `>= 3.2` | *[Link](#rails)* | *[Link](https://github.com/rails/rails)* |
| Rake | `rake` | `>= 12.0` | `>= 12.0` | *[Link](#rake)* | *[Link](https://github.com/ruby/rake)* |
| Redis | `redis` | `>= 3.2` | `>= 3.2` | *[Link](#redis)* | *[Link](https://github.com/redis/redis-rb)* |
| Redis | `redis` | `>= 3.2`, `< 5` | `>= 3.2`, `< 5` | *[Link](#redis)* | *[Link](https://github.com/redis/redis-rb)* |
| Resque | `resque` | `>= 1.0` | `>= 1.0` | *[Link](#resque)* | *[Link](https://github.com/resque/resque)* |
| Rest Client | `rest-client` | `>= 1.8` | `>= 1.8` | *[Link](#rest-client)* | *[Link](https://github.com/rest-client/rest-client)* |
| Sequel | `sequel` | `>= 3.41` | `>= 3.41` | *[Link](#sequel)* | *[Link](https://github.com/jeremyevans/sequel)* |
Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/tracing/contrib/redis/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Integration
include Contrib::Integration

MINIMUM_VERSION = Gem::Version.new('3.2')
MAX_VERSION = Gem::Version.new('5')

# @public_api Changing the integration name or integration options can cause breaking changes
register_as :redis, auto_patch: true
Expand All @@ -26,7 +27,7 @@ def self.loaded?
end

def self.compatible?
super && version >= MINIMUM_VERSION
super && version >= MINIMUM_VERSION && version < MAX_VERSION
end

def new_configuration
Expand Down
5 changes: 2 additions & 3 deletions lib/datadog/tracing/contrib/redis/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ def self.included(base)

# Instance method patch for redis instance
module InstanceMethods
# `options` could be frozen
def initialize(options = {})
options[:redis_instance] = self

super(options)
super(options.merge(redis_instance: self))
end
TonyCTHsu marked this conversation as resolved.
Show resolved Hide resolved
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/datadog/tracing/contrib/redis/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
let(:default_service_name) { 'default-service' }
let(:service_name) { 'multiplex-service' }
let(:redis_url) { "redis://#{test_host}:#{test_port}/#{test_database}" }
let(:client) { Redis.new(url: redis_url) }
let(:redis_options) { { url: redis_url } }
let(:client) { Redis.new(redis_options.freeze) }

before do
Datadog.configure do |c|
Expand Down Expand Up @@ -105,7 +106,8 @@
describe 'when multiplexed configuration is provided via hash' do
let(:default_service_name) { 'default-service' }
let(:service_name) { 'multiplex-service' }
let(:client) { Redis.new(host: test_host, port: test_port, db: test_database) }
let(:redis_options) { { host: test_host, port: test_port, db: test_database } }
let(:client) { Redis.new(redis_options.freeze) }

before do
Datadog.configure do |c|
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/tracing/contrib/redis/integration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
Datadog.registry[:redis].reset_configuration!
without_warnings { Datadog.configuration.reset! }
end

let(:redis) { Redis.new(host: host, port: port) }
let(:redis_options) { { host: host, port: port } }
let(:redis) { Redis.new(redis_options.freeze) }
let(:host) { ENV.fetch('TEST_REDIS_HOST', '127.0.0.1') }
let(:port) { ENV.fetch('TEST_REDIS_PORT', 6379).to_i }

Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/tracing/contrib/redis/miniapp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
Datadog.configure_onto(redis, service_name: 'test-service')
end

let(:redis) { Redis.new(host: host, port: port) }
let(:redis_options) { { host: host, port: port } }
let(:redis) { Redis.new(redis_options.freeze) }
let(:host) { ENV.fetch('TEST_REDIS_HOST', '127.0.0.1') }
let(:port) { ENV.fetch('TEST_REDIS_PORT', 6379).to_i }

Expand Down
6 changes: 4 additions & 2 deletions spec/datadog/tracing/contrib/redis/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
end

shared_examples_for 'a Redis driver' do |driver|
let(:redis) { Redis.new(host: host, port: port, driver: driver) }
let(:redis_options) { { host: host, port: port, driver: driver } }
let(:redis) { Redis.new(redis_options.freeze) }
let(:host) { ENV.fetch('TEST_REDIS_HOST', '127.0.0.1') }
let(:port) { ENV.fetch('TEST_REDIS_PORT', 6379).to_i }

Expand All @@ -39,7 +40,8 @@
end

shared_context 'password-protected Redis server' do
let(:redis) { Redis.new(host: host, port: port, driver: driver, password: password) }
let(:redis_options) { { host: host, port: port, driver: driver, password: password } }
let(:redis) { Redis.new(redis_options.freeze) }
let(:password) { 'foobar' }

before do
Expand Down