newrelic_rpm 3.5.4.35.beta → 3.5.5.38
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +42 -0
- data/GUIDELINES_FOR_CONTRIBUTING.md +3 -0
- data/Rakefile +8 -0
- data/bin/mongrel_rpm +1 -1
- data/init.rb +1 -8
- data/lib/new_relic/agent.rb +11 -13
- data/lib/new_relic/agent/agent.rb +89 -110
- data/lib/new_relic/agent/agent_logger.rb +165 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +4 -4
- data/lib/new_relic/agent/browser_monitoring.rb +13 -7
- data/lib/new_relic/agent/busy_calculator.rb +2 -2
- data/lib/new_relic/agent/configuration.rb +25 -0
- data/lib/new_relic/agent/configuration/defaults.rb +45 -8
- data/lib/new_relic/agent/configuration/environment_source.rb +8 -15
- data/lib/new_relic/agent/configuration/manager.rb +22 -2
- data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +4 -2
- data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
- data/lib/new_relic/agent/database.rb +2 -4
- data/lib/new_relic/agent/error_collector.rb +4 -9
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -7
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +1 -1
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
- data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -2
- data/lib/new_relic/agent/method_tracer.rb +6 -8
- data/lib/new_relic/agent/new_relic_service.rb +94 -106
- data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
- data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -6
- data/lib/new_relic/agent/sql_sampler.rb +3 -18
- data/lib/new_relic/agent/stats_engine.rb +0 -5
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
- data/lib/new_relic/agent/stats_engine/samplers.rb +2 -4
- data/lib/new_relic/agent/thread.rb +8 -3
- data/lib/new_relic/agent/thread_profiler.rb +38 -27
- data/lib/new_relic/agent/transaction_info.rb +1 -1
- data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
- data/lib/new_relic/agent/transaction_sampler.rb +3 -7
- data/lib/new_relic/agent/worker_loop.rb +3 -11
- data/lib/new_relic/control.rb +0 -2
- data/lib/new_relic/control/class_methods.rb +8 -2
- data/lib/new_relic/control/frameworks/merb.rb +0 -6
- data/lib/new_relic/control/frameworks/rails.rb +8 -29
- data/lib/new_relic/control/frameworks/rails3.rb +8 -20
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +1 -22
- data/lib/new_relic/control/instance_methods.rb +12 -34
- data/lib/new_relic/control/instrumentation.rb +7 -12
- data/lib/new_relic/control/server_methods.rb +5 -8
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/local_environment.rb +30 -64
- data/lib/new_relic/metric_data.rb +1 -1
- data/lib/new_relic/metric_spec.rb +1 -1
- data/lib/new_relic/noticed_error.rb +1 -1
- data/lib/new_relic/rack/browser_monitoring.rb +5 -5
- data/lib/new_relic/stats.rb +9 -7
- data/lib/new_relic/transaction_sample.rb +2 -7
- data/lib/new_relic/version.rb +1 -1
- data/lib/newrelic_rpm.rb +1 -1
- data/newrelic_rpm.gemspec.erb +15 -17
- data/test/config/newrelic.yml +1 -1
- data/test/config/test_control.rb +18 -18
- data/test/fixtures/gemspec_no_build.rb +0 -2
- data/test/fixtures/gemspec_with_build.rb +0 -2
- data/test/fixtures/gemspec_with_build_and_stage.rb +0 -2
- data/test/multiverse/README.md +3 -8
- data/test/multiverse/suites/agent_only/Envfile +1 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
- data/test/multiverse/suites/config_file_loading/Envfile +7 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
- data/test/multiverse/suites/logging/Envfile +4 -0
- data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
- data/test/multiverse/suites/logging/logging_test.rb +143 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +1 -2
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +0 -13
- data/test/new_relic/agent/agent/connect_test.rb +30 -92
- data/test/new_relic/agent/agent/start_test.rb +4 -84
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -43
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +10 -9
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +2 -1
- data/test/new_relic/agent/busy_calculator_test.rb +7 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +25 -20
- data/test/new_relic/agent/configuration/manager_test.rb +59 -4
- data/test/new_relic/agent/configuration/yaml_source_test.rb +20 -1
- data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
- data/test/new_relic/agent/database_test.rb +0 -11
- data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -3
- data/test/new_relic/agent/error_collector_test.rb +11 -7
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +39 -19
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -6
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
- data/test/new_relic/agent/new_relic_service_test.rb +48 -8
- data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
- data/test/new_relic/agent/sql_sampler_test.rb +1 -1
- data/test/new_relic/agent/thread_profiler_test.rb +46 -45
- data/test/new_relic/agent/thread_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -1
- data/test/new_relic/agent/worker_loop_test.rb +4 -9
- data/test/new_relic/agent_test.rb +6 -9
- data/test/new_relic/control/class_methods_test.rb +0 -18
- data/test/new_relic/control_test.rb +6 -9
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +15 -14
- data/test/new_relic/fake_service.rb +4 -1
- data/test/new_relic/fakes_sending_data.rb +30 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/local_environment_test.rb +5 -2
- data/test/new_relic/rack/browser_monitoring_test.rb +2 -1
- data/test/new_relic/rack/developer_mode_test.rb +1 -1
- data/test/new_relic/stats_test.rb +10 -0
- data/test/new_relic/transaction_sample_test.rb +2 -2
- data/test/script/ci.sh +1 -1
- data/test/test_helper.rb +23 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- metadata +47 -41
- data/InstallationNotes.md +0 -15
- data/lib/new_relic/control/logging_methods.rb +0 -125
- data/test/multiverse/Rakefile +0 -17
- data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +0 -422
- data/test/new_relic/control/logging_methods_test.rb +0 -211
@@ -1,5 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
2
|
require 'new_relic/agent/configuration/manager'
|
3
|
+
require 'new_relic/agent/configuration/mask_defaults'
|
3
4
|
|
4
5
|
module NewRelic::Agent::Configuration
|
5
6
|
class ManagerTest < Test::Unit::TestCase
|
@@ -91,15 +92,56 @@ module NewRelic::Agent::Configuration
|
|
91
92
|
assert_equal 'correct value', @manager[:setting]
|
92
93
|
end
|
93
94
|
|
94
|
-
def
|
95
|
+
def test_dotted_hash_to_hash_is_plain_hash
|
96
|
+
dotted = NewRelic::Agent::Configuration::DottedHash.new({})
|
97
|
+
assert_equal(::Hash, dotted.to_hash.class)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_to_collector_hash
|
95
101
|
@manager.instance_variable_set(:@config_stack, [])
|
96
102
|
@manager.apply_config(:eins => Proc.new { self[:one] })
|
97
103
|
@manager.apply_config(:one => 1)
|
98
104
|
@manager.apply_config(:two => 2)
|
99
|
-
@manager.apply_config(:
|
105
|
+
@manager.apply_config(:nested => {:madness => 'test'})
|
106
|
+
@manager.apply_config(:'nested.madness' => 'test')
|
107
|
+
|
108
|
+
assert_equal({ :eins => 1, :one => 1, :two => 2, :'nested.madness' => 'test' },
|
109
|
+
@manager.to_collector_hash)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Necessary to keep the pruby marshaller happy
|
113
|
+
def test_to_collector_hash_returns_bare_hash
|
114
|
+
@manager.instance_variable_set(:@config_stack, [])
|
115
|
+
@manager.apply_config(:eins => Proc.new { self[:one] })
|
116
|
+
|
117
|
+
assert_equal(::Hash, @manager.to_collector_hash.class)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_config_masks
|
121
|
+
NewRelic::Agent::Configuration::MASK_DEFAULTS[:boo] = Proc.new { true }
|
122
|
+
|
123
|
+
@manager.apply_config(:boo => 1)
|
124
|
+
|
125
|
+
assert_equal false, @manager.to_collector_hash.has_key?(:boo)
|
126
|
+
end
|
100
127
|
|
101
|
-
|
102
|
-
|
128
|
+
def test_config_masks_conditionally
|
129
|
+
NewRelic::Agent::Configuration::MASK_DEFAULTS[:boo] = Proc.new { false }
|
130
|
+
|
131
|
+
@manager.apply_config(:boo => 1)
|
132
|
+
|
133
|
+
assert @manager.to_collector_hash.has_key?(:boo)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_config_masks_thread_profiler
|
137
|
+
supported = NewRelic::Agent::ThreadProfiler.is_supported?
|
138
|
+
reported_config = @manager.to_collector_hash
|
139
|
+
|
140
|
+
if supported
|
141
|
+
assert_not_nil reported_config[:'thread_profiler.enabled']
|
142
|
+
else
|
143
|
+
assert_equal nil, reported_config[:'thread_profiler.enabled']
|
144
|
+
end
|
103
145
|
end
|
104
146
|
|
105
147
|
def test_replacing_a_layer_by_class
|
@@ -140,6 +182,19 @@ module NewRelic::Agent::Configuration
|
|
140
182
|
assert_equal 'right', state
|
141
183
|
end
|
142
184
|
|
185
|
+
def test_should_log_when_applying
|
186
|
+
expects_logging(:debug, anything, includes("asdf"))
|
187
|
+
@manager.apply_config(:test => "asdf")
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_should_log_when_removing
|
191
|
+
config = { :test => "asdf" }
|
192
|
+
@manager.apply_config(config)
|
193
|
+
|
194
|
+
expects_logging(:debug, anything, Not(includes("asdf")))
|
195
|
+
@manager.remove_config(config)
|
196
|
+
end
|
197
|
+
|
143
198
|
class TestSource < ::Hash
|
144
199
|
def test_config_accessor
|
145
200
|
'some value'
|
@@ -49,8 +49,27 @@ module NewRelic::Agent::Configuration
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_should_log_if_no_file_is_found
|
52
|
-
|
52
|
+
expects_logging(:error, any_parameters)
|
53
53
|
source = YamlSource.new('no_such_file.yml', 'test')
|
54
54
|
end
|
55
|
+
|
56
|
+
def test_should_not_fail_to_log_missing_file_during_startup
|
57
|
+
without_logger do
|
58
|
+
::NewRelic::Agent::StartupLogger.any_instance.expects(:error)
|
59
|
+
source = YamlSource.new('no_such_file.yml', 'test')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_not_fail_to_log_invalid_file_during_startup
|
64
|
+
without_logger do
|
65
|
+
::NewRelic::Agent::StartupLogger.any_instance.expects(:error)
|
66
|
+
|
67
|
+
File.stubs(:exists?).returns(true)
|
68
|
+
File.stubs(:read).raises(StandardError.new("boo"))
|
69
|
+
|
70
|
+
source = YamlSource.new('fake.yml', 'test')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
55
74
|
end
|
56
75
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
module NewRelic::Agent
|
4
|
+
class CrossProcessMonitoringTest < Test::Unit::TestCase
|
5
|
+
AGENT_CROSS_PROCESS_ID = "qwerty"
|
6
|
+
REQUEST_CROSS_PROCESS_ID = "asdf"
|
7
|
+
|
8
|
+
def setup
|
9
|
+
NewRelic::Agent.instance.stubs(:cross_process_id).returns(AGENT_CROSS_PROCESS_ID)
|
10
|
+
NewRelic::Agent.instance.stubs(:cross_process_encoding_bytes).returns([0])
|
11
|
+
|
12
|
+
@request_with_id = stub(:env => {'X-NewRelic-ID' => REQUEST_CROSS_PROCESS_ID})
|
13
|
+
@empty_request = stub(:env => {})
|
14
|
+
|
15
|
+
@response = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_adds_response_header
|
19
|
+
timings = stub(
|
20
|
+
:transaction_name => "transaction",
|
21
|
+
:queue_time_in_millis => 1000,
|
22
|
+
:app_time_in_millis => 2000)
|
23
|
+
|
24
|
+
NewRelic::Agent::BrowserMonitoring.stubs(:timings).returns(timings)
|
25
|
+
|
26
|
+
CrossProcessMonitoring.insert_response_header(@request_with_id, @response)
|
27
|
+
|
28
|
+
assert unpacked_response.include?("transaction")
|
29
|
+
assert unpacked_response.include?("1000")
|
30
|
+
assert unpacked_response.include?("2000")
|
31
|
+
assert unpacked_response.include?(AGENT_CROSS_PROCESS_ID)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_doesnt_add_header_if_no_id_in_request
|
35
|
+
CrossProcessMonitoring.insert_response_header(@empty_request, @response)
|
36
|
+
assert_nil response_app_data
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_doesnt_add_header_if_no_id_on_agent
|
40
|
+
NewRelic::Agent.instance.stubs(:cross_process_id).returns(nil)
|
41
|
+
|
42
|
+
CrossProcessMonitoring.insert_response_header(@request_with_id, @response)
|
43
|
+
assert_nil response_app_data
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_doesnt_add_header_if_config_disabled
|
47
|
+
with_config(:'cross_process.enabled' => false) do
|
48
|
+
CrossProcessMonitoring.insert_response_header(@request_with_id, @response)
|
49
|
+
assert_nil response_app_data
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_finds_id_from_headers
|
54
|
+
%w{X-NewRelic-ID HTTP_X_NEWRELIC_ID X_NEWRELIC_ID}.each do |key|
|
55
|
+
request = stub(:env => { key => REQUEST_CROSS_PROCESS_ID })
|
56
|
+
|
57
|
+
assert_equal(
|
58
|
+
REQUEST_CROSS_PROCESS_ID, \
|
59
|
+
CrossProcessMonitoring.id_from_request(request),
|
60
|
+
"Failed to find header on key #{key}")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_doesnt_find_id_in_headers
|
65
|
+
request = stub(:env => {})
|
66
|
+
assert_nil CrossProcessMonitoring.id_from_request(request)
|
67
|
+
end
|
68
|
+
|
69
|
+
def response_app_data
|
70
|
+
@response['X-NewRelic-App-Data']
|
71
|
+
end
|
72
|
+
|
73
|
+
def unpacked_response
|
74
|
+
response_app_data.unpack("m0").first
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -73,17 +73,6 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
|
|
73
73
|
assert_equal([], NewRelic::Agent::Database.explain_sql('SELECT', config))
|
74
74
|
end
|
75
75
|
|
76
|
-
def test_handle_exception_in_explain
|
77
|
-
fake_error = StandardError.new('a message')
|
78
|
-
NewRelic::Control.instance.log.expects(:error).with('Error getting query plan: a message')
|
79
|
-
# backtrace can be basically any string, just should get logged
|
80
|
-
NewRelic::Control.instance.log.expects(:debug).with(instance_of(String))
|
81
|
-
|
82
|
-
NewRelic::Agent::Database.handle_exception_in_explain do
|
83
|
-
raise(fake_error)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
76
|
def test_obfuscation_mysql_basic
|
88
77
|
insert = %q[INSERT INTO `X` values("test",0, 1 , 2, 'test')]
|
89
78
|
assert_equal("INSERT INTO `X` values(?,?, ? , ?, ?)",
|
@@ -126,9 +126,7 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Test::Unit::TestCase
|
|
126
126
|
|
127
127
|
def test_over_queue_limit_positive
|
128
128
|
@errors = %w(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21)
|
129
|
-
|
130
|
-
self.expects(:log).returns(fake_log)
|
131
|
-
fake_log.expects(:warn).with('The error reporting queue has reached 20. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: hooray')
|
129
|
+
expects_logging(:warn, includes('The error reporting queue has reached 20'))
|
132
130
|
assert over_queue_limit?('hooray')
|
133
131
|
end
|
134
132
|
|
@@ -5,10 +5,17 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
5
5
|
class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
7
|
super
|
8
|
+
@test_config = { :capture_params => true }
|
9
|
+
NewRelic::Agent.config.apply_config(@test_config)
|
8
10
|
@error_collector = NewRelic::Agent::ErrorCollector.new
|
9
11
|
@error_collector.stubs(:enabled).returns(true)
|
10
12
|
end
|
11
|
-
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
super
|
16
|
+
NewRelic::Agent.config.remove_config(@test_config)
|
17
|
+
end
|
18
|
+
|
12
19
|
def test_empty
|
13
20
|
@error_collector.harvest_errors([])
|
14
21
|
@error_collector.notice_error(nil, :metric=> 'path', :request_params => {:x => 'y'})
|
@@ -27,7 +34,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
27
34
|
assert_equal 'path', err.path
|
28
35
|
assert_equal 'Error', err.exception_class
|
29
36
|
end
|
30
|
-
|
37
|
+
|
31
38
|
def test_simple
|
32
39
|
@error_collector.notice_error(StandardError.new("message"), :uri => '/myurl/', :metric => 'path', :referer => 'test_referer', :request_params => {:x => 'y'})
|
33
40
|
|
@@ -115,7 +122,6 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
115
122
|
|
116
123
|
|
117
124
|
def test_supported_param_types
|
118
|
-
|
119
125
|
types = [[1, '1'],
|
120
126
|
[1.1, '1.1'],
|
121
127
|
['hi', 'hi'],
|
@@ -124,10 +130,9 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
124
130
|
[TestClass.new, "#<NewRelic::Agent::ErrorCollectorTest::TestClass>"]
|
125
131
|
]
|
126
132
|
|
127
|
-
|
128
133
|
types.each do |test|
|
129
|
-
@error_collector.notice_error(StandardError.new("message"), :metric => 'path',
|
130
|
-
|
134
|
+
@error_collector.notice_error(StandardError.new("message"), :metric => 'path',
|
135
|
+
:request_params => {:x => test[0]})
|
131
136
|
assert_equal test[1], @error_collector.harvest_errors([])[0].params[:request_params][:x]
|
132
137
|
end
|
133
138
|
end
|
@@ -156,7 +161,6 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
156
161
|
end
|
157
162
|
|
158
163
|
def test_exclude_block
|
159
|
-
NewRelic::Agent.logger.expects(:error).never
|
160
164
|
@error_collector.ignore_error_filter &wrapped_filter_proc
|
161
165
|
|
162
166
|
@error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
|
@@ -45,9 +45,13 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
45
45
|
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
46
46
|
|
47
47
|
assert_calls_metrics(find_metric) do
|
48
|
-
ActiveRecordFixtures::Order
|
48
|
+
all_finder(ActiveRecordFixtures::Order)
|
49
49
|
check_metric_count(find_metric, 1)
|
50
|
-
|
50
|
+
if NewRelic::Control.instance.rails_version >= "4"
|
51
|
+
ActiveRecordFixtures::Order.where(:name => "jeff").load
|
52
|
+
else
|
53
|
+
ActiveRecordFixtures::Order.find_all_by_name "jeff"
|
54
|
+
end
|
51
55
|
check_metric_count(find_metric, 2)
|
52
56
|
end
|
53
57
|
end
|
@@ -74,9 +78,9 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
74
78
|
|
75
79
|
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
76
80
|
ActiveRecordFixtures::Order.cache do
|
77
|
-
m = ActiveRecordFixtures::Order.create :id =>
|
81
|
+
m = ActiveRecordFixtures::Order.create :id => 1, :name => 'jeff'
|
78
82
|
assert_calls_metrics(find_metric) do
|
79
|
-
ActiveRecordFixtures::Order
|
83
|
+
all_finder(ActiveRecordFixtures::Order)
|
80
84
|
end
|
81
85
|
|
82
86
|
check_metric_count(find_metric, 1)
|
@@ -151,7 +155,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
151
155
|
# fails due to a bug in rails 3 - log does not provide the correct
|
152
156
|
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
153
157
|
return if defined?(JRuby) || isSqlite?
|
154
|
-
|
158
|
+
|
155
159
|
expected = %W[
|
156
160
|
ActiveRecord/all
|
157
161
|
ActiveRecord/find
|
@@ -169,14 +173,14 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
169
173
|
end
|
170
174
|
|
171
175
|
assert_calls_metrics(*expected) do
|
172
|
-
m = ActiveRecordFixtures::Order.create :id =>
|
176
|
+
m = ActiveRecordFixtures::Order.create :id => 1, :name => 'donkey'
|
173
177
|
m = ActiveRecordFixtures::Order.find(m.id)
|
174
178
|
m.id = 999
|
175
179
|
m.save!
|
176
180
|
end
|
177
181
|
|
178
182
|
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
179
|
-
|
183
|
+
|
180
184
|
compare_metrics expected, metrics
|
181
185
|
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
182
186
|
if NewRelic::Control.instance.rails_version < '3.0.0'
|
@@ -261,7 +265,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
261
265
|
end
|
262
266
|
|
263
267
|
def test_join_metrics_standard
|
264
|
-
return if (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i
|
268
|
+
return if (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i >= 3)
|
265
269
|
return if defined?(JRuby) || isSqlite?
|
266
270
|
|
267
271
|
expected_metrics = %W[
|
@@ -357,7 +361,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
357
361
|
ActiveRecordFixtures::Order.add_delay
|
358
362
|
NewRelic::Agent.disable_all_tracing do
|
359
363
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
360
|
-
ActiveRecordFixtures::Order
|
364
|
+
all_finder(ActiveRecordFixtures::Order)
|
361
365
|
end
|
362
366
|
end
|
363
367
|
assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
|
@@ -368,7 +372,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
368
372
|
def test_run_explains
|
369
373
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
370
374
|
ActiveRecordFixtures::Order.add_delay
|
371
|
-
ActiveRecordFixtures::Order
|
375
|
+
all_finder(ActiveRecordFixtures::Order)
|
372
376
|
end
|
373
377
|
|
374
378
|
# that's a mouthful. perhaps we should ponder our API.
|
@@ -381,7 +385,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
381
385
|
def test_prepare_to_send
|
382
386
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
383
387
|
ActiveRecordFixtures::Order.add_delay
|
384
|
-
ActiveRecordFixtures::Order
|
388
|
+
all_finder(ActiveRecordFixtures::Order)
|
385
389
|
end
|
386
390
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
387
391
|
assert_not_nil sample
|
@@ -412,7 +416,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
412
416
|
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
413
417
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
414
418
|
ActiveRecordFixtures::Order.add_delay
|
415
|
-
ActiveRecordFixtures::Order
|
419
|
+
all_finder(ActiveRecordFixtures::Order)
|
416
420
|
end
|
417
421
|
|
418
422
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
@@ -442,7 +446,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
442
446
|
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
443
447
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
444
448
|
ActiveRecordFixtures::Order.add_delay
|
445
|
-
ActiveRecordFixtures::Order
|
449
|
+
all_finder(ActiveRecordFixtures::Order)
|
446
450
|
end
|
447
451
|
|
448
452
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
@@ -467,7 +471,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
467
471
|
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
468
472
|
perform_action_with_newrelic_trace :name => 'bogosity' do
|
469
473
|
ActiveRecordFixtures::Order.add_delay
|
470
|
-
ActiveRecordFixtures::Order
|
474
|
+
all_finder(ActiveRecordFixtures::Order)
|
471
475
|
end
|
472
476
|
|
473
477
|
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
@@ -482,10 +486,12 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
482
486
|
# These are only valid for rails 2.1 and later
|
483
487
|
if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
|
484
488
|
ActiveRecordFixtures::Order.class_eval do
|
485
|
-
if NewRelic::Control.instance.rails_version
|
486
|
-
|
487
|
-
|
489
|
+
if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4")
|
490
|
+
scope :jeffs, lambda { where(:name => 'Jeff') }
|
491
|
+
elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.1")
|
488
492
|
scope :jeffs, :conditions => { :name => 'Jeff' }
|
493
|
+
else
|
494
|
+
named_scope :jeffs, :conditions => { :name => 'Jeff' }
|
489
495
|
end
|
490
496
|
end
|
491
497
|
def test_named_scope
|
@@ -495,7 +501,11 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
495
501
|
|
496
502
|
check_metric_count(find_metric, 0)
|
497
503
|
assert_calls_metrics(find_metric) do
|
498
|
-
|
504
|
+
if NewRelic::Control.instance.rails_version >= "4"
|
505
|
+
x = ActiveRecordFixtures::Order.jeffs.load
|
506
|
+
else
|
507
|
+
x = ActiveRecordFixtures::Order.jeffs.find(:all)
|
508
|
+
end
|
499
509
|
end
|
500
510
|
check_metric_count(find_metric, 1)
|
501
511
|
end
|
@@ -566,7 +576,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
566
576
|
private
|
567
577
|
|
568
578
|
def rails3?
|
569
|
-
(defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i
|
579
|
+
(defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i >= 3)
|
570
580
|
end
|
571
581
|
|
572
582
|
def rails_env
|
@@ -583,4 +593,14 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
|
|
583
593
|
def isSqlite?
|
584
594
|
ActiveRecord::Base.configurations[rails_env]['adapter'] =~ /sqlite/i
|
585
595
|
end
|
596
|
+
|
597
|
+
def all_finder(relation)
|
598
|
+
if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4.0")
|
599
|
+
relation.all.load
|
600
|
+
elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.0")
|
601
|
+
relation.all
|
602
|
+
else
|
603
|
+
relation.find(:all)
|
604
|
+
end
|
605
|
+
end
|
586
606
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::Instrumentation::BrowserMonitoringTimingsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Time.stubs(:now).returns(2000)
|
7
|
+
@transaction = stub(
|
8
|
+
:transaction_name => "Name",
|
9
|
+
:start_time => 0
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_queue_time
|
14
|
+
t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(1000.1234, @transaction)
|
15
|
+
assert_equal 1_000_123, t.queue_time_in_millis
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_queue_time_clamps_to_positive
|
19
|
+
t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(-1000, @transaction)
|
20
|
+
assert_equal 0, t.queue_time_in_millis
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_app_time
|
24
|
+
t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(nil, @transaction)
|
25
|
+
assert_equal 2_000_000, t.app_time_in_millis
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_transaction_name
|
29
|
+
t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(nil, @transaction)
|
30
|
+
assert_equal "Name", t.transaction_name
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_defaults_to_transaction_info
|
34
|
+
t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(1000, nil)
|
35
|
+
assert_equal nil, t.transaction_name
|
36
|
+
assert_equal 0.0, t.start_time_in_millis
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|