newrelic_rpm 2.8.11 → 2.9.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +267 -0
- data/LICENSE +1 -1
- data/Manifest +142 -0
- data/README.md +138 -0
- data/Rakefile +10 -28
- data/bin/mongrel_rpm +33 -0
- data/cert/cacert.pem +34 -0
- data/init.rb +38 -0
- data/lib/new_relic/agent/agent.rb +160 -347
- data/lib/new_relic/agent/collection_helper.rb +13 -24
- data/lib/new_relic/agent/error_collector.rb +29 -15
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +63 -76
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +90 -48
- data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +72 -47
- data/lib/new_relic/agent/instrumentation/error_instrumentation.rb +14 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +10 -1
- data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +5 -7
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +3 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +7 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +34 -7
- data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +20 -12
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +5 -4
- data/lib/new_relic/agent/method_tracer.rb +159 -135
- data/lib/new_relic/agent/patch_const_missing.rb +46 -26
- data/lib/new_relic/agent/sampler.rb +12 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +44 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +126 -0
- data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
- data/lib/new_relic/agent/shim_agent.rb +11 -0
- data/lib/new_relic/agent/stats_engine.rb +85 -46
- data/lib/new_relic/agent/transaction_sampler.rb +63 -38
- data/lib/new_relic/agent/worker_loop.rb +8 -18
- data/lib/new_relic/agent.rb +200 -25
- data/lib/new_relic/commands/deployments.rb +9 -9
- data/lib/new_relic/control/merb.rb +22 -0
- data/lib/new_relic/control/rails.rb +141 -0
- data/lib/new_relic/{config → control}/ruby.rb +13 -2
- data/lib/new_relic/control.rb +424 -0
- data/lib/new_relic/local_environment.rb +201 -79
- data/lib/new_relic/metric_data.rb +7 -0
- data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
- data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
- data/lib/new_relic/metric_parser/active_record.rb +11 -0
- data/lib/new_relic/metric_parser/controller.rb +51 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/database.rb +23 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_parser.rb +107 -0
- data/lib/new_relic/metric_spec.rb +5 -0
- data/lib/new_relic/noticed_error.rb +5 -1
- data/lib/new_relic/rack/metric_app.rb +57 -0
- data/lib/new_relic/rack/newrelic.ru +25 -0
- data/lib/new_relic/rack/newrelic.yml +25 -0
- data/lib/new_relic/rack.rb +5 -0
- data/lib/new_relic/recipes.rb +10 -3
- data/lib/new_relic/stats.rb +130 -144
- data/lib/new_relic/transaction_analysis.rb +7 -8
- data/lib/new_relic/transaction_sample.rb +86 -10
- data/lib/new_relic/version.rb +41 -160
- data/lib/new_relic_api.rb +7 -6
- data/lib/newrelic_rpm.rb +30 -17
- data/lib/tasks/{agent_tests.rake → tests.rake} +1 -1
- data/newrelic.yml +115 -62
- data/newrelic_rpm.gemspec +36 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +21 -3
- data/test/config/{test_config.rb → test_control.rb} +14 -10
- data/test/new_relic/agent/active_record_instrumentation_test.rb +189 -0
- data/test/new_relic/agent/agent_test.rb +104 -0
- data/test/new_relic/agent/agent_test_controller.rb +18 -1
- data/test/new_relic/agent/classloader_patch_test.rb +56 -0
- data/test/new_relic/agent/{tc_collection_helper.rb → collection_helper_test.rb} +28 -23
- data/test/new_relic/agent/controller_test.rb +107 -0
- data/test/new_relic/agent/dispatcher_instrumentation_test.rb +70 -0
- data/test/new_relic/agent/error_collector_test.rb +155 -0
- data/test/new_relic/agent/{tc_method_tracer.rb → method_tracer_test.rb} +6 -12
- data/test/new_relic/agent/metric_data_test.rb +56 -0
- data/test/new_relic/agent/stats_engine_test.rb +266 -0
- data/test/new_relic/agent/{tc_transaction_sample_builder.rb → transaction_sample_builder_test.rb} +6 -5
- data/test/new_relic/agent/{tc_transaction_sample.rb → transaction_sample_test.rb} +9 -13
- data/test/new_relic/agent/transaction_sampler_test.rb +317 -0
- data/test/new_relic/agent/{tc_worker_loop.rb → worker_loop_test.rb} +1 -1
- data/test/new_relic/control_test.rb +97 -0
- data/test/new_relic/{tc_deployments_api.rb → deployments_api_test.rb} +8 -4
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +142 -0
- data/test/new_relic/{tc_metric_spec.rb → metric_spec_test.rb} +28 -1
- data/test/new_relic/samplers_test.rb +71 -0
- data/test/new_relic/{tc_shim_agent.rb → shim_agent_test.rb} +1 -1
- data/test/new_relic/stats_test.rb +291 -0
- data/test/new_relic/version_number_test.rb +46 -0
- data/test/test_helper.rb +7 -30
- data/test/ui/newrelic_controller_test.rb +14 -0
- data/test/ui/{tc_newrelic_helper.rb → newrelic_helper_test.rb} +16 -7
- data/ui/controllers/newrelic_controller.rb +17 -3
- data/ui/helpers/newrelic_helper.rb +44 -15
- data/ui/views/layouts/newrelic_default.rhtml +7 -8
- data/ui/views/newrelic/_sample.rhtml +5 -2
- data/ui/views/newrelic/_segment.rhtml +1 -1
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +4 -4
- data/ui/views/newrelic/_show_sample_detail.rhtml +3 -1
- data/ui/views/newrelic/_show_sample_sql.rhtml +2 -1
- data/ui/views/newrelic/explain_sql.rhtml +2 -5
- data/ui/views/newrelic/images/file_icon.png +0 -0
- data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/index.rhtml +21 -13
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
- data/ui/views/newrelic/show_sample.rhtml +18 -3
- data/ui/views/newrelic/stylesheets/style.css +39 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +192 -70
- data/README +0 -136
- data/lib/new_relic/agent/instrumentation/rails/rails.rb +0 -6
- data/lib/new_relic/agent/samplers/cpu.rb +0 -29
- data/lib/new_relic/agent/samplers/memory.rb +0 -53
- data/lib/new_relic/agent/samplers/mongrel.rb +0 -26
- data/lib/new_relic/agent/synchronize.rb +0 -40
- data/lib/new_relic/config/merb.rb +0 -35
- data/lib/new_relic/config/rails.rb +0 -114
- data/lib/new_relic/config.rb +0 -279
- data/lib/new_relic/shim_agent.rb +0 -96
- data/test/new_relic/agent/model_fixture.rb +0 -15
- data/test/new_relic/agent/tc_active_record.rb +0 -90
- data/test/new_relic/agent/tc_agent.rb +0 -148
- data/test/new_relic/agent/tc_controller.rb +0 -77
- data/test/new_relic/agent/tc_dispatcher_instrumentation.rb +0 -52
- data/test/new_relic/agent/tc_error_collector.rb +0 -127
- data/test/new_relic/agent/tc_stats_engine.rb +0 -218
- data/test/new_relic/agent/tc_synchronize.rb +0 -37
- data/test/new_relic/agent/tc_transaction_sampler.rb +0 -302
- data/test/new_relic/tc_config.rb +0 -36
- data/test/new_relic/tc_environment.rb +0 -94
- data/test/new_relic/tc_stats.rb +0 -141
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'action_controller/base'
|
3
|
+
|
4
|
+
class AgentControllerTest < ActionController::TestCase
|
5
|
+
|
6
|
+
self.controller_class = NewRelic::Agent::AgentTestController
|
7
|
+
|
8
|
+
attr_accessor :agent
|
9
|
+
|
10
|
+
# Normally you can do this with #setup but for some reason in rails 2.0.2
|
11
|
+
# setup is not called.
|
12
|
+
def initialize name
|
13
|
+
super name
|
14
|
+
Thread.current[:controller_ignored] = nil
|
15
|
+
NewRelic::Agent.manual_start
|
16
|
+
@agent = NewRelic::Agent.instance
|
17
|
+
# @agent.instrument_app
|
18
|
+
agent.transaction_sampler.harvest
|
19
|
+
NewRelic::Agent::AgentTestController.class_eval do
|
20
|
+
newrelic_ignore :only => [:action_to_ignore, :entry_action, :base_action]
|
21
|
+
newrelic_ignore_apdex :only => :action_to_ignore_apdex
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
Thread.current[:controller_ignored] = nil
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_metric__ignore
|
31
|
+
engine = @agent.stats_engine
|
32
|
+
get :action_to_ignore
|
33
|
+
assert_equal true, Thread.current[:controller_ignored]
|
34
|
+
end
|
35
|
+
def test_metric__ignore_base
|
36
|
+
engine = @agent.stats_engine
|
37
|
+
get :base_action
|
38
|
+
assert_equal true, Thread.current[:controller_ignored]
|
39
|
+
end
|
40
|
+
def test_metric__no_ignore
|
41
|
+
engine = @agent.stats_engine
|
42
|
+
path = 'new_relic/agent/agent_test/index'
|
43
|
+
cpu_stats = engine.get_stats_no_scope("ControllerCPU/#{path}")
|
44
|
+
index_stats = engine.get_stats_no_scope("Controller/#{path}")
|
45
|
+
index_apdex_stats = engine.get_custom_stats("Apdex/#{path}", NewRelic::ApdexStats)
|
46
|
+
assert_difference 'index_stats.call_count' do
|
47
|
+
assert_difference 'index_apdex_stats.call_count' do
|
48
|
+
assert_difference 'cpu_stats.call_count' do
|
49
|
+
get :index
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
assert_nil Thread.current[:controller_ignored]
|
54
|
+
end
|
55
|
+
def test_metric__ignore_apdex
|
56
|
+
engine = @agent.stats_engine
|
57
|
+
path = 'new_relic/agent/agent_test/action_to_ignore_apdex'
|
58
|
+
cpu_stats = engine.get_stats_no_scope("ControllerCPU/#{path}")
|
59
|
+
index_stats = engine.get_stats_no_scope("Controller/#{path}")
|
60
|
+
index_apdex_stats = engine.get_custom_stats("Apdex/#{path}", NewRelic::ApdexStats)
|
61
|
+
assert_difference 'index_stats.call_count' do
|
62
|
+
assert_no_difference 'index_apdex_stats.call_count' do
|
63
|
+
assert_difference 'cpu_stats.call_count' do
|
64
|
+
get :action_to_ignore_apdex
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
assert_nil Thread.current[:controller_ignored]
|
69
|
+
|
70
|
+
end
|
71
|
+
def test_metric__dispatched
|
72
|
+
engine = @agent.stats_engine
|
73
|
+
get :entry_action
|
74
|
+
assert_nil Thread.current[:controller_ignored]
|
75
|
+
assert_nil engine.lookup_stat('Controller/agent_test/entry_action')
|
76
|
+
assert_equal 1, engine.lookup_stat('Controller/new_relic/agent/agent_test/internal_action').call_count
|
77
|
+
end
|
78
|
+
def test_action_instrumentation
|
79
|
+
begin
|
80
|
+
get :index, :foo => 'bar'
|
81
|
+
assert_match /bar/, @response.body
|
82
|
+
#rescue ActionController::RoutingError
|
83
|
+
# you might get here if you don't have the default route installed.
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_controller_params
|
88
|
+
|
89
|
+
assert agent.transaction_sampler
|
90
|
+
|
91
|
+
num_samples = NewRelic::Agent.instance.transaction_sampler.samples.length
|
92
|
+
|
93
|
+
assert_equal "[FILTERED]", @controller._filter_parameters({'social_security_number' => 'test'})['social_security_number']
|
94
|
+
|
95
|
+
get :index, 'social_security_number' => "001-555-1212"
|
96
|
+
|
97
|
+
samples = agent.transaction_sampler.samples
|
98
|
+
|
99
|
+
agent.transaction_sampler.expects(:notice_transaction).never
|
100
|
+
|
101
|
+
assert_equal num_samples + 1, samples.length
|
102
|
+
|
103
|
+
assert_equal "[FILTERED]", samples.last.params[:request_params]["social_security_number"]
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::DispatcherInstrumentationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class FunnyDispatcher
|
6
|
+
include NewRelic::Agent::Instrumentation::DispatcherInstrumentation
|
7
|
+
def newrelic_response_code; end
|
8
|
+
end
|
9
|
+
def setup
|
10
|
+
@instance_busy = NewRelic::Agent.agent.stats_engine.get_stats('Instance/Busy')
|
11
|
+
@dispatch_stat = NewRelic::Agent.agent.stats_engine.get_stats 'Rails/HTTP Dispatch'
|
12
|
+
@mongrel_queue_stat = NewRelic::Agent.agent.stats_engine.get_stats 'WebFrontend/Mongrel/Average Queue Time'
|
13
|
+
|
14
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
15
|
+
@instance_busy.reset
|
16
|
+
@dispatch_stat.reset
|
17
|
+
@mongrel_queue_stat.reset
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_normal_call
|
22
|
+
d = FunnyDispatcher.new
|
23
|
+
assert_equal 0, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
24
|
+
d.newrelic_dispatcher_start
|
25
|
+
sleep 1.0
|
26
|
+
assert_equal 1, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
27
|
+
d.newrelic_dispatcher_finish
|
28
|
+
assert_equal 0, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
29
|
+
assert_nil Thread.current[:newrelic_t0]
|
30
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
31
|
+
|
32
|
+
assert_equal 1, @instance_busy.call_count
|
33
|
+
assert_equal 1, @dispatch_stat.call_count
|
34
|
+
assert_equal 0, @mongrel_queue_stat.call_count
|
35
|
+
assert @dispatch_stat.total_call_time >= 1.0, "Total call time must be at least one second"
|
36
|
+
assert @instance_busy.total_call_time > 0.9 && @instance_busy.total_call_time <= 1.0, "instance busy = #{@instance_busy.inspect}"
|
37
|
+
end
|
38
|
+
def test_ignore_zero_counts
|
39
|
+
assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
|
40
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
41
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
42
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
43
|
+
assert_equal 0, @instance_busy.call_count
|
44
|
+
end
|
45
|
+
def test_recursive_call
|
46
|
+
d0 = FunnyDispatcher.new
|
47
|
+
d1 = FunnyDispatcher.new
|
48
|
+
|
49
|
+
assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
|
50
|
+
|
51
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
52
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
53
|
+
assert_equal 0, @instance_busy.call_count
|
54
|
+
|
55
|
+
assert_equal 0, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
56
|
+
d0.newrelic_dispatcher_start
|
57
|
+
assert_equal 1, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
58
|
+
d1.newrelic_dispatcher_start
|
59
|
+
assert_equal 2, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
60
|
+
sleep 1
|
61
|
+
d0.newrelic_dispatcher_finish
|
62
|
+
assert_equal 1, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
63
|
+
d1.newrelic_dispatcher_finish
|
64
|
+
assert_equal 0, NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.busy_count
|
65
|
+
assert_nil Thread.current[:newrelic_t0]
|
66
|
+
NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.harvest_busy
|
67
|
+
assert_equal 1, @instance_busy.call_count
|
68
|
+
assert @instance_busy.total_call_time.between?(1.8, 2.1), "Should be about 200%: #{@instance_busy.total_call_time}"
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
##require 'new_relic/agent/error_collector'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
|
6
|
+
class FakeRequest
|
7
|
+
attr_reader :path
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def referer
|
14
|
+
"test_referer"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def setup
|
21
|
+
@error_collector = NewRelic::Agent::ErrorCollector.new(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_simple
|
25
|
+
@error_collector.notice_error(Exception.new("message"), FakeRequest.new('/myurl/'), 'path', {:x => 'y'})
|
26
|
+
|
27
|
+
old_errors = []
|
28
|
+
errors = @error_collector.harvest_errors(old_errors)
|
29
|
+
|
30
|
+
assert_equal errors.length, 1
|
31
|
+
|
32
|
+
err = errors.first
|
33
|
+
assert_equal 'message', err.message
|
34
|
+
assert_equal 'y', err.params[:request_params][:x]
|
35
|
+
assert err.params[:request_uri] == '/myurl/'
|
36
|
+
assert err.params[:request_referer] == "test_referer"
|
37
|
+
assert err.path == 'path'
|
38
|
+
assert err.exception_class == 'Exception'
|
39
|
+
|
40
|
+
# the collector should now return an empty array since nothing
|
41
|
+
# has been added since its last harvest
|
42
|
+
errors = @error_collector.harvest_errors(nil)
|
43
|
+
assert errors.length == 0
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_long_message
|
47
|
+
#yes, times 500. it's a 5000 byte string. Assuming strings are
|
48
|
+
#still 1 byte / char.
|
49
|
+
@error_collector.notice_error(Exception.new("1234567890" * 500), FakeRequest.new('/myurl/'), 'path', {:x => 'y'})
|
50
|
+
|
51
|
+
old_errors = []
|
52
|
+
errors = @error_collector.harvest_errors(old_errors)
|
53
|
+
|
54
|
+
assert_equal errors.length, 1
|
55
|
+
|
56
|
+
err = errors.first
|
57
|
+
assert_equal ('1234567890' * 500)[0..4096], err.message
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_collect_failover
|
61
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'first', {:x => 'y'})
|
62
|
+
|
63
|
+
errors = @error_collector.harvest_errors([])
|
64
|
+
|
65
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'second', {:x => 'y'})
|
66
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => 'y'})
|
67
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => 'y'})
|
68
|
+
|
69
|
+
errors = @error_collector.harvest_errors(errors)
|
70
|
+
|
71
|
+
assert_equal 1, errors.length
|
72
|
+
assert_equal 'first', errors.first.path
|
73
|
+
|
74
|
+
# add two more
|
75
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => 'y'})
|
76
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'last', {:x => 'y'})
|
77
|
+
|
78
|
+
errors = @error_collector.harvest_errors(nil)
|
79
|
+
assert_equal 5, errors.length
|
80
|
+
assert_equal 'second', errors.first.path
|
81
|
+
assert_equal 'last', errors.last.path
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_queue_overflow
|
86
|
+
|
87
|
+
max_q_length = 20 # for some reason I can't read the constant in ErrorCollector
|
88
|
+
|
89
|
+
silence_stream(::STDERR) do
|
90
|
+
(max_q_length + 5).times do |n|
|
91
|
+
@error_collector.notice_error(Exception.new("exception #{n}"), nil, "path", {:x => n})
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
errors = @error_collector.harvest_errors([])
|
96
|
+
assert errors.length == max_q_length
|
97
|
+
errors.each_index do |i|
|
98
|
+
err = errors.shift
|
99
|
+
assert_equal i.to_s, err.params[:request_params][:x], err.params.inspect
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Why would anyone undef these methods?
|
104
|
+
class TestClass
|
105
|
+
undef to_s
|
106
|
+
undef inspect
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def test_supported_param_types
|
111
|
+
|
112
|
+
types = [[1, '1'],
|
113
|
+
[1.1, '1.1'],
|
114
|
+
['hi', 'hi'],
|
115
|
+
[:hi, :hi],
|
116
|
+
[Exception.new("test"), "#<Exception>"],
|
117
|
+
[TestClass.new, "#<NewRelic::Agent::ErrorCollectorTest::TestClass>"]
|
118
|
+
]
|
119
|
+
|
120
|
+
|
121
|
+
types.each do |test|
|
122
|
+
@error_collector.notice_error(Exception.new("message"), nil, 'path', {:x => test[0]})
|
123
|
+
|
124
|
+
assert_equal test[1], @error_collector.harvest_errors([])[0].params[:request_params][:x]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
def test_exclude
|
130
|
+
@error_collector.ignore(["ActionController::RoutingError"])
|
131
|
+
|
132
|
+
@error_collector.notice_error(ActionController::RoutingError.new("message"), nil, 'path', {:x => 'y'})
|
133
|
+
|
134
|
+
errors = @error_collector.harvest_errors([])
|
135
|
+
|
136
|
+
assert_equal 0, errors.length
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_exclude_block
|
140
|
+
@error_collector.ignore_error_filter do |e|
|
141
|
+
if e.is_a? ActionController::RoutingError
|
142
|
+
nil
|
143
|
+
else
|
144
|
+
e
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
@error_collector.notice_error(ActionController::RoutingError.new("message"), nil, 'path', {:x => 'y'})
|
149
|
+
|
150
|
+
errors = @error_collector.harvest_errors([])
|
151
|
+
|
152
|
+
assert_equal 0, errors.length
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
2
|
require 'new_relic/agent/mock_scope_listener'
|
3
3
|
|
4
|
-
::RPM_TRACERS_ENABLED = true unless defined? ::RPM_TRACERS_ENABLED
|
5
|
-
|
6
4
|
class Module
|
7
5
|
def method_traced?(method_name, metric_name)
|
8
6
|
traced_method_prefix = _traced_method_name(method_name, metric_name)
|
@@ -52,23 +50,20 @@ module NewRelic
|
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
|
-
class NewRelic::Agent::
|
53
|
+
class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
56
54
|
attr_reader :stats_engine
|
57
55
|
|
58
56
|
def setup
|
59
|
-
NewRelic::Agent
|
60
|
-
NewRelic::Agent
|
61
|
-
@stats_engine = NewRelic::Agent::Agent.instance.stats_engine
|
57
|
+
NewRelic::Agent.manual_start
|
58
|
+
@stats_engine = NewRelic::Agent.instance.stats_engine
|
62
59
|
@stats_engine.reset
|
63
60
|
@scope_listener = NewRelic::Agent::MockScopeListener.new
|
64
|
-
|
65
61
|
@stats_engine.add_scope_stack_listener(@scope_listener)
|
66
62
|
end
|
67
63
|
|
68
64
|
def teardown
|
69
65
|
self.class.remove_method_tracer :method_to_be_traced, @metric_name if @metric_name
|
70
66
|
@metric_name = nil
|
71
|
-
NewRelic::Agent::Agent.instance.shutdown
|
72
67
|
end
|
73
68
|
|
74
69
|
def test_basic
|
@@ -102,7 +97,6 @@ class NewRelic::Agent::MethodTracerTests < Test::Unit::TestCase
|
|
102
97
|
METRIC = "metric"
|
103
98
|
def test_add_method_tracer
|
104
99
|
@metric_name = METRIC
|
105
|
-
assert ::RPM_TRACERS_ENABLED
|
106
100
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
107
101
|
|
108
102
|
t1 = Time.now
|
@@ -141,7 +135,7 @@ class NewRelic::Agent::MethodTracerTests < Test::Unit::TestCase
|
|
141
135
|
def test_nested_scope_tracer
|
142
136
|
Insider.add_method_tracer :catcher, "catcher", :push_scope => true
|
143
137
|
Insider.add_method_tracer :thrower, "thrower", :push_scope => true
|
144
|
-
sampler = NewRelic::Agent
|
138
|
+
sampler = NewRelic::Agent.instance.transaction_sampler
|
145
139
|
mock = Insider.new(@stats_engine)
|
146
140
|
mock.catcher(0)
|
147
141
|
mock.catcher(5)
|
@@ -149,7 +143,7 @@ class NewRelic::Agent::MethodTracerTests < Test::Unit::TestCase
|
|
149
143
|
assert_equal 2, stats.call_count
|
150
144
|
stats = @stats_engine.get_stats("thrower")
|
151
145
|
assert_equal 6, stats.call_count
|
152
|
-
sample = sampler.
|
146
|
+
sample = sampler.harvest
|
153
147
|
assert_not_nil sample
|
154
148
|
end
|
155
149
|
|
@@ -263,7 +257,7 @@ class NewRelic::Agent::MethodTracerTests < Test::Unit::TestCase
|
|
263
257
|
end
|
264
258
|
|
265
259
|
def check_time (t1, t2)
|
266
|
-
assert((t2-t1).abs < 0.01)
|
260
|
+
assert((t2-t1).abs < 0.01, "Times not close: #{t1} ~ #{t2}")
|
267
261
|
end
|
268
262
|
|
269
263
|
# =======================================================
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
|
5
|
+
class NewRelic::Agent::MetricDataTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
|
8
|
+
# test to make sure the MetricData class can serialize to json
|
9
|
+
def test_json
|
10
|
+
spec = NewRelic::MetricSpec.new("controller", "metric#find")
|
11
|
+
|
12
|
+
import = ActiveSupport::JSON.decode(spec.to_json)
|
13
|
+
|
14
|
+
compare_spec(spec, import)
|
15
|
+
|
16
|
+
stats = NewRelic::MethodTraceStats.new
|
17
|
+
|
18
|
+
import = ActiveSupport::JSON.decode(stats.to_json)
|
19
|
+
|
20
|
+
compare_stat(stats, import)
|
21
|
+
|
22
|
+
metric_data = NewRelic::MetricData.new(spec, stats, 10)
|
23
|
+
|
24
|
+
import = ActiveSupport::JSON.decode(metric_data.to_json)
|
25
|
+
|
26
|
+
compare_metric_data(metric_data, import)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def compare_spec(spec, import)
|
33
|
+
assert_equal 2, import.length
|
34
|
+
assert_equal spec.name, import['name']
|
35
|
+
assert_equal spec.scope, import['scope']
|
36
|
+
end
|
37
|
+
|
38
|
+
def compare_stat(stats, import)
|
39
|
+
assert_equal 6, import.length
|
40
|
+
assert_equal stats.total_call_time, import['total_call_time']
|
41
|
+
assert_equal stats.max_call_time, import['max_call_time']
|
42
|
+
assert_equal stats.min_call_time, import['min_call_time']
|
43
|
+
assert_equal stats.sum_of_squares, import['sum_of_squares']
|
44
|
+
assert_equal stats.call_count, import['call_count']
|
45
|
+
assert_equal stats.total_exclusive_time, import['total_exclusive_time']
|
46
|
+
end
|
47
|
+
|
48
|
+
def compare_metric_data(metric_data, import)
|
49
|
+
assert_equal 3, import.length
|
50
|
+
compare_spec(metric_data.metric_spec, import['metric_spec'])
|
51
|
+
compare_stat(metric_data.stats, import['stats'])
|
52
|
+
assert_equal metric_data.metric_id, import['metric_id']
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|