Class: Gitlab::Instrumentation::RedisBase

Inherits:
Object
  • Object
show all
Extended by:
RedisPayload, Utils::StrongMemoize
Defined in:
lib/gitlab/instrumentation/redis_base.rb

Class Method Summary collapse

Methods included from RedisPayload

known_payload_keys, payload

Methods included from Utils::StrongMemoize

clear_memoization, strong_memoize, strong_memoized?

Class Method Details

.add_call_details(duration, args) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/instrumentation/redis_base.rb', line 23

def add_call_details(duration, args)
  return unless Gitlab::PerformanceBar.enabled_for_request?
  # redis-rb passes an array (e.g. [[:get, key]])
  return unless args.length == 1

  detail_store << {
    cmd: args.first,
    duration: duration,
    backtrace: ::Gitlab::BacktraceCleaner.clean_backtrace(caller)
  }
end

.add_duration(duration) ⇒ Object


18
19
20
21
# File 'lib/gitlab/instrumentation/redis_base.rb', line 18

def add_duration(duration)
  ::RequestStore[call_duration_key] ||= 0
  ::RequestStore[call_duration_key] += duration
end

.detail_storeObject


62
63
64
# File 'lib/gitlab/instrumentation/redis_base.rb', line 62

def detail_store
  ::RequestStore[call_details_key] ||= []
end

.enable_redis_cluster_validationObject


75
76
77
78
79
# File 'lib/gitlab/instrumentation/redis_base.rb', line 75

def enable_redis_cluster_validation
  @redis_cluster_validation = true

  self
end

.get_request_countObject


50
51
52
# File 'lib/gitlab/instrumentation/redis_base.rb', line 50

def get_request_count
  ::RequestStore[request_count_key] || 0
end

.increment_read_bytes(num_bytes) ⇒ Object


40
41
42
43
# File 'lib/gitlab/instrumentation/redis_base.rb', line 40

def increment_read_bytes(num_bytes)
  ::RequestStore[read_bytes_key] ||= 0
  ::RequestStore[read_bytes_key] += num_bytes
end

.increment_request_countObject


35
36
37
38
# File 'lib/gitlab/instrumentation/redis_base.rb', line 35

def increment_request_count
  ::RequestStore[request_count_key] ||= 0
  ::RequestStore[request_count_key] += 1
end

.increment_write_bytes(num_bytes) ⇒ Object


45
46
47
48
# File 'lib/gitlab/instrumentation/redis_base.rb', line 45

def increment_write_bytes(num_bytes)
  ::RequestStore[write_bytes_key] ||= 0
  ::RequestStore[write_bytes_key] += num_bytes
end

.instance_count_exception(ex) ⇒ Object


86
87
88
89
90
91
92
# File 'lib/gitlab/instrumentation/redis_base.rb', line 86

def instance_count_exception(ex)
  # This metric is meant to give a client side view of how the Redis
  # server is doing. Redis itself does not expose error counts. This
  # metric can be used for Redis alerting and service health monitoring.
  @exception_counter ||= Gitlab::Metrics.counter(:gitlab_redis_client_exceptions_total, 'Client side Redis exception count, per Redis server, per exception class')
  @exception_counter.increment({ storage: storage_key, exception: ex.class.to_s })
end

.instance_count_requestObject


81
82
83
84
# File 'lib/gitlab/instrumentation/redis_base.rb', line 81

def instance_count_request
  @request_counter ||= Gitlab::Metrics.counter(:gitlab_redis_client_requests_total, 'Client side Redis request count, per Redis server')
  @request_counter.increment({ storage: storage_key })
end

.instance_observe_duration(duration) ⇒ Object


94
95
96
97
98
99
100
101
102
103
# File 'lib/gitlab/instrumentation/redis_base.rb', line 94

def instance_observe_duration(duration)
  @request_latency_histogram ||= Gitlab::Metrics.histogram(
    :gitlab_redis_client_requests_duration_seconds,
    'Client side Redis request latency, per Redis server, excluding blocking commands',
    {},
    [0.1, 0.5, 0.75, 1]
  )

  @request_latency_histogram.observe({ storage: storage_key }, duration)
end

.query_timeObject


66
67
68
69
# File 'lib/gitlab/instrumentation/redis_base.rb', line 66

def query_time
  query_time = ::RequestStore[call_duration_key] || 0
  query_time.round(::Gitlab::InstrumentationHelper::DURATION_PRECISION)
end

.read_bytesObject


54
55
56
# File 'lib/gitlab/instrumentation/redis_base.rb', line 54

def read_bytes
  ::RequestStore[read_bytes_key] || 0
end

.redis_cluster_validate!(command) ⇒ Object


71
72
73
# File 'lib/gitlab/instrumentation/redis_base.rb', line 71

def redis_cluster_validate!(command)
  ::Gitlab::Instrumentation::RedisClusterValidator.validate!(command) if @redis_cluster_validation
end

.storage_keyObject

TODO: To be used by gitlab.com/gitlab-com/gl-infra/scalability/-/issues/395 as a 'label' alias.


14
15
16
# File 'lib/gitlab/instrumentation/redis_base.rb', line 14

def storage_key
  self.name.demodulize.underscore
end

.write_bytesObject


58
59
60
# File 'lib/gitlab/instrumentation/redis_base.rb', line 58

def write_bytes
  ::RequestStore[write_bytes_key] || 0
end