Skip to content

Commit

Permalink
Merge pull request #3810 from jlledom/rename-redis-size
Browse files Browse the repository at this point in the history
Rename `:size` back to `:pool_size`
  • Loading branch information
jlledom committed May 28, 2024
2 parents 5b43959 + 45c8c0c commit db75972
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/lib/system/redis_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class RedisPool

def initialize(config = {})
cfg = config.to_h
pool_config = cfg.extract!(:size, :pool_timeout)
@pool = ConnectionPool.new(size: pool_config[:size] || 5, timeout: pool_config[:pool_timeout] || 5 ) do
pool_config = cfg.extract!(:pool_size, :pool_timeout)
@pool = ConnectionPool.new(size: pool_config[:pool_size] || 5, timeout: pool_config[:pool_timeout] || 5 ) do
Redis.new(cfg)
end
end
Expand Down
1 change: 0 additions & 1 deletion app/lib/three_scale/redis_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def initialize(redis_config = {})
raw_config = (redis_config || {}).deep_symbolize_keys
sentinels = raw_config.delete(:sentinels).presence
raw_config.delete_if { |key, value| value.blank? }
raw_config[:size] ||= raw_config.delete(:pool_size) if raw_config.key?(:pool_size)
uri = URI.parse(raw_config[:url].to_s)
raw_config[:db] ||= uri.path[1..]
raw_config[:name] ||= uri.host if sentinels
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def cache_store_config

initializer :load_configs, before: :load_config_initializers do
config.backend_client = { max_tries: 5 }.merge(config_for(:backend).symbolize_keys)
config.redis = config.sidekiq = config_for(:redis)
config.redis = config_for(:redis)
config.s3 = config_for(:amazon_s3)
config.three_scale.oauth2 = config_for(:oauth2)
end
Expand Down
2 changes: 1 addition & 1 deletion config/examples/backend_redis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base: &default
url: "<%= ENV.fetch('BACKEND_REDIS_URL', 'redis://localhost:6379/6') %>"
timeout: <%= ENV.fetch('BACKEND_REDIS_TIMEOUT', 1) %>
size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_timeout: 5 # this is in seconds
sentinels: "<%= ENV['BACKEND_REDIS_SENTINEL_HOSTS'] %>"
sentinel_username: <%= ENV['BACKEND_REDIS_SENTINEL_USERNAME'].to_json %>
Expand Down
2 changes: 1 addition & 1 deletion config/examples/redis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
base: &default
url: "<%= ENV.fetch('REDIS_URL', 'redis://localhost:6379/1') %>"
size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_timeout: 5 # this is in seconds
sentinels: "<%= ENV['REDIS_SENTINEL_HOSTS'] %>"
sentinel_username: <%= ENV['REDIS_SENTINEL_USERNAME'].to_json %>
Expand Down
13 changes: 11 additions & 2 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
require 'three_scale/sidekiq_retry_support'
require 'three_scale/sidekiq_logging_middleware'

REDIS_PARAMS_WHITELIST = %i[username password db id timeout read_timeout write_timeout connect_timeout ssl
custom ssl_params driver protocol client_implementation command_builder inherit_socket
reconnect_attempts middlewares circuit_breaker sentinels sentinel_password
sentinel_username role name url].freeze

def sanitize_redis_config(cfg)
cfg.slice(*REDIS_PARAMS_WHITELIST)
end

Sidekiq::Client.try(:reliable_push!) unless Rails.env.test?

Rails.application.config.to_prepare do
Sidekiq.configure_server do |config|
config.try(:reliable!)

config.redis = ThreeScale::RedisConfig.new(System::Application.config.sidekiq).config
config.redis = sanitize_redis_config(ThreeScale::RedisConfig.new(System::Application.config.redis).config)

config.logger.formatter = Sidekiq::Logger::Formatters::Pretty.new

Expand Down Expand Up @@ -44,7 +53,7 @@

Rails.application.config.to_prepare do
Sidekiq.configure_client do |config|
config.redis = ThreeScale::RedisConfig.new(System::Application.config.sidekiq).config
config.redis = sanitize_redis_config(ThreeScale::RedisConfig.new(System::Application.config.redis).config)

config.client_middleware do |chain|
chain.add ThreeScale::SidekiqLoggingMiddleware
Expand Down
2 changes: 1 addition & 1 deletion openshift/system/config/backend_redis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
production:
url: "<%= ENV.fetch('BACKEND_REDIS_URL', 'redis://backend-redis:6379') %>"
timeout: <%= ENV.fetch('REDIS_BACKEND_TIMEOUT', 1) %>
size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_timeout: 5 # this is in seconds
sentinels: "<%= ENV['BACKEND_REDIS_SENTINEL_HOSTS'] %>"
sentinel_username: <%= ENV['BACKEND_REDIS_SENTINEL_USERNAME'].to_json %>
Expand Down
2 changes: 1 addition & 1 deletion openshift/system/config/redis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
production:
url: "<%= ENV.fetch('REDIS_URL', 'redis://system-redis/1') %>"
size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_size: <%= ENV.fetch('RAILS_MAX_THREADS', 5) %>
pool_timeout: 5 # this is in seconds
sentinels: "<%= ENV['REDIS_SENTINEL_HOSTS'] %>"
sentinel_username: <%= ENV['REDIS_SENTINEL_USERNAME'].to_json %>
Expand Down
4 changes: 2 additions & 2 deletions test/unit/system/redis_pool_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class System::RedisPoolTest < ActiveSupport::TestCase
test 'config' do
ConnectionPool.expects(:new).with(timeout: 5, size: 5).at_least_once
pool = System::RedisPool.new
System::RedisPool.new
ConnectionPool.expects(:new).with(size: 3, timeout: 7).at_least_once
pool = System::RedisPool.new(size: 3, pool_timeout: 7)
System::RedisPool.new(pool_size: 3, pool_timeout: 7)
end

test 'delegation' do
Expand Down
7 changes: 0 additions & 7 deletions test/unit/three_scale/redis_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ class RedisConfigTest < ActiveSupport::TestCase
assert_not config.key? :name
end

test ':pool_size is renamed to :size' do
config = RedisConfig.new(pool_size: 5)

assert config.key? :size
assert_equal 5, config[:size]
end

test "it takes given ca_file when provided" do
value = 'any_value'
raw_config = { url: 'rediss://my-secure-redis/1', ssl_params: {}}
Expand Down

0 comments on commit db75972

Please sign in to comment.