Commit 535139b6 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Merge branch 'jv-redis-instrument-recursion' into 'master'

Correctly measure Redis nested array responses

See merge request gitlab-org/gitlab!34444
parents eca17ef7 fdd24d0f
......@@ -61,15 +61,14 @@ module Gitlab
# 4. "Binary" string (i.e. may contain zero byte)
# 5. Array of binary string
size = if result.is_a? Array
# This count is an approximation that omits the Redis protocol overhead
# of type prefixes, length prefixes and line endings.
result.inject(0) { |sum, y| sum + y.to_s.bytesize }
else
result.to_s.bytesize
end
instrumentation_class.increment_read_bytes(size)
if result.is_a? Array
# Redis can return nested arrays, e.g. from XRANGE or GEOPOS, so we use recursion here.
result.each { |x| measure_read_size(x) }
else
# This count is an approximation that omits the Redis protocol overhead
# of type prefixes, length prefixes and line endings.
instrumentation_class.increment_read_bytes(result.to_s.bytesize)
end
end
# That's required so it knows which GitLab Redis instance
......
......@@ -24,6 +24,9 @@ describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_s
# Exercise counting of a bulk reply
[[:set, 'foo', 'bar' * 100]] | [:get, 'foo'] | 3 + 3 | 3 * 100
# Nested array response: ['123456-89', ['foo', 'bar']]
[[:xadd, 'mystream', '123456-89', 'foo', 'bar']] | [:xrange, 'mystream', '-', '+'] | 6 + 8 + 1 + 1 | 9 + 3 + 3
end
with_them do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment