Commit fdd24d0f authored by Jacob Vosmaer's avatar Jacob Vosmaer

Correctly measure Redis nested array responses

parent e65dfa05
...@@ -61,15 +61,14 @@ module Gitlab ...@@ -61,15 +61,14 @@ module Gitlab
# 4. "Binary" string (i.e. may contain zero byte) # 4. "Binary" string (i.e. may contain zero byte)
# 5. Array of binary string # 5. Array of binary string
size = if result.is_a? Array if result.is_a? Array
# This count is an approximation that omits the Redis protocol overhead # Redis can return nested arrays, e.g. from XRANGE or GEOPOS, so we use recursion here.
# of type prefixes, length prefixes and line endings. result.each { |x| measure_read_size(x) }
result.inject(0) { |sum, y| sum + y.to_s.bytesize } else
else # This count is an approximation that omits the Redis protocol overhead
result.to_s.bytesize # of type prefixes, length prefixes and line endings.
end instrumentation_class.increment_read_bytes(result.to_s.bytesize)
end
instrumentation_class.increment_read_bytes(size)
end end
# That's required so it knows which GitLab Redis instance # That's required so it knows which GitLab Redis instance
......
...@@ -24,6 +24,9 @@ describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_s ...@@ -24,6 +24,9 @@ describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_s
# Exercise counting of a bulk reply # Exercise counting of a bulk reply
[[:set, 'foo', 'bar' * 100]] | [:get, 'foo'] | 3 + 3 | 3 * 100 [[: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 end
with_them do 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