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
@@ -8,15 +8,16 @@ require 'new_relic/agent/datastores/mongo'
|
|
8
8
|
require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
|
9
9
|
|
10
10
|
if !NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
11
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'mongo_server')
|
11
12
|
|
12
|
-
class NewRelic::Agent::Instrumentation::
|
13
|
+
class NewRelic::Agent::Instrumentation::MongoUnsupportedVersionTest < MiniTest::Unit::TestCase
|
13
14
|
include Mongo
|
14
15
|
|
15
16
|
def setup
|
16
|
-
@client = Mongo::Connection.new(
|
17
|
-
@database_name =
|
17
|
+
@client = Mongo::Connection.new($mongo.host, $mongo.port)
|
18
|
+
@database_name = "multiverse"
|
18
19
|
@database = @client.db(@database_name)
|
19
|
-
@collection_name =
|
20
|
+
@collection_name = "tribbles-#{SecureRandom.hex(16)}"
|
20
21
|
@collection = @database.collection(@collection_name)
|
21
22
|
|
22
23
|
@tribble = {'name' => 'soterios johnson'}
|
@@ -26,6 +27,7 @@ if !NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
|
26
27
|
|
27
28
|
def teardown
|
28
29
|
NewRelic::Agent.drop_buffered_data
|
30
|
+
@database.drop_collection(@collection_name)
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_records_metrics_for_insert
|
@@ -24,10 +24,11 @@ class IgnoredController < ApplicationController
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class IgnoredActionsTest < ActionDispatch::IntegrationTest
|
27
|
-
|
28
27
|
include MultiverseHelpers
|
29
28
|
|
30
|
-
setup_and_teardown_agent
|
29
|
+
setup_and_teardown_agent(:cross_process_id => "boo",
|
30
|
+
:encoding_key => "\0",
|
31
|
+
:trusted_account_ids => [1])
|
31
32
|
|
32
33
|
def after_setup
|
33
34
|
# Make sure we've got a blank slate for doing easier metric comparisons
|
@@ -45,4 +46,8 @@ class IgnoredActionsTest < ActionDispatch::IntegrationTest
|
|
45
46
|
assert_metrics_not_recorded(["Apdex"])
|
46
47
|
end
|
47
48
|
|
49
|
+
def test_should_not_write_cat_response_headers_for_ignored_transactions
|
50
|
+
get 'ignored/action_to_ignore', nil, {'X-NewRelic-ID' => Base64.encode64('1#234')}
|
51
|
+
assert_nil @response.headers["X-NewRelic-App-Data"]
|
52
|
+
end
|
48
53
|
end
|
@@ -14,6 +14,28 @@ if !defined?(DB)
|
|
14
14
|
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
15
15
|
end
|
16
16
|
|
17
|
+
def create_tables(db)
|
18
|
+
db.create_table( :authors ) do
|
19
|
+
primary_key :id
|
20
|
+
string :name
|
21
|
+
string :login
|
22
|
+
end
|
23
|
+
|
24
|
+
db.create_table( :posts ) do
|
25
|
+
primary_key :id
|
26
|
+
string :title
|
27
|
+
string :content
|
28
|
+
time :created_at
|
29
|
+
end
|
30
|
+
|
31
|
+
db.create_table( :users ) do
|
32
|
+
primary_key :uid
|
33
|
+
string :login
|
34
|
+
string :firstname
|
35
|
+
string :lastname
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
17
39
|
# Use an in-memory SQLite database
|
18
40
|
if (jruby?)
|
19
41
|
DB = Sequel.connect('jdbc:sqlite::memory:')
|
@@ -21,28 +43,10 @@ if !defined?(DB)
|
|
21
43
|
DB = Sequel.sqlite
|
22
44
|
end
|
23
45
|
|
24
|
-
|
25
|
-
DB.create_table( :authors ) do
|
26
|
-
primary_key :id
|
27
|
-
string :name
|
28
|
-
string :login
|
29
|
-
end
|
30
|
-
class Author < Sequel::Model; end
|
46
|
+
create_tables(DB)
|
31
47
|
|
32
|
-
|
33
|
-
primary_key :id
|
34
|
-
string :title
|
35
|
-
string :content
|
36
|
-
time :created_at
|
37
|
-
end
|
48
|
+
class Author < Sequel::Model; end
|
38
49
|
class Post < Sequel::Model; end
|
39
|
-
|
40
|
-
DB.create_table( :users ) do
|
41
|
-
primary_key :uid
|
42
|
-
string :login
|
43
|
-
string :firstname
|
44
|
-
string :lastname
|
45
|
-
end
|
46
50
|
class User < Sequel::Model; end
|
47
51
|
|
48
52
|
# Version 4.0 of Sequel moved update_except off to a plugin
|
@@ -210,6 +210,22 @@ class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < MiniTest::Un
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
|
+
def test_no_explain_plans_with_single_threaded_connection
|
214
|
+
connect_opts = DB.opts
|
215
|
+
single_threaded_db = Sequel.connect(connect_opts.merge(:single_threaded => true))
|
216
|
+
create_tables(single_threaded_db)
|
217
|
+
model_class = Class.new(Sequel::Model(single_threaded_db[:posts]))
|
218
|
+
|
219
|
+
with_config(:'transaction_tracer.explain_threshold' => -0.01,
|
220
|
+
:'transaction_tracer.record_sql' => 'raw') do
|
221
|
+
segment = last_segment_for do
|
222
|
+
model_class[11]
|
223
|
+
end
|
224
|
+
assert_match %r{select \* from `posts` where `id` = 11}i, segment.params[:sql]
|
225
|
+
assert_equal([], segment.params[:explain_plan], "Should not capture explain plan with single-threaded connection pool")
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
213
229
|
def test_queries_can_get_explain_plan_with_obfuscated_sql
|
214
230
|
config = {
|
215
231
|
:'transaction_tracer.explain_threshold' => -0.01,
|
@@ -41,7 +41,6 @@ module NewRelic::Agent
|
|
41
41
|
|
42
42
|
NewRelic::Agent.config.apply_config( @config )
|
43
43
|
@monitor.on_finished_configuring
|
44
|
-
NewRelic::Agent::TransactionState.get.request_guid = TRANSACTION_GUID
|
45
44
|
end
|
46
45
|
|
47
46
|
def teardown
|
@@ -195,7 +194,10 @@ module NewRelic::Agent
|
|
195
194
|
def when_request_runs(request=for_id(REQUEST_CROSS_APP_ID))
|
196
195
|
event_listener = NewRelic::Agent.instance.events
|
197
196
|
event_listener.notify(:before_call, request)
|
198
|
-
|
197
|
+
in_transaction('transaction') do
|
198
|
+
# nothing
|
199
|
+
end
|
200
|
+
NewRelic::Agent::TransactionState.get.request_guid = TRANSACTION_GUID
|
199
201
|
event_listener.notify(:after_call, request, [200, @response, ''])
|
200
202
|
end
|
201
203
|
|
@@ -9,7 +9,7 @@ class NewRelic::Agent::Datastores::Mongo::MetricGeneratorTest < MiniTest::Unit::
|
|
9
9
|
include ::NewRelic::TestHelpers::MongoMetricBuilder
|
10
10
|
|
11
11
|
def setup
|
12
|
-
@payload = { :collection => 'tribbles' }
|
12
|
+
@payload = { :collection => 'tribbles', :database => 'enterprise' }
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_generate_metrics_for_includes_all_web_for_web_requests
|
@@ -40,4 +40,30 @@ class NewRelic::Agent::Datastores::Mongo::MetricGeneratorTest < MiniTest::Unit::
|
|
40
40
|
refute metrics.include? 'Datastore/allWeb'
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_generate_metrics_for_is_graceful_if_exceptions_are_raised
|
44
|
+
NewRelic::Agent::Datastores::Mongo::MetricTranslator.stubs(:metrics_for).raises("Booom")
|
45
|
+
metrics = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_metrics_for(:insert, @payload)
|
46
|
+
|
47
|
+
assert_empty metrics
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_generate_instance_metric_for_returns_instance_metric_for_given_attributes
|
51
|
+
result = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_instance_metric_for('host', 'port', 'database')
|
52
|
+
assert_equal 'Datastore/instance/MongoDB/host:port/database', result
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_generate_metrics_for_does_not_include_instance_metric_without_host
|
56
|
+
result = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_instance_metric_for(nil, 'port', 'database')
|
57
|
+
assert_nil result
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_generate_metrics_for_does_not_include_instance_metric_without_port
|
61
|
+
result = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_instance_metric_for('host', nil, 'database')
|
62
|
+
assert_nil result
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_generate_metrics_for_does_not_include_instance_metric_without_database_name
|
66
|
+
result = NewRelic::Agent::Datastores::Mongo::MetricGenerator.generate_instance_metric_for('host', 'port', nil)
|
67
|
+
assert_nil result
|
68
|
+
end
|
43
69
|
end
|
@@ -21,17 +21,23 @@ class NewRelic::Agent::Datastores::Mongo::MetricTranslatorTest < MiniTest::Unit:
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_build_metrics_includes_web
|
24
|
-
expected = 'Datastore/allWeb'
|
25
24
|
metrics = build_test_metrics('test')
|
26
|
-
|
27
|
-
assert metrics.include? expected
|
25
|
+
assert_includes metrics, 'Datastore/allWeb'
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_build_metrics_includes_other
|
31
|
-
expected = 'Datastore/allOther'
|
32
29
|
metrics = build_test_metrics('test', :other)
|
30
|
+
assert_includes metrics, 'Datastore/allOther'
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_build_metrics_includes_activerecord_all_on_web
|
34
|
+
metrics = build_test_metrics('test', :web)
|
35
|
+
assert_includes metrics, 'ActiveRecord/all'
|
36
|
+
end
|
33
37
|
|
34
|
-
|
38
|
+
def test_build_metrics_doesnt_include_activerecord_all_on_other
|
39
|
+
metrics = build_test_metrics('test', :other)
|
40
|
+
assert_not_includes metrics, 'ActiveRecord/all'
|
35
41
|
end
|
36
42
|
|
37
43
|
def test_metrics_for_find
|
@@ -263,7 +269,7 @@ class NewRelic::Agent::Datastores::Mongo::MetricTranslatorTest < MiniTest::Unit:
|
|
263
269
|
:limit => -1,
|
264
270
|
:selector => { :ismaster => 1 } }
|
265
271
|
|
266
|
-
@collection_name = "
|
272
|
+
@collection_name = "$cmd"
|
267
273
|
|
268
274
|
metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
|
269
275
|
expected = build_test_metrics(:ismaster)
|
@@ -289,13 +295,17 @@ class NewRelic::Agent::Datastores::Mongo::MetricTranslatorTest < MiniTest::Unit:
|
|
289
295
|
:limit => -1,
|
290
296
|
:selector => { :mongomongomongo => @collection_name } }
|
291
297
|
|
292
|
-
@collection_name = "
|
298
|
+
@collection_name = "$cmd"
|
293
299
|
|
294
300
|
metrics = NewRelic::Agent::Datastores::Mongo::MetricTranslator.metrics_for(:find, payload)
|
295
|
-
expected = build_test_metrics(:
|
301
|
+
expected = build_test_metrics(:mongomongomongo)
|
296
302
|
|
297
303
|
assert_equal expected, metrics
|
298
|
-
assert_metrics_recorded(["Supportability/Mongo/
|
304
|
+
assert_metrics_recorded(["Supportability/Mongo/UnknownCollection"])
|
299
305
|
end
|
300
306
|
|
307
|
+
def test_instance_metric
|
308
|
+
metric = NewRelic::Agent::Datastores::Mongo::MetricTranslator.instance_metric('localhost', '27017', @database_name)
|
309
|
+
assert_equal 'Datastore/instance/MongoDB/localhost:27017/multiverse', metric
|
310
|
+
end
|
301
311
|
end
|
@@ -78,499 +78,503 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < MiniTe
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
#
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
#
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
81
|
+
def test_metric_names_jruby
|
82
|
+
# fails due to a bug in rails 3 - log does not provide the correct
|
83
|
+
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
84
|
+
return if rails3? || !defined?(JRuby)
|
85
|
+
expected = %W[
|
86
|
+
ActiveRecord/all
|
87
|
+
ActiveRecord/find
|
88
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
89
|
+
Database/SQL/insert
|
90
|
+
RemoteService/sql/#{adapter}/localhost
|
91
|
+
]
|
92
|
+
|
93
|
+
if NewRelic::Control.instance.rails_version < '2.1.0'
|
94
|
+
expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_calls_metrics(*expected) do
|
98
|
+
m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
99
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
100
|
+
m.id = 999
|
101
|
+
m.save!
|
102
|
+
end
|
103
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
104
|
+
|
105
|
+
compare_metrics expected, metrics
|
106
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
107
|
+
# zero because jruby uses a different mysql adapter
|
108
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 0)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_metric_names_sqlite
|
112
|
+
# fails due to a bug in rails 3 - log does not provide the correct
|
113
|
+
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
114
|
+
return if rails3? || !isSqlite? || defined?(JRuby)
|
115
|
+
|
116
|
+
expected = %W[
|
117
|
+
ActiveRecord/all
|
118
|
+
ActiveRecord/find
|
119
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
120
|
+
ActiveRecord/create
|
121
|
+
ActiveRecord/ActiveRecordFixtures::Order/create]
|
122
|
+
|
123
|
+
if NewRelic::Control.instance.rails_version < '2.1.0'
|
124
|
+
expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
|
125
|
+
end
|
126
|
+
|
127
|
+
assert_calls_metrics(*expected) do
|
128
|
+
m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
129
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
130
|
+
m.id = 999
|
131
|
+
m.save!
|
132
|
+
end
|
133
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
134
|
+
|
135
|
+
compare_metrics expected, metrics
|
136
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
137
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_metric_names_standard
|
141
|
+
# fails due to a bug in rails 3 - log does not provide the correct
|
142
|
+
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
143
|
+
return if defined?(JRuby) || isSqlite?
|
144
|
+
|
145
|
+
expected = %W[
|
146
|
+
ActiveRecord/all
|
147
|
+
ActiveRecord/find
|
148
|
+
ActiveRecord/create
|
149
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
150
|
+
ActiveRecord/ActiveRecordFixtures::Order/create
|
151
|
+
Database/SQL/other
|
152
|
+
Database/SQL/show
|
153
|
+
RemoteService/sql/#{adapter}/localhost]
|
154
|
+
|
155
|
+
if NewRelic::Control.instance.rails_version < '2.1.0'
|
156
|
+
expected += ['ActiveRecord/save',
|
157
|
+
'ActiveRecord/ActiveRecordFixtures::Order/save']
|
158
|
+
end
|
159
|
+
|
160
|
+
if NewRelic::Control.instance.rails_version >= '3.0.0'
|
161
|
+
expected << 'Database/SQL/insert'
|
162
|
+
end
|
163
|
+
|
164
|
+
if NewRelic::Control.instance.rails_version >= '4.0'
|
165
|
+
expected << 'Database/SQL/update'
|
166
|
+
end
|
167
|
+
|
168
|
+
assert_calls_metrics(*expected) do
|
169
|
+
m = ActiveRecordFixtures::Order.create :id => 1, :name => 'donkey'
|
170
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
171
|
+
m.id = 999
|
172
|
+
m.save!
|
173
|
+
end
|
174
|
+
|
175
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
176
|
+
|
177
|
+
compare_metrics expected, metrics
|
178
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
179
|
+
if NewRelic::Control.instance.rails_version < '3.0.0'
|
180
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
|
181
|
+
else
|
182
|
+
check_metric_count("Database/SQL/insert", 1)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_join_metrics_jruby
|
187
|
+
return unless defined?(JRuby)
|
188
|
+
return if rails3?
|
189
|
+
|
190
|
+
expected_metrics = %W[
|
191
|
+
ActiveRecord/all
|
192
|
+
ActiveRecord/destroy
|
193
|
+
ActiveRecord/ActiveRecordFixtures::Order/destroy
|
194
|
+
Database/SQL/insert
|
195
|
+
Database/SQL/delete
|
196
|
+
Database/SQL/show
|
197
|
+
ActiveRecord/find
|
198
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
199
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/find
|
200
|
+
RemoteService/sql/#{adapter}/localhost
|
201
|
+
]
|
202
|
+
|
203
|
+
assert_calls_metrics(*expected_metrics) do
|
204
|
+
m = ActiveRecordFixtures::Order.create :name => 'jeff'
|
205
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
206
|
+
s = m.shipments.create
|
207
|
+
m.shipments.to_a
|
208
|
+
m.destroy
|
209
|
+
end
|
210
|
+
|
211
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
212
|
+
|
213
|
+
compare_metrics expected_metrics, metrics
|
214
|
+
|
215
|
+
check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
|
216
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
217
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
|
218
|
+
check_metric_count("Database/SQL/insert", 3)
|
219
|
+
check_metric_count("Database/SQL/delete", 1)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_join_metrics_sqlite
|
223
|
+
return if (defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3)
|
224
|
+
return if defined?(JRuby)
|
225
|
+
return unless isSqlite?
|
226
|
+
|
227
|
+
expected_metrics = %W[
|
228
|
+
ActiveRecord/all
|
229
|
+
ActiveRecord/destroy
|
230
|
+
ActiveRecord/ActiveRecordFixtures::Order/destroy
|
231
|
+
Database/SQL/insert
|
232
|
+
Database/SQL/delete
|
233
|
+
ActiveRecord/find
|
234
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
235
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/find
|
236
|
+
ActiveRecord/create
|
237
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/create
|
238
|
+
ActiveRecord/ActiveRecordFixtures::Order/create
|
239
|
+
]
|
240
|
+
|
241
|
+
assert_calls_metrics(*expected_metrics) do
|
242
|
+
m = ActiveRecordFixtures::Order.create :name => 'jeff'
|
243
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
244
|
+
s = m.shipments.create
|
245
|
+
m.shipments.to_a
|
246
|
+
m.destroy
|
247
|
+
end
|
248
|
+
|
249
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
250
|
+
compare_metrics expected_metrics, metrics
|
251
|
+
if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
|
252
|
+
check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
|
253
|
+
end
|
254
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
255
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
|
256
|
+
check_metric_count("Database/SQL/insert", 3)
|
257
|
+
check_metric_count("Database/SQL/delete", 1)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_join_metrics_standard
|
261
|
+
return if (defined?(Rails) && Rails::VERSION::MAJOR.to_i >= 3)
|
262
|
+
return if defined?(JRuby) || isSqlite?
|
263
|
+
|
264
|
+
expected_metrics = %W[
|
265
|
+
ActiveRecord/all
|
266
|
+
RemoteService/sql/#{adapter}/localhost
|
267
|
+
ActiveRecord/destroy
|
268
|
+
ActiveRecord/ActiveRecordFixtures::Order/destroy
|
269
|
+
Database/SQL/insert
|
270
|
+
Database/SQL/delete
|
271
|
+
ActiveRecord/find
|
272
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
273
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/find
|
274
|
+
Database/SQL/other
|
275
|
+
Database/SQL/show
|
276
|
+
ActiveRecord/create
|
277
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/create
|
278
|
+
ActiveRecord/ActiveRecordFixtures::Order/create
|
279
|
+
]
|
280
|
+
|
281
|
+
assert_calls_metrics(*expected_metrics) do
|
282
|
+
m = ActiveRecordFixtures::Order.create :name => 'jeff'
|
283
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
284
|
+
s = m.shipments.create
|
285
|
+
m.shipments.to_a
|
286
|
+
m.destroy
|
287
|
+
end
|
288
|
+
|
289
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
290
|
+
|
291
|
+
compare_metrics expected_metrics, metrics
|
292
|
+
if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
|
293
|
+
check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
|
294
|
+
end
|
295
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
296
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
|
297
|
+
check_metric_count("Database/SQL/insert", 1)
|
298
|
+
check_metric_count("Database/SQL/delete", 1)
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_direct_sql
|
302
|
+
assert_nil NewRelic::Agent::Transaction.current
|
303
|
+
assert_equal 0, NewRelic::Agent.instance.stats_engine.metrics.size, NewRelic::Agent.instance.stats_engine.metrics.inspect
|
304
|
+
|
305
|
+
expected_metrics = %W[
|
306
|
+
ActiveRecord/all
|
307
|
+
Database/SQL/select
|
308
|
+
RemoteService/sql/#{adapter}/localhost
|
309
|
+
]
|
310
|
+
|
311
|
+
assert_calls_unscoped_metrics(*expected_metrics) do
|
312
|
+
ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
|
313
|
+
end
|
314
|
+
|
315
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
316
|
+
compare_metrics(expected_metrics, metrics)
|
317
|
+
|
318
|
+
check_unscoped_metric_count('Database/SQL/select', 1)
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_other_sql
|
323
|
+
expected_metrics = %W[
|
324
|
+
ActiveRecord/all
|
325
|
+
Database/SQL/other
|
326
|
+
RemoteService/sql/#{adapter}/localhost
|
327
|
+
]
|
328
|
+
assert_calls_unscoped_metrics(*expected_metrics) do
|
329
|
+
ActiveRecordFixtures::Order.connection.execute "begin"
|
330
|
+
end
|
331
|
+
|
332
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
333
|
+
|
334
|
+
compare_metrics expected_metrics, metrics
|
335
|
+
check_unscoped_metric_count('Database/SQL/other', 1)
|
336
|
+
ensure
|
337
|
+
# Make sure we get the transaction closed up for other tests
|
338
|
+
ActiveRecordFixtures::Order.connection.execute "commit"
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_show_sql
|
342
|
+
return if isSqlite?
|
343
|
+
return if isPostgres?
|
344
|
+
|
345
|
+
expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/#{adapter}/localhost]
|
346
|
+
assert_calls_metrics(*expected_metrics) do
|
347
|
+
ActiveRecordFixtures::Order.connection.execute "show tables"
|
348
|
+
end
|
349
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
350
|
+
compare_metrics expected_metrics, metrics
|
351
|
+
check_unscoped_metric_count('Database/SQL/show', 1)
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_blocked_instrumentation
|
355
|
+
ActiveRecordFixtures::Order.add_delay
|
356
|
+
NewRelic::Agent.disable_all_tracing do
|
357
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
358
|
+
all_finder(ActiveRecordFixtures::Order)
|
359
|
+
end
|
360
|
+
end
|
361
|
+
assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
|
362
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
363
|
+
compare_metrics [], metrics
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_run_explains
|
367
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
368
|
+
ActiveRecordFixtures::Order.add_delay
|
369
|
+
all_finder(ActiveRecordFixtures::Order)
|
370
|
+
end
|
371
|
+
|
372
|
+
# that's a mouthful. perhaps we should ponder our API.
|
373
|
+
segment = last_segment(NewRelic::Agent.instance.transaction_sampler.last_sample)
|
374
|
+
regex = /^SELECT (["`]?#{ActiveRecordFixtures::Order.table_name}["`]?.)?\* FROM ["`]?#{ActiveRecordFixtures::Order.table_name}["`]?$/
|
375
|
+
assert_match regex, segment.params[:sql].strip
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_prepare_to_send
|
379
|
+
with_config(:'transaction_tracer.explain_enabled' => true,
|
380
|
+
:'transaction_tracer.explain_threshold' => 0.0) do
|
381
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
382
|
+
ActiveRecordFixtures::Order.add_delay
|
383
|
+
all_finder(ActiveRecordFixtures::Order)
|
384
|
+
end
|
385
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
386
|
+
refute_nil sample
|
387
|
+
|
388
|
+
includes_gc = false
|
389
|
+
sample.each_segment {|s| includes_gc ||= s.metric_name =~ /GC/ }
|
390
|
+
|
391
|
+
sql_segment = last_segment(sample)
|
392
|
+
refute_nil sql_segment, sample.to_s
|
393
|
+
assert_match /^SELECT /, sql_segment.params[:sql]
|
394
|
+
assert sql_segment.duration > 0.0, "Segment duration must be greater than zero."
|
395
|
+
sample = sample.prepare_to_send!
|
396
|
+
sql_segment = last_segment(sample)
|
397
|
+
assert_match /^SELECT /, sql_segment.params[:sql]
|
398
|
+
explanations = sql_segment.params[:explain_plan]
|
399
|
+
if (isMysql? || isPostgres?) && !NewRelic::LanguageSupport.using_engine?('jruby')
|
400
|
+
refute_nil explanations, "No explains in segment: #{sql_segment}"
|
401
|
+
assert_equal(2, explanations.size,
|
402
|
+
"No explains in segment: #{sql_segment}")
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_transaction_mysql
|
408
|
+
return unless isMysql? && !defined?(JRuby)
|
409
|
+
|
410
|
+
with_config(:record_sql => :obfuscated,
|
411
|
+
:'transaction_tracer.explain_enabled' => true,
|
412
|
+
:'transaction_tracer.explain_threshold' => 0.0) do
|
413
|
+
ActiveRecordFixtures.setup
|
414
|
+
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
415
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
416
|
+
ActiveRecordFixtures::Order.add_delay
|
417
|
+
all_finder(ActiveRecordFixtures::Order)
|
418
|
+
end
|
419
|
+
|
420
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
421
|
+
sample = sample.prepare_to_send!
|
422
|
+
segment = last_segment(sample)
|
423
|
+
explanation = segment.params[:explain_plan]
|
424
|
+
refute_nil explanation, "No explains in segment: #{segment}"
|
425
|
+
assert_equal 2, explanation.size,"No explains in segment: #{segment}"
|
426
|
+
|
427
|
+
assert_equal 10, explanation[0].size
|
428
|
+
['id', 'select_type', 'table'].each do |c|
|
429
|
+
assert explanation[0].include?(c)
|
430
|
+
end
|
431
|
+
['1', 'SIMPLE', ActiveRecordFixtures::Order.table_name].each do |c|
|
432
|
+
assert explanation[1][0].include?(c)
|
433
|
+
end
|
434
|
+
|
435
|
+
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
436
|
+
assert_equal 1, s.call_count
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_transaction_postgres
|
441
|
+
return unless isPostgres?
|
442
|
+
|
443
|
+
with_config(:record_sql => :obfuscated,
|
444
|
+
:'transaction_tracer.explain_enabled' => true,
|
445
|
+
:'transaction_tracer.explain_threshold' => 0.0) do
|
446
|
+
# note that our current test builds do not use postgres, this is
|
447
|
+
# here strictly for troubleshooting, not CI builds
|
448
|
+
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
449
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
450
|
+
ActiveRecordFixtures::Order.add_delay
|
451
|
+
all_finder(ActiveRecordFixtures::Order)
|
452
|
+
end
|
453
|
+
|
454
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
455
|
+
|
456
|
+
sample = sample.prepare_to_send!
|
457
|
+
segment = last_segment(sample)
|
458
|
+
explanations = segment.params[:explain_plan]
|
459
|
+
|
460
|
+
refute_nil explanations, "No explains in segment: #{segment}"
|
461
|
+
assert_equal 1, explanations.size,"No explains in segment: #{segment}"
|
462
|
+
assert_equal 1, explanations.first.size
|
463
|
+
|
464
|
+
assert_equal("Explain Plan", explanations[0][0])
|
465
|
+
assert_match /Seq Scan on test_data/, explanations[0][1].join(";")
|
466
|
+
|
467
|
+
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
468
|
+
assert_equal 1, s.call_count
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_transaction_other
|
473
|
+
return if isMysql? || isPostgres?
|
474
|
+
|
475
|
+
with_config(:record_sql => :obfuscated,
|
476
|
+
:'transaction_tracer.explain_enabled' => true,
|
477
|
+
:'transaction_tracer.explain_threshold' => 0.0) do
|
478
|
+
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
479
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
480
|
+
ActiveRecordFixtures::Order.add_delay
|
481
|
+
all_finder(ActiveRecordFixtures::Order)
|
482
|
+
end
|
483
|
+
|
484
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
485
|
+
|
486
|
+
sample = sample.prepare_to_send!
|
487
|
+
segment = last_segment(sample)
|
488
|
+
|
489
|
+
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
490
|
+
assert_equal 1, s.call_count
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
# These are only valid for rails 2.1 and later
|
495
|
+
if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
|
496
|
+
ActiveRecordFixtures::Order.class_eval do
|
497
|
+
if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4")
|
498
|
+
scope :jeffs, lambda { where(:name => 'Jeff') }
|
499
|
+
elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.1")
|
500
|
+
scope :jeffs, :conditions => { :name => 'Jeff' }
|
501
|
+
else
|
502
|
+
named_scope :jeffs, :conditions => { :name => 'Jeff' }
|
503
|
+
end
|
504
|
+
end
|
505
|
+
def test_named_scope
|
506
|
+
ActiveRecordFixtures::Order.create :name => 'Jeff'
|
507
|
+
|
508
|
+
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
509
|
+
|
510
|
+
check_metric_count(find_metric, 0)
|
511
|
+
assert_calls_metrics(find_metric) do
|
512
|
+
if NewRelic::Control.instance.rails_version >= "4"
|
513
|
+
x = ActiveRecordFixtures::Order.jeffs.load
|
514
|
+
else
|
515
|
+
x = ActiveRecordFixtures::Order.jeffs.find(:all)
|
516
|
+
end
|
517
|
+
end
|
518
|
+
check_metric_count(find_metric, 1)
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
# This is to make sure the all metric is recorded for exceptional cases
|
523
|
+
def test_error_handling
|
524
|
+
# have the AR select throw an error
|
525
|
+
ActiveRecordFixtures::Order.connection.stubs(:log_info).with do | sql, x, y |
|
526
|
+
raise "Error" if sql =~ /select/
|
527
|
+
true
|
528
|
+
end
|
529
|
+
|
530
|
+
in_web_transaction do
|
531
|
+
begin
|
532
|
+
ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
|
533
|
+
rescue RuntimeError => e
|
534
|
+
# catch only the error we raise above
|
535
|
+
raise unless e.message == 'Error'
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
assert_metrics_recorded(
|
540
|
+
'ActiveRecord/all' => { :call_count => 1 },
|
541
|
+
'Database/SQL/select' => { :call_count => 1 }
|
542
|
+
)
|
543
|
+
|
544
|
+
if !NewRelic::LanguageSupport.using_engine?('jruby')
|
545
|
+
assert_metrics_recorded("RemoteService/sql/#{adapter}/localhost" => { :call_count => 1 })
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
def test_rescue_handling
|
550
|
+
# Not sure why we get a transaction error with sqlite
|
551
|
+
return if isSqlite?
|
552
|
+
|
553
|
+
begin
|
554
|
+
ActiveRecordFixtures::Order.transaction do
|
555
|
+
raise ActiveRecord::ActiveRecordError.new('preserve-me!')
|
556
|
+
end
|
557
|
+
rescue ActiveRecord::ActiveRecordError => e
|
558
|
+
assert_equal 'preserve-me!', e.message
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
def test_remote_service_metric_respects_dynamic_connection_config
|
563
|
+
return unless isMysql? && !NewRelic::LanguageSupport.using_engine?('jruby')
|
564
|
+
|
565
|
+
ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
|
566
|
+
assert_metrics_recorded(["RemoteService/sql/#{adapter}/localhost"])
|
567
|
+
|
568
|
+
config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
|
569
|
+
config[:host] = '127.0.0.1'
|
570
|
+
connection = ActiveRecordFixtures::Shipment.establish_connection(config)
|
571
|
+
|
572
|
+
ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
|
573
|
+
assert_metrics_recorded(["RemoteService/sql/#{adapter}/127.0.0.1"])
|
574
|
+
|
575
|
+
config[:host] = 'localhost'
|
576
|
+
ActiveRecordFixtures::Shipment.establish_connection(config)
|
577
|
+
end
|
574
578
|
|
575
579
|
private
|
576
580
|
|