@@ -6,23 +6,6 @@ module Subscribers
6
6
class RailsCache < ActiveSupport ::Subscriber
7
7
attach_to :active_support
8
8
9
- def self . metric_cache_operation_duration_seconds
10
- @metric_cache_operation_duration_seconds ||= Gitlab ::Metrics . histogram (
11
- :gitlab_cache_operation_duration_seconds ,
12
- 'Cache access time' ,
13
- Transaction ::BASE_LABELS . merge ( { action : nil } ) ,
14
- [ 0.001 , 0.002 , 0.005 , 0.01 , 0.02 , 0.05 , 0.1 , 0.500 , 2.0 , 10.0 ]
15
- )
16
- end
17
-
18
- def self . metric_cache_misses_total
19
- @metric_cache_misses_total ||= Gitlab ::Metrics . counter (
20
- :gitlab_cache_misses_total ,
21
- 'Cache read miss' ,
22
- Transaction ::BASE_LABELS
23
- )
24
- end
25
-
26
9
def cache_read ( event )
27
10
observe ( :read , event . duration )
28
11
@@ -32,7 +15,7 @@ def cache_read(event)
32
15
if event . payload [ :hit ]
33
16
current_transaction . increment ( :cache_read_hit_count , 1 , false )
34
17
else
35
- self . class . metric_cache_misses_total . increment ( current_transaction . labels )
18
+ self . metric_cache_misses_total . increment ( current_transaction . labels )
36
19
current_transaction . increment ( :cache_read_miss_count , 1 , false )
37
20
end
38
21
end
@@ -58,14 +41,14 @@ def cache_fetch_hit(event)
58
41
def cache_generate ( event )
59
42
return unless current_transaction
60
43
61
- self . class . metric_cache_misses_total . increment ( current_transaction . labels )
44
+ self . metric_cache_misses_total . increment ( current_transaction . labels )
62
45
current_transaction . increment ( :cache_read_miss_count , 1 )
63
46
end
64
47
65
48
def observe ( key , duration )
66
49
return unless current_transaction
67
50
68
- self . class . metric_cache_operation_duration_seconds . observe ( current_transaction . labels . merge ( { operation : key } ) , duration / 1000.0 )
51
+ self . metric_cache_operation_duration_seconds . observe ( current_transaction . labels . merge ( { operation : key } ) , duration / 1000.0 )
69
52
current_transaction . increment ( :cache_duration , duration , false )
70
53
current_transaction . increment ( :cache_count , 1 , false )
71
54
current_transaction . increment ( "cache_#{ key } _duration" . to_sym , duration , false )
@@ -77,6 +60,23 @@ def observe(key, duration)
77
60
def current_transaction
78
61
Transaction . current
79
62
end
63
+
64
+ def metric_cache_operation_duration_seconds
65
+ @metric_cache_operation_duration_seconds ||= Gitlab ::Metrics . histogram (
66
+ :gitlab_cache_operation_duration_seconds ,
67
+ 'Cache access time' ,
68
+ Transaction ::BASE_LABELS . merge ( { action : nil } ) ,
69
+ [ 0.001 , 0.002 , 0.005 , 0.01 , 0.02 , 0.05 , 0.1 , 0.500 , 2.0 , 10.0 ]
70
+ )
71
+ end
72
+
73
+ def metric_cache_misses_total
74
+ @metric_cache_misses_total ||= Gitlab ::Metrics . counter (
75
+ :gitlab_cache_misses_total ,
76
+ 'Cache read miss' ,
77
+ Transaction ::BASE_LABELS
78
+ )
79
+ end
80
80
end
81
81
end
82
82
end
0 commit comments