Welcome to mirror list, hosted at ThFree Co, Russian Federation.

redis_payload.rb « instrumentation « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 86a6525c8d00ba6ceb55d7a0d98febd25b790db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Gitlab
  module Instrumentation
    module RedisPayload
      include ::Gitlab::Utils::StrongMemoize

      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