Skip to content

Commit

Permalink
Debug Redis calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBr committed Jan 15, 2024
1 parent c23168d commit 0e678b0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ruby/lib/ci/queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def from_env(env)
flaky_tests: load_flaky_tests(env['CI_QUEUE_FLAKY_TESTS']),
statsd_endpoint: env['CI_QUEUE_STATSD_ADDR'],
redis_ttl: env['CI_QUEUE_REDIS_TTL']&.to_i || 8 * 60 * 60,
debug_log: env['CI_QUEUE_DEBUG_LOG'],
)
end

Expand All @@ -36,7 +37,7 @@ def initialize(
grind_count: nil, max_duration: nil, failure_file: nil, max_test_duration: nil,
max_test_duration_percentile: 0.5, track_test_duration: false, max_test_failed: nil,
queue_init_timeout: nil, redis_ttl: 8 * 60 * 60, report_timeout: nil, inactive_workers_timeout: nil,
export_flaky_tests_file: nil, warnings_file: nil
export_flaky_tests_file: nil, warnings_file: nil, debug_log: nil,
)
@build_id = build_id
@circuit_breakers = [CircuitBreaker::Disabled]
Expand All @@ -62,6 +63,7 @@ def initialize(
@inactive_workers_timeout = inactive_workers_timeout
@export_flaky_tests_file = export_flaky_tests_file
@warnings_file = warnings_file
@debug_log = debug_log
end

def queue_init_timeout
Expand Down
26 changes: 26 additions & 0 deletions ruby/lib/ci/queue/redis/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ class Base
::SocketError, # https://github.com/redis/redis-rb/pull/631
].freeze

class RedisInstrumentation
def initialize(debug_log)
require 'logger'
@Logger.new(debug_log)
end

def call(command, redis_config)
result = super
@logger.info("#{command}: #{result}")
result
end

def call_pipelined(commands, redis_config)
result = super
@logger.info("#{commands}: #{result}")
result
end
end

def initialize(redis_url, config)
@redis_url = redis_url
if ::Redis::VERSION > "5.0.0"
Expand All @@ -19,13 +38,20 @@ def initialize(redis_url, config)
# Booting a CI worker is costly, so in case of a Redis blip,
# it makes sense to retry for a while before giving up.
reconnect_attempts: [0, 0, 0.1, 0.5, 1, 3, 5],
middlewares: middlewares,
)
else
@redis = ::Redis.new(url: redis_url)
end
@config = config
end

def middlewares
[].tap do |result|
result << RedisInstrumentation.new(config.debug_log) if config.debug_log
end
end

def exhausted?
queue_initialized? && size == 0
end
Expand Down
4 changes: 4 additions & 0 deletions ruby/lib/minitest/queue/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ def parser
self.verbose = true
end

opts.on("--debug-log", "Path to debug log file for e.g. Redis instrumentation") do |path|
self.debug_log = path
end

opts.separator ""
opts.separator " retry: Replays a previous run in the same order."

Expand Down

0 comments on commit 0e678b0

Please sign in to comment.