Module: Oboe::Inst::MemCache
Constant Summary
API::Memcache::MEMCACHE_OPS
Class Method Summary
collapse
Instance Method Summary
collapse
#memcache_hit?, #remote_host
Class Method Details
.included(cls) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/oboe/inst/memcache.rb', line 9
def self.included(cls)
Oboe.logger.info "[oboe/loading] Instrumenting memcache" if Oboe::Config[:verbose]
cls.class_eval do
MEMCACHE_OPS.reject { |m| not method_defined?(m) }.each do |m|
define_method("#{m}_with_oboe") do |*args|
report_kvs = { :KVOp => m }
report_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:memcache][:collect_backtraces]
if Oboe.tracing?
Oboe::API.trace('memcache', report_kvs) do
result = send("#{m}_without_oboe", *args)
end
else
result = send("#{m}_without_oboe", *args)
end
result
end
class_eval "alias #{m}_without_oboe #{m}"
class_eval "alias #{m} #{m}_with_oboe"
end
if ::MemCache.method_defined? :request_setup
alias request_setup_without_oboe request_setup
alias request_setup request_setup_with_oboe
elsif Oboe::Config[:verbose]
Oboe.logger.warn "[oboe/loading] Couldn't properly instrument Memcache. Partial traces may occur."
end
if ::MemCache.method_defined? :cache_get
alias cache_get_without_oboe cache_get
alias cache_get cache_get_with_oboe
elsif Oboe::Config[:verbose]
Oboe.logger.warn "[oboe/loading] Couldn't properly instrument Memcache. Partial traces may occur."
end
if ::MemCache.method_defined? :get_multi
alias get_multi_without_oboe get_multi
alias get_multi get_multi_with_oboe
elsif Oboe::Config[:verbose]
Oboe.logger.warn "[oboe/loading] Couldn't properly instrument Memcache. Partial traces may occur."
end
end
end
|
Instance Method Details
#cache_get_with_oboe(server, cache_key) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/oboe/inst/memcache.rb', line 100
def cache_get_with_oboe(server, cache_key)
result = cache_get_without_oboe(server, cache_key)
info_kvs = { :KVHit => memcache_hit?(result) }
info_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:memcache][:collect_backtraces]
Oboe::API.log('memcache', 'info', info_kvs)
result
end
|
#get_multi_with_oboe(*args) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/oboe/inst/memcache.rb', line 56
def get_multi_with_oboe(*args)
if Oboe.tracing?
layer_kvs = {}
layer_kvs[:KVOp] = :get_multi
Oboe::API.trace('memcache', layer_kvs || {}, :get_multi) do
begin
info_kvs = {}
info_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:memcache][:collect_backtraces]
if args.last.is_a?(Hash) || args.last.nil?
info_kvs[:KVKeyCount] = args.flatten.length - 1
else
info_kvs[:KVKeyCount] = args.flatten.length
end
values = get_multi_without_oboe(args)
info_kvs[:KVHitCount] = values.length
Oboe::API.log('memcache', 'info', info_kvs)
rescue
values = get_multi_without_oboe(args)
end
values
end
else
get_multi_without_oboe(args)
end
end
|
#request_setup_with_oboe(*args) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/oboe/inst/memcache.rb', line 86
def request_setup_with_oboe(*args)
if Oboe.tracing? and not Oboe::Context.tracing_layer_op?(:get_multi)
server, cache_key = request_setup_without_oboe(*args)
info_kvs = { :KVKey => cache_key, :RemoteHost => server.host }
info_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:memcache][:collect_backtraces]
Oboe::API.log('memcache', 'info', info_kvs)
else
server, cache_key = request_setup_without_oboe(*args)
end
return [server, cache_key]
end
|