oboe 2.7.0.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +51 -0
- data/Appraisals +10 -0
- data/CHANGELOG.md +223 -0
- data/Gemfile +49 -0
- data/LICENSE +199 -0
- data/README.md +380 -0
- data/Rakefile +106 -0
- data/ext/oboe_metal/extconf.rb +61 -0
- data/ext/oboe_metal/noop/noop.c +7 -0
- data/ext/oboe_metal/src/bson/bson.h +221 -0
- data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
- data/ext/oboe_metal/src/oboe.h +275 -0
- data/ext/oboe_metal/src/oboe.hpp +352 -0
- data/ext/oboe_metal/src/oboe_wrap.cxx +3886 -0
- data/ext/oboe_metal/tests/test.rb +11 -0
- data/gemfiles/mongo.gemfile +33 -0
- data/gemfiles/moped.gemfile +33 -0
- data/get_version.rb +5 -0
- data/init.rb +4 -0
- data/lib/base.rb +99 -0
- data/lib/joboe_metal.rb +185 -0
- data/lib/method_profiling.rb +70 -0
- data/lib/oboe.rb +50 -0
- data/lib/oboe/api.rb +14 -0
- data/lib/oboe/api/layerinit.rb +99 -0
- data/lib/oboe/api/logging.rb +129 -0
- data/lib/oboe/api/memcache.rb +29 -0
- data/lib/oboe/api/profiling.rb +50 -0
- data/lib/oboe/api/tracing.rb +134 -0
- data/lib/oboe/api/util.rb +117 -0
- data/lib/oboe/config.rb +140 -0
- data/lib/oboe/frameworks/grape.rb +74 -0
- data/lib/oboe/frameworks/padrino.rb +66 -0
- data/lib/oboe/frameworks/padrino/templates.rb +59 -0
- data/lib/oboe/frameworks/rails.rb +139 -0
- data/lib/oboe/frameworks/rails/helpers/rum/rum_ajax_header.js.erb +5 -0
- data/lib/oboe/frameworks/rails/helpers/rum/rum_footer.js.erb +1 -0
- data/lib/oboe/frameworks/rails/helpers/rum/rum_header.js.erb +3 -0
- data/lib/oboe/frameworks/rails/inst/action_controller.rb +123 -0
- data/lib/oboe/frameworks/rails/inst/action_view.rb +56 -0
- data/lib/oboe/frameworks/rails/inst/action_view_2x.rb +54 -0
- data/lib/oboe/frameworks/rails/inst/action_view_30.rb +48 -0
- data/lib/oboe/frameworks/rails/inst/active_record.rb +24 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/oracle.rb +18 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
- data/lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb +118 -0
- data/lib/oboe/frameworks/sinatra.rb +96 -0
- data/lib/oboe/frameworks/sinatra/templates.rb +56 -0
- data/lib/oboe/inst/cassandra.rb +281 -0
- data/lib/oboe/inst/dalli.rb +75 -0
- data/lib/oboe/inst/http.rb +72 -0
- data/lib/oboe/inst/memcache.rb +105 -0
- data/lib/oboe/inst/memcached.rb +96 -0
- data/lib/oboe/inst/mongo.rb +240 -0
- data/lib/oboe/inst/moped.rb +474 -0
- data/lib/oboe/inst/rack.rb +81 -0
- data/lib/oboe/inst/redis.rb +273 -0
- data/lib/oboe/inst/resque.rb +193 -0
- data/lib/oboe/instrumentation.rb +18 -0
- data/lib/oboe/loading.rb +98 -0
- data/lib/oboe/logger.rb +41 -0
- data/lib/oboe/ruby.rb +11 -0
- data/lib/oboe/util.rb +129 -0
- data/lib/oboe/version.rb +13 -0
- data/lib/oboe/xtrace.rb +52 -0
- data/lib/oboe_metal.rb +140 -0
- data/lib/rails/generators/oboe/install_generator.rb +76 -0
- data/lib/rails/generators/oboe/templates/oboe_initializer.rb +94 -0
- data/oboe.gemspec +29 -0
- data/release.sh +65 -0
- data/test/frameworks/apps/grape_simple.rb +10 -0
- data/test/frameworks/apps/padrino_simple.rb +41 -0
- data/test/frameworks/apps/sinatra_simple.rb +20 -0
- data/test/frameworks/grape_test.rb +27 -0
- data/test/frameworks/padrino_test.rb +25 -0
- data/test/frameworks/sinatra_test.rb +25 -0
- data/test/instrumentation/cassandra_test.rb +381 -0
- data/test/instrumentation/dalli_test.rb +164 -0
- data/test/instrumentation/http_test.rb +97 -0
- data/test/instrumentation/memcache_test.rb +251 -0
- data/test/instrumentation/memcached_test.rb +226 -0
- data/test/instrumentation/mongo_test.rb +462 -0
- data/test/instrumentation/moped_test.rb +473 -0
- data/test/instrumentation/rack_test.rb +73 -0
- data/test/instrumentation/redis_hashes_test.rb +265 -0
- data/test/instrumentation/redis_keys_test.rb +318 -0
- data/test/instrumentation/redis_lists_test.rb +310 -0
- data/test/instrumentation/redis_misc_test.rb +160 -0
- data/test/instrumentation/redis_sets_test.rb +293 -0
- data/test/instrumentation/redis_sortedsets_test.rb +325 -0
- data/test/instrumentation/redis_strings_test.rb +333 -0
- data/test/instrumentation/resque_test.rb +62 -0
- data/test/minitest_helper.rb +148 -0
- data/test/profiling/method_test.rb +198 -0
- data/test/support/config_test.rb +39 -0
- data/test/support/liboboe_settings_test.rb +46 -0
- data/test/support/xtrace_test.rb +35 -0
- metadata +200 -0
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
if RUBY_VERSION < '2.0' and not defined?(JRUBY_VERSION)
|
4
|
+
describe Oboe::Inst::Memcached do
|
5
|
+
require 'memcached'
|
6
|
+
require 'memcached/rails'
|
7
|
+
|
8
|
+
before do
|
9
|
+
clear_all_traces
|
10
|
+
@mc = ::Memcached::Rails.new(:servers => ['localhost'])
|
11
|
+
|
12
|
+
# These are standard entry/exit KVs that are passed up with all mongo operations
|
13
|
+
@entry_kvs = {
|
14
|
+
'Layer' => 'memcache',
|
15
|
+
'Label' => 'entry' }
|
16
|
+
|
17
|
+
@info_kvs = {
|
18
|
+
'Layer' => 'memcache',
|
19
|
+
'Label' => 'info' }
|
20
|
+
|
21
|
+
@exit_kvs = { 'Layer' => 'memcache', 'Label' => 'exit' }
|
22
|
+
@collect_backtraces = Oboe::Config[:memcached][:collect_backtraces]
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
Oboe::Config[:memcached][:collect_backtraces] = @collect_backtraces
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'Stock Memcached should be loaded, defined and ready' do
|
30
|
+
defined?(::Memcached).wont_match nil
|
31
|
+
defined?(::Memcached::Rails).wont_match nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'Memcached should have oboe methods defined' do
|
35
|
+
Oboe::API::Memcache::MEMCACHE_OPS.each do |m|
|
36
|
+
if ::Memcached.method_defined?(m)
|
37
|
+
::Memcached.method_defined?("#{m}_with_oboe").must_equal true
|
38
|
+
end
|
39
|
+
::Memcached::Rails.method_defined?(:get_multi_with_oboe).must_equal true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should trace set" do
|
44
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
45
|
+
@mc.set('testKey', 'blah')
|
46
|
+
end
|
47
|
+
|
48
|
+
traces = get_all_traces
|
49
|
+
traces.count.must_equal 4
|
50
|
+
|
51
|
+
validate_outer_layers(traces, 'memcached_test')
|
52
|
+
validate_event_keys(traces[1], @entry_kvs)
|
53
|
+
validate_event_keys(traces[2], @exit_kvs)
|
54
|
+
|
55
|
+
traces[1]['KVOp'].must_equal "set"
|
56
|
+
traces[1]['KVKey'].must_equal "testKey"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should trace get" do
|
60
|
+
@mc.set('testKey', 'blah')
|
61
|
+
|
62
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
63
|
+
@mc.get('testKey')
|
64
|
+
end
|
65
|
+
|
66
|
+
traces = get_all_traces
|
67
|
+
traces.count.must_equal 4
|
68
|
+
|
69
|
+
validate_outer_layers(traces, 'memcached_test')
|
70
|
+
validate_event_keys(traces[1], @entry_kvs)
|
71
|
+
validate_event_keys(traces[2], @exit_kvs)
|
72
|
+
|
73
|
+
traces[1]['KVOp'].must_equal "get"
|
74
|
+
traces[1]['KVKey'].must_equal "testKey"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should trace get_multi" do
|
78
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
79
|
+
@mc.get_multi(['one', 'two', 'three', 'four', 'five', 'six'])
|
80
|
+
end
|
81
|
+
|
82
|
+
traces = get_all_traces
|
83
|
+
traces.count.must_equal 5
|
84
|
+
|
85
|
+
validate_outer_layers(traces, 'memcached_test')
|
86
|
+
validate_event_keys(traces[1], @entry_kvs)
|
87
|
+
validate_event_keys(traces[2], @info_kvs)
|
88
|
+
validate_event_keys(traces[3], @exit_kvs)
|
89
|
+
|
90
|
+
traces[1]['KVOp'].must_equal "get_multi"
|
91
|
+
|
92
|
+
traces[2]['KVKeyCount'].must_equal "6"
|
93
|
+
traces[2].has_key?('KVHitCount').must_equal true
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should trace add for existing key" do
|
97
|
+
@mc.set('testKey', 'x', 1200)
|
98
|
+
|
99
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
100
|
+
@mc.add('testKey', 'x', 1200)
|
101
|
+
end
|
102
|
+
|
103
|
+
traces = get_all_traces
|
104
|
+
traces.count.must_equal 5
|
105
|
+
|
106
|
+
validate_outer_layers(traces, 'memcached_test')
|
107
|
+
validate_event_keys(traces[1], @entry_kvs)
|
108
|
+
validate_event_keys(traces[3], @exit_kvs)
|
109
|
+
|
110
|
+
traces[1]['KVOp'].must_equal "add"
|
111
|
+
traces[1]['KVKey'].must_equal "testKey"
|
112
|
+
|
113
|
+
traces[2]['ErrorClass'].must_equal "Memcached::NotStored"
|
114
|
+
traces[2]['Message'].must_equal "Memcached::NotStored"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should trace append" do
|
118
|
+
@mc.set('rawKey', "Peanut Butter ", 600, :raw => true)
|
119
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
120
|
+
@mc.append('rawKey', "Jelly")
|
121
|
+
end
|
122
|
+
|
123
|
+
traces = get_all_traces
|
124
|
+
traces.count.must_equal 4
|
125
|
+
|
126
|
+
validate_outer_layers(traces, 'memcached_test')
|
127
|
+
validate_event_keys(traces[1], @entry_kvs)
|
128
|
+
validate_event_keys(traces[2], @exit_kvs)
|
129
|
+
|
130
|
+
traces[1]['KVOp'].must_equal "append"
|
131
|
+
traces[1]['KVKey'].must_equal "rawKey"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should trace decr" do
|
135
|
+
@mc.set('some_key_counter', "100", 0, false)
|
136
|
+
|
137
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
138
|
+
@mc.decr('some_key_counter', 1)
|
139
|
+
end
|
140
|
+
|
141
|
+
traces = get_all_traces
|
142
|
+
traces.count.must_equal 4
|
143
|
+
|
144
|
+
validate_outer_layers(traces, 'memcached_test')
|
145
|
+
validate_event_keys(traces[1], @entry_kvs)
|
146
|
+
validate_event_keys(traces[2], @exit_kvs)
|
147
|
+
|
148
|
+
traces[1]['KVOp'].must_equal "decr"
|
149
|
+
traces[1]['KVKey'].must_equal "some_key_counter"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should trace increment" do
|
153
|
+
@mc.set('some_key_counter', "100", 0, false)
|
154
|
+
|
155
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
156
|
+
@mc.incr("some_key_counter", 1)
|
157
|
+
end
|
158
|
+
|
159
|
+
traces = get_all_traces
|
160
|
+
traces.count.must_equal 4
|
161
|
+
|
162
|
+
validate_outer_layers(traces, 'memcached_test')
|
163
|
+
validate_event_keys(traces[1], @entry_kvs)
|
164
|
+
validate_event_keys(traces[2], @exit_kvs)
|
165
|
+
|
166
|
+
traces[1]['KVOp'].must_equal "incr"
|
167
|
+
traces[1]['KVKey'].must_equal "some_key_counter"
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should trace replace" do
|
171
|
+
@mc.set('some_key', 'blah')
|
172
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
173
|
+
@mc.replace("some_key", "woop")
|
174
|
+
end
|
175
|
+
|
176
|
+
traces = get_all_traces
|
177
|
+
traces.count.must_equal 4
|
178
|
+
|
179
|
+
validate_outer_layers(traces, 'memcached_test')
|
180
|
+
validate_event_keys(traces[1], @entry_kvs)
|
181
|
+
validate_event_keys(traces[2], @exit_kvs)
|
182
|
+
|
183
|
+
traces[1]['KVOp'].must_equal "replace"
|
184
|
+
traces[1]['KVKey'].must_equal "some_key"
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should trace delete" do
|
188
|
+
@mc.set('some_key', 'blah')
|
189
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
190
|
+
@mc.delete("some_key")
|
191
|
+
end
|
192
|
+
|
193
|
+
traces = get_all_traces
|
194
|
+
traces.count.must_equal 4
|
195
|
+
|
196
|
+
validate_outer_layers(traces, 'memcached_test')
|
197
|
+
validate_event_keys(traces[1], @entry_kvs)
|
198
|
+
validate_event_keys(traces[2], @exit_kvs)
|
199
|
+
|
200
|
+
traces[1]['KVOp'].must_equal "delete"
|
201
|
+
traces[1]['KVKey'].must_equal "some_key"
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should obey :collect_backtraces setting when true" do
|
205
|
+
Oboe::Config[:memcached][:collect_backtraces] = true
|
206
|
+
|
207
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
208
|
+
@mc.set('some_key', 1)
|
209
|
+
end
|
210
|
+
|
211
|
+
traces = get_all_traces
|
212
|
+
layer_has_key(traces, 'memcache', 'Backtrace')
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should obey :collect_backtraces setting when false" do
|
216
|
+
Oboe::Config[:memcached][:collect_backtraces] = false
|
217
|
+
|
218
|
+
Oboe::API.start_trace('memcached_test', '', {}) do
|
219
|
+
@mc.set('some_key', 1)
|
220
|
+
end
|
221
|
+
|
222
|
+
traces = get_all_traces
|
223
|
+
layer_doesnt_have_key(traces, 'memcache', 'Backtrace')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
@@ -0,0 +1,462 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
if defined?(::BSON::VERSION) and (BSON::VERSION < "2.0")
|
4
|
+
describe Oboe::Inst::Mongo do
|
5
|
+
before do
|
6
|
+
clear_all_traces
|
7
|
+
@connection = Mongo::Connection.new("localhost", 27017, :slave_ok => true)
|
8
|
+
@db = @connection.db("test-#{ENV['RACK_ENV']}")
|
9
|
+
|
10
|
+
@collections = @db.collection_names
|
11
|
+
@db.create_collection("testCollection") unless @collections.include? "testCollection"
|
12
|
+
|
13
|
+
# These are standard entry/exit KVs that are passed up with all mongo operations
|
14
|
+
@entry_kvs = {
|
15
|
+
'Layer' => 'mongo',
|
16
|
+
'Label' => 'entry',
|
17
|
+
'Flavor' => 'mongodb',
|
18
|
+
'Database' => 'test-test',
|
19
|
+
'RemoteHost' => 'localhost',
|
20
|
+
'RemotePort' => '27017' }
|
21
|
+
|
22
|
+
@exit_kvs = { 'Layer' => 'mongo', 'Label' => 'exit' }
|
23
|
+
@collect_backtraces = Oboe::Config[:mongo][:collect_backtraces]
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
Oboe::Config[:mongo][:collect_backtraces] = @collect_backtraces
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'Stock Mongo should be loaded, defined and ready' do
|
31
|
+
defined?(::Mongo).wont_match nil
|
32
|
+
defined?(::Mongo::DB).wont_match nil
|
33
|
+
defined?(::Mongo::Cursor).wont_match nil
|
34
|
+
defined?(::Mongo::Collection).wont_match nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'Mongo should have oboe methods defined' do
|
38
|
+
Oboe::Inst::Mongo::DB_OPS.each do |m|
|
39
|
+
::Mongo::DB.method_defined?("#{m}_with_oboe").must_equal true
|
40
|
+
end
|
41
|
+
Oboe::Inst::Mongo::CURSOR_OPS.each do |m|
|
42
|
+
::Mongo::Cursor.method_defined?("#{m}_with_oboe").must_equal true
|
43
|
+
end
|
44
|
+
Oboe::Inst::Mongo::COLL_WRITE_OPS.each do |m|
|
45
|
+
::Mongo::Collection.method_defined?("#{m}_with_oboe").must_equal true
|
46
|
+
end
|
47
|
+
Oboe::Inst::Mongo::COLL_QUERY_OPS.each do |m|
|
48
|
+
::Mongo::Collection.method_defined?("#{m}_with_oboe").must_equal true
|
49
|
+
end
|
50
|
+
Oboe::Inst::Mongo::COLL_INDEX_OPS.each do |m|
|
51
|
+
::Mongo::Collection.method_defined?("#{m}_with_oboe").must_equal true
|
52
|
+
end
|
53
|
+
::Mongo::Collection.method_defined?(:oboe_collect).must_equal true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should trace create_collection" do
|
57
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
58
|
+
@db.create_collection("create_and_drop_collection_test")
|
59
|
+
end
|
60
|
+
|
61
|
+
traces = get_all_traces
|
62
|
+
traces.count.must_equal 4
|
63
|
+
|
64
|
+
validate_outer_layers(traces, 'mongo_test')
|
65
|
+
validate_event_keys(traces[1], @entry_kvs)
|
66
|
+
validate_event_keys(traces[2], @exit_kvs)
|
67
|
+
|
68
|
+
traces[1]['QueryOp'].must_equal "create_collection"
|
69
|
+
traces[1]['New_Collection_Name'].must_equal "create_and_drop_collection_test"
|
70
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should trace drop_collection" do
|
74
|
+
# Create a collection so we have one to drop
|
75
|
+
@db.create_collection("create_and_drop_collection_test")
|
76
|
+
|
77
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
78
|
+
@db.drop_collection("create_and_drop_collection_test")
|
79
|
+
end
|
80
|
+
|
81
|
+
traces = get_all_traces
|
82
|
+
traces.count.must_equal 4
|
83
|
+
|
84
|
+
validate_outer_layers(traces, 'mongo_test')
|
85
|
+
validate_event_keys(traces[1], @entry_kvs)
|
86
|
+
validate_event_keys(traces[2], @exit_kvs)
|
87
|
+
|
88
|
+
traces[1]['QueryOp'].must_equal "drop_collection"
|
89
|
+
traces[1]['Collection'].must_equal "create_and_drop_collection_test"
|
90
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should trace count" do
|
94
|
+
coll = @db.collection("testCollection")
|
95
|
+
|
96
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
97
|
+
coll.count(:query => {:name => "MyName"})
|
98
|
+
end
|
99
|
+
|
100
|
+
traces = get_all_traces
|
101
|
+
traces.count.must_equal 6
|
102
|
+
|
103
|
+
validate_outer_layers(traces, 'mongo_test')
|
104
|
+
validate_event_keys(traces[1], @entry_kvs)
|
105
|
+
validate_event_keys(traces[2], @exit_kvs)
|
106
|
+
|
107
|
+
traces[3]['QueryOp'].must_equal "count"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should trace find_and_modify" do
|
111
|
+
coll = @db.collection("testCollection")
|
112
|
+
|
113
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
114
|
+
coll.find_and_modify({ :query => { :name => "MyName" }, :update => { :count => 203 }})
|
115
|
+
end
|
116
|
+
|
117
|
+
traces = get_all_traces
|
118
|
+
traces.count.must_equal 4
|
119
|
+
|
120
|
+
validate_outer_layers(traces, 'mongo_test')
|
121
|
+
validate_event_keys(traces[1], @entry_kvs)
|
122
|
+
validate_event_keys(traces[2], @exit_kvs)
|
123
|
+
|
124
|
+
traces[1]['Collection'].must_equal "testCollection"
|
125
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
126
|
+
traces[1]['QueryOp'].must_equal "find_and_modify"
|
127
|
+
traces[1]['Update_Document'].must_equal "{:count=>203}"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should trace insert" do
|
131
|
+
coll = @db.collection("testCollection")
|
132
|
+
|
133
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
134
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
135
|
+
id = coll.insert(doc)
|
136
|
+
end
|
137
|
+
|
138
|
+
traces = get_all_traces
|
139
|
+
traces.count.must_equal 4
|
140
|
+
|
141
|
+
validate_outer_layers(traces, 'mongo_test')
|
142
|
+
validate_event_keys(traces[1], @entry_kvs)
|
143
|
+
validate_event_keys(traces[2], @exit_kvs)
|
144
|
+
|
145
|
+
traces[1]['Collection'].must_equal "testCollection"
|
146
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
147
|
+
traces[1]['QueryOp'].must_equal "insert"
|
148
|
+
# Don't test exact hash value since to_json hash ordering varies between 1.8.7 and 1.9+
|
149
|
+
traces[1].has_key?('Query').must_equal true
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should trace map_reduce" do
|
153
|
+
coll = @db.collection("testCollection")
|
154
|
+
|
155
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
156
|
+
map = "function() { emit(this.name, 1); }"
|
157
|
+
reduce = "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
|
158
|
+
coll.map_reduce(map, reduce, { :out => "mr_results", :limit => 100, :read => :primary })
|
159
|
+
end
|
160
|
+
|
161
|
+
traces = get_all_traces
|
162
|
+
traces.count.must_equal 4
|
163
|
+
|
164
|
+
validate_outer_layers(traces, 'mongo_test')
|
165
|
+
validate_event_keys(traces[1], @entry_kvs)
|
166
|
+
validate_event_keys(traces[2], @exit_kvs)
|
167
|
+
|
168
|
+
traces[1]['Collection'].must_equal "testCollection"
|
169
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
170
|
+
traces[1]['QueryOp'].must_equal "map_reduce"
|
171
|
+
traces[1]['Map_Function'].must_equal "function() { emit(this.name, 1); }"
|
172
|
+
traces[1]['Reduce_Function'].must_equal "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
|
173
|
+
traces[1]['Limit'].must_equal "100"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should trace remove" do
|
177
|
+
coll = @db.collection("testCollection")
|
178
|
+
|
179
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
180
|
+
coll.remove(:name => "SaveOp")
|
181
|
+
end
|
182
|
+
|
183
|
+
traces = get_all_traces
|
184
|
+
traces.count.must_equal 4
|
185
|
+
|
186
|
+
validate_outer_layers(traces, 'mongo_test')
|
187
|
+
validate_event_keys(traces[1], @entry_kvs)
|
188
|
+
validate_event_keys(traces[2], @exit_kvs)
|
189
|
+
|
190
|
+
traces[1]['Collection'].must_equal "testCollection"
|
191
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
192
|
+
traces[1]['QueryOp'].must_equal "remove"
|
193
|
+
traces[1]['Query'].must_equal "{\"name\":\"SaveOp\"}"
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should trace rename" do
|
197
|
+
coll = @db.collection("testCollection")
|
198
|
+
new_name = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
|
199
|
+
|
200
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
201
|
+
coll.rename(new_name)
|
202
|
+
end
|
203
|
+
|
204
|
+
traces = get_all_traces
|
205
|
+
traces.count.must_equal 4
|
206
|
+
|
207
|
+
validate_outer_layers(traces, 'mongo_test')
|
208
|
+
validate_event_keys(traces[1], @entry_kvs)
|
209
|
+
validate_event_keys(traces[2], @exit_kvs)
|
210
|
+
|
211
|
+
traces[1]['Collection'].must_equal "testCollection"
|
212
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
213
|
+
traces[1]['QueryOp'].must_equal "rename"
|
214
|
+
traces[1]['New_Collection_Name'].must_equal new_name
|
215
|
+
|
216
|
+
# Clean up after test and set collection name back to original
|
217
|
+
coll.rename("testCollection")
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should trace update" do
|
221
|
+
coll = @db.collection("testCollection")
|
222
|
+
|
223
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
224
|
+
# Two types of update calls
|
225
|
+
coll.update({"_id" => 1}, { "$set" => {"name" => "MongoDB Ruby"}}, :multi => true)
|
226
|
+
|
227
|
+
doc = {"name" => "MyOtherName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
228
|
+
coll.update({"_id" => 1}, doc)
|
229
|
+
end
|
230
|
+
|
231
|
+
traces = get_all_traces
|
232
|
+
traces.count.must_equal 6
|
233
|
+
|
234
|
+
validate_outer_layers(traces, 'mongo_test')
|
235
|
+
validate_event_keys(traces[1], @entry_kvs)
|
236
|
+
validate_event_keys(traces[2], @exit_kvs)
|
237
|
+
|
238
|
+
traces[1]['Collection'].must_equal "testCollection"
|
239
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
240
|
+
traces[1]['QueryOp'].must_equal "update"
|
241
|
+
traces[1]['Query'].must_equal "{\"_id\":1}"
|
242
|
+
|
243
|
+
validate_event_keys(traces[3], @entry_kvs)
|
244
|
+
validate_event_keys(traces[4], @exit_kvs)
|
245
|
+
|
246
|
+
traces[3].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
247
|
+
traces[3]['QueryOp'].must_equal "update"
|
248
|
+
traces[3]['Query'].must_equal "{\"_id\":1}"
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should trace distinct" do
|
252
|
+
coll = @db.collection("testCollection")
|
253
|
+
|
254
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
255
|
+
coll.distinct("count")
|
256
|
+
end
|
257
|
+
|
258
|
+
traces = get_all_traces
|
259
|
+
traces.count.must_equal 4
|
260
|
+
|
261
|
+
validate_outer_layers(traces, 'mongo_test')
|
262
|
+
validate_event_keys(traces[1], @entry_kvs)
|
263
|
+
validate_event_keys(traces[2], @exit_kvs)
|
264
|
+
|
265
|
+
traces[1]['Collection'].must_equal "testCollection"
|
266
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
267
|
+
traces[1]['QueryOp'].must_equal "distinct"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should trace find" do
|
271
|
+
coll = @db.collection("testCollection")
|
272
|
+
result = nil
|
273
|
+
|
274
|
+
# Insert a doc to assure we get a result
|
275
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
276
|
+
id = coll.insert(doc)
|
277
|
+
|
278
|
+
# If given an optional block +find+ will yield a Cursor to that block,
|
279
|
+
# close the cursor, and then return nil. This guarantees that partially
|
280
|
+
# evaluated cursors will be closed. If given no block +find+ returns a
|
281
|
+
# cursor.
|
282
|
+
# https://github.com/mongodb/mongo-ruby-driver/blob/1.10.1/lib/mongo/collection.rb#L178
|
283
|
+
|
284
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
285
|
+
result = coll.find(:name => "MyName", :limit => 1)
|
286
|
+
end
|
287
|
+
|
288
|
+
traces = get_all_traces
|
289
|
+
traces.count.must_equal 4
|
290
|
+
|
291
|
+
validate_outer_layers(traces, 'mongo_test')
|
292
|
+
validate_event_keys(traces[1], @entry_kvs)
|
293
|
+
validate_event_keys(traces[2], @exit_kvs)
|
294
|
+
|
295
|
+
result.wont_match nil
|
296
|
+
result.is_a?(Mongo::Cursor).must_equal true
|
297
|
+
traces[1]['Collection'].must_equal "testCollection"
|
298
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
299
|
+
traces[1]['QueryOp'].must_equal "find"
|
300
|
+
traces[1].has_key?('Query').must_equal true
|
301
|
+
traces[1]['Limit'].must_equal "1"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should trace find (with block)" do
|
305
|
+
coll = @db.collection("testCollection")
|
306
|
+
result = []
|
307
|
+
|
308
|
+
# Insert a doc to assure we get a result
|
309
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
310
|
+
id = coll.insert(doc)
|
311
|
+
|
312
|
+
# If given an optional block +find+ will yield a Cursor to that block,
|
313
|
+
# close the cursor, and then return nil. This guarantees that partially
|
314
|
+
# evaluated cursors will be closed. If given no block +find+ returns a
|
315
|
+
# cursor.
|
316
|
+
# https://github.com/mongodb/mongo-ruby-driver/blob/1.10.1/lib/mongo/collection.rb#L178
|
317
|
+
|
318
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
319
|
+
blk = lambda { |x| x }
|
320
|
+
result = coll.find(:name => "MyName", :limit => 10, &blk)
|
321
|
+
end
|
322
|
+
|
323
|
+
traces = get_all_traces
|
324
|
+
traces.count.must_equal 4
|
325
|
+
|
326
|
+
validate_outer_layers(traces, 'mongo_test')
|
327
|
+
validate_event_keys(traces[1], @entry_kvs)
|
328
|
+
validate_event_keys(traces[2], @exit_kvs)
|
329
|
+
|
330
|
+
result.must_equal nil
|
331
|
+
traces[1]['Collection'].must_equal "testCollection"
|
332
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
333
|
+
traces[1]['QueryOp'].must_equal "find"
|
334
|
+
traces[1].has_key?('Query').must_equal true
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should trace group" do
|
338
|
+
coll = @db.collection("testCollection")
|
339
|
+
|
340
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
341
|
+
coll.group( :key => :type,
|
342
|
+
:cond => { :count => 1 },
|
343
|
+
:initial => { :count => 0 },
|
344
|
+
:reduce => 'function(obj,prev) { prev.count += obj.c; }')
|
345
|
+
end
|
346
|
+
|
347
|
+
traces = get_all_traces
|
348
|
+
traces.count.must_equal 4
|
349
|
+
|
350
|
+
validate_outer_layers(traces, 'mongo_test')
|
351
|
+
validate_event_keys(traces[1], @entry_kvs)
|
352
|
+
validate_event_keys(traces[2], @exit_kvs)
|
353
|
+
|
354
|
+
traces[1]['Collection'].must_equal "testCollection"
|
355
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
356
|
+
traces[1]['QueryOp'].must_equal "group"
|
357
|
+
# Don't test exact hash value since to_json hash ordering varies between 1.8.7 and 1.9+
|
358
|
+
traces[1].has_key?('Query').must_equal true
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should trace create, ensure and drop index" do
|
362
|
+
coll = @db.collection("testCollection")
|
363
|
+
|
364
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
365
|
+
coll.create_index("i")
|
366
|
+
coll.ensure_index("i")
|
367
|
+
coll.drop_index("i_1")
|
368
|
+
end
|
369
|
+
|
370
|
+
traces = get_all_traces
|
371
|
+
traces.count.must_equal 8
|
372
|
+
|
373
|
+
validate_outer_layers(traces, 'mongo_test')
|
374
|
+
validate_event_keys(traces[1], @entry_kvs)
|
375
|
+
validate_event_keys(traces[2], @exit_kvs)
|
376
|
+
|
377
|
+
traces[1]['Collection'].must_equal "testCollection"
|
378
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
379
|
+
traces[1]['QueryOp'].must_equal "create_index"
|
380
|
+
|
381
|
+
validate_event_keys(traces[3], @entry_kvs)
|
382
|
+
validate_event_keys(traces[4], @exit_kvs)
|
383
|
+
|
384
|
+
traces[3]['Collection'].must_equal "testCollection"
|
385
|
+
traces[3].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
386
|
+
traces[3]['QueryOp'].must_equal "ensure_index"
|
387
|
+
|
388
|
+
validate_event_keys(traces[5], @entry_kvs)
|
389
|
+
validate_event_keys(traces[6], @exit_kvs)
|
390
|
+
|
391
|
+
traces[5]['Collection'].must_equal "testCollection"
|
392
|
+
traces[5].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
393
|
+
traces[5]['QueryOp'].must_equal "drop_index"
|
394
|
+
end
|
395
|
+
|
396
|
+
it "should trace drop_indexes" do
|
397
|
+
coll = @db.collection("testCollection")
|
398
|
+
|
399
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
400
|
+
coll.drop_indexes
|
401
|
+
end
|
402
|
+
|
403
|
+
traces = get_all_traces
|
404
|
+
traces.count.must_equal 4
|
405
|
+
|
406
|
+
validate_outer_layers(traces, 'mongo_test')
|
407
|
+
validate_event_keys(traces[1], @entry_kvs)
|
408
|
+
validate_event_keys(traces[2], @exit_kvs)
|
409
|
+
|
410
|
+
traces[1]['Collection'].must_equal "testCollection"
|
411
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
412
|
+
traces[1]['QueryOp'].must_equal "drop_indexes"
|
413
|
+
end
|
414
|
+
|
415
|
+
it "should trace index_information" do
|
416
|
+
coll = @db.collection("testCollection")
|
417
|
+
|
418
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
419
|
+
coll.index_information
|
420
|
+
end
|
421
|
+
|
422
|
+
traces = get_all_traces
|
423
|
+
traces.count.must_equal 4
|
424
|
+
|
425
|
+
validate_outer_layers(traces, 'mongo_test')
|
426
|
+
validate_event_keys(traces[1], @entry_kvs)
|
427
|
+
validate_event_keys(traces[2], @exit_kvs)
|
428
|
+
|
429
|
+
traces[1]['Collection'].must_equal "testCollection"
|
430
|
+
traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
|
431
|
+
traces[1]['QueryOp'].must_equal "index_information"
|
432
|
+
end
|
433
|
+
|
434
|
+
it "should obey :collect_backtraces setting when true" do
|
435
|
+
Oboe::Config[:mongo][:collect_backtraces] = true
|
436
|
+
|
437
|
+
coll = @db.collection("testCollection")
|
438
|
+
|
439
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
440
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
441
|
+
id = coll.insert(doc)
|
442
|
+
end
|
443
|
+
|
444
|
+
traces = get_all_traces
|
445
|
+
layer_has_key(traces, 'mongo', 'Backtrace')
|
446
|
+
end
|
447
|
+
|
448
|
+
it "should obey :collect_backtraces setting when false" do
|
449
|
+
Oboe::Config[:mongo][:collect_backtraces] = false
|
450
|
+
|
451
|
+
coll = @db.collection("testCollection")
|
452
|
+
|
453
|
+
Oboe::API.start_trace('mongo_test', '', {}) do
|
454
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
455
|
+
id = coll.insert(doc)
|
456
|
+
end
|
457
|
+
|
458
|
+
traces = get_all_traces
|
459
|
+
layer_doesnt_have_key(traces, 'mongo', 'Backtrace')
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|