Class: Gitlab::Metrics::Subscribers::RailsCache

Inherits:
ActiveSupport::Subscriber
  • Object
show all
Defined in:
lib/gitlab/metrics/subscribers/rails_cache.rb

Overview

Class for tracking the total time spent in Rails cache calls guides.rubyonrails.org/active_support_instrumentation.html

Instance Method Summary collapse

Instance Method Details

#cache_delete(event) ⇒ Object


28
29
30
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 28

def cache_delete(event)
  observe(:delete, event.duration)
end

#cache_exist?(event) ⇒ Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 32

def cache_exist?(event)
  observe(:exists, event.duration)
end

#cache_fetch_hit(event) ⇒ Object


36
37
38
39
40
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 36

def cache_fetch_hit(event)
  return unless current_transaction

  current_transaction.increment(:gitlab_transaction_cache_read_hit_count_total, 1)
end

#cache_generate(event) ⇒ Object


42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 42

def cache_generate(event)
  return unless current_transaction

  current_transaction.increment(:gitlab_cache_misses_total, 1) do
    docstring 'Cache read miss'
  end

  current_transaction.increment(:gitlab_transaction_cache_read_miss_count_total, 1)
end

#cache_read(event) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 11

def cache_read(event)
  observe(:read, event.duration)

  return unless current_transaction
  return if event.payload[:super_operation] == :fetch

  unless event.payload[:hit]
    current_transaction.increment(:gitlab_cache_misses_total, 1) do
      docstring 'Cache read miss'
    end
  end
end

#cache_write(event) ⇒ Object


24
25
26
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 24

def cache_write(event)
  observe(:write, event.duration)
end

#observe(key, duration) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gitlab/metrics/subscribers/rails_cache.rb', line 52

def observe(key, duration)
  return unless current_transaction

  labels = { operation: key }

  current_transaction.increment(:gitlab_cache_operations_total, 1, labels) do
    docstring 'Cache operations'
    label_keys labels.keys
  end

  metric_cache_operation_duration_seconds.observe(labels, duration / 1000.0)
end