newrelic_rpm 3.6.0.83 → 3.6.1.85.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +27 -0
- data/Gemfile +2 -7
- data/README.md +1 -1
- data/lib/new_relic/agent/agent.rb +3 -2
- data/lib/new_relic/agent/autostart.rb +56 -0
- data/lib/new_relic/agent/browser_monitoring.rb +19 -14
- data/lib/new_relic/agent/configuration/defaults.rb +12 -2
- data/lib/new_relic/agent/configuration/environment_source.rb +4 -1
- data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
- data/lib/new_relic/agent/cross_app_tracing.rb +19 -10
- data/lib/new_relic/agent/error_collector.rb +5 -4
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +204 -0
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +88 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +84 -0
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +3 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +104 -87
- data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +91 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +20 -20
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -5
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +3 -25
- data/lib/new_relic/agent/instrumentation/rails4/action_view.rb +2 -115
- data/lib/new_relic/agent/instrumentation/rails4/active_record.rb +2 -82
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +3 -4
- data/lib/new_relic/agent/method_tracer.rb +93 -56
- data/lib/new_relic/agent/null_logger.rb +6 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +9 -4
- data/lib/new_relic/agent/sql_sampler.rb +10 -6
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +19 -3
- data/lib/new_relic/agent/stats_engine/transactions.rb +53 -34
- data/lib/new_relic/agent/system_info.rb +54 -0
- data/lib/new_relic/agent/thread.rb +2 -2
- data/lib/new_relic/agent/transaction/pop.rb +52 -0
- data/lib/new_relic/agent/transaction.rb +388 -0
- data/lib/new_relic/agent/transaction_info.rb +5 -13
- data/lib/new_relic/agent/transaction_sample_builder.rb +13 -20
- data/lib/new_relic/agent/transaction_sampler.rb +13 -15
- data/lib/new_relic/agent/uri_util.rb +35 -0
- data/lib/new_relic/agent.rb +54 -11
- data/lib/new_relic/build.rb +2 -2
- data/lib/new_relic/control/frameworks/rails.rb +0 -1
- data/lib/new_relic/control/frameworks/rails3.rb +2 -0
- data/lib/new_relic/control/frameworks/rails4.rb +0 -4
- data/lib/new_relic/control/instance_methods.rb +5 -19
- data/lib/new_relic/control/server_methods.rb +2 -0
- data/lib/new_relic/environment_report.rb +4 -34
- data/lib/new_relic/latest_changes.rb +1 -1
- data/lib/new_relic/local_environment.rb +0 -6
- data/lib/new_relic/metric_spec.rb +2 -2
- data/lib/new_relic/rack/error_collector.rb +6 -4
- data/lib/new_relic/transaction_sample.rb +7 -1
- data/lib/new_relic/version.rb +1 -1
- data/lib/newrelic_rpm.rb +2 -2
- data/newrelic.yml +20 -20
- data/test/config/test_control.rb +2 -2
- data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -1
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +0 -2
- data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
- data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -3
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -0
- data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +96 -0
- data/test/multiverse/suites/agent_only/testing_app.rb +1 -0
- data/test/multiverse/suites/rails/error_tracing_test.rb +17 -29
- data/test/multiverse/suites/rails/queue_time_test.rb +8 -2
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -3
- data/test/multiverse/suites/resque/instrumentation_test.rb +1 -1
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +8 -0
- data/test/new_relic/agent/agent/connect_test.rb +2 -1
- data/test/new_relic/agent/agent/start_test.rb +0 -10
- data/test/new_relic/agent/agent_logger_test.rb +15 -0
- data/test/new_relic/agent/agent_test_controller.rb +6 -2
- data/test/new_relic/agent/agent_test_controller_test.rb +20 -69
- data/test/new_relic/agent/autostart_test.rb +67 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +60 -38
- data/test/new_relic/agent/configuration/environment_source_test.rb +19 -17
- data/test/new_relic/agent/cross_app_monitor_test.rb +8 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +0 -5
- data/test/new_relic/agent/error_collector_test.rb +8 -9
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +228 -0
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +18 -34
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +5 -5
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +8 -9
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +24 -38
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +126 -178
- data/test/new_relic/agent/instrumentation/rack_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +135 -151
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +153 -81
- data/test/new_relic/agent/method_tracer_test.rb +42 -33
- data/test/new_relic/agent/mock_scope_listener.rb +4 -4
- data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -2
- data/test/new_relic/agent/rpm_agent_test.rb +86 -89
- data/test/new_relic/agent/sql_sampler_test.rb +18 -19
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +5 -8
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +20 -8
- data/test/new_relic/agent/stats_engine/samplers_test.rb +31 -14
- data/test/new_relic/agent/stats_engine_test.rb +53 -60
- data/test/new_relic/agent/thread_test.rb +7 -7
- data/test/new_relic/agent/transaction/pop_test.rb +96 -0
- data/test/new_relic/agent/transaction_info_test.rb +6 -17
- data/test/new_relic/agent/transaction_sample_builder_test.rb +10 -18
- data/test/new_relic/agent/transaction_sampler_test.rb +80 -75
- data/test/new_relic/agent/{instrumentation/metric_frame_test.rb → transaction_test.rb} +76 -42
- data/test/new_relic/agent/uri_util_test.rb +75 -0
- data/test/new_relic/agent_test.rb +115 -9
- data/test/test_helper.rb +138 -9
- data.tar.gz.sig +0 -0
- metadata +37 -74
- metadata.gz.sig +0 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +0 -84
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -353
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +0 -175
- data/test/test_contexts.rb +0 -34
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
# https://newrelic.atlassian.net/wiki/display/eng/The+Terror+and+Glory+of+Transaction+Traces
|
6
6
|
# https://newrelic.atlassian.net/browse/RUBY-914
|
7
|
+
require 'ostruct'
|
7
8
|
|
8
9
|
class MarshalingTest < Test::Unit::TestCase
|
9
10
|
def setup
|
@@ -26,13 +27,14 @@ class MarshalingTest < Test::Unit::TestCase
|
|
26
27
|
# create fake transaction trace
|
27
28
|
time = Time.now.to_f
|
28
29
|
@sampler.notice_first_scope_push time
|
29
|
-
@sampler.notice_transaction
|
30
|
+
@sampler.notice_transaction nil, {}
|
30
31
|
@sampler.notice_push_scope "a"
|
31
32
|
@sampler.notice_push_scope "ab"
|
32
33
|
sleep 1
|
33
34
|
@sampler.notice_pop_scope "ab"
|
34
35
|
@sampler.notice_pop_scope "a"
|
35
|
-
@sampler.notice_scope_empty
|
36
|
+
@sampler.notice_scope_empty(OpenStruct.new(:name => 'path',
|
37
|
+
:custom_parameters => {}))
|
36
38
|
|
37
39
|
expected_sample = @sampler.instance_variable_get(:@slowest_sample)
|
38
40
|
|
@@ -81,7 +83,7 @@ class MarshalingTest < Test::Unit::TestCase
|
|
81
83
|
@agent.sql_sampler.notice_sql("select * from test",
|
82
84
|
"Database/test/select",
|
83
85
|
nil, 1.5)
|
84
|
-
@agent.sql_sampler.notice_scope_empty
|
86
|
+
@agent.sql_sampler.notice_scope_empty('txn')
|
85
87
|
|
86
88
|
@agent.service.connect
|
87
89
|
@agent.send(:harvest_and_send_slowest_sql)
|
@@ -0,0 +1,96 @@
|
|
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
|
+
class SetTransactionNameTest < Test::Unit::TestCase
|
6
|
+
include NewRelic::Agent::MethodTracer
|
7
|
+
|
8
|
+
class TestTransactor
|
9
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
10
|
+
def parent_txn
|
11
|
+
NewRelic::Agent.set_transaction_name('TestTransactor/parent')
|
12
|
+
yield if block_given?
|
13
|
+
child_txn
|
14
|
+
end
|
15
|
+
add_transaction_tracer :parent_txn
|
16
|
+
|
17
|
+
def child_txn
|
18
|
+
NewRelic::Agent.set_transaction_name('TestTransactor/child', :category => :task)
|
19
|
+
end
|
20
|
+
add_transaction_tracer :child_txn
|
21
|
+
|
22
|
+
newrelic_ignore :only => :ignored_txn
|
23
|
+
def ignored_txn
|
24
|
+
NewRelic::Agent.set_transaction_name('Ignore/me')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup
|
29
|
+
NewRelic::Agent.manual_start(:browser_key => 'browserKey', :application_id => 'appId',
|
30
|
+
:beacon => 'beacon', :episodes_file => 'this_is_my_file')
|
31
|
+
@transactor = TestTransactor.new
|
32
|
+
@stats_engine = NewRelic::Agent.instance.stats_engine
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown
|
36
|
+
NewRelic::Agent.shutdown
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_apply_to_metric_names
|
40
|
+
@transactor.parent_txn
|
41
|
+
[ 'Controller/TestTransactor/parent',
|
42
|
+
'OtherTransaction/Background/TestTransactor/child',
|
43
|
+
[ 'OtherTransaction/Background/TestTransactor/child',
|
44
|
+
'Controller/TestTransactor/parent'],
|
45
|
+
'Apdex/TestTransactor/parent' ].each do |metric|
|
46
|
+
assert(@stats_engine.lookup_stats(*metric),
|
47
|
+
"Expected to find #{metric} in stats hash #{NewRelic::Agent.instance.stats_engine.instance_variable_get(:@stats_hash)}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_apply_to_metric_scopes
|
52
|
+
@transactor.parent_txn do
|
53
|
+
trace_execution_scoped('Custom/something') {}
|
54
|
+
end
|
55
|
+
assert @stats_engine.lookup_stats('Custom/something',
|
56
|
+
'Controller/TestTransactor/parent')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_apply_to_traced_transactions
|
60
|
+
@transactor.parent_txn
|
61
|
+
assert_equal('Controller/TestTransactor/parent',
|
62
|
+
NewRelic::Agent.instance.transaction_sampler.last_sample \
|
63
|
+
.params[:path])
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_apply_to_traced_errors
|
67
|
+
@transactor.parent_txn do
|
68
|
+
NewRelic::Agent.notice_error(RuntimeError.new('toot'))
|
69
|
+
end
|
70
|
+
assert_equal('Controller/TestTransactor/parent',
|
71
|
+
NewRelic::Agent.instance.error_collector.errors.last.path)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_set_name_is_subject_to_txn_name_rules
|
75
|
+
rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => 'parent',
|
76
|
+
'replacement' => 'dad')
|
77
|
+
NewRelic::Agent.instance.transaction_rules << rule
|
78
|
+
@transactor.parent_txn
|
79
|
+
assert @stats_engine.lookup_stats('Controller/TestTransactor/dad')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_does_not_overwrite_name_when_set_by_RUM
|
83
|
+
@transactor.parent_txn do
|
84
|
+
NewRelic::Agent.browser_timing_header
|
85
|
+
NewRelic::Agent.browser_timing_footer
|
86
|
+
NewRelic::Agent.set_transaction_name('this/should/not/work')
|
87
|
+
end
|
88
|
+
assert_nil @stats_engine.lookup_stats('Controller/this/should/not/work')
|
89
|
+
assert @stats_engine.lookup_stats('Controller/TestTransactor/parent')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_ignoring_action
|
93
|
+
@transactor.ignored_txn
|
94
|
+
assert_nil @stats_engine.lookup_stats('Controller/Ignore/me')
|
95
|
+
end
|
96
|
+
end
|
@@ -80,15 +80,11 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
|
80
80
|
'no ignore error filter should be set')
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
assert Rails.application.config.middleware.include?(NewRelic::Rack::ErrorCollector)
|
89
|
-
end
|
90
|
-
else
|
91
|
-
puts yellow("SKIPPED test_error_collector_should_be_enabled : not working in Rails 4")
|
83
|
+
def test_error_collector_should_be_enabled
|
84
|
+
assert NewRelic::Agent.config[:agent_enabled]
|
85
|
+
assert NewRelic::Agent.config[:'error_collector.enabled']
|
86
|
+
assert @error_collector.enabled?
|
87
|
+
assert Rails.application.config.middleware.include?(NewRelic::Rack::ErrorCollector)
|
92
88
|
end
|
93
89
|
|
94
90
|
def test_should_capture_error_raised_in_view
|
@@ -116,7 +112,7 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
|
116
112
|
end
|
117
113
|
|
118
114
|
# Important choice of controllor_error, since this goes through both the
|
119
|
-
#
|
115
|
+
# transaction and the rack error collector, so risks multiple counting!
|
120
116
|
def test_should_capture_multiple_errors
|
121
117
|
40.times do
|
122
118
|
get '/error/controller_error'
|
@@ -130,25 +126,17 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
|
130
126
|
assert_error_reported_once('this is a noticed error')
|
131
127
|
end
|
132
128
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
assert_error_reported_once('this is an uncaught routing error')
|
137
|
-
end
|
138
|
-
else
|
139
|
-
puts yellow("SKIPPED test_should_capture_routing_error : not working in Rails 4")
|
129
|
+
def test_should_capture_routing_error
|
130
|
+
get '/bad_route'
|
131
|
+
assert_error_reported_once('this is an uncaught routing error')
|
140
132
|
end
|
141
133
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
@error_collector.errors[0].params[:request_params])
|
149
|
-
end
|
150
|
-
else
|
151
|
-
puts yellow("SKIPPED test_should_capture_request_uri_and_params : not working in Rails 4")
|
134
|
+
def test_should_capture_request_uri_and_params
|
135
|
+
get '/bad_route?eat=static'
|
136
|
+
assert_equal('/bad_route',
|
137
|
+
@error_collector.errors[0].params[:request_uri])
|
138
|
+
assert_equal({'eat' => 'static'},
|
139
|
+
@error_collector.errors[0].params[:request_params])
|
152
140
|
end
|
153
141
|
|
154
142
|
def test_should_not_notice_errors_from_ignored_action
|
@@ -181,13 +169,13 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
|
181
169
|
protected
|
182
170
|
|
183
171
|
def assert_errors_reported(message, queued_count, total_count=queued_count, txn_name=nil)
|
184
|
-
error_count = NewRelic::Agent::Agent.instance.stats_engine.
|
172
|
+
error_count = NewRelic::Agent::Agent.instance.stats_engine.lookup_stats("Errors/all")
|
185
173
|
assert_equal(total_count, error_count.call_count,
|
186
174
|
'Incorrect call count on Errors/all')
|
187
175
|
|
188
176
|
if txn_name
|
189
177
|
error_count = NewRelic::Agent::Agent.instance.stats_engine \
|
190
|
-
.
|
178
|
+
.lookup_stats("Errors/#{txn_name}")
|
191
179
|
assert_equal(total_count, error_count.call_count,
|
192
180
|
"Incorrect call count on Errors/#{txn_name}")
|
193
181
|
end
|
@@ -27,6 +27,12 @@ class QueueTimeTest < ActionDispatch::IntegrationTest
|
|
27
27
|
NewRelic::Agent::Agent.instance_variable_set(:@instance, @agent)
|
28
28
|
NewRelic::Agent.manual_start
|
29
29
|
|
30
|
+
# ActiveSupport testing keeps blowing away my subscribers on
|
31
|
+
# teardown for some reason. Have to keep putting it back.
|
32
|
+
NewRelic::Agent.instance.events.subscribe(:before_call) do |env|
|
33
|
+
NewRelic::Agent::TransactionInfo.reset(::Rack::Request.new(env))
|
34
|
+
end
|
35
|
+
|
30
36
|
@agent.finish_setup({})
|
31
37
|
end
|
32
38
|
|
@@ -48,8 +54,8 @@ class QueueTimeTest < ActionDispatch::IntegrationTest
|
|
48
54
|
end
|
49
55
|
|
50
56
|
def get_queued(header="HTTP_X_REQUEST_START")
|
51
|
-
|
52
|
-
|
57
|
+
value = "t=#{(Time.now.to_i * 1_000_000) - 1_000}"
|
58
|
+
get('/queue/queued', nil, header => value)
|
53
59
|
end
|
54
60
|
|
55
61
|
def extract_queue_time_from_response
|
@@ -79,11 +79,15 @@ class ViewControllerTest < ActionController::TestCase
|
|
79
79
|
tests ViewsController
|
80
80
|
def setup
|
81
81
|
super
|
82
|
+
NewRelic::Agent.manual_start
|
82
83
|
@controller = ViewsController.new
|
83
|
-
# ActiveSupport testing keeps blowing away my
|
84
|
+
# ActiveSupport testing keeps blowing away my subscribers on
|
84
85
|
# teardown for some reason. Have to keep putting it back.
|
85
86
|
if Rails::VERSION::MAJOR.to_i == 4
|
86
|
-
NewRelic::Agent::Instrumentation::ActionViewSubscriber
|
87
|
+
NewRelic::Agent::Instrumentation::ActionViewSubscriber \
|
88
|
+
.subscribe(/render_.+\.action_view$/)
|
89
|
+
NewRelic::Agent::Instrumentation::ActionControllerSubscriber \
|
90
|
+
.subscribe(/^process_action.action_controller$/)
|
87
91
|
end
|
88
92
|
end
|
89
93
|
end
|
@@ -212,4 +216,3 @@ class FileRenderTest < ViewControllerTest
|
|
212
216
|
assert_equal 'View/file/Rendering', text_segment.metric_name
|
213
217
|
end
|
214
218
|
end
|
215
|
-
|
@@ -28,6 +28,7 @@ class SinatraErrorTracingTest < Test::Unit::TestCase
|
|
28
28
|
::NewRelic::Agent.manual_start
|
29
29
|
@error_collector = ::NewRelic::Agent.instance.error_collector
|
30
30
|
|
31
|
+
@error_collector.errors.clear
|
31
32
|
assert(@error_collector.enabled?,
|
32
33
|
'error collector should be enabled')
|
33
34
|
end
|
@@ -39,4 +40,11 @@ class SinatraErrorTracingTest < Test::Unit::TestCase
|
|
39
40
|
|
40
41
|
assert_equal(1, @error_collector.errors.size)
|
41
42
|
end
|
43
|
+
|
44
|
+
def test_ignores_notfound_errors_by_default
|
45
|
+
get '/ignored_boom'
|
46
|
+
assert_equal 404, last_response.status
|
47
|
+
assert_match %r{Sinatra doesn’t know this ditty\.}, last_response.body
|
48
|
+
assert_equal(0, @error_collector.errors.size)
|
49
|
+
end
|
42
50
|
end
|
@@ -8,6 +8,7 @@ require 'ostruct'
|
|
8
8
|
|
9
9
|
class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
10
10
|
include NewRelic::Agent::Agent::Connect
|
11
|
+
include TransactionSampleTestHelper
|
11
12
|
|
12
13
|
def setup
|
13
14
|
@connected = nil
|
@@ -108,7 +109,7 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
108
109
|
def test_configure_transaction_tracer_with_random_sampling
|
109
110
|
with_config(:'transaction_tracer.transaction_threshold' => 5,
|
110
111
|
:'transaction_tracer.random_sample' => true) do
|
111
|
-
sample =
|
112
|
+
sample = make_sql_transaction
|
112
113
|
@transaction_sampler.store_sample(sample)
|
113
114
|
|
114
115
|
assert_equal sample, @transaction_sampler.instance_variable_get(:@random_sample)
|
@@ -7,16 +7,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
7
7
|
require 'new_relic/agent/agent'
|
8
8
|
include NewRelic::Agent::Agent::Start
|
9
9
|
|
10
|
-
def setup
|
11
|
-
ENV['NEW_RELIC_APP_NAME'] = 'start_test'
|
12
|
-
NewRelic::Agent.reset_config
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
ENV['NEW_RELIC_APP_NAME'] = nil
|
17
|
-
NewRelic::Agent.reset_config
|
18
|
-
end
|
19
|
-
|
20
10
|
def test_already_started_positive
|
21
11
|
dummy_logger = mock
|
22
12
|
dummy_logger.expects(:error).with("Agent Started Already!")
|
@@ -154,4 +154,19 @@ class AgentLoggerTest < Test::Unit::TestCase
|
|
154
154
|
|
155
155
|
assert_equal stdout, logger.instance_variable_get(:@log)
|
156
156
|
end
|
157
|
+
|
158
|
+
def test_null_logger_works_with_impolite_gems_that_add_stuff_to_kernel
|
159
|
+
Kernel.module_eval do
|
160
|
+
def debug; end
|
161
|
+
end
|
162
|
+
|
163
|
+
logger = NewRelic::Agent::AgentLogger.new(@config.merge(:agent_enabled => false))
|
164
|
+
assert_nothing_raised do
|
165
|
+
logger.debug('hi!')
|
166
|
+
end
|
167
|
+
ensure
|
168
|
+
Kernel.module_eval do
|
169
|
+
remove_method :debug
|
170
|
+
end
|
171
|
+
end
|
157
172
|
end
|
@@ -60,8 +60,12 @@ class NewRelic::Agent::AgentTestController < NewRelic::Agent::SuperclassControll
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.set_some_headers(hash_of_headers)
|
63
|
-
|
64
|
-
|
63
|
+
if ::Rails::VERSION::MAJOR.to_i == 4
|
64
|
+
NewRelic::Agent.instance.events.notify(:before_call, hash_of_headers)
|
65
|
+
else
|
66
|
+
@@headers_to_add ||= {}
|
67
|
+
@@headers_to_add.merge!(hash_of_headers)
|
68
|
+
end
|
65
69
|
end
|
66
70
|
|
67
71
|
def self.clear_headers
|
@@ -44,6 +44,12 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
44
44
|
newrelic_ignore_apdex :only => :action_to_ignore_apdex
|
45
45
|
end
|
46
46
|
@engine = @agent.stats_engine
|
47
|
+
|
48
|
+
# ActiveSupport testing keeps blowing away my subscribers on
|
49
|
+
# teardown for some reason. Have to keep putting it back.
|
50
|
+
NewRelic::Agent.instance.events.subscribe(:before_call) do |env|
|
51
|
+
NewRelic::Agent::TransactionInfo.reset(::Rack::Request.new(env))
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
# Normally you can do this with #setup but for some reason in rails 2.0.2
|
@@ -77,17 +83,7 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
77
83
|
assert_equal 1, engine.get_stats_no_scope('Mongrel/Queue Length').call_count
|
78
84
|
assert_equal 9, engine.get_stats_no_scope('Mongrel/Queue Length').total_call_time
|
79
85
|
assert_equal 0, engine.get_stats_no_scope('WebFrontend/Mongrel/Average Queue Time').call_count
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_heroku_queue
|
83
|
-
engine.clear_stats
|
84
|
-
NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_HEROKU_QUEUE_DEPTH'=>'15'
|
85
|
-
get :index
|
86
|
-
assert_equal 1, stats('HttpDispatcher').call_count
|
87
|
-
assert_equal 1, engine.get_stats_no_scope('Mongrel/Queue Length').call_count
|
88
|
-
assert_equal 15, engine.get_stats_no_scope('Mongrel/Queue Length').total_call_time
|
89
|
-
assert_equal 0, engine.get_stats_no_scope('WebFrontend/Mongrel/Average Queue Time').call_count
|
90
|
-
end
|
86
|
+
end if ::Rails::VERSION::MAJOR.to_i <= 3
|
91
87
|
|
92
88
|
def test_new_queue_integration
|
93
89
|
# make this test deterministic
|
@@ -120,7 +116,8 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
120
116
|
engine.clear_stats
|
121
117
|
get :action_inline
|
122
118
|
assert_equal 'foofah', @response.body
|
123
|
-
compare_metrics
|
119
|
+
compare_metrics(%w[Controller/new_relic/agent/agent_test/action_inline],
|
120
|
+
engine.metrics.grep(/^Controller/))
|
124
121
|
end
|
125
122
|
|
126
123
|
def test_metric__ignore
|
@@ -130,6 +127,9 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
130
127
|
compare_metrics [], engine.metrics
|
131
128
|
end
|
132
129
|
|
130
|
+
# Rails 4 does all error tracking in Rack, not testable here
|
131
|
+
# see the rails Multiverse suit for Rails 4 error tests
|
132
|
+
if ::Rails::VERSION::MAJOR.to_i <= 3
|
133
133
|
def test_controller_rescued_error
|
134
134
|
engine.clear_stats
|
135
135
|
assert_raise RuntimeError do
|
@@ -195,6 +195,7 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
195
195
|
assert_equal 0, apdex.apdex_t, 'tol'
|
196
196
|
assert_equal 0, apdex.apdex_s, 'satisfied'
|
197
197
|
end
|
198
|
+
end
|
198
199
|
|
199
200
|
def test_metric__ignore_base
|
200
201
|
engine.clear_stats
|
@@ -228,15 +229,18 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
228
229
|
assert_nil Thread.current[:newrelic_ignore_controller]
|
229
230
|
end
|
230
231
|
|
231
|
-
def
|
232
|
+
def test_records_metric_dispite_ignore_state_when_forced
|
232
233
|
engine = @agent.stats_engine
|
233
234
|
get :entry_action
|
234
235
|
assert_nil Thread.current[:newrelic_ignore_controller]
|
236
|
+
# explicitly ignored
|
235
237
|
assert_nil engine.lookup_stats('Controller/agent_test/entry_action')
|
236
238
|
assert_nil engine.lookup_stats('Controller/agent_test_controller/entry_action')
|
237
239
|
assert_nil engine.lookup_stats('Controller/AgentTestController/entry_action')
|
240
|
+
# implicitly ignored because parent action ignored
|
238
241
|
assert_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController/internal_action')
|
239
242
|
assert_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController_controller/internal_action')
|
243
|
+
# forced to be recorded, overrides parent ignore state
|
240
244
|
assert_not_nil engine.lookup_stats('Controller/NewRelic::Agent::AgentTestController/internal_traced_action')
|
241
245
|
end
|
242
246
|
|
@@ -245,24 +249,15 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
245
249
|
assert_match /bar/, @response.body
|
246
250
|
end
|
247
251
|
|
248
|
-
def
|
249
|
-
assert agent.transaction_sampler
|
250
|
-
num_samples = NewRelic::Agent.instance.transaction_sampler.samples.length
|
251
|
-
assert_equal "[FILTERED]", @controller._filter_parameters({'social_security_number' => 'test'})['social_security_number']
|
252
|
-
get :index, 'social_security_number' => "001-555-1212"
|
253
|
-
samples = agent.transaction_sampler.samples
|
254
|
-
assert_equal num_samples + 1, samples.length
|
255
|
-
assert_equal "[FILTERED]", samples.last.params[:request_params]["social_security_number"]
|
256
|
-
end
|
257
|
-
|
258
|
-
def test_controller_params
|
252
|
+
def test_request_params
|
259
253
|
s = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
260
254
|
agent.transaction_sampler.reset!
|
261
255
|
get :index, 'number' => "001-555-1212"
|
262
256
|
agent.transaction_sampler.harvest(nil)
|
263
257
|
end
|
264
258
|
assert_equal 1, s.size
|
265
|
-
assert_equal
|
259
|
+
assert_equal('001-555-1212',
|
260
|
+
s.first.params[:request_params]['number'])
|
266
261
|
end
|
267
262
|
|
268
263
|
def test_busy_calculation_correctly_calculates_based_acccumlator
|
@@ -337,50 +332,6 @@ class NewRelic::Agent::AgentTestControllerTest < ActionController::TestCase
|
|
337
332
|
|
338
333
|
end
|
339
334
|
|
340
|
-
def test_queue_headers_heroku
|
341
|
-
# make this test deterministic
|
342
|
-
Time.stubs(:now => Time.at(1360973845))
|
343
|
-
|
344
|
-
engine.clear_stats
|
345
|
-
NewRelic::Agent::AgentTestController.clear_headers
|
346
|
-
|
347
|
-
queue_length_stat = stats('Mongrel/Queue Length')
|
348
|
-
queue_time_stat = stats('WebFrontend/QueueTime')
|
349
|
-
|
350
|
-
# heroku version
|
351
|
-
request_start = ((Time.now.to_f - 0.5) * 1e6).to_i.to_s
|
352
|
-
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_QUEUE_START' => "t=#{request_start}", 'HTTP_X_HEROKU_QUEUE_DEPTH' => '0'})
|
353
|
-
get :index
|
354
|
-
assert_equal(0, queue_length_stat.total_call_time, 'queue should be empty')
|
355
|
-
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
356
|
-
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
357
|
-
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
358
|
-
end
|
359
|
-
|
360
|
-
def test_queue_headers_heroku_queue_length
|
361
|
-
# make this test deterministic
|
362
|
-
Time.stubs(:now => Time.at(1360973845))
|
363
|
-
|
364
|
-
engine.clear_stats
|
365
|
-
NewRelic::Agent::AgentTestController.clear_headers
|
366
|
-
|
367
|
-
queue_length_stat = stats('Mongrel/Queue Length')
|
368
|
-
queue_time_stat = stats('WebFrontend/QueueTime')
|
369
|
-
|
370
|
-
# heroku version with queue length > 0
|
371
|
-
request_start = ((Time.now.to_f - 0.5) * 1e6).to_i.to_s
|
372
|
-
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_QUEUE_START' => "t=#{request_start}", 'HTTP_X_HEROKU_QUEUE_DEPTH' => '3'})
|
373
|
-
get :index
|
374
|
-
|
375
|
-
assert_equal(1, queue_length_stat.call_count, 'queue should have been seen once')
|
376
|
-
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
377
|
-
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
378
|
-
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
379
|
-
assert_equal(3, queue_length_stat.total_call_time, 'queue should be 3 long')
|
380
|
-
|
381
|
-
NewRelic::Agent::AgentTestController.clear_headers
|
382
|
-
end
|
383
|
-
|
384
335
|
private
|
385
336
|
def stats(name)
|
386
337
|
engine.get_stats_no_scope(name)
|
@@ -0,0 +1,67 @@
|
|
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
|
+
require 'new_relic/agent/autostart'
|
7
|
+
|
8
|
+
class AutostartTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_typically_the_agent_should_autostart
|
11
|
+
assert ::NewRelic::Agent::Autostart.agent_should_start?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_agent_wont_autostart_if_RAILS_CONSOLE_constant_is_defined
|
15
|
+
assert !defined?(::Rails::Console), "precondition: Rails::Console shouldn't be defined"
|
16
|
+
Rails.const_set(:Console, true)
|
17
|
+
assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't autostart in Rails Console session"
|
18
|
+
ensure
|
19
|
+
Rails.send(:remove_const, :Console)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_agent_wont_start_if_dollar_0_is_irb
|
23
|
+
@orig_dollar_0, $0 = $0, '/foo/bar/irb'
|
24
|
+
assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't autostart when process is invoked by irb"
|
25
|
+
ensure
|
26
|
+
$0 = @orig_dollar_0
|
27
|
+
end
|
28
|
+
|
29
|
+
RAILS_DEFAULT_RAKE_TASKS = %w| about assets:clean assets:clobber
|
30
|
+
assets:environment assets:precompile db:create db:drop db:fixtures:load
|
31
|
+
db:migrate db:migrate:status db:rollback db:schema:cache:clear
|
32
|
+
db:schema:cache:dump db:schema:dump db:schema:load db:seed db:setup
|
33
|
+
db:structure:dump db:version doc:app log:clear middleware notes notes:custom
|
34
|
+
rails:template rails:update routes secret spec spec:controllers spec:helpers
|
35
|
+
spec:models spec:rcov stats test test:all test:all:db test:recent test:single
|
36
|
+
test:uncommitted time:zones:all tmp:clear tmp:create |.each do |task|
|
37
|
+
|
38
|
+
define_method("test_agent_wont_autostart_if_top_level_rake_task_is_#{task}") do
|
39
|
+
Rake.stubs(:application => stub(:top_level_tasks => [task]))
|
40
|
+
assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't start during #{task.inspect} rake task"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
MyConst = true
|
46
|
+
def test_blacklisted_constants_can_be_configured
|
47
|
+
with_config('autostart.blacklisted_constants' => "IRB,::AutostartTest::MyConst") do
|
48
|
+
assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't autostart when environment contains blacklisted constant"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_blacklisted_executable_can_be_configured
|
53
|
+
@orig_dollar_0, $0 = $0, '/foo/bar/baz'
|
54
|
+
with_config('autostart.blacklisted_executables' => 'boo,baz') do
|
55
|
+
assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't autostart when process is invoked by blacklisted executable"
|
56
|
+
end
|
57
|
+
ensure
|
58
|
+
$0 = @orig_dollar_0
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_blacklisted_rake_tasks_can_be_configured
|
62
|
+
with_config('autostart.blacklisted_rake_tasks' => 'foo,bar,baz:bang') do
|
63
|
+
Rake.stubs(:application => stub(:top_level_tasks => ['biz', 'baz:bang']))
|
64
|
+
assert ! ::NewRelic::Agent::Autostart.agent_should_start?, "Agent shouldn't during blacklisted rake task"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|