traceview 3.7.0-java → 3.7.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,435 @@
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 "MongoCollectionView" do
12
+ before do
13
+ clear_all_traces
14
+
15
+ @client = Mongo::Client.new([ ENV['TV_MONGO_SERVER'] ], :database => "traceview-#{ENV['RACK_ENV']}")
16
+ if Mongo::VERSION < '2.2'
17
+ Mongo::Logger.logger.level = Logger::INFO
18
+ else
19
+ @client.logger.level = Logger::INFO
20
+ end
21
+
22
+ @db = @client.database
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
+ end
43
+
44
+ it "should trace find_one_and_delete" do
45
+ coll = @db[:test_collection]
46
+ r = nil
47
+
48
+ # Insert a doc to assure we get a result
49
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
50
+ coll.insert_one(doc)
51
+ cv = coll.find({:name => "MyName"})
52
+
53
+ TraceView::API.start_trace('mongo_test', '', {}) do
54
+ r = cv.find_one_and_delete
55
+ end
56
+
57
+ traces = get_all_traces
58
+ traces.count.must_equal 4
59
+
60
+ validate_outer_layers(traces, 'mongo_test')
61
+ validate_event_keys(traces[1], @entry_kvs)
62
+ validate_event_keys(traces[2], @exit_kvs)
63
+
64
+ r.must_be_instance_of BSON::Document
65
+
66
+ traces[1]['Collection'].must_equal "test_collection"
67
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
68
+ traces[1]['QueryOp'].must_equal "find_one_and_delete"
69
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
70
+ traces[1].has_key?('Query').must_equal true
71
+ end
72
+
73
+ it "should trace find_one_and_update" do
74
+ coll = @db[:test_collection]
75
+ r = nil
76
+
77
+ # Insert a doc to assure we get a result
78
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
79
+ coll.insert_one(doc)
80
+ cv = coll.find({:name => "MyName"})
81
+
82
+ TraceView::API.start_trace('mongo_test', '', {}) do
83
+ r = cv.find_one_and_update({ "$set" => { :name => 'test1' }}, :return_document => :after)
84
+ end
85
+
86
+ traces = get_all_traces
87
+ traces.count.must_equal 4
88
+
89
+ validate_outer_layers(traces, 'mongo_test')
90
+ validate_event_keys(traces[1], @entry_kvs)
91
+ validate_event_keys(traces[2], @exit_kvs)
92
+
93
+ r.must_be_instance_of BSON::Document
94
+
95
+ traces[1]['Collection'].must_equal "test_collection"
96
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
97
+ traces[1]['QueryOp'].must_equal "find_one_and_update"
98
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
99
+ traces[1].has_key?('Query').must_equal true
100
+ end
101
+
102
+ it "should trace update_one" do
103
+ coll = @db[:test_collection]
104
+ r = nil
105
+
106
+ # Insert a doc to assure we get a result
107
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
108
+ coll.insert_one(doc)
109
+ cv = coll.find({:name => "MyName"})
110
+
111
+ TraceView::API.start_trace('mongo_test', '', {}) do
112
+ r = cv.update_one({ "$set" => { :name => 'test1' }}, :return_document => :after)
113
+ end
114
+
115
+ traces = get_all_traces
116
+ traces.count.must_equal 4
117
+
118
+ validate_outer_layers(traces, 'mongo_test')
119
+ validate_event_keys(traces[1], @entry_kvs)
120
+ validate_event_keys(traces[2], @exit_kvs)
121
+
122
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
123
+
124
+ traces[1]['Collection'].must_equal "test_collection"
125
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
126
+ traces[1]['QueryOp'].must_equal "update_one"
127
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
128
+ traces[1].has_key?('Query').must_equal true
129
+ end
130
+
131
+ it "should trace update_many" do
132
+ coll = @db[:test_collection]
133
+ r = nil
134
+
135
+ # Insert a doc to assure we get a result
136
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
137
+ coll.insert_one(doc)
138
+ cv = coll.find({:name => "MyName"})
139
+
140
+ TraceView::API.start_trace('mongo_test', '', {}) do
141
+ r = cv.update_many({ "$set" => { :name => 'test1' }}, :return_document => :after)
142
+ end
143
+
144
+ traces = get_all_traces
145
+ traces.count.must_equal 4
146
+
147
+ validate_outer_layers(traces, 'mongo_test')
148
+ validate_event_keys(traces[1], @entry_kvs)
149
+ validate_event_keys(traces[2], @exit_kvs)
150
+
151
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
152
+
153
+ traces[1]['Collection'].must_equal "test_collection"
154
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
155
+ traces[1]['QueryOp'].must_equal "update_many"
156
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
157
+ traces[1].has_key?('Query').must_equal true
158
+ end
159
+
160
+ it "should trace collection delete_one" do
161
+ coll = @db[:test_collection]
162
+ r = nil
163
+
164
+ # Insert a doc to assure we get a result
165
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
166
+ coll.insert_one(doc)
167
+ cv = coll.find({:name => "MyName"})
168
+
169
+ TraceView::API.start_trace('mongo_test', '', {}) do
170
+ r = cv.delete_one
171
+ end
172
+
173
+ traces = get_all_traces
174
+ traces.count.must_equal 4
175
+
176
+ validate_outer_layers(traces, 'mongo_test')
177
+ validate_event_keys(traces[1], @entry_kvs)
178
+ validate_event_keys(traces[2], @exit_kvs)
179
+
180
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
181
+
182
+ traces[1]['Collection'].must_equal "test_collection"
183
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
184
+ traces[1]['QueryOp'].must_equal "delete_one"
185
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
186
+ traces[1].has_key?('Query').must_equal true
187
+ end
188
+
189
+ it "should trace collection delete_many" do
190
+ coll = @db[:test_collection]
191
+ r = nil
192
+
193
+ # Insert a doc to assure we get a result
194
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
195
+ coll.insert_one(doc)
196
+ cv = coll.find({ :name => 'MyName' })
197
+
198
+ TraceView::API.start_trace('mongo_test', '', {}) do
199
+ r = cv.delete_many
200
+ end
201
+
202
+ traces = get_all_traces
203
+ traces.count.must_equal 4
204
+
205
+ validate_outer_layers(traces, 'mongo_test')
206
+ validate_event_keys(traces[1], @entry_kvs)
207
+ validate_event_keys(traces[2], @exit_kvs)
208
+
209
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
210
+
211
+ traces[1]['Collection'].must_equal "test_collection"
212
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
213
+ traces[1]['QueryOp'].must_equal "delete_many"
214
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
215
+ traces[1].has_key?('Query').must_equal true
216
+ end
217
+
218
+ it "should trace collection view delete_one" do
219
+ coll = @db[:test_collection]
220
+ r = nil
221
+
222
+ # Insert a doc to assure we get a result
223
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
224
+ coll.insert_one(doc)
225
+ cv = coll.find({ :name => 'MyName' })
226
+
227
+ TraceView::API.start_trace('mongo_test', '', {}) do
228
+ r = cv.delete_one
229
+ end
230
+
231
+ traces = get_all_traces
232
+ traces.count.must_equal 4
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
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
239
+
240
+ traces[1]['Collection'].must_equal "test_collection"
241
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
242
+ traces[1]['QueryOp'].must_equal "delete_one"
243
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
244
+ traces[1].has_key?('Query').must_equal true
245
+ end
246
+
247
+ it "should trace collection view delete_many" do
248
+ coll = @db[:test_collection]
249
+ r = nil
250
+
251
+ # Insert a doc to assure we get a result
252
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
253
+ coll.insert_one(doc)
254
+ cv = coll.find({ :name => 'MyName' })
255
+
256
+ TraceView::API.start_trace('mongo_test', '', {}) do
257
+ r = cv.delete_many
258
+ end
259
+
260
+ traces = get_all_traces
261
+ traces.count.must_equal 4
262
+
263
+ validate_outer_layers(traces, 'mongo_test')
264
+ validate_event_keys(traces[1], @entry_kvs)
265
+ validate_event_keys(traces[2], @exit_kvs)
266
+
267
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
268
+
269
+ traces[1]['Collection'].must_equal "test_collection"
270
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
271
+ traces[1]['QueryOp'].must_equal "delete_many"
272
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
273
+ traces[1].has_key?('Query').must_equal true
274
+ end
275
+
276
+ it "should trace replace_one" do
277
+ coll = @db[:test_collection]
278
+ r = nil
279
+
280
+ # Insert a doc to assure we get a result
281
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
282
+ coll.insert_one(doc)
283
+ cv = coll.find({ :name => 'MyName' })
284
+
285
+ TraceView::API.start_trace('mongo_test', '', {}) do
286
+ r = cv.replace_one({ :name => 'test1' })
287
+ end
288
+
289
+ traces = get_all_traces
290
+ traces.count.must_equal 4
291
+
292
+ validate_outer_layers(traces, 'mongo_test')
293
+ validate_event_keys(traces[1], @entry_kvs)
294
+ validate_event_keys(traces[2], @exit_kvs)
295
+
296
+ r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
297
+
298
+ traces[1]['Collection'].must_equal "test_collection"
299
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
300
+ traces[1]['QueryOp'].must_equal "replace_one"
301
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
302
+ traces[1].has_key?('Query').must_equal true
303
+ end
304
+
305
+ it "should trace count" do
306
+ coll = @db[:test_collection]
307
+ r = nil
308
+
309
+ cv = coll.find({ :name => 'MyName' })
310
+
311
+ TraceView::API.start_trace('mongo_test', '', {}) do
312
+ r = cv.count({ :name => 'MyName' })
313
+ end
314
+
315
+ traces = get_all_traces
316
+ traces.count.must_equal 4
317
+
318
+ validate_outer_layers(traces, 'mongo_test')
319
+ validate_event_keys(traces[1], @entry_kvs)
320
+ validate_event_keys(traces[2], @exit_kvs)
321
+
322
+ r.is_a?(Numeric).must_equal true
323
+
324
+ traces[1]['Collection'].must_equal "test_collection"
325
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
326
+ traces[1]['QueryOp'].must_equal "count"
327
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
328
+ traces[1].has_key?('Query').must_equal true
329
+ end
330
+
331
+ it "should trace distinct" do
332
+ coll = @db[:test_collection]
333
+ r = nil
334
+
335
+ cv = coll.find({ :name => 'MyName' })
336
+
337
+ TraceView::API.start_trace('mongo_test', '', {}) do
338
+ r = cv.distinct('name', { :name => 'MyName' })
339
+ end
340
+
341
+ traces = get_all_traces
342
+ traces.count.must_equal 4
343
+
344
+ validate_outer_layers(traces, 'mongo_test')
345
+ validate_event_keys(traces[1], @entry_kvs)
346
+ validate_event_keys(traces[2], @exit_kvs)
347
+
348
+ r.is_a?(Array).must_equal true
349
+
350
+ traces[1]['Collection'].must_equal "test_collection"
351
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
352
+ traces[1]['QueryOp'].must_equal "distinct"
353
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
354
+ traces[1].has_key?('Query').must_equal true
355
+ end
356
+
357
+ it "should trace aggregate" do
358
+ coll = @db[:test_collection]
359
+ r = nil
360
+
361
+ cv = coll.find({ :name => 'MyName' })
362
+
363
+ TraceView::API.start_trace('mongo_test', '', {}) do
364
+ r = cv.aggregate([ { "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}} ])
365
+ end
366
+
367
+ traces = get_all_traces
368
+ traces.count.must_equal 4
369
+
370
+ validate_outer_layers(traces, 'mongo_test')
371
+ validate_event_keys(traces[1], @entry_kvs)
372
+ validate_event_keys(traces[2], @exit_kvs)
373
+
374
+ r.must_be_instance_of Mongo::Collection::View::Aggregation
375
+
376
+ traces[1]['Collection'].must_equal "test_collection"
377
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
378
+ traces[1]['QueryOp'].must_equal "aggregate"
379
+ traces[1].key?('Query').must_equal false
380
+ end
381
+
382
+ it "should trace map_reduce" do
383
+ coll = @db[:test_collection]
384
+ view = coll.find(:name => "MyName")
385
+
386
+ TraceView::API.start_trace('mongo_test', '', {}) do
387
+ map = "function() { emit(this.name, 1); }"
388
+ reduce = "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
389
+ view.map_reduce(map, reduce, { :out => "mr_results", :limit => 100, :read => :primary })
390
+ end
391
+
392
+ traces = get_all_traces
393
+ traces.count.must_equal 4
394
+
395
+ validate_outer_layers(traces, 'mongo_test')
396
+ validate_event_keys(traces[1], @entry_kvs)
397
+ validate_event_keys(traces[2], @exit_kvs)
398
+
399
+ traces[1]['Collection'].must_equal "test_collection"
400
+ traces[1].has_key?('Backtrace').must_equal TraceView::Config[:mongo][:collect_backtraces]
401
+ traces[1]['QueryOp'].must_equal "map_reduce"
402
+ traces[1]['Map_Function'].must_equal "function() { emit(this.name, 1); }"
403
+ traces[1]['Reduce_Function'].must_equal "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
404
+ traces[1]['Limit'].must_equal 100
405
+ end
406
+
407
+ it "should obey :collect_backtraces setting when true" do
408
+ TraceView::Config[:mongo][:collect_backtraces] = true
409
+
410
+ coll = @db[:test_collection]
411
+
412
+ TraceView::API.start_trace('mongo_test', '', {}) do
413
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
414
+ coll.insert_one(doc)
415
+ end
416
+
417
+ traces = get_all_traces
418
+ layer_has_key(traces, 'mongo', 'Backtrace')
419
+ end
420
+
421
+ it "should obey :collect_backtraces setting when false" do
422
+ TraceView::Config[:mongo][:collect_backtraces] = false
423
+
424
+ coll = @db[:test_collection]
425
+
426
+ TraceView::API.start_trace('mongo_test', '', {}) do
427
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
428
+ coll.insert_one(doc)
429
+ end
430
+
431
+ traces = get_all_traces
432
+ layer_doesnt_have_key(traces, 'mongo', 'Backtrace')
433
+ end
434
+ end
435
+ end
@@ -25,8 +25,7 @@ if RUBY_VERSION >= '1.9.3'
25
25
  'Label' => 'entry',
26
26
  'Flavor' => 'mongodb',
27
27
  'Database' => 'moped_test',
28
- 'RemoteHost' => ENV['TV_MONGO_SERVER'].split(':')[0],
29
- 'RemotePort' => ENV['TV_MONGO_SERVER'].split(':')[1].to_i }
28
+ 'RemoteHost' => ENV['TV_MONGO_SERVER'] }
30
29
 
31
30
  @exit_kvs = { 'Layer' => 'mongo', 'Label' => 'exit' }
32
31
  @collect_backtraces = TraceView::Config[:moped][:collect_backtraces]
@@ -124,7 +124,7 @@ end
124
124
  def validate_event_keys(event, kvs)
125
125
  kvs.each do |k, v|
126
126
  assert_equal true, event.key?(k), "#{k} is missing"
127
- assert event[k] == v, "#{k} != #{v}"
127
+ assert event[k] == v, "#{k} != #{v} (#{event[k]})"
128
128
  end
129
129
  end
130
130
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traceview
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.1
5
5
  platform: java
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-16 00:00:00.000000000 Z
12
+ date: 2016-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -152,6 +152,7 @@ files:
152
152
  - lib/traceview/inst/memcache.rb
153
153
  - lib/traceview/inst/memcached.rb
154
154
  - lib/traceview/inst/mongo.rb
155
+ - lib/traceview/inst/mongo2.rb
155
156
  - lib/traceview/inst/moped.rb
156
157
  - lib/traceview/inst/rack.rb
157
158
  - lib/traceview/inst/redis.rb
@@ -196,7 +197,10 @@ files:
196
197
  - test/instrumentation/httpclient_test.rb
197
198
  - test/instrumentation/memcache_test.rb
198
199
  - test/instrumentation/memcached_test.rb
199
- - test/instrumentation/mongo_test.rb
200
+ - test/instrumentation/mongo_v1_test.rb
201
+ - test/instrumentation/mongo_v2_index_test.rb
202
+ - test/instrumentation/mongo_v2_test.rb
203
+ - test/instrumentation/mongo_v2_view_test.rb
200
204
  - test/instrumentation/moped_test.rb
201
205
  - test/instrumentation/rack_test.rb
202
206
  - test/instrumentation/redis_hashes_test.rb
@@ -294,11 +298,13 @@ test_files:
294
298
  - test/instrumentation/redis_sortedsets_test.rb
295
299
  - test/instrumentation/rack_test.rb
296
300
  - test/instrumentation/sidekiq-client_test.rb
301
+ - test/instrumentation/mongo_v2_index_test.rb
297
302
  - test/instrumentation/cassandra_test.rb
298
303
  - test/instrumentation/redis_strings_test.rb
299
304
  - test/instrumentation/typhoeus_test.rb
300
305
  - test/instrumentation/sequel_mysql2_test.rb
301
306
  - test/instrumentation/bunny_consumer_test.rb
307
+ - test/instrumentation/mongo_v2_view_test.rb
302
308
  - test/instrumentation/sidekiq-worker_test.rb
303
309
  - test/instrumentation/redis_misc_test.rb
304
310
  - test/instrumentation/faraday_test.rb
@@ -307,12 +313,13 @@ test_files:
307
313
  - test/instrumentation/memcache_test.rb
308
314
  - test/instrumentation/resque_test.rb
309
315
  - test/instrumentation/redis_hashes_test.rb
310
- - test/instrumentation/mongo_test.rb
311
316
  - test/instrumentation/redis_lists_test.rb
317
+ - test/instrumentation/mongo_v2_test.rb
312
318
  - test/instrumentation/curb_test.rb
313
319
  - test/instrumentation/memcached_test.rb
314
320
  - test/instrumentation/em_http_request_test.rb
315
321
  - test/instrumentation/rest-client_test.rb
322
+ - test/instrumentation/mongo_v1_test.rb
316
323
  - test/reporter/reporter_test.rb
317
324
  - test/models/widget.rb
318
325
  - test/profiling/method_profiling_test.rb