newrelic_rpm 3.6.0.74.beta → 3.6.0.78
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.
- data.tar.gz.sig +1 -2
- data/CHANGELOG +18 -0
- data/Gemfile +3 -3
- data/Rakefile +8 -0
- data/lib/new_relic/agent/agent.rb +4 -9
- data/lib/new_relic/agent/agent_logger.rb +1 -2
- data/lib/new_relic/agent/audit_logger.rb +7 -3
- data/lib/new_relic/agent/busy_calculator.rb +3 -3
- data/lib/new_relic/agent/configuration/server_source.rb +23 -10
- data/lib/new_relic/agent/cross_app_monitor.rb +1 -0
- data/lib/new_relic/agent/database.rb +2 -0
- data/lib/new_relic/agent/error_collector.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +14 -13
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +72 -0
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -76
- data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +138 -0
- data/lib/new_relic/agent/instrumentation/rails4/active_record.rb +108 -0
- data/lib/new_relic/agent/null_logger.rb +15 -0
- data/lib/new_relic/agent/stats.rb +1 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +4 -4
- data/lib/new_relic/control/frameworks/rails.rb +0 -37
- data/lib/new_relic/control/frameworks/rails3.rb +0 -17
- data/lib/new_relic/control/instance_methods.rb +1 -2
- data/lib/new_relic/environment_report.rb +159 -0
- data/lib/new_relic/helper.rb +4 -0
- data/lib/new_relic/local_environment.rb +0 -161
- data/lib/newrelic_rpm.rb +1 -1
- data/test/multiverse/lib/multiverse/suite.rb +7 -0
- data/test/multiverse/suites/active_record/Envfile +0 -1
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +22 -12
- data/test/multiverse/suites/rails/Envfile +8 -1
- data/test/multiverse/suites/rails/app.rb +7 -2
- data/test/multiverse/suites/rails/error_tracing_test.rb +28 -16
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +8 -2
- data/test/new_relic/agent/agent/connect_test.rb +5 -8
- data/test/new_relic/agent/agent/start_test.rb +3 -1
- data/test/new_relic/agent/agent_logger_test.rb +8 -8
- data/test/new_relic/agent/agent_test.rb +0 -6
- data/test/new_relic/agent/agent_test_controller_test.rb +18 -14
- data/test/new_relic/agent/audit_logger_test.rb +12 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +48 -0
- data/test/new_relic/agent/cross_app_monitor_test.rb +8 -0
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +254 -0
- data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +52 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +32 -51
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +132 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +20 -0
- data/test/new_relic/agent_test.rb +0 -8
- data/test/new_relic/control_test.rb +1 -2
- data/test/new_relic/dispatcher_test.rb +1 -5
- data/test/new_relic/environment_report_test.rb +89 -0
- data/test/new_relic/license_test.rb +1 -3
- data/test/new_relic/load_test.rb +5 -1
- data/test/new_relic/local_environment_test.rb +0 -27
- data/test/new_relic/rack/browser_monitoring_test.rb +1 -0
- data/test/script/ci.sh +19 -18
- data/test/test_helper.rb +15 -3
- metadata +42 -3
- metadata.gz.sig +0 -0
@@ -0,0 +1,52 @@
|
|
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
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
5
|
+
require 'new_relic/agent/instrumentation/active_record_helper'
|
6
|
+
|
7
|
+
class NewRelic::Agent::Instrumentation::ActiveRecordHelperTest < Test::Unit::TestCase
|
8
|
+
include NewRelic::Agent::Instrumentation
|
9
|
+
|
10
|
+
def test_metric_for_name_find
|
11
|
+
metric_name = 'ActiveRecord/Model/find'
|
12
|
+
assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Find')
|
13
|
+
assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Load')
|
14
|
+
assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Count')
|
15
|
+
assert_equal metric_name, ActiveRecordHelper.metric_for_name('Model Exists')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_metric_for_name_with_namespace
|
19
|
+
assert_equal('ActiveRecord/Namespace::Model/find',
|
20
|
+
ActiveRecordHelper.metric_for_name('Namespace::Model Load'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_metric_for_name_destroy
|
24
|
+
assert_equal('ActiveRecord/Model/destroy',
|
25
|
+
ActiveRecordHelper.metric_for_name('Model Destroy'))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_metric_for_name_create
|
29
|
+
assert_equal('ActiveRecord/Model/create',
|
30
|
+
ActiveRecordHelper.metric_for_name('Model Create'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_metric_for_name_update
|
34
|
+
assert_equal('ActiveRecord/Model/save',
|
35
|
+
ActiveRecordHelper.metric_for_name('Model Update'))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_metric_for_name_columns
|
39
|
+
assert_nil ActiveRecordHelper.metric_for_name('Model Columns')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rollup_metric_for_lists_rollups
|
43
|
+
rollup_metrics = ActiveRecordHelper.rollup_metrics_for('ActiveRecord/Model/find')
|
44
|
+
assert rollup_metrics.include?('ActiveRecord/find')
|
45
|
+
assert rollup_metrics.include?('ActiveRecord/all')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_remote_service_metric
|
49
|
+
assert_equal('RemoteService/sql/mysql/server',
|
50
|
+
ActiveRecordHelper.remote_service_metric('mysql', 'server'))
|
51
|
+
end
|
52
|
+
end
|
@@ -31,6 +31,8 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
31
31
|
|
32
32
|
def teardown
|
33
33
|
super
|
34
|
+
NewRelic::Agent::TransactionInfo.reset
|
35
|
+
Thread::current[:newrelic_scope_name] = nil
|
34
36
|
NewRelic::Agent.shutdown
|
35
37
|
end
|
36
38
|
|
@@ -74,28 +76,6 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
# multiple duplicate find calls should only cause metric trigger on the first
|
78
|
-
# call. the others are ignored.
|
79
|
-
def test_query_cache
|
80
|
-
# Not sure why we get a transaction error with sqlite
|
81
|
-
return if isSqlite?
|
82
|
-
|
83
|
-
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
84
|
-
ActiveRecordFixtures::Order.cache do
|
85
|
-
m = ActiveRecordFixtures::Order.create :id => 1, :name => 'jeff'
|
86
|
-
assert_calls_metrics(find_metric) do
|
87
|
-
all_finder(ActiveRecordFixtures::Order)
|
88
|
-
end
|
89
|
-
|
90
|
-
check_metric_count(find_metric, 1)
|
91
|
-
|
92
|
-
assert_calls_metrics(find_metric) do
|
93
|
-
10.times { ActiveRecordFixtures::Order.find m.id }
|
94
|
-
end
|
95
|
-
check_metric_count(find_metric, 2)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
79
|
def test_metric_names_jruby
|
100
80
|
# fails due to a bug in rails 3 - log does not provide the correct
|
101
81
|
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
@@ -352,7 +332,6 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
352
332
|
return if isPostgres?
|
353
333
|
|
354
334
|
expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/#{adapter}/localhost]
|
355
|
-
|
356
335
|
assert_calls_metrics(*expected_metrics) do
|
357
336
|
ActiveRecordFixtures::Order.connection.execute "show tables"
|
358
337
|
end
|
@@ -372,7 +351,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
372
351
|
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
373
352
|
compare_metrics [], metrics
|
374
353
|
end
|
375
|
-
|
354
|
+
|
376
355
|
def test_run_explains
|
377
356
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
378
357
|
ActiveRecordFixtures::Order.add_delay
|
@@ -380,12 +359,11 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
380
359
|
end
|
381
360
|
|
382
361
|
# that's a mouthful. perhaps we should ponder our API.
|
383
|
-
segment = NewRelic::Agent.instance.transaction_sampler.last_sample
|
384
|
-
.root_segment.called_segments[0].called_segments[0].called_segments[0]
|
362
|
+
segment = last_segment(NewRelic::Agent.instance.transaction_sampler.last_sample)
|
385
363
|
regex = /^SELECT (["`]?#{ActiveRecordFixtures::Order.table_name}["`]?.)?\* FROM ["`]?#{ActiveRecordFixtures::Order.table_name}["`]?$/
|
386
364
|
assert_match regex, segment.params[:sql].strip
|
387
365
|
end
|
388
|
-
|
366
|
+
|
389
367
|
def test_prepare_to_send
|
390
368
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
391
369
|
ActiveRecordFixtures::Order.add_delay
|
@@ -397,14 +375,12 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
397
375
|
includes_gc = false
|
398
376
|
sample.each_segment {|s| includes_gc ||= s.metric_name =~ /GC/ }
|
399
377
|
|
400
|
-
|
401
|
-
|
402
|
-
sql_segment = sample.root_segment.called_segments.first.called_segments.first.called_segments.first
|
378
|
+
sql_segment = last_segment(sample)
|
403
379
|
assert_not_nil sql_segment, sample.to_s
|
404
380
|
assert_match /^SELECT /, sql_segment.params[:sql]
|
405
381
|
assert sql_segment.duration > 0.0, "Segment duration must be greater than zero."
|
406
382
|
sample = sample.prepare_to_send(:record_sql => :raw, :explain_sql => 0.0)
|
407
|
-
sql_segment = sample
|
383
|
+
sql_segment = last_segment(sample)
|
408
384
|
assert_match /^SELECT /, sql_segment.params[:sql]
|
409
385
|
explanations = sql_segment.params[:explain_plan]
|
410
386
|
if isMysql? || isPostgres?
|
@@ -416,6 +392,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
416
392
|
|
417
393
|
def test_transaction_mysql
|
418
394
|
return unless isMysql? && !defined?(JRuby)
|
395
|
+
|
419
396
|
ActiveRecordFixtures.setup
|
420
397
|
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
421
398
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
@@ -424,9 +401,8 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
424
401
|
end
|
425
402
|
|
426
403
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
427
|
-
|
428
404
|
sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
|
429
|
-
segment = sample
|
405
|
+
segment = last_segment(sample)
|
430
406
|
explanation = segment.params[:explain_plan]
|
431
407
|
assert_not_nil explanation, "No explains in segment: #{segment}"
|
432
408
|
assert_equal 2, explanation.size,"No explains in segment: #{segment}"
|
@@ -456,7 +432,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
456
432
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
457
433
|
|
458
434
|
sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
|
459
|
-
segment = sample
|
435
|
+
segment = last_segment(sample)
|
460
436
|
explanations = segment.params[:explain_plan]
|
461
437
|
|
462
438
|
assert_not_nil explanations, "No explains in segment: #{segment}"
|
@@ -481,7 +457,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
481
457
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
482
458
|
|
483
459
|
sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
|
484
|
-
segment = sample
|
460
|
+
segment = last_segment(sample)
|
485
461
|
|
486
462
|
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
487
463
|
assert_equal 1, s.call_count
|
@@ -496,7 +472,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
496
472
|
scope :jeffs, :conditions => { :name => 'Jeff' }
|
497
473
|
else
|
498
474
|
named_scope :jeffs, :conditions => { :name => 'Jeff' }
|
499
|
-
end
|
475
|
+
end
|
500
476
|
end
|
501
477
|
def test_named_scope
|
502
478
|
ActiveRecordFixtures::Order.create :name => 'Jeff'
|
@@ -552,31 +528,24 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
552
528
|
assert_equal 'preserve-me!', e.message
|
553
529
|
end
|
554
530
|
end
|
555
|
-
|
531
|
+
|
556
532
|
def test_remote_service_metric_respects_dynamic_connection_config
|
557
533
|
return unless isMysql?
|
558
534
|
|
559
|
-
# puts NewRelic::Agent::Database.config.inspect
|
560
|
-
|
561
535
|
ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
|
562
536
|
assert(NewRelic::Agent.get_stats("RemoteService/sql/#{adapter}/localhost").call_count != 0)
|
563
537
|
|
564
|
-
config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
|
538
|
+
config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
|
565
539
|
config[:host] = '127.0.0.1'
|
566
540
|
connection = ActiveRecordFixtures::Shipment.establish_connection(config)
|
567
|
-
|
568
|
-
# puts ActiveRecord::Base.connection.instance_eval { @config }.inspect
|
569
|
-
# puts NewRelic::Agent::Database.config.inspect
|
570
|
-
|
541
|
+
|
571
542
|
ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
|
572
543
|
assert(NewRelic::Agent.get_stats("RemoteService/sql/#{adapter}/127.0.0.1").call_count != 0)
|
573
544
|
|
574
545
|
config[:host] = 'localhost'
|
575
546
|
ActiveRecordFixtures::Shipment.establish_connection(config)
|
576
|
-
|
577
|
-
# raise NewRelic::Agent.instance.stats_engine.inspect
|
578
547
|
end
|
579
|
-
|
548
|
+
|
580
549
|
private
|
581
550
|
|
582
551
|
def rails3?
|
@@ -599,12 +568,24 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
599
568
|
end
|
600
569
|
|
601
570
|
def all_finder(relation)
|
602
|
-
if
|
603
|
-
|
604
|
-
|
605
|
-
|
571
|
+
if defined?(::ActiveRecord::VERSION)
|
572
|
+
if ::ActiveRecord::VERSION::MAJOR.to_i >= 4
|
573
|
+
relation.all.load
|
574
|
+
elsif ::ActiveRecord::VERSION::MAJOR.to_i >= 3
|
575
|
+
relation.all
|
576
|
+
else
|
577
|
+
relation.find(:all)
|
578
|
+
end
|
606
579
|
else
|
607
580
|
relation.find(:all)
|
608
581
|
end
|
609
582
|
end
|
583
|
+
|
584
|
+
def last_segment(txn_sample)
|
585
|
+
last = nil
|
586
|
+
txn_sample.root_segment.each_segment do |segment|
|
587
|
+
last = segment
|
588
|
+
end
|
589
|
+
last
|
590
|
+
end
|
610
591
|
end
|
@@ -0,0 +1,132 @@
|
|
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
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
5
|
+
require 'new_relic/agent/instrumentation/rails4/active_record'
|
6
|
+
|
7
|
+
if ::Rails::VERSION::MAJOR.to_i >= 4 && !NewRelic::LanguageSupport.using_engine?('jruby')
|
8
|
+
class NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest < Test::Unit::TestCase
|
9
|
+
class Order; end
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@config = { :adapter => 'mysql', :host => 'server' }
|
13
|
+
@connection = Object.new
|
14
|
+
@connection.instance_variable_set(:@config, @config)
|
15
|
+
Order.stubs(:connection_pool).returns(stub(:connections => [ @connection ]))
|
16
|
+
|
17
|
+
@params = {
|
18
|
+
:name => 'NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order Load',
|
19
|
+
:sql => 'SELECT * FROM sandwiches',
|
20
|
+
:connection_id => @connection.object_id
|
21
|
+
}
|
22
|
+
|
23
|
+
@subscriber = NewRelic::Agent::Instrumentation::ActiveRecordSubscriber.new
|
24
|
+
|
25
|
+
@stats_engine = NewRelic::Agent.instance.stats_engine
|
26
|
+
@stats_engine.clear_stats
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_records_metrics_for_simple_find
|
30
|
+
t1 = Time.now
|
31
|
+
t0 = t1 - 2
|
32
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
33
|
+
|
34
|
+
metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
|
35
|
+
|
36
|
+
metric = @stats_engine.lookup_stats(metric_name)
|
37
|
+
assert_equal(1, metric.call_count)
|
38
|
+
assert_equal(2.0, metric.total_call_time)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_records_scoped_metrics
|
42
|
+
t1 = Time.now
|
43
|
+
t0 = t1 - 2
|
44
|
+
|
45
|
+
@stats_engine.start_transaction('test_txn')
|
46
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
47
|
+
|
48
|
+
metric_name = 'ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find'
|
49
|
+
|
50
|
+
scoped_metric = @stats_engine.lookup_stats(metric_name, 'test_txn')
|
51
|
+
assert_equal(1, scoped_metric.call_count)
|
52
|
+
assert_equal(2.0, scoped_metric.total_call_time)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_records_nothing_if_tracing_disabled
|
56
|
+
t1 = Time.now
|
57
|
+
t0 = t1 - 2
|
58
|
+
|
59
|
+
NewRelic::Agent.disable_all_tracing do
|
60
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
61
|
+
end
|
62
|
+
|
63
|
+
metric = @stats_engine \
|
64
|
+
.lookup_stats('ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find')
|
65
|
+
assert_nil metric
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_records_rollup_metrics
|
69
|
+
t1 = Time.now
|
70
|
+
t0 = t1 - 2
|
71
|
+
|
72
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
73
|
+
|
74
|
+
['ActiveRecord/find', 'ActiveRecord/all'].each do |metric_name|
|
75
|
+
metric = @stats_engine.lookup_stats(metric_name)
|
76
|
+
assert_equal(1, metric.call_count,
|
77
|
+
"Incorrect call count for #{metric_name}")
|
78
|
+
assert_equal(2.0, metric.total_call_time,
|
79
|
+
"Incorrect call time for #{metric_name}")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_records_remote_service_metric
|
84
|
+
t1 = Time.now
|
85
|
+
t0 = t1 - 2
|
86
|
+
|
87
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
88
|
+
|
89
|
+
metric = @stats_engine.lookup_stats('RemoteService/sql/mysql/server')
|
90
|
+
assert_equal(1, metric.call_count)
|
91
|
+
assert_equal(2.0, metric.total_call_time)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_creates_txn_segment
|
95
|
+
t1 = Time.now
|
96
|
+
t0 = t1 - 2
|
97
|
+
|
98
|
+
NewRelic::Agent.manual_start
|
99
|
+
@stats_engine.start_transaction('test')
|
100
|
+
sampler = NewRelic::Agent.instance.transaction_sampler
|
101
|
+
sampler.notice_first_scope_push(Time.now.to_f)
|
102
|
+
sampler.notice_transaction('/path', '/path', {})
|
103
|
+
sampler.notice_push_scope('Controller/sandwiches/index')
|
104
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
105
|
+
sampler.notice_pop_scope('Controller/sandwiches/index')
|
106
|
+
sampler.notice_scope_empty
|
107
|
+
|
108
|
+
last_segment = nil
|
109
|
+
sampler.last_sample.root_segment.each_segment{|s| last_segment = s }
|
110
|
+
NewRelic::Agent.shutdown
|
111
|
+
|
112
|
+
assert_equal('ActiveRecord/NewRelic::Agent::Instrumentation::ActiveRecordSubscriberTest::Order/find',
|
113
|
+
last_segment.metric_name)
|
114
|
+
assert_equal('SELECT * FROM sandwiches',
|
115
|
+
last_segment.params[:sql])
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_creates_slow_sql_node
|
119
|
+
NewRelic::Agent.manual_start
|
120
|
+
sampler = NewRelic::Agent.instance.sql_sampler
|
121
|
+
sampler.notice_first_scope_push nil
|
122
|
+
t1 = Time.now
|
123
|
+
t0 = t1 - 2
|
124
|
+
|
125
|
+
@subscriber.call('sql.active_record', t0, t1, :id, @params)
|
126
|
+
|
127
|
+
assert_equal 'SELECT * FROM sandwiches', sampler.transaction_data.sql_data[0].sql
|
128
|
+
ensure
|
129
|
+
NewRelic::Agent.shutdown
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -461,4 +461,24 @@ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::Tes
|
|
461
461
|
end
|
462
462
|
end
|
463
463
|
end
|
464
|
+
|
465
|
+
def test_doesnt_misbehave_when_transaction_tracing_is_disabled
|
466
|
+
@engine.transaction_sampler = nil
|
467
|
+
|
468
|
+
# The error should have any other consequence other than logging the error, so
|
469
|
+
# this will capture logs
|
470
|
+
logger = NewRelic::Agent::MemoryLogger.new
|
471
|
+
NewRelic::Agent.logger = logger
|
472
|
+
|
473
|
+
with_config(:"cross_application_tracer.enabled" => true) do
|
474
|
+
Net::HTTP.get(URI.parse('http://www.google.com/index.html'))
|
475
|
+
end
|
476
|
+
|
477
|
+
assert_no_match( /undefined method `rename_scope_segment' for nil:NilClass/i,
|
478
|
+
logger.messages.flatten.map {|log| log.to_s }.join(' ') )
|
479
|
+
|
480
|
+
ensure
|
481
|
+
@engine.transaction_sampler = NewRelic::Agent.agent.transaction_sampler
|
482
|
+
end
|
483
|
+
|
464
484
|
end
|
@@ -62,14 +62,6 @@ module NewRelic
|
|
62
62
|
NewRelic::Agent.after_fork
|
63
63
|
end
|
64
64
|
|
65
|
-
def test_after_fork_sets_forked_flag
|
66
|
-
agent = NewRelic::Agent::Agent.new
|
67
|
-
assert !agent.forked?
|
68
|
-
agent.after_fork
|
69
|
-
|
70
|
-
assert agent.forked?
|
71
|
-
end
|
72
|
-
|
73
65
|
if NewRelic::LanguageSupport.can_fork? &&
|
74
66
|
!NewRelic::LanguageSupport.using_version?('1.9.1')
|
75
67
|
def test_timeslice_harvest_with_after_fork_report_to_channel
|
@@ -48,9 +48,8 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
48
48
|
|
49
49
|
def test_info
|
50
50
|
NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
|
51
|
-
props = NewRelic::Control.instance.local_env.snapshot
|
52
51
|
if defined?(Rails)
|
53
|
-
assert_match /jdbc|postgres|mysql|sqlite/,
|
52
|
+
assert_match /jdbc|postgres|mysql|sqlite/, NewRelic::EnvironmentReport.new["Database adapter"]
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -13,11 +13,7 @@ class DispatcherTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def assert_dispatcher_reported_to_environment_report(dispatcher)
|
16
|
-
NewRelic::
|
17
|
-
key, value = NewRelic::Control.instance.local_env.snapshot.detect do |(k, v)|
|
18
|
-
k == "Dispatcher"
|
19
|
-
end
|
20
|
-
assert_equal dispatcher.to_s, value
|
16
|
+
assert_equal dispatcher.to_s, NewRelic::EnvironmentReport.new["Dispatcher"]
|
21
17
|
end
|
22
18
|
|
23
19
|
def test_detects_dispatcher_via_loaded_libraries
|
@@ -0,0 +1,89 @@
|
|
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 File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
|
6
|
+
|
7
|
+
require 'new_relic/environment_report'
|
8
|
+
|
9
|
+
class EnvironmentReportTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@old_logic = ::NewRelic::EnvironmentReport.registered_reporters.dup
|
12
|
+
@report = ::NewRelic::EnvironmentReport.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
::NewRelic::EnvironmentReport.registered_reporters = @old_logic
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_converts_to_array
|
20
|
+
::NewRelic::EnvironmentReport.report_on("something"){"awesome"}
|
21
|
+
data = Array(::NewRelic::EnvironmentReport.new)
|
22
|
+
expected = ["something", "awesome"]
|
23
|
+
assert data.include?(expected), "expected to find #{expected} in #{data.inspect}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_register_a_value_to_report_on
|
27
|
+
::NewRelic::EnvironmentReport.report_on("What time is it?") do
|
28
|
+
"beer-o-clock"
|
29
|
+
end
|
30
|
+
assert_equal 'beer-o-clock', ::NewRelic::EnvironmentReport.new["What time is it?"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_report_on_handles_errors_gracefully
|
34
|
+
assert_nothing_raised do
|
35
|
+
::NewRelic::EnvironmentReport.report_on("What time is it?") do
|
36
|
+
raise ArgumentError, "woah! something blew up"
|
37
|
+
end
|
38
|
+
assert_nil ::NewRelic::EnvironmentReport.new["What time is it?"]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_it_does_not_set_keys_for_nil_values
|
43
|
+
::NewRelic::EnvironmentReport.report_on("What time is it?") do
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
assert ! NewRelic::EnvironmentReport.new.data.has_key?("What time is it?")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_can_set_an_environment_value_directly
|
50
|
+
@report['My Value'] = "so awesome!!"
|
51
|
+
assert_equal "so awesome!!", @report['My Value']
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_it_knows_what_gems_are_in_the_environment
|
55
|
+
assert(@report['Gems'].size > 5, "Expected at least 5 gems in #{@report['Gems'].inspect}")
|
56
|
+
rake = @report['Gems'].detect{|s| s.include? 'rake'}
|
57
|
+
assert_match(/^rake\([\d\.]+\)$/, rake)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_gathers_ruby_version
|
61
|
+
assert_equal RUBY_VERSION, @report['Ruby version']
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_has_logic_for_keys
|
65
|
+
[
|
66
|
+
"Gems",
|
67
|
+
"Plugin List",
|
68
|
+
"Ruby version",
|
69
|
+
"Ruby description",
|
70
|
+
"Ruby platform",
|
71
|
+
"Ruby patchlevel",
|
72
|
+
'JRuby version',
|
73
|
+
'Java VM version',
|
74
|
+
'Processors',
|
75
|
+
'Database adapter',
|
76
|
+
'Framework',
|
77
|
+
'Dispatcher',
|
78
|
+
'Environment',
|
79
|
+
'Arch',
|
80
|
+
'OS version',
|
81
|
+
'OS',
|
82
|
+
'Rails Env',
|
83
|
+
'Rails version',
|
84
|
+
'Rails threadsafe',
|
85
|
+
].each do |key|
|
86
|
+
assert NewRelic::EnvironmentReport.registered_reporters.has_key?(key), "Expected logic for #{key.inspect} in EnvironmentReport."
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|