traceview 3.7.0-java → 3.7.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/gemfiles/delayed_job.gemfile +5 -0
- data/gemfiles/frameworks.gemfile +5 -0
- data/gemfiles/libraries.gemfile +8 -5
- data/gemfiles/rails32.gemfile +1 -1
- data/gemfiles/rails42.gemfile +5 -0
- data/lib/oboe_metal.rb +20 -7
- data/lib/traceview/inst/mongo.rb +1 -1
- data/lib/traceview/inst/mongo2.rb +226 -0
- data/lib/traceview/inst/moped.rb +32 -31
- data/lib/traceview/version.rb +1 -1
- data/test/frameworks/rails3x_test.rb +1 -0
- data/test/instrumentation/{mongo_test.rb → mongo_v1_test.rb} +9 -3
- data/test/instrumentation/mongo_v2_index_test.rb +124 -0
- data/test/instrumentation/mongo_v2_test.rb +585 -0
- data/test/instrumentation/mongo_v2_view_test.rb +435 -0
- data/test/instrumentation/moped_test.rb +1 -2
- data/test/minitest_helper.rb +1 -1
- metadata +11 -4
@@ -0,0 +1,585 @@
|
|
1
|
+
# Copyright (c) 2015 AppNeta, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
require 'minitest_helper'
|
5
|
+
|
6
|
+
unless ENV['TV_MONGO_SERVER']
|
7
|
+
ENV['TV_MONGO_SERVER'] = "127.0.0.1:27017"
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined?(::Mongo::VERSION) && Mongo::VERSION >= '2.0.0'
|
11
|
+
describe "MongoCollection" do
|
12
|
+
before do
|
13
|
+
clear_all_traces
|
14
|
+
|
15
|
+
@client = Mongo::Client.new([ ENV['TV_MONGO_SERVER'] ], :database => "traceview-#{ENV['RACK_ENV']}")
|
16
|
+
@db = @client.database
|
17
|
+
|
18
|
+
if Mongo::VERSION < '2.2'
|
19
|
+
Mongo::Logger.logger.level = Logger::INFO
|
20
|
+
else
|
21
|
+
@client.logger.level = Logger::INFO
|
22
|
+
end
|
23
|
+
|
24
|
+
@collections = @db.collection_names
|
25
|
+
@testCollection = @client[:test_collection]
|
26
|
+
@testCollection.create unless @collections.include? "test_collection"
|
27
|
+
|
28
|
+
# These are standard entry/exit KVs that are passed up with all mongo operations
|
29
|
+
@entry_kvs = {
|
30
|
+
'Layer' => 'mongo',
|
31
|
+
'Label' => 'entry',
|
32
|
+
'Flavor' => 'mongodb',
|
33
|
+
'Database' => 'traceview-test',
|
34
|
+
'RemoteHost' => ENV['TV_MONGO_SERVER'] }
|
35
|
+
|
36
|
+
@exit_kvs = { 'Layer' => 'mongo', 'Label' => 'exit' }
|
37
|
+
@collect_backtraces = TraceView::Config[:mongo][:collect_backtraces]
|
38
|
+
end
|
39
|
+
|
40
|
+
after do
|
41
|
+
TraceView::Config[:mongo][:collect_backtraces] = @collect_backtraces
|
42
|
+
|
43
|
+
if @db.collection_names.include?("temp_collection")
|
44
|
+
@db[:temp_collection].drop
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should trace collection creation" do
|
49
|
+
r = nil
|
50
|
+
collection = @db[:temp_collection]
|
51
|
+
TraceView::API.start_trace('mongo_test', nil, {}) do
|
52
|
+
r = collection.create
|
53
|
+
end
|
54
|
+
|
55
|
+
traces = get_all_traces
|
56
|
+
traces.count.must_equal 4
|
57
|
+
|
58
|
+
r.must_be_instance_of ::Mongo::Operation::Result
|
59
|
+
if Mongo::VERSION < '2.2'
|
60
|
+
r.successful?.must_equal true
|
61
|
+
else
|
62
|
+
r.ok?.must_equal true
|
63
|
+
end
|
64
|
+
|
65
|
+
validate_outer_layers(traces, 'mongo_test')
|
66
|
+
validate_event_keys(traces[1], @entry_kvs)
|
67
|
+
validate_event_keys(traces[2], @exit_kvs)
|
68
|
+
|
69
|
+
traces[1]['QueryOp'].must_equal "create"
|
70
|
+
traces[1]['New_Collection_Name'].must_equal "temp_collection"
|
71
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should trace drop_collection" do
|
75
|
+
r = nil
|
76
|
+
collection = @db[:deleteme_collection]
|
77
|
+
|
78
|
+
# Create something to drop unless it already exists
|
79
|
+
unless @db.collection_names.include?("deleteme_collection")
|
80
|
+
collection.create
|
81
|
+
end
|
82
|
+
|
83
|
+
TraceView::API.start_trace('mongo_test', nil, {}) do
|
84
|
+
r = collection.drop
|
85
|
+
end
|
86
|
+
|
87
|
+
traces = get_all_traces
|
88
|
+
traces.count.must_equal 4
|
89
|
+
|
90
|
+
r.must_be_instance_of ::Mongo::Operation::Result
|
91
|
+
if Mongo::VERSION < '2.2'
|
92
|
+
r.successful?.must_equal true
|
93
|
+
else
|
94
|
+
r.ok?.must_equal true
|
95
|
+
end
|
96
|
+
|
97
|
+
validate_outer_layers(traces, 'mongo_test')
|
98
|
+
validate_event_keys(traces[1], @entry_kvs)
|
99
|
+
validate_event_keys(traces[2], @exit_kvs)
|
100
|
+
|
101
|
+
traces[1]['QueryOp'].must_equal "drop"
|
102
|
+
traces[1]['Collection'].must_equal "deleteme_collection"
|
103
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should capture collection creation errors" do
|
107
|
+
collection = @db[:temp_collection]
|
108
|
+
collection.create
|
109
|
+
|
110
|
+
begin
|
111
|
+
TraceView::API.start_trace('mongo_test', nil, {}) do
|
112
|
+
collection.create
|
113
|
+
end
|
114
|
+
rescue
|
115
|
+
end
|
116
|
+
|
117
|
+
traces = get_all_traces
|
118
|
+
traces.count.must_equal 5
|
119
|
+
|
120
|
+
validate_outer_layers(traces, 'mongo_test')
|
121
|
+
validate_event_keys(traces[1], @entry_kvs)
|
122
|
+
validate_event_keys(traces[3], @exit_kvs)
|
123
|
+
|
124
|
+
traces[1]['QueryOp'].must_equal "create"
|
125
|
+
traces[1]['New_Collection_Name'].must_equal "temp_collection"
|
126
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
127
|
+
|
128
|
+
traces[2]['Layer'].must_equal "mongo"
|
129
|
+
traces[2]['Label'].must_equal "error"
|
130
|
+
traces[2]['ErrorClass'].must_equal "Mongo::Error::OperationFailure"
|
131
|
+
traces[2]['ErrorMsg'].must_equal "collection already exists ()"
|
132
|
+
traces[2].has_key?('Backtrace').must_equal true
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should trace insert_one" do
|
136
|
+
r = nil
|
137
|
+
collection = @db[:tv_collection]
|
138
|
+
|
139
|
+
TraceView::API.start_trace('mongo_test', nil, {}) do
|
140
|
+
r = collection.insert_one({ name => 'Rabel Lasen' })
|
141
|
+
end
|
142
|
+
|
143
|
+
traces = get_all_traces
|
144
|
+
traces.count.must_equal 4
|
145
|
+
|
146
|
+
r.must_be_instance_of Mongo::Operation::Write::Insert::Result
|
147
|
+
if Mongo::VERSION < '2.2'
|
148
|
+
r.successful?.must_equal true
|
149
|
+
else
|
150
|
+
r.ok?.must_equal true
|
151
|
+
end
|
152
|
+
|
153
|
+
validate_outer_layers(traces, 'mongo_test')
|
154
|
+
validate_event_keys(traces[1], @entry_kvs)
|
155
|
+
validate_event_keys(traces[2], @exit_kvs)
|
156
|
+
|
157
|
+
traces[1]['QueryOp'].must_equal "insert_one"
|
158
|
+
traces[1]['Collection'].must_equal "tv_collection"
|
159
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should trace insert_many" do
|
163
|
+
r = nil
|
164
|
+
collection = @db[:tv_collection]
|
165
|
+
|
166
|
+
TraceView::API.start_trace('mongo_test', nil, {}) do
|
167
|
+
r = collection.insert_many([
|
168
|
+
{ :name => 'Rabel Lasen' },
|
169
|
+
{ :name => 'Louval Raiden' }])
|
170
|
+
end
|
171
|
+
|
172
|
+
traces = get_all_traces
|
173
|
+
traces.count.must_equal 4
|
174
|
+
|
175
|
+
if Mongo::VERSION < '2.1'
|
176
|
+
r.must_be_instance_of Mongo::Operation::Write::Insert::Result
|
177
|
+
else
|
178
|
+
r.must_be_instance_of Mongo::BulkWrite::Result
|
179
|
+
r.inserted_count.must_equal 2
|
180
|
+
end
|
181
|
+
|
182
|
+
validate_outer_layers(traces, 'mongo_test')
|
183
|
+
validate_event_keys(traces[1], @entry_kvs)
|
184
|
+
validate_event_keys(traces[2], @exit_kvs)
|
185
|
+
|
186
|
+
traces[1]['QueryOp'].must_equal "insert_many"
|
187
|
+
traces[1]['Collection'].must_equal "tv_collection"
|
188
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should trace find" do
|
192
|
+
coll = @db[:test_collection]
|
193
|
+
r = nil
|
194
|
+
|
195
|
+
# Insert a doc to assure we get a result
|
196
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
197
|
+
coll.insert_one(doc)
|
198
|
+
|
199
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
200
|
+
r = coll.find(:name => "MyName", :limit => 1)
|
201
|
+
end
|
202
|
+
|
203
|
+
traces = get_all_traces
|
204
|
+
traces.count.must_equal 4
|
205
|
+
|
206
|
+
validate_outer_layers(traces, 'mongo_test')
|
207
|
+
validate_event_keys(traces[1], @entry_kvs)
|
208
|
+
validate_event_keys(traces[2], @exit_kvs)
|
209
|
+
|
210
|
+
r.must_be_instance_of Mongo::Collection::View
|
211
|
+
|
212
|
+
traces[1]['Collection'].must_equal "test_collection"
|
213
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
214
|
+
traces[1]['QueryOp'].must_equal "find"
|
215
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\",\"limit\":1}"
|
216
|
+
traces[1].has_key?('Query').must_equal true
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should trace find_one_and_delete" do
|
220
|
+
skip unless Mongo::VERSION >= '2.1'
|
221
|
+
|
222
|
+
coll = @db[:test_collection]
|
223
|
+
r = nil
|
224
|
+
|
225
|
+
# Insert a doc to assure we get a result
|
226
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
227
|
+
coll.insert_one(doc)
|
228
|
+
|
229
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
230
|
+
r = coll.find_one_and_delete(:name => "MyName")
|
231
|
+
end
|
232
|
+
|
233
|
+
traces = get_all_traces
|
234
|
+
traces.count.must_equal 4
|
235
|
+
|
236
|
+
validate_outer_layers(traces, 'mongo_test')
|
237
|
+
validate_event_keys(traces[1], @entry_kvs)
|
238
|
+
validate_event_keys(traces[2], @exit_kvs)
|
239
|
+
|
240
|
+
r.must_be_instance_of BSON::Document
|
241
|
+
|
242
|
+
traces[1]['Collection'].must_equal "test_collection"
|
243
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
244
|
+
traces[1]['QueryOp'].must_equal "find_one_and_delete"
|
245
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
246
|
+
traces[1].has_key?('Query').must_equal true
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should trace find_one_and_update" do
|
250
|
+
skip unless Mongo::VERSION >= '2.1'
|
251
|
+
coll = @db[:test_collection]
|
252
|
+
r = nil
|
253
|
+
|
254
|
+
# Insert a doc to assure we get a result
|
255
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
256
|
+
coll.insert_one(doc)
|
257
|
+
|
258
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
259
|
+
r = coll.find_one_and_update({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
|
260
|
+
end
|
261
|
+
|
262
|
+
traces = get_all_traces
|
263
|
+
traces.count.must_equal 4
|
264
|
+
|
265
|
+
validate_outer_layers(traces, 'mongo_test')
|
266
|
+
validate_event_keys(traces[1], @entry_kvs)
|
267
|
+
validate_event_keys(traces[2], @exit_kvs)
|
268
|
+
|
269
|
+
r.must_be_instance_of BSON::Document
|
270
|
+
|
271
|
+
traces[1]['Collection'].must_equal "test_collection"
|
272
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
273
|
+
traces[1]['QueryOp'].must_equal "find_one_and_update"
|
274
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
275
|
+
traces[1].has_key?('Query').must_equal true
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should trace find_one_and_replace" do
|
279
|
+
skip unless Mongo::VERSION >= '2.1'
|
280
|
+
coll = @db[:test_collection]
|
281
|
+
r = nil
|
282
|
+
|
283
|
+
# Insert a doc to assure we get a result
|
284
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
285
|
+
coll.insert_one(doc)
|
286
|
+
|
287
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
288
|
+
r = coll.find_one_and_replace({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
|
289
|
+
end
|
290
|
+
|
291
|
+
traces = get_all_traces
|
292
|
+
traces.count.must_equal 4
|
293
|
+
|
294
|
+
validate_outer_layers(traces, 'mongo_test')
|
295
|
+
validate_event_keys(traces[1], @entry_kvs)
|
296
|
+
validate_event_keys(traces[2], @exit_kvs)
|
297
|
+
|
298
|
+
r.must_be_instance_of BSON::Document
|
299
|
+
|
300
|
+
traces[1]['Collection'].must_equal "test_collection"
|
301
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
302
|
+
traces[1]['QueryOp'].must_equal "find_one_and_replace"
|
303
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
304
|
+
traces[1].has_key?('Query').must_equal true
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should trace update_one" do
|
308
|
+
skip unless Mongo::VERSION >= '2.1'
|
309
|
+
|
310
|
+
coll = @db[:test_collection]
|
311
|
+
r = nil
|
312
|
+
|
313
|
+
# Insert a doc to assure we get a result
|
314
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
315
|
+
coll.insert_one(doc)
|
316
|
+
|
317
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
318
|
+
r = coll.update_one({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
|
319
|
+
end
|
320
|
+
|
321
|
+
traces = get_all_traces
|
322
|
+
traces.count.must_equal 4
|
323
|
+
|
324
|
+
validate_outer_layers(traces, 'mongo_test')
|
325
|
+
validate_event_keys(traces[1], @entry_kvs)
|
326
|
+
validate_event_keys(traces[2], @exit_kvs)
|
327
|
+
|
328
|
+
r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
|
329
|
+
|
330
|
+
traces[1]['Collection'].must_equal "test_collection"
|
331
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
332
|
+
traces[1]['QueryOp'].must_equal "update_one"
|
333
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
334
|
+
traces[1].has_key?('Query').must_equal true
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should trace update_many" do
|
338
|
+
skip unless Mongo::VERSION > '2.1'
|
339
|
+
coll = @db[:test_collection]
|
340
|
+
r = nil
|
341
|
+
|
342
|
+
# Insert a doc to assure we get a result
|
343
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
344
|
+
coll.insert_one(doc)
|
345
|
+
|
346
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
347
|
+
r = coll.update_many({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
|
348
|
+
end
|
349
|
+
|
350
|
+
traces = get_all_traces
|
351
|
+
traces.count.must_equal 4
|
352
|
+
|
353
|
+
validate_outer_layers(traces, 'mongo_test')
|
354
|
+
validate_event_keys(traces[1], @entry_kvs)
|
355
|
+
validate_event_keys(traces[2], @exit_kvs)
|
356
|
+
|
357
|
+
r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
|
358
|
+
|
359
|
+
traces[1]['Collection'].must_equal "test_collection"
|
360
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
361
|
+
traces[1]['QueryOp'].must_equal "update_many"
|
362
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
363
|
+
traces[1].has_key?('Query').must_equal true
|
364
|
+
end
|
365
|
+
|
366
|
+
it "should trace delete_one" do
|
367
|
+
skip unless Mongo::VERSION > '2.1'
|
368
|
+
coll = @db[:test_collection]
|
369
|
+
r = nil
|
370
|
+
|
371
|
+
# Insert a doc to assure we get a result
|
372
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
373
|
+
coll.insert_one(doc)
|
374
|
+
|
375
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
376
|
+
r = coll.delete_one({ :name => 'MyName' })
|
377
|
+
end
|
378
|
+
|
379
|
+
traces = get_all_traces
|
380
|
+
traces.count.must_equal 4
|
381
|
+
|
382
|
+
validate_outer_layers(traces, 'mongo_test')
|
383
|
+
validate_event_keys(traces[1], @entry_kvs)
|
384
|
+
validate_event_keys(traces[2], @exit_kvs)
|
385
|
+
|
386
|
+
r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
|
387
|
+
|
388
|
+
traces[1]['Collection'].must_equal "test_collection"
|
389
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
390
|
+
traces[1]['QueryOp'].must_equal "delete_one"
|
391
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
392
|
+
traces[1].has_key?('Query').must_equal true
|
393
|
+
end
|
394
|
+
|
395
|
+
it "should trace delete_many" do
|
396
|
+
skip unless Mongo::VERSION > '2.1'
|
397
|
+
coll = @db[:test_collection]
|
398
|
+
r = nil
|
399
|
+
|
400
|
+
# Insert a doc to assure we get a result
|
401
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
402
|
+
coll.insert_one(doc)
|
403
|
+
|
404
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
405
|
+
r = coll.delete_many({ :name => 'MyName' })
|
406
|
+
end
|
407
|
+
|
408
|
+
traces = get_all_traces
|
409
|
+
traces.count.must_equal 4
|
410
|
+
|
411
|
+
validate_outer_layers(traces, 'mongo_test')
|
412
|
+
validate_event_keys(traces[1], @entry_kvs)
|
413
|
+
validate_event_keys(traces[2], @exit_kvs)
|
414
|
+
|
415
|
+
r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
|
416
|
+
|
417
|
+
traces[1]['Collection'].must_equal "test_collection"
|
418
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
419
|
+
traces[1]['QueryOp'].must_equal "delete_many"
|
420
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
421
|
+
traces[1].has_key?('Query').must_equal true
|
422
|
+
end
|
423
|
+
|
424
|
+
it "should trace replace_one" do
|
425
|
+
skip unless Mongo::VERSION > '2.1'
|
426
|
+
coll = @db[:test_collection]
|
427
|
+
r = nil
|
428
|
+
|
429
|
+
# Insert a doc to assure we get a result
|
430
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
431
|
+
coll.insert_one(doc)
|
432
|
+
|
433
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
434
|
+
r = coll.replace_one({ :name => 'test' }, { :name => 'test1' })
|
435
|
+
end
|
436
|
+
|
437
|
+
traces = get_all_traces
|
438
|
+
traces.count.must_equal 4
|
439
|
+
|
440
|
+
validate_outer_layers(traces, 'mongo_test')
|
441
|
+
validate_event_keys(traces[1], @entry_kvs)
|
442
|
+
validate_event_keys(traces[2], @exit_kvs)
|
443
|
+
|
444
|
+
r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
|
445
|
+
|
446
|
+
traces[1]['Collection'].must_equal "test_collection"
|
447
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
448
|
+
traces[1]['QueryOp'].must_equal "replace_one"
|
449
|
+
traces[1]['Query'].must_equal "{\"name\":\"test\"}"
|
450
|
+
traces[1].has_key?('Query').must_equal true
|
451
|
+
end
|
452
|
+
|
453
|
+
it "should trace count" do
|
454
|
+
skip unless Mongo::VERSION > '2.1'
|
455
|
+
coll = @db[:test_collection]
|
456
|
+
r = nil
|
457
|
+
|
458
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
459
|
+
r = coll.count({ :name => 'MyName' })
|
460
|
+
end
|
461
|
+
|
462
|
+
traces = get_all_traces
|
463
|
+
traces.count.must_equal 4
|
464
|
+
|
465
|
+
validate_outer_layers(traces, 'mongo_test')
|
466
|
+
validate_event_keys(traces[1], @entry_kvs)
|
467
|
+
validate_event_keys(traces[2], @exit_kvs)
|
468
|
+
|
469
|
+
r.is_a?(Numeric).must_equal true
|
470
|
+
|
471
|
+
traces[1]['Collection'].must_equal "test_collection"
|
472
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
473
|
+
traces[1]['QueryOp'].must_equal "count"
|
474
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
475
|
+
traces[1].has_key?('Query').must_equal true
|
476
|
+
end
|
477
|
+
|
478
|
+
it "should trace distinct" do
|
479
|
+
skip unless Mongo::VERSION > '2.1'
|
480
|
+
coll = @db[:test_collection]
|
481
|
+
r = nil
|
482
|
+
|
483
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
484
|
+
r = coll.distinct('name', { :name => 'MyName' })
|
485
|
+
end
|
486
|
+
|
487
|
+
traces = get_all_traces
|
488
|
+
traces.count.must_equal 4
|
489
|
+
|
490
|
+
validate_outer_layers(traces, 'mongo_test')
|
491
|
+
validate_event_keys(traces[1], @entry_kvs)
|
492
|
+
validate_event_keys(traces[2], @exit_kvs)
|
493
|
+
|
494
|
+
r.is_a?(Array).must_equal true
|
495
|
+
|
496
|
+
traces[1]['Collection'].must_equal "test_collection"
|
497
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
498
|
+
traces[1]['QueryOp'].must_equal "distinct"
|
499
|
+
traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
|
500
|
+
traces[1].has_key?('Query').must_equal true
|
501
|
+
end
|
502
|
+
|
503
|
+
it "should trace aggregate" do
|
504
|
+
skip unless Mongo::VERSION >= '2.1'
|
505
|
+
coll = @db[:test_collection]
|
506
|
+
r = nil
|
507
|
+
|
508
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
509
|
+
r = coll.aggregate([ { "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}} ])
|
510
|
+
end
|
511
|
+
|
512
|
+
traces = get_all_traces
|
513
|
+
traces.count.must_equal 4
|
514
|
+
|
515
|
+
validate_outer_layers(traces, 'mongo_test')
|
516
|
+
validate_event_keys(traces[1], @entry_kvs)
|
517
|
+
validate_event_keys(traces[2], @exit_kvs)
|
518
|
+
|
519
|
+
r.must_be_instance_of Mongo::Collection::View::Aggregation
|
520
|
+
|
521
|
+
traces[1]['Collection'].must_equal "test_collection"
|
522
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
523
|
+
traces[1]['QueryOp'].must_equal "aggregate"
|
524
|
+
traces[1].key?('Query').must_equal false
|
525
|
+
end
|
526
|
+
|
527
|
+
it "should trace bulk_write" do
|
528
|
+
coll = @db[:test_collection]
|
529
|
+
r = nil
|
530
|
+
|
531
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
532
|
+
r = coll.bulk_write([ { :insert_one => { :x => 1} },
|
533
|
+
{ :insert_one => { :x => 3} } ],
|
534
|
+
:ordered => true)
|
535
|
+
end
|
536
|
+
|
537
|
+
traces = get_all_traces
|
538
|
+
traces.count.must_equal 4
|
539
|
+
|
540
|
+
validate_outer_layers(traces, 'mongo_test')
|
541
|
+
validate_event_keys(traces[1], @entry_kvs)
|
542
|
+
validate_event_keys(traces[2], @exit_kvs)
|
543
|
+
|
544
|
+
if Mongo::VERSION < '2.1'
|
545
|
+
r.must_be_instance_of Hash
|
546
|
+
r[:n_inserted].must_equal 2
|
547
|
+
else
|
548
|
+
r.must_be_instance_of Mongo::BulkWrite::Result
|
549
|
+
end
|
550
|
+
|
551
|
+
traces[1]['Collection'].must_equal "test_collection"
|
552
|
+
traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
|
553
|
+
traces[1]['QueryOp'].must_equal "bulk_write"
|
554
|
+
traces[1].key?('Query').must_equal false
|
555
|
+
end
|
556
|
+
|
557
|
+
it "should obey :collect_backtraces setting when true" do
|
558
|
+
TraceView::Config[:mongo][:collect_backtraces] = true
|
559
|
+
|
560
|
+
coll = @db[:test_collection]
|
561
|
+
|
562
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
563
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
564
|
+
coll.insert_one(doc)
|
565
|
+
end
|
566
|
+
|
567
|
+
traces = get_all_traces
|
568
|
+
layer_has_key(traces, 'mongo', 'Backtrace')
|
569
|
+
end
|
570
|
+
|
571
|
+
it "should obey :collect_backtraces setting when false" do
|
572
|
+
TraceView::Config[:mongo][:collect_backtraces] = false
|
573
|
+
|
574
|
+
coll = @db[:test_collection]
|
575
|
+
|
576
|
+
TraceView::API.start_trace('mongo_test', '', {}) do
|
577
|
+
doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
|
578
|
+
coll.insert_one(doc)
|
579
|
+
end
|
580
|
+
|
581
|
+
traces = get_all_traces
|
582
|
+
layer_doesnt_have_key(traces, 'mongo', 'Backtrace')
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|