diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-16 15:09:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-16 15:09:00 +0300 |
commit | 9bfdb5cf67ca45ac6d354e18168f5df12b60ccd2 (patch) | |
tree | 632218f5978fd547675f4b4e73dabcb22d62fc87 /lib/gitlab/instrumentation | |
parent | 6cf1f4c521a621fa2b4dc1735bf5a8c2846f7e6a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/instrumentation')
-rw-r--r-- | lib/gitlab/instrumentation/redis.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/instrumentation/redis_base.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/instrumentation/redis_payload.rb | 37 |
3 files changed, 56 insertions, 2 deletions
diff --git a/lib/gitlab/instrumentation/redis.rb b/lib/gitlab/instrumentation/redis.rb index 3ed1b18281e..82b4701872f 100644 --- a/lib/gitlab/instrumentation/redis.rb +++ b/lib/gitlab/instrumentation/redis.rb @@ -15,8 +15,24 @@ module Gitlab QUERY_TIME_BUCKETS = [0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2].freeze class << self + include ::Gitlab::Instrumentation::RedisPayload + + def storage_key + nil + end + + def known_payload_keys + super + STORAGES.flat_map(&:known_payload_keys) + end + + def payload + super.merge(*STORAGES.flat_map(&:payload)) + end + def detail_store - STORAGES.flat_map(&:detail_store) + STORAGES.flat_map do |storage| + storage.detail_store.map { |details| details.merge(storage: storage.name.demodulize) } + end end %i[get_request_count query_time read_bytes write_bytes].each do |method| diff --git a/lib/gitlab/instrumentation/redis_base.rb b/lib/gitlab/instrumentation/redis_base.rb index a8fb8f5076b..012543e1645 100644 --- a/lib/gitlab/instrumentation/redis_base.rb +++ b/lib/gitlab/instrumentation/redis_base.rb @@ -7,11 +7,12 @@ module Gitlab class RedisBase class << self include ::Gitlab::Utils::StrongMemoize + include ::Gitlab::Instrumentation::RedisPayload # TODO: To be used by https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/395 # as a 'label' alias. def storage_key - self.name.underscore + self.name.demodulize.underscore end def add_duration(duration) diff --git a/lib/gitlab/instrumentation/redis_payload.rb b/lib/gitlab/instrumentation/redis_payload.rb new file mode 100644 index 00000000000..69aafffd124 --- /dev/null +++ b/lib/gitlab/instrumentation/redis_payload.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Gitlab + module Instrumentation + module RedisPayload + include ::Gitlab::Utils::StrongMemoize + + # Fetches payload keys from the lazy payload (this avoids + # unnecessary processing of the values). + def known_payload_keys + to_lazy_payload.keys + end + + def payload + to_lazy_payload.transform_values do |value| + result = value.call + result if result > 0 + end.compact + end + + private + + def to_lazy_payload + strong_memoize(:to_lazy_payload) do + key_prefix = storage_key ? "redis_#{storage_key}" : 'redis' + + { + "#{key_prefix}_calls": -> { get_request_count }, + "#{key_prefix}_duration_s": -> { query_time }, + "#{key_prefix}_read_bytes": -> { read_bytes }, + "#{key_prefix}_write_bytes": -> { write_bytes } + }.symbolize_keys + end + end + end + end +end |