Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ruby/lib/ci/queue/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'ci/queue/redis/test_time_record'
require 'ci/queue/redis/test_duration_moving_averages'
require 'ci/queue/redis/update_test_duration_moving_average'
require 'ci/queue/redis/key_shortener'

module CI
module Queue
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/ci/queue/redis/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def master_worker_id
attr_reader :redis, :redis_url

def key(*args)
['build', build_id, *args].join(':')
KeyShortener.key(config.build_id, *args)
end

def build_id
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/ci/queue/redis/build_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def record_stats(stats, pipeline: redis)
end

def key(*args)
['build', config.build_id, *args].join(':')
KeyShortener.key(config.build_id, *args)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/ci/queue/redis/grind_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def pop_warnings
attr_reader :redis, :config

def key(*args)
['build', config.build_id, *args].join(':')
KeyShortener.key(config.build_id, *args)
end

def record_stats(stats, pipeline: redis)
Expand Down
53 changes: 53 additions & 0 deletions ruby/lib/ci/queue/redis/key_shortener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true
require 'digest/md5'

module CI
module Queue
module Redis
module KeyShortener
# Suffix mapping for common key patterns
SUFFIX_ALIASES = {
'running' => 'r',
'processed' => 'p',
'queue' => 'q',
'owners' => 'o',
'error-reports' => 'e',
'requeues-count' => 'rc',
'assertions' => 'a',
'errors' => 'er',
'failures' => 'f',
'skips' => 's',
'requeues' => 'rq',
'total_time' => 't',
'test_failed_count' => 'fc',
'completed' => 'c',
'master-status' => 'm',
'created-at' => 'ca',
'workers' => 'w',
'worker' => 'w',
'warnings' => 'wn',
'worker-errors' => 'we',
'flaky-reports' => 'fl',
}.freeze

# We're transforming the key to a shorter format to minimize network traffic.
#
# Strategy:
# - Shorten prefix: 'b' instead of 'build'
# - Hash UUID: 8-char MD5 instead of 36-char UUID
# - Alias suffixes: single letters instead of full words
#
# Example:
# build:unit:019aef0e-c010-433e-b706-c658d3c16372:running (55 bytes)
# -> b:f03d3bef:r (13 bytes, 76% reduction)

def self.key(build_id, *args)
digest = Digest::MD5.hexdigest(build_id)[0..7]
shortened_args = args.map { |arg| SUFFIX_ALIASES[arg] || arg }

['b', digest, *shortened_args].join(':')
end
end
end
end
end
4 changes: 2 additions & 2 deletions ruby/test/ci/queue/redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ def test_acknowledge_returns_false_if_the_test_was_picked_up_by_another_worker
end

def test_workers_register
assert_equal 1, @redis.scard('build:42:workers')
assert_equal 1, @redis.scard(CI::Queue::Redis::KeyShortener.key('42', 'workers'))
worker(2)
assert_equal 2, @redis.scard('build:42:workers')
assert_equal 2, @redis.scard(CI::Queue::Redis::KeyShortener.key('42', 'workers'))
end

def test_timeout_warning
Expand Down
2 changes: 1 addition & 1 deletion ruby/test/integration/minitest_redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_retry_fails_when_test_run_is_expired
assert_equal 'Ran 100 tests, 100 assertions, 0 failures, 0 errors, 0 skips, 0 requeues in X.XXs', output

one_day = 60 * 60 * 24
key = ['build', "1", "created-at"].join(':')
key = CI::Queue::Redis::KeyShortener.key("1", "created-at")
@redis.set(key, Time.now - one_day)

out, err = capture_subprocess_io do
Expand Down
Loading