summaryrefslogtreecommitdiff
path: root/lib/gitlab/redis
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /lib/gitlab/redis
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
downloadgitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'lib/gitlab/redis')
-rw-r--r--lib/gitlab/redis/cache.rb15
-rw-r--r--lib/gitlab/redis/queues.rb9
-rw-r--r--lib/gitlab/redis/rate_limiting.rb16
-rw-r--r--lib/gitlab/redis/sessions.rb12
-rw-r--r--lib/gitlab/redis/shared_state.rb8
-rw-r--r--lib/gitlab/redis/wrapper.rb39
6 files changed, 72 insertions, 27 deletions
diff --git a/lib/gitlab/redis/cache.rb b/lib/gitlab/redis/cache.rb
index 98b66080b42..a2c7b5e29db 100644
--- a/lib/gitlab/redis/cache.rb
+++ b/lib/gitlab/redis/cache.rb
@@ -5,12 +5,15 @@ module Gitlab
class Cache < ::Gitlab::Redis::Wrapper
CACHE_NAMESPACE = 'cache:gitlab'
- private
-
- def raw_config_hash
- config = super
- config[:url] = 'redis://localhost:6380' if config[:url].blank?
- config
+ # Full list of options:
+ # https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new
+ def self.active_support_config
+ {
+ redis: pool,
+ compress: Gitlab::Utils.to_boolean(ENV.fetch('ENABLE_REDIS_CACHE_COMPRESSION', '1')),
+ namespace: CACHE_NAMESPACE,
+ expires_in: 2.weeks # Cache should not grow forever
+ }
end
end
end
diff --git a/lib/gitlab/redis/queues.rb b/lib/gitlab/redis/queues.rb
index 9e291a73bb6..e60e59dcf01 100644
--- a/lib/gitlab/redis/queues.rb
+++ b/lib/gitlab/redis/queues.rb
@@ -2,21 +2,12 @@
# We need this require for MailRoom
require_relative 'wrapper' unless defined?(::Gitlab::Redis::Wrapper)
-require 'active_support/core_ext/object/blank'
module Gitlab
module Redis
class Queues < ::Gitlab::Redis::Wrapper
SIDEKIQ_NAMESPACE = 'resque:gitlab'
MAILROOM_NAMESPACE = 'mail_room:gitlab'
-
- private
-
- def raw_config_hash
- config = super
- config[:url] = 'redis://localhost:6381' if config[:url].blank?
- config
- end
end
end
end
diff --git a/lib/gitlab/redis/rate_limiting.rb b/lib/gitlab/redis/rate_limiting.rb
new file mode 100644
index 00000000000..4ae1d55e4ce
--- /dev/null
+++ b/lib/gitlab/redis/rate_limiting.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Redis
+ class RateLimiting < ::Gitlab::Redis::Wrapper
+ # The data we store on RateLimiting used to be stored on Cache.
+ def self.config_fallback
+ Cache
+ end
+
+ def self.cache_store
+ @cache_store ||= ActiveSupport::Cache::RedisCacheStore.new(redis: pool, namespace: Cache::CACHE_NAMESPACE)
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/redis/sessions.rb b/lib/gitlab/redis/sessions.rb
new file mode 100644
index 00000000000..3bf1eb6211d
--- /dev/null
+++ b/lib/gitlab/redis/sessions.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Redis
+ class Sessions < ::Gitlab::Redis::Wrapper
+ # The data we store on Sessions used to be stored on SharedState.
+ def self.config_fallback
+ SharedState
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/redis/shared_state.rb b/lib/gitlab/redis/shared_state.rb
index d62516bd287..1250eabb041 100644
--- a/lib/gitlab/redis/shared_state.rb
+++ b/lib/gitlab/redis/shared_state.rb
@@ -7,14 +7,6 @@ module Gitlab
USER_SESSIONS_NAMESPACE = 'session:user:gitlab'
USER_SESSIONS_LOOKUP_NAMESPACE = 'session:lookup:user:gitlab'
IP_SESSIONS_LOOKUP_NAMESPACE = 'session:lookup:ip:gitlab2'
-
- private
-
- def raw_config_hash
- config = super
- config[:url] = 'redis://localhost:6382' if config[:url].blank?
- config
- end
end
end
end
diff --git a/lib/gitlab/redis/wrapper.rb b/lib/gitlab/redis/wrapper.rb
index 3c8ac07215d..7b804038146 100644
--- a/lib/gitlab/redis/wrapper.rb
+++ b/lib/gitlab/redis/wrapper.rb
@@ -6,6 +6,7 @@
# Rails.
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/string/inflections'
# Explicitly load Redis::Store::Factory so we can read Redis configuration in
@@ -95,6 +96,8 @@ module Gitlab
end
def instrumentation_class
+ return unless defined?(::Gitlab::Instrumentation::Redis)
+
"::Gitlab::Instrumentation::Redis::#{store_name}".constantize
end
end
@@ -111,6 +114,10 @@ module Gitlab
raw_config_hash[:url]
end
+ def db
+ redis_store_options[:db]
+ end
+
def sentinels
raw_config_hash[:sentinels]
end
@@ -150,11 +157,35 @@ module Gitlab
def raw_config_hash
config_data = fetch_config
- if config_data
- config_data.is_a?(String) ? { url: config_data } : config_data.deep_symbolize_keys
- else
- { url: '' }
+ config_hash =
+ if config_data
+ config_data.is_a?(String) ? { url: config_data } : config_data.deep_symbolize_keys
+ else
+ { url: '' }
+ end
+
+ if config_hash[:url].blank?
+ config_hash[:url] = legacy_fallback_urls[self.class.store_name] || legacy_fallback_urls[self.class.config_fallback.store_name]
end
+
+ config_hash
+ end
+
+ # These URLs were defined for cache, queues, and shared_state in
+ # code. They are used only when no config file exists at all for a
+ # given instance. The configuration does not seem particularly
+ # useful - it uses different ports on localhost - but we cannot
+ # confidently delete it as we don't know if any instances rely on
+ # this.
+ #
+ # DO NOT ADD new instances here. All new instances should define a
+ # `.config_fallback`, which will then be used to look up this URL.
+ def legacy_fallback_urls
+ {
+ 'Cache' => 'redis://localhost:6380',
+ 'Queues' => 'redis://localhost:6381',
+ 'SharedState' => 'redis://localhost:6382'
+ }
end
def fetch_config