Skip to content

Commit 2df54d0

Browse files
fixed connectivity issue
1 parent 59b3716 commit 2df54d0

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

lib/slowlog_check/redis.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ def initialize(opts)
1414
@host = parsed[:host]
1515
@port = (opts[:port] || parsed[:port] || Integer(ENV.fetch('REDIS_PORT', 6379)))
1616

17-
# SSL precedence: explicit opts[:ssl] → URI scheme rediss → truthy ENV REDIS_SSL → false
17+
# SSL precedence:
18+
# 1) explicit opts[:ssl]
19+
# 2) URI scheme rediss://
20+
# 3) hostname implies TLS (master.* or clustercfg.*)
21+
# 4) truthy ENV REDIS_SSL
22+
# 5) default false
1823
@ssl =
1924
if opts.key?(:ssl)
2025
to_bool(opts[:ssl])
2126
elsif parsed[:scheme] == 'rediss'
2227
true
28+
elsif infer_tls_from_host(@host)
29+
true
2330
else
2431
env_truthy?(ENV['REDIS_SSL'])
2532
end
@@ -78,24 +85,21 @@ def replication_group
7885
rg
7986
end
8087

81-
# Keep doubling until Redis returns fewer than requested (we got it all) or we hit 2*MAXLENGTH
88+
# Keep doubling until Redis returns fewer than requested (we got it all) or we hit 2*MAXLENGTH.
8289
# Also expands once immediately if we spot a "zeroeth entry" sentinel.
8390
def slowlog_get(length = 128)
84-
# Hard cap per spec expectation (they assert 2*MAXLENGTH at the extreme)
8591
max_cap = MAXLENGTH * 2
8692

8793
req_len = length
8894
resp = Array(redis_rb.slowlog('get', req_len) || [])
8995

9096
# If first page shows "zeroeth entry", force an expansion pass
91-
force_expand_once = zeroeth_entry?(resp) && req_len < max_cap
92-
93-
if force_expand_once
97+
if zeroeth_entry?(resp) && req_len < max_cap
9498
req_len = [req_len * 2, max_cap].min
9599
resp = Array(redis_rb.slowlog('get', req_len) || [])
96100
end
97101

98-
# Continue expanding while the page is full (== requested) and we haven't hit the cap
102+
# Continue expanding while page is "full"
99103
while resp.length == req_len && req_len < max_cap
100104
req_len = [req_len * 2, max_cap].min
101105
resp = Array(redis_rb.slowlog('get', req_len) || [])
@@ -143,6 +147,15 @@ def infer_cluster_from_host(host)
143147
false
144148
end
145149

150+
# TLS implied by ElastiCache TLS endpoint hostnames:
151+
# - master.<replication-group>… (cluster mode disabled, TLS)
152+
# - clustercfg.<replication-group>… (cluster mode enabled, TLS)
153+
def infer_tls_from_host(host)
154+
return false if host.to_s.empty?
155+
first = host.split('.').first
156+
first == 'master' || first == 'clustercfg'
157+
end
158+
146159
# A “zeroeth entry” (id==0) suggests more data; tests refer to this case explicitly
147160
def zeroeth_entry?(resp)
148161
first = resp.first

0 commit comments

Comments
 (0)