2020-03-24 14:07:55 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Instrumentation
|
2020-06-04 08:08:21 -04:00
|
|
|
# Aggregates Redis measurements from different request storage sources.
|
2020-03-24 14:07:55 -04:00
|
|
|
class Redis
|
2020-06-04 08:08:21 -04:00
|
|
|
ActionCable = Class.new(RedisBase)
|
2020-06-24 17:08:46 -04:00
|
|
|
Cache = Class.new(RedisBase).enable_redis_cluster_validation
|
2020-06-04 08:08:21 -04:00
|
|
|
Queues = Class.new(RedisBase)
|
2020-06-24 17:08:46 -04:00
|
|
|
SharedState = Class.new(RedisBase).enable_redis_cluster_validation
|
2020-06-04 08:08:21 -04:00
|
|
|
|
|
|
|
STORAGES = [ActionCable, Cache, Queues, SharedState].freeze
|
2020-03-24 14:07:55 -04:00
|
|
|
|
2020-06-15 23:08:24 -04:00
|
|
|
# Milliseconds represented in seconds (from 1 millisecond to 2 seconds).
|
|
|
|
QUERY_TIME_BUCKETS = [0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2].freeze
|
2020-05-20 08:07:52 -04:00
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
class << self
|
2020-06-16 08:09:00 -04:00
|
|
|
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
|
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
def detail_store
|
2020-06-16 08:09:00 -04:00
|
|
|
STORAGES.flat_map do |storage|
|
|
|
|
storage.detail_store.map { |details| details.merge(storage: storage.name.demodulize) }
|
|
|
|
end
|
2020-06-04 08:08:21 -04:00
|
|
|
end
|
2020-03-24 14:07:55 -04:00
|
|
|
|
2020-06-04 08:08:21 -04:00
|
|
|
%i[get_request_count query_time read_bytes write_bytes].each do |method|
|
|
|
|
define_method method do
|
|
|
|
STORAGES.sum(&method) # rubocop:disable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|
2020-03-24 14:07:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|