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
@@ -211,9 +211,6 @@ module NewRelic
|
|
211
211
|
statement.adapter = config[:adapter]
|
212
212
|
statement.config = config
|
213
213
|
end
|
214
|
-
if Agent.config[:override_sql_obfuscation_adapter]
|
215
|
-
statement.adapter = Agent.config[:override_sql_obfuscation_adapter]
|
216
|
-
end
|
217
214
|
statement.explainer = explainer
|
218
215
|
|
219
216
|
statement
|
@@ -67,6 +67,9 @@ module Sequel
|
|
67
67
|
engine.record_metrics( metrics, duration, :scoped => false )
|
68
68
|
end
|
69
69
|
|
70
|
+
THREAD_SAFE_CONNECTION_POOL_CLASSES = [
|
71
|
+
(defined?(::Sequel::ThreadedConnectionPool) && ::Sequel::ThreadedConnectionPool),
|
72
|
+
].compact.freeze
|
70
73
|
|
71
74
|
# Record the given +sql+ within a new scope, using the given +start+ and
|
72
75
|
# +finish+ times.
|
@@ -77,12 +80,16 @@ module Sequel
|
|
77
80
|
|
78
81
|
begin
|
79
82
|
scope = agent.stats_engine.push_scope( :sequel, start )
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
explainer = Proc.new do |*|
|
84
|
+
if THREAD_SAFE_CONNECTION_POOL_CLASSES.include?(self.pool.class)
|
85
|
+
self[ sql ].explain
|
86
|
+
else
|
87
|
+
NewRelic::Agent.logger.log_once(:info, :sequel_explain_skipped, "Not running SQL explains because Sequel is not in recognized multi-threaded mode")
|
88
|
+
nil
|
89
|
+
end
|
85
90
|
end
|
91
|
+
agent.transaction_sampler.notice_sql( sql, self.opts, duration, &explainer )
|
92
|
+
agent.sql_sampler.notice_sql( sql, metric, self.opts, duration, &explainer )
|
86
93
|
ensure
|
87
94
|
agent.stats_engine.pop_scope( scope, metric, finish )
|
88
95
|
end
|
@@ -70,7 +70,7 @@ class ThreadProfilingTest < MiniTest::Unit::TestCase
|
|
70
70
|
|
71
71
|
profile_data = $collector.calls_for('profile_data')[0]
|
72
72
|
assert_equal('666', profile_data.run_id, "Missing run_id, profile_data was #{profile_data.inspect}")
|
73
|
-
assert(profile_data.sample_count
|
73
|
+
assert(profile_data.sample_count >= 2, "Expected sample_count >= 2, but was #{profile_data.sample_count}")
|
74
74
|
|
75
75
|
assert_saw_traces(profile_data, "OTHER")
|
76
76
|
assert_saw_traces(profile_data, "AGENT")
|
@@ -90,7 +90,7 @@ class ThreadProfilingTest < MiniTest::Unit::TestCase
|
|
90
90
|
|
91
91
|
profile_data = $collector.calls_for('profile_data')[0]
|
92
92
|
assert_equal('666', profile_data.run_id, "Missing run_id, profile_data was #{profile_data.inspect}")
|
93
|
-
assert(profile_data.sample_count
|
93
|
+
assert(profile_data.sample_count >= 2, "Expected sample_count >= 2, but was #{profile_data.sample_count}")
|
94
94
|
|
95
95
|
assert_saw_traces(profile_data, "OTHER")
|
96
96
|
assert_saw_traces(profile_data, "AGENT")
|
@@ -17,13 +17,24 @@ RB
|
|
17
17
|
require 'timeout'
|
18
18
|
require 'socket'
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
class PreExistingMongo
|
21
|
+
attr_reader :host, :port
|
22
|
+
|
23
|
+
def initialize(host, port)
|
24
|
+
@host = host
|
25
|
+
@port = port
|
26
|
+
end
|
27
|
+
|
28
|
+
def stop(*_)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
$mongo = PreExistingMongo.new("localhost", 27017)
|
22
33
|
|
23
34
|
def mongo_running?
|
24
35
|
Timeout::timeout(1) do
|
25
36
|
begin
|
26
|
-
TCPSocket.new(
|
37
|
+
TCPSocket.new($mongo.host, $mongo.port).close
|
27
38
|
true
|
28
39
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
29
40
|
false
|
@@ -33,34 +44,14 @@ rescue Timeout::Error
|
|
33
44
|
false
|
34
45
|
end
|
35
46
|
|
36
|
-
def wait_for_mongo
|
37
|
-
Timeout::timeout(10) do
|
38
|
-
until mongo_running? do
|
39
|
-
sleep(0.1)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
47
|
before_suite do
|
45
|
-
if mongo_running?
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
`mkdir -p tmp`
|
50
|
-
`mongod --port #{ENV["MONGO_PORT"]} --pidfilepath tmp/mongo.pid &`
|
51
|
-
wait_for_mongo
|
52
|
-
|
53
|
-
$started_mongo = true
|
54
|
-
puts "Mongo Mongo Mongo!"
|
48
|
+
if !mongo_running?
|
49
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_server')
|
50
|
+
$mongo = MongoServer.new
|
51
|
+
$mongo.start(false)
|
55
52
|
end
|
56
53
|
end
|
57
54
|
|
58
55
|
after_suite do
|
59
|
-
|
60
|
-
puts "Shutting down test initiated Mongo."
|
61
|
-
mongo_pid = `cat tmp/mongo.pid`
|
62
|
-
`kill -9 #{mongo_pid}`
|
63
|
-
`rm tmp/mongo.pid`
|
64
|
-
puts "Mongo Mongo Mongo!"
|
65
|
-
end
|
56
|
+
$mongo.stop
|
66
57
|
end
|
@@ -0,0 +1,437 @@
|
|
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
|
+
module MongoOperationTests
|
6
|
+
def test_records_metrics_for_insert
|
7
|
+
@collection.insert(@tribble)
|
8
|
+
|
9
|
+
metrics = build_test_metrics(:insert)
|
10
|
+
expected = metrics_with_attributes(metrics)
|
11
|
+
|
12
|
+
assert_metrics_recorded(expected)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_records_metrics_for_find
|
16
|
+
@collection.insert(@tribble)
|
17
|
+
NewRelic::Agent.drop_buffered_data
|
18
|
+
|
19
|
+
@collection.find(@tribble).to_a
|
20
|
+
|
21
|
+
metrics = build_test_metrics(:find)
|
22
|
+
expected = metrics_with_attributes(metrics)
|
23
|
+
|
24
|
+
assert_metrics_recorded(expected)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_records_metrics_for_find_one
|
28
|
+
@collection.insert(@tribble)
|
29
|
+
NewRelic::Agent.drop_buffered_data
|
30
|
+
|
31
|
+
@collection.find_one
|
32
|
+
|
33
|
+
metrics = build_test_metrics(:findOne)
|
34
|
+
expected = metrics_with_attributes(metrics)
|
35
|
+
|
36
|
+
assert_metrics_recorded(expected)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_records_metrics_for_remove
|
40
|
+
@collection.insert(@tribble)
|
41
|
+
NewRelic::Agent.drop_buffered_data
|
42
|
+
|
43
|
+
@collection.remove(@tribble).to_a
|
44
|
+
|
45
|
+
metrics = build_test_metrics(:remove)
|
46
|
+
expected = metrics_with_attributes(metrics)
|
47
|
+
|
48
|
+
assert_metrics_recorded(expected)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_records_metrics_for_save
|
52
|
+
@collection.save(@tribble)
|
53
|
+
|
54
|
+
metrics = build_test_metrics(:save)
|
55
|
+
expected = metrics_with_attributes(metrics)
|
56
|
+
|
57
|
+
assert_metrics_recorded(expected)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_save_does_not_record_insert
|
61
|
+
@collection.save(@tribble)
|
62
|
+
|
63
|
+
metrics = build_test_metrics(:save)
|
64
|
+
expected = metrics_with_attributes(metrics)
|
65
|
+
|
66
|
+
assert_metrics_not_recorded(['Datastore/operation/MongoDB/insert'])
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_records_metrics_for_update
|
70
|
+
updated = @tribble.dup
|
71
|
+
updated['name'] = 'codemonkey'
|
72
|
+
|
73
|
+
@collection.update(@tribble, updated)
|
74
|
+
|
75
|
+
metrics = build_test_metrics(:update)
|
76
|
+
expected = metrics_with_attributes(metrics)
|
77
|
+
|
78
|
+
assert_metrics_recorded(expected)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_records_metrics_for_distinct
|
82
|
+
@collection.distinct('name')
|
83
|
+
|
84
|
+
metrics = build_test_metrics(:distinct)
|
85
|
+
expected = metrics_with_attributes(metrics)
|
86
|
+
|
87
|
+
assert_metrics_recorded(expected)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_records_metrics_for_count
|
91
|
+
@collection.count
|
92
|
+
|
93
|
+
metrics = build_test_metrics(:count)
|
94
|
+
expected = metrics_with_attributes(metrics)
|
95
|
+
|
96
|
+
assert_metrics_recorded(expected)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_records_metrics_for_group
|
100
|
+
@collection.group({:key => "name",
|
101
|
+
:initial => {:count => 0},
|
102
|
+
:reduce => "function(k,v) { v.count += 1; }" })
|
103
|
+
|
104
|
+
metrics = build_test_metrics(:group)
|
105
|
+
expected = metrics_with_attributes(metrics)
|
106
|
+
|
107
|
+
assert_metrics_recorded(expected)
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_records_metrics_for_find_and_modify
|
111
|
+
updated = @tribble.dup
|
112
|
+
updated['name'] = 'codemonkey'
|
113
|
+
@collection.find_and_modify(:query => @tribble, :update => updated)
|
114
|
+
|
115
|
+
metrics = build_test_metrics(:findAndModify)
|
116
|
+
expected = metrics_with_attributes(metrics)
|
117
|
+
|
118
|
+
assert_metrics_recorded(expected)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_records_metrics_for_find_and_remove
|
122
|
+
@collection.find_and_modify(:query => @tribble, :remove =>true)
|
123
|
+
|
124
|
+
metrics = build_test_metrics(:findAndRemove)
|
125
|
+
expected = metrics_with_attributes(metrics)
|
126
|
+
|
127
|
+
assert_metrics_recorded(expected)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_records_metrics_for_create_index
|
131
|
+
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
132
|
+
|
133
|
+
metrics = build_test_metrics(:createIndex)
|
134
|
+
expected = metrics_with_attributes(metrics)
|
135
|
+
|
136
|
+
assert_metrics_recorded(expected)
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_records_metrics_for_ensure_index
|
140
|
+
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
141
|
+
|
142
|
+
metrics = build_test_metrics(:ensureIndex)
|
143
|
+
expected = metrics_with_attributes(metrics)
|
144
|
+
|
145
|
+
assert_metrics_recorded(expected)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_records_metrics_for_ensure_index_with_symbol
|
149
|
+
@collection.ensure_index(unique_field_name.to_sym)
|
150
|
+
|
151
|
+
metrics = build_test_metrics(:ensureIndex)
|
152
|
+
expected = metrics_with_attributes(metrics)
|
153
|
+
|
154
|
+
assert_metrics_recorded(expected)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_records_metrics_for_ensure_index_with_string
|
158
|
+
@collection.ensure_index(unique_field_name)
|
159
|
+
|
160
|
+
metrics = build_test_metrics(:ensureIndex)
|
161
|
+
expected = metrics_with_attributes(metrics)
|
162
|
+
|
163
|
+
assert_metrics_recorded(expected)
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_ensure_index_does_not_record_insert
|
167
|
+
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
168
|
+
|
169
|
+
assert_metrics_not_recorded(['Datastore/operation/MongoDB/insert'])
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_ensure_index_does_call_ensure_index
|
173
|
+
options = [[unique_field_name, Mongo::ASCENDING]]
|
174
|
+
|
175
|
+
@collection.expects(:ensure_index_without_new_relic_trace).with(options, any_parameters).once
|
176
|
+
@collection.ensure_index(options)
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_records_metrics_for_drop_index
|
180
|
+
name = @collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
181
|
+
NewRelic::Agent.drop_buffered_data
|
182
|
+
|
183
|
+
@collection.drop_index(name)
|
184
|
+
|
185
|
+
metrics = build_test_metrics(:dropIndex)
|
186
|
+
expected = metrics_with_attributes(metrics)
|
187
|
+
|
188
|
+
assert_metrics_recorded(expected)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_records_metrics_for_drop_indexes
|
192
|
+
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
193
|
+
NewRelic::Agent.drop_buffered_data
|
194
|
+
|
195
|
+
@collection.drop_indexes
|
196
|
+
|
197
|
+
metrics = build_test_metrics(:dropIndexes)
|
198
|
+
expected = metrics_with_attributes(metrics)
|
199
|
+
|
200
|
+
assert_metrics_recorded(expected)
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_records_metrics_for_reindex
|
204
|
+
@collection.create_index([[unique_field_name, Mongo::ASCENDING]])
|
205
|
+
NewRelic::Agent.drop_buffered_data
|
206
|
+
|
207
|
+
@database.command({ :reIndex => @collection_name })
|
208
|
+
|
209
|
+
metrics = build_test_metrics(:reIndex)
|
210
|
+
expected = metrics_with_attributes(metrics)
|
211
|
+
|
212
|
+
assert_metrics_recorded(expected)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_rename_collection
|
216
|
+
ensure_collection_exists
|
217
|
+
|
218
|
+
@collection.rename("renamed_#{@collection_name}")
|
219
|
+
|
220
|
+
metrics = build_test_metrics(:renameCollection)
|
221
|
+
expected = metrics_with_attributes(metrics)
|
222
|
+
|
223
|
+
assert_metrics_recorded(expected)
|
224
|
+
ensure
|
225
|
+
@collection_name = "renamed_#{@collection_name}"
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_rename_collection_via_db
|
229
|
+
ensure_collection_exists
|
230
|
+
|
231
|
+
@database.rename_collection(@collection_name, "renamed_#{@collection_name}")
|
232
|
+
|
233
|
+
metrics = build_test_metrics(:renameCollection)
|
234
|
+
expected = metrics_with_attributes(metrics)
|
235
|
+
|
236
|
+
assert_metrics_recorded(expected)
|
237
|
+
ensure
|
238
|
+
@collection_name = "renamed_#{@collection_name}"
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_drop_collection
|
242
|
+
ensure_collection_exists
|
243
|
+
|
244
|
+
@database.drop_collection(@collection_name)
|
245
|
+
|
246
|
+
metrics = build_test_metrics(:drop)
|
247
|
+
expected = metrics_with_attributes(metrics)
|
248
|
+
|
249
|
+
assert_metrics_recorded(expected)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_collstats
|
253
|
+
@collection.insert(@tribble)
|
254
|
+
NewRelic::Agent.drop_buffered_data
|
255
|
+
@collection.stats
|
256
|
+
|
257
|
+
metrics = build_test_metrics(:collstats)
|
258
|
+
expected = metrics_with_attributes(metrics)
|
259
|
+
|
260
|
+
assert_metrics_recorded(expected)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_notices_nosql
|
264
|
+
segment = nil
|
265
|
+
|
266
|
+
in_transaction do
|
267
|
+
@collection.insert(@tribble)
|
268
|
+
segment = find_last_transaction_segment
|
269
|
+
end
|
270
|
+
|
271
|
+
expected = { :database => @database_name,
|
272
|
+
:collection => @collection_name,
|
273
|
+
:operation => :insert}
|
274
|
+
|
275
|
+
result = segment.params[:statement]
|
276
|
+
|
277
|
+
assert_equal expected, result, "Expected result (#{result}) to be #{expected}"
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_noticed_nosql_includes_operation
|
281
|
+
segment = nil
|
282
|
+
|
283
|
+
in_transaction do
|
284
|
+
@collection.insert(@tribble)
|
285
|
+
segment = find_last_transaction_segment
|
286
|
+
end
|
287
|
+
|
288
|
+
expected = :insert
|
289
|
+
|
290
|
+
query = segment.params[:statement]
|
291
|
+
result = query[:operation]
|
292
|
+
|
293
|
+
assert_equal expected, result
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_noticed_nosql_includes_save_operation
|
297
|
+
segment = nil
|
298
|
+
|
299
|
+
in_transaction do
|
300
|
+
@collection.save(@tribble)
|
301
|
+
segment = find_last_transaction_segment
|
302
|
+
end
|
303
|
+
|
304
|
+
expected = :save
|
305
|
+
|
306
|
+
query = segment.params[:statement]
|
307
|
+
result = query[:operation]
|
308
|
+
|
309
|
+
assert_equal expected, result
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_noticed_nosql_includes_ensure_index_operation
|
313
|
+
segment = nil
|
314
|
+
|
315
|
+
in_transaction do
|
316
|
+
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
317
|
+
segment = find_last_transaction_segment
|
318
|
+
end
|
319
|
+
|
320
|
+
assert_ensure_index_in_transaction_segment(segment)
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_noticed_nosql_includes_ensure_index_operation_with_symbol
|
324
|
+
segment = nil
|
325
|
+
|
326
|
+
in_transaction do
|
327
|
+
@collection.ensure_index(unique_field_name.to_sym)
|
328
|
+
segment = find_last_transaction_segment
|
329
|
+
end
|
330
|
+
|
331
|
+
assert_ensure_index_in_transaction_segment(segment)
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_noticed_nosql_includes_ensure_index_operation_with_string
|
335
|
+
segment = nil
|
336
|
+
|
337
|
+
in_transaction do
|
338
|
+
@collection.ensure_index(unique_field_name)
|
339
|
+
segment = find_last_transaction_segment
|
340
|
+
end
|
341
|
+
|
342
|
+
assert_ensure_index_in_transaction_segment(segment)
|
343
|
+
end
|
344
|
+
|
345
|
+
def assert_ensure_index_in_transaction_segment(segment)
|
346
|
+
query = segment.params[:statement]
|
347
|
+
result = query[:operation]
|
348
|
+
|
349
|
+
assert_equal :ensureIndex, result
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_noticed_nosql_does_not_contain_documents
|
353
|
+
segment = nil
|
354
|
+
|
355
|
+
in_transaction do
|
356
|
+
@collection.insert({'name' => 'soterios johnson'})
|
357
|
+
segment = find_last_transaction_segment
|
358
|
+
end
|
359
|
+
|
360
|
+
statement = segment.params[:statement]
|
361
|
+
|
362
|
+
refute statement.keys.include?(:documents), "Noticed NoSQL should not include documents: #{statement}"
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_noticed_nosql_does_not_contain_selector_values
|
366
|
+
@collection.insert({'password' => '$ecret'})
|
367
|
+
segment = nil
|
368
|
+
|
369
|
+
in_transaction do
|
370
|
+
@collection.remove({'password' => '$ecret'})
|
371
|
+
segment = find_last_transaction_segment
|
372
|
+
end
|
373
|
+
|
374
|
+
statement = segment.params[:statement]
|
375
|
+
|
376
|
+
assert_equal '?', statement[:selector]['password']
|
377
|
+
end
|
378
|
+
|
379
|
+
def test_web_requests_record_all_web_metric
|
380
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
381
|
+
@collection.insert(@tribble)
|
382
|
+
|
383
|
+
metrics = build_test_metrics(:insert)
|
384
|
+
expected = metrics_with_attributes(metrics)
|
385
|
+
|
386
|
+
assert_metrics_recorded(expected)
|
387
|
+
end
|
388
|
+
|
389
|
+
def test_web_requests_do_not_record_all_other_metric
|
390
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(true)
|
391
|
+
@collection.insert(@tribble)
|
392
|
+
|
393
|
+
assert_metrics_not_recorded(['Datastore/allOther'])
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_other_requests_record_all_other_metric
|
397
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
|
398
|
+
@collection.insert(@tribble)
|
399
|
+
|
400
|
+
metrics = build_test_metrics(:insert, :other)
|
401
|
+
expected = metrics_with_attributes(metrics)
|
402
|
+
|
403
|
+
assert_metrics_recorded(expected)
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_other_requests_do_not_record_all_web_metric
|
407
|
+
NewRelic::Agent::Transaction.stubs(:recording_web_transaction?).returns(false)
|
408
|
+
@collection.insert(@tribble)
|
409
|
+
|
410
|
+
assert_metrics_not_recorded(['Datastore/allWeb'])
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_insert_records_instance_metric
|
414
|
+
@collection.insert(@tribble)
|
415
|
+
assert_metrics_recorded(["Datastore/instance/MongoDB/localhost:#{@client.port}/#{@database_name}"])
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_save_records_instance_metric
|
419
|
+
@collection.save(@tribble)
|
420
|
+
assert_metrics_recorded(["Datastore/instance/MongoDB/localhost:#{@client.port}/#{@database_name}"])
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_ensure_index_records_instance_metric
|
424
|
+
@collection.ensure_index([[unique_field_name, Mongo::ASCENDING]])
|
425
|
+
assert_metrics_recorded(["Datastore/instance/MongoDB/localhost:#{@client.port}/#{@database_name}"])
|
426
|
+
end
|
427
|
+
|
428
|
+
def unique_field_name
|
429
|
+
"field#{SecureRandom.hex(10)}"
|
430
|
+
end
|
431
|
+
|
432
|
+
def ensure_collection_exists
|
433
|
+
@collection.insert(:junk => "data")
|
434
|
+
NewRelic::Agent.drop_buffered_data
|
435
|
+
end
|
436
|
+
|
437
|
+
end
|