lib/gitlab_exporter/sidekiq.rb in gitlab-exporter-14.5.0 vs lib/gitlab_exporter/sidekiq.rb in gitlab-exporter-15.0.0
- old
+ new
@@ -5,11 +5,11 @@
module GitLab
module Exporter
# A prober for Sidekiq queues
#
# It takes the Redis URL Sidekiq is connected to
- class SidekiqProber
+ class SidekiqProber # rubocop:disable Metrics/ClassLength
# The maximum depth (from the head) of each queue to probe. Probing the
# entirety of a very large queue will take longer and run the risk of
# timing out. But when we have a very large queue, we are most in need of
# reliable metrics. This trades off completeness for predictability by
# only taking a limited amount of items from the head of the queue.
@@ -193,10 +193,11 @@
end
def redis_options
options = {
url: @opts[:redis_url],
+ sentinels: redis_sentinel_options,
connect_timeout: 1,
reconnect_attempts: 0
}
%i[username password].each do |credential|
@@ -205,10 +206,23 @@
options[:id] = nil unless redis_enable_client?
options
end
+ def redis_sentinel_options
+ sentinels = @opts[:redis_sentinels]
+
+ return sentinels unless sentinels.is_a?(Array)
+
+ sentinels.each do |sentinel_config|
+ sentinel_config[:username] = @opts[:redis_sentinel_username] if @opts.key?(:redis_sentinel_username)
+ sentinel_config[:password] = @opts[:redis_sentinel_password] if @opts.key?(:redis_sentinel_password)
+ end
+
+ sentinels
+ end
+
def redis_enable_client?
return true if @opts[:redis_enable_client].nil?
@opts[:redis_enable_client]
end
@@ -219,9 +233,11 @@
Sidekiq.redis do |conn|
@connected = (conn.ping == "PONG")
end
rescue Redis::BaseConnectionError => e
@logger&.error "Error connecting to the Redis: #{e}"
+ pool = self.class.connection_pool[redis_options]
+ pool.reload(&:close)
@connected = false
end
end
end
end