newrelic_rpm 3.7.2.190.beta → 3.7.2.192
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +48 -0
- data/LICENSE +1 -1
- data/lib/new_relic/agent/configuration/default_source.rb +0 -6
- data/lib/new_relic/agent/cross_app_monitor.rb +7 -6
- data/lib/new_relic/agent/datastores/mongo/metric_generator.rb +8 -0
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +27 -36
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +21 -11
- data/lib/new_relic/agent/instrumentation/mongo.rb +56 -40
- data/lib/new_relic/agent/method_tracer.rb +10 -3
- data/lib/new_relic/agent/transaction_sampler.rb +0 -3
- data/lib/sequel/extensions/newrelic_instrumentation.rb +12 -5
- data/test/helpers/mongo_metric_builder.rb +1 -1
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +2 -2
- data/test/multiverse/suites/mongo/Envfile +19 -28
- data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +437 -0
- data/test/multiverse/suites/mongo/helpers/mongo_replica_set.rb +97 -0
- data/test/multiverse/suites/mongo/helpers/mongo_replica_set_test.rb +82 -0
- data/test/multiverse/suites/mongo/helpers/mongo_server.rb +239 -0
- data/test/multiverse/suites/mongo/helpers/mongo_server_test.rb +176 -0
- data/test/multiverse/suites/mongo/mongo_connection_test.rb +40 -0
- data/test/multiverse/suites/mongo/mongo_instrumentation_test.rb +8 -393
- data/test/multiverse/suites/mongo/mongo_unsupported_version_test.rb +6 -4
- data/test/multiverse/suites/rails/ignore_test.rb +7 -2
- data/test/multiverse/suites/sequel/database.rb +24 -20
- data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +16 -0
- data/test/new_relic/agent/cross_app_monitor_test.rb +4 -2
- data/test/new_relic/agent/datastores/mongo/metric_generator_test.rb +27 -1
- data/test/new_relic/agent/datastores/mongo/metric_translator_test.rb +19 -9
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +497 -493
- data/test/new_relic/agent/method_tracer_test.rb +23 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +5 -16
- data/test/new_relic/json_wrapper_test.rb +5 -6
- data/test/performance/suites/trace_execution_scoped.rb +32 -0
- metadata +34 -26
- metadata.gz.sig +0 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'mongo'
|
6
|
+
require 'newrelic_rpm'
|
7
|
+
require 'new_relic/agent/datastores/mongo'
|
8
|
+
require 'securerandom'
|
9
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
|
10
|
+
|
11
|
+
if NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
12
|
+
require File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'mongo_metric_builder')
|
13
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_server')
|
14
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_replica_set')
|
15
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_operation_tests')
|
16
|
+
|
17
|
+
class NewRelic::Agent::Instrumentation::MongoConnectionTest
|
18
|
+
include Mongo
|
19
|
+
include ::NewRelic::TestHelpers::MongoMetricBuilder
|
20
|
+
include ::MongoOperationTests
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@client = Mongo::Connection.new($mongo.host, $mongo.port)
|
24
|
+
@database_name = "multiverse"
|
25
|
+
@database = @client.db(@database_name)
|
26
|
+
@collection_name = "tribbles-#{SecureRandom.hex(16)}"
|
27
|
+
@collection = @database.collection(@collection_name)
|
28
|
+
|
29
|
+
@tribble = {'name' => 'soterios johnson'}
|
30
|
+
|
31
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
32
|
+
NewRelic::Agent.drop_buffered_data
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown
|
36
|
+
NewRelic::Agent.drop_buffered_data
|
37
|
+
@database.drop_collection(@collection_name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -10,20 +10,20 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
|
|
10
10
|
|
11
11
|
if NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
12
12
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'mongo_metric_builder')
|
13
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_server')
|
14
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_replica_set')
|
15
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_operation_tests')
|
13
16
|
|
14
17
|
class NewRelic::Agent::Instrumentation::MongoInstrumentationTest < MiniTest::Unit::TestCase
|
15
18
|
include Mongo
|
16
19
|
include ::NewRelic::TestHelpers::MongoMetricBuilder
|
17
|
-
|
18
|
-
def client
|
19
|
-
MongoClient.new(ENV["MONGO_HOST"], ENV["MONGO_PORT"].to_i)
|
20
|
-
end
|
20
|
+
include ::MongoOperationTests
|
21
21
|
|
22
22
|
def setup
|
23
|
-
@client =
|
24
|
-
@database_name =
|
23
|
+
@client = Mongo::MongoClient.new($mongo.host, $mongo.port)
|
24
|
+
@database_name = "multiverse"
|
25
25
|
@database = @client.db(@database_name)
|
26
|
-
@collection_name =
|
26
|
+
@collection_name = "tribbles-#{SecureRandom.hex(16)}"
|
27
27
|
@collection = @database.collection(@collection_name)
|
28
28
|
|
29
29
|
@tribble = {'name' => 'soterios johnson'}
|
@@ -34,392 +34,7 @@ if NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
|
34
34
|
|
35
35
|
def teardown
|
36
36
|
NewRelic::Agent.drop_buffered_data
|
37
|
-
|
38
|
-
|
39
|
-
def test_records_metrics_for_insert
|
40
|
-
@collection.insert(@tribble)
|
41
|
-
|
42
|
-
metrics = build_test_metrics(:insert)
|
43
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
44
|
-
|
45
|
-
assert_metrics_recorded(expected)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_records_metrics_for_find
|
49
|
-
@collection.insert(@tribble)
|
50
|
-
NewRelic::Agent.drop_buffered_data
|
51
|
-
|
52
|
-
@collection.find(@tribble).to_a
|
53
|
-
|
54
|
-
metrics = build_test_metrics(:find)
|
55
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
56
|
-
|
57
|
-
assert_metrics_recorded(expected)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_records_metrics_for_find_one
|
61
|
-
@collection.insert(@tribble)
|
62
|
-
NewRelic::Agent.drop_buffered_data
|
63
|
-
|
64
|
-
@collection.find_one
|
65
|
-
|
66
|
-
metrics = build_test_metrics(:findOne)
|
67
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
68
|
-
|
69
|
-
assert_metrics_recorded(expected)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_records_metrics_for_remove
|
73
|
-
@collection.insert(@tribble)
|
74
|
-
NewRelic::Agent.drop_buffered_data
|
75
|
-
|
76
|
-
@collection.remove(@tribble).to_a
|
77
|
-
|
78
|
-
metrics = build_test_metrics(:remove)
|
79
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
80
|
-
|
81
|
-
assert_metrics_recorded(expected)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_records_metrics_for_save
|
85
|
-
@collection.save(@tribble)
|
86
|
-
|
87
|
-
metrics = build_test_metrics(:save)
|
88
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
89
|
-
|
90
|
-
assert_metrics_recorded(expected)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_save_does_not_record_insert
|
94
|
-
@collection.save(@tribble)
|
95
|
-
|
96
|
-
metrics = build_test_metrics(:save)
|
97
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
98
|
-
|
99
|
-
assert_metrics_not_recorded(['Datastore/operation/MongoDB/insert'])
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_records_metrics_for_update
|
103
|
-
updated = @tribble.dup
|
104
|
-
updated['name'] = 'codemonkey'
|
105
|
-
|
106
|
-
@collection.update(@tribble, updated)
|
107
|
-
|
108
|
-
metrics = build_test_metrics(:update)
|
109
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
110
|
-
|
111
|
-
assert_metrics_recorded(expected)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_records_metrics_for_distinct
|
115
|
-
@collection.distinct('name')
|
116
|
-
|
117
|
-
metrics = build_test_metrics(:distinct)
|
118
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
119
|
-
|
120
|
-
assert_metrics_recorded(expected)
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_records_metrics_for_count
|
124
|
-
@collection.count
|
125
|
-
|
126
|
-
metrics = build_test_metrics(:count)
|
127
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
128
|
-
|
129
|
-
assert_metrics_recorded(expected)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_records_metrics_for_group
|
133
|
-
@collection.group({:key => "name",
|
134
|
-
:initial => {:count => 0},
|
135
|
-
:reduce => "function(k,v) { v.count += 1; }" })
|
136
|
-
|
137
|
-
metrics = build_test_metrics(:group)
|
138
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
139
|
-
|
140
|
-
assert_metrics_recorded(expected)
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_records_metrics_for_find_and_modify
|
144
|
-
updated = @tribble.dup
|
145
|
-
updated['name'] = 'codemonkey'
|
146
|
-
@collection.find_and_modify(:query => @tribble, :update => updated)
|
147
|
-
|
148
|
-
metrics = build_test_metrics(:findAndModify)
|
149
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
150
|
-
|
151
|
-
assert_metrics_recorded(expected)
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_records_metrics_for_find_and_remove
|
155
|
-
@collection.find_and_modify(:query => @tribble, :remove =>true)
|
156
|
-
|
157
|
-
metrics = build_test_metrics(:findAndRemove)
|
158
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
159
|
-
|
160
|
-
assert_metrics_recorded(expected)
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_records_metrics_for_create_index
|
164
|
-
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
165
|
-
|
166
|
-
metrics = build_test_metrics(:createIndex)
|
167
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
168
|
-
|
169
|
-
assert_metrics_recorded(expected)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_records_metrics_for_ensure_index
|
173
|
-
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
174
|
-
|
175
|
-
metrics = build_test_metrics(:ensureIndex)
|
176
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
177
|
-
|
178
|
-
assert_metrics_recorded(expected)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_ensure_index_does_not_record_insert
|
182
|
-
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
183
|
-
|
184
|
-
assert_metrics_not_recorded(['Datastore/operation/MongoDB/insert'])
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_ensure_index_does_call_ensure_index
|
188
|
-
options = [[unique_field_name, Mongo::ASCENDING]]
|
189
|
-
|
190
|
-
@collection.expects(:ensure_index_without_new_relic_trace).with(options, any_parameters).once
|
191
|
-
@collection.ensure_index(options)
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_records_metrics_for_drop_index
|
195
|
-
name = @collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
196
|
-
NewRelic::Agent.drop_buffered_data
|
197
|
-
|
198
|
-
@collection.drop_index(name)
|
199
|
-
|
200
|
-
metrics = build_test_metrics(:dropIndex)
|
201
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
202
|
-
|
203
|
-
assert_metrics_recorded(expected)
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_records_metrics_for_drop_indexes
|
207
|
-
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
208
|
-
NewRelic::Agent.drop_buffered_data
|
209
|
-
|
210
|
-
@collection.drop_indexes
|
211
|
-
|
212
|
-
metrics = build_test_metrics(:dropIndexes)
|
213
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
214
|
-
|
215
|
-
assert_metrics_recorded(expected)
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_records_metrics_for_reindex
|
219
|
-
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
220
|
-
NewRelic::Agent.drop_buffered_data
|
221
|
-
|
222
|
-
@database.command({ :reIndex => @collection_name })
|
223
|
-
|
224
|
-
metrics = build_test_metrics(:reIndex)
|
225
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
226
|
-
|
227
|
-
assert_metrics_recorded(expected)
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_rename_collection
|
231
|
-
with_unique_collection do
|
232
|
-
@collection.rename("renamed_#{@collection_name}")
|
233
|
-
|
234
|
-
metrics = build_test_metrics(:renameCollection)
|
235
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
236
|
-
|
237
|
-
assert_metrics_recorded(expected)
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_rename_collection_via_db
|
242
|
-
with_unique_collection do
|
243
|
-
@database.rename_collection(@collection_name, "renamed_#{@collection_name}")
|
244
|
-
|
245
|
-
metrics = build_test_metrics(:renameCollection)
|
246
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
247
|
-
|
248
|
-
assert_metrics_recorded(expected)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
def test_drop_collection
|
253
|
-
with_unique_collection do
|
254
|
-
@database.drop_collection(@collection_name)
|
255
|
-
|
256
|
-
metrics = build_test_metrics(:drop)
|
257
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
258
|
-
|
259
|
-
assert_metrics_recorded(expected)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_collstats
|
264
|
-
@collection.stats
|
265
|
-
|
266
|
-
metrics = build_test_metrics(:collstats)
|
267
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
268
|
-
|
269
|
-
assert_metrics_recorded(expected)
|
270
|
-
end
|
271
|
-
|
272
|
-
def test_notices_nosql
|
273
|
-
segment = nil
|
274
|
-
|
275
|
-
in_transaction do
|
276
|
-
@collection.insert(@tribble)
|
277
|
-
segment = find_last_transaction_segment
|
278
|
-
end
|
279
|
-
|
280
|
-
expected = { :database => 'multiverse',
|
281
|
-
:collection => 'tribbles',
|
282
|
-
:operation => :insert}
|
283
|
-
|
284
|
-
result = segment.params[:statement]
|
285
|
-
|
286
|
-
assert_equal expected, result, "Expected result (#{result}) to be #{expected}"
|
287
|
-
end
|
288
|
-
|
289
|
-
def test_noticed_nosql_includes_operation
|
290
|
-
segment = nil
|
291
|
-
|
292
|
-
in_transaction do
|
293
|
-
@collection.insert(@tribble)
|
294
|
-
segment = find_last_transaction_segment
|
295
|
-
end
|
296
|
-
|
297
|
-
expected = :insert
|
298
|
-
|
299
|
-
query = segment.params[:statement]
|
300
|
-
result = query[:operation]
|
301
|
-
|
302
|
-
assert_equal expected, result
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_noticed_nosql_includes_save_operation
|
306
|
-
segment = nil
|
307
|
-
|
308
|
-
in_transaction do
|
309
|
-
@collection.save(@tribble)
|
310
|
-
segment = find_last_transaction_segment
|
311
|
-
end
|
312
|
-
|
313
|
-
expected = :save
|
314
|
-
|
315
|
-
query = segment.params[:statement]
|
316
|
-
result = query[:operation]
|
317
|
-
|
318
|
-
assert_equal expected, result
|
319
|
-
end
|
320
|
-
|
321
|
-
def test_noticed_nosql_includes_ensure_index_operation
|
322
|
-
segment = nil
|
323
|
-
|
324
|
-
in_transaction do
|
325
|
-
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
326
|
-
segment = find_last_transaction_segment
|
327
|
-
end
|
328
|
-
|
329
|
-
expected = :ensureIndex
|
330
|
-
|
331
|
-
query = segment.params[:statement]
|
332
|
-
result = query[:operation]
|
333
|
-
|
334
|
-
assert_equal expected, result
|
335
|
-
end
|
336
|
-
|
337
|
-
def test_noticed_nosql_does_not_contain_documents
|
338
|
-
segment = nil
|
339
|
-
|
340
|
-
in_transaction do
|
341
|
-
@collection.insert({'name' => 'soterios johnson'})
|
342
|
-
segment = find_last_transaction_segment
|
343
|
-
end
|
344
|
-
|
345
|
-
statement = segment.params[:statement]
|
346
|
-
|
347
|
-
refute statement.keys.include?(:documents), "Noticed NoSQL should not include documents: #{statement}"
|
348
|
-
end
|
349
|
-
|
350
|
-
def test_noticed_nosql_does_not_contain_selector_values
|
351
|
-
@collection.insert({'password' => '$ecret'})
|
352
|
-
segment = nil
|
353
|
-
|
354
|
-
in_transaction do
|
355
|
-
@collection.remove({'password' => '$ecret'})
|
356
|
-
segment = find_last_transaction_segment
|
357
|
-
end
|
358
|
-
|
359
|
-
statement = segment.params[:statement]
|
360
|
-
|
361
|
-
assert_equal '?', statement[:selector]['password']
|
362
|
-
end
|
363
|
-
|
364
|
-
def test_web_requests_record_all_web_metric
|
365
|
-
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
366
|
-
@collection.insert(@tribble)
|
367
|
-
|
368
|
-
metrics = build_test_metrics(:insert)
|
369
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
370
|
-
|
371
|
-
assert_metrics_recorded(expected)
|
372
|
-
end
|
373
|
-
|
374
|
-
def test_web_requests_do_not_record_all_other_metric
|
375
|
-
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
376
|
-
@collection.insert(@tribble)
|
377
|
-
|
378
|
-
assert_metrics_not_recorded(['Datastore/allOther'])
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_other_requests_record_all_other_metric
|
382
|
-
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
|
383
|
-
@collection.insert(@tribble)
|
384
|
-
|
385
|
-
metrics = build_test_metrics(:insert, :other)
|
386
|
-
expected = metrics_with_attributes(metrics, { :call_count => 1 })
|
387
|
-
|
388
|
-
assert_metrics_recorded(expected)
|
389
|
-
end
|
390
|
-
|
391
|
-
def test_other_requests_do_not_record_all_web_metric
|
392
|
-
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
|
393
|
-
@collection.insert(@tribble)
|
394
|
-
|
395
|
-
assert_metrics_not_recorded(['Datastore/allWeb'])
|
396
|
-
end
|
397
|
-
|
398
|
-
def with_unique_collection
|
399
|
-
original_collection_name = @collection_name
|
400
|
-
original_collection = @collection
|
401
|
-
|
402
|
-
@collection_name = "coll#{SecureRandom.hex(10)}"
|
403
|
-
@collection = @database.collection(@collection_name)
|
404
|
-
|
405
|
-
# Insert to make sure the collection actually exists...
|
406
|
-
@collection.insert({:junk => "data"})
|
407
|
-
NewRelic::Agent.drop_buffered_data
|
408
|
-
|
409
|
-
yield
|
410
|
-
ensure
|
411
|
-
@collection_name = original_collection_name
|
412
|
-
@collection = original_collection
|
413
|
-
end
|
414
|
-
|
415
|
-
def unique_field_name
|
416
|
-
"field#{SecureRandom.hex(10)}"
|
417
|
-
end
|
418
|
-
end
|
419
|
-
|
420
|
-
class NewRelic::Agent::Instrumentation::MongoConnectionTest < NewRelic::Agent::Instrumentation::MongoInstrumentationTest
|
421
|
-
def client
|
422
|
-
Mongo::Connection.new(ENV["MONGO_HOST"], ENV["MONGO_PORT"].to_i)
|
37
|
+
@database.drop_collection(@collection_name)
|
423
38
|
end
|
424
39
|
end
|
425
40
|
end
|