newrelic_rpm 2.12.3 → 2.13.0.beta3
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 +24 -2
- data/README.rdoc +172 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +2 -1
- data/install.rb +8 -45
- data/lib/new_relic/agent.rb +43 -30
- data/lib/new_relic/agent/agent.rb +699 -631
- data/lib/new_relic/agent/busy_calculator.rb +81 -81
- data/lib/new_relic/agent/error_collector.rb +9 -6
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +10 -5
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +13 -45
- data/lib/new_relic/agent/instrumentation/memcache.rb +15 -4
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +37 -29
- data/lib/new_relic/agent/instrumentation/rack.rb +20 -34
- data/lib/new_relic/agent/method_tracer.rb +9 -9
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +31 -31
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +5 -5
- data/lib/new_relic/agent/stats_engine/samplers.rb +3 -0
- data/lib/new_relic/agent/transaction_sampler.rb +31 -15
- data/lib/new_relic/agent/worker_loop.rb +29 -28
- data/lib/new_relic/collection_helper.rb +4 -2
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +74 -114
- data/lib/new_relic/commands/install.rb +81 -0
- data/lib/new_relic/control.rb +54 -379
- data/lib/new_relic/control/configuration.rb +149 -0
- data/lib/new_relic/control/{external.rb → frameworks/external.rb} +2 -2
- data/lib/new_relic/control/{merb.rb → frameworks/merb.rb} +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +126 -0
- data/lib/new_relic/control/{rails3.rb → frameworks/rails3.rb} +11 -10
- data/lib/new_relic/control/{ruby.rb → frameworks/ruby.rb} +1 -1
- data/lib/new_relic/control/{sinatra.rb → frameworks/sinatra.rb} +2 -2
- data/lib/new_relic/control/instrumentation.rb +84 -0
- data/lib/new_relic/control/logging_methods.rb +74 -0
- data/lib/new_relic/control/profiling.rb +24 -0
- data/lib/new_relic/control/server_methods.rb +88 -0
- data/lib/new_relic/local_environment.rb +3 -3
- data/lib/new_relic/metric_parser.rb +13 -2
- data/lib/new_relic/metric_parser/active_record.rb +4 -1
- data/lib/new_relic/metric_parser/apdex.rb +53 -0
- data/lib/new_relic/metric_parser/controller.rb +13 -5
- data/lib/new_relic/metric_parser/mem_cache.rb +1 -1
- data/lib/new_relic/metric_parser/other_transaction.rb +21 -0
- data/lib/new_relic/metric_spec.rb +3 -3
- data/lib/new_relic/noticed_error.rb +1 -1
- data/lib/new_relic/rack/developer_mode.rb +257 -0
- data/lib/new_relic/rack/metric_app.rb +56 -50
- data/lib/new_relic/rack/mongrel_rpm.ru +7 -6
- data/lib/new_relic/rack/newrelic.yml +4 -3
- data/lib/new_relic/rack_app.rb +2 -1
- data/lib/new_relic/recipes.rb +7 -7
- data/lib/new_relic/stats.rb +6 -14
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +2 -7
- data/lib/new_relic/transaction_sample.rb +17 -85
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +3 -3
- data/lib/newrelic_rpm.rb +5 -9
- data/newrelic.yml +26 -9
- data/newrelic_rpm.gemspec +67 -32
- data/test/config/newrelic.yml +5 -0
- data/test/config/test_control.rb +6 -8
- data/test/new_relic/agent/active_record_instrumentation_test.rb +5 -6
- data/test/new_relic/agent/agent_controller_test.rb +18 -4
- data/test/new_relic/agent/agent_test_controller.rb +1 -6
- data/test/new_relic/agent/busy_calculator_test.rb +2 -0
- data/test/new_relic/agent/collection_helper_test.rb +6 -6
- data/test/new_relic/agent/error_collector_test.rb +13 -21
- data/test/new_relic/agent/metric_data_test.rb +3 -6
- data/test/new_relic/agent/rpm_agent_test.rb +121 -117
- data/test/new_relic/agent/task_instrumentation_test.rb +128 -133
- data/test/new_relic/agent/transaction_sample_test.rb +176 -170
- data/test/new_relic/agent/worker_loop_test.rb +24 -18
- data/test/new_relic/control_test.rb +13 -3
- data/test/new_relic/deployments_api_test.rb +7 -7
- data/test/new_relic/environment_test.rb +1 -1
- data/test/new_relic/metric_parser_test.rb +58 -4
- data/test/new_relic/rack/episodes_test.rb +317 -0
- data/test/new_relic/stats_test.rb +3 -2
- data/test/test_contexts.rb +28 -0
- data/test/test_helper.rb +24 -5
- data/ui/helpers/{newrelic_helper.rb → developer_mode_helper.rb} +63 -23
- data/ui/views/layouts/newrelic_default.rhtml +6 -6
- data/ui/views/newrelic/_explain_plans.rhtml +4 -4
- data/ui/views/newrelic/_sample.rhtml +18 -17
- data/ui/views/newrelic/_segment.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +8 -8
- data/ui/views/newrelic/_show_sample_detail.rhtml +1 -1
- data/ui/views/newrelic/_show_sample_sql.rhtml +2 -2
- data/ui/views/newrelic/_sql_row.rhtml +8 -3
- data/ui/views/newrelic/_stack_trace.rhtml +9 -24
- data/ui/views/newrelic/_table.rhtml +1 -1
- data/ui/views/newrelic/explain_sql.rhtml +3 -2
- data/ui/views/newrelic/{images → file/images}/arrow-close.png +0 -0
- data/ui/views/newrelic/{images → file/images}/arrow-open.png +0 -0
- data/ui/views/newrelic/{images → file/images}/blue_bar.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/file_icon.png +0 -0
- data/ui/views/newrelic/{images → file/images}/gray_bar.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/{images → file/images}/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/{stylesheets → file/stylesheets}/style.css +0 -0
- data/ui/views/newrelic/index.rhtml +7 -5
- data/ui/views/newrelic/sample_not_found.rhtml +1 -1
- data/ui/views/newrelic/show_sample.rhtml +5 -6
- metadata +92 -34
- data/README.md +0 -138
- data/lib/new_relic/commands/new_relic_commands.rb +0 -30
- data/lib/new_relic/control/rails.rb +0 -151
- data/test/new_relic/agent/mock_ar_connection.rb +0 -40
- data/test/ui/newrelic_controller_test.rb +0 -14
- data/test/ui/newrelic_helper_test.rb +0 -53
- data/ui/controllers/newrelic_controller.rb +0 -220
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +0 -7288
- data/ui/views/newrelic/javascript/transaction_sample.js +0 -107
@@ -10,12 +10,7 @@ class NewRelic::Agent::AgentTestController < NewRelic::Agent::SuperclassControll
|
|
10
10
|
filter_parameter_logging :social_security_number
|
11
11
|
|
12
12
|
@@headers_to_add = nil
|
13
|
-
|
14
|
-
# def rescue_action(e) raise e end
|
15
|
-
|
16
|
-
ActionController::Routing::Routes.draw do | map |
|
17
|
-
map.connect ':controller/:action.:format'
|
18
|
-
end
|
13
|
+
|
19
14
|
def index
|
20
15
|
sleep params['wait'].to_i if params['wait']
|
21
16
|
render :text => params.inspect
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
2
|
require 'ostruct'
|
3
|
-
require 'active_record_fixtures'
|
3
|
+
require 'active_record_fixtures' if defined?(::ActiveRecord)
|
4
4
|
class NewRelic::Agent::CollectionHelperTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
@@ -17,8 +17,8 @@ class NewRelic::Agent::CollectionHelperTest < Test::Unit::TestCase
|
|
17
17
|
assert_equal val[0...256] + "...", normalize_params(val)
|
18
18
|
end
|
19
19
|
def test_array
|
20
|
-
new_array = normalize_params [ 1000 ] *
|
21
|
-
assert_equal
|
20
|
+
new_array = normalize_params [ 1000 ] * 2000
|
21
|
+
assert_equal 1024, new_array.size
|
22
22
|
assert_equal '1000', new_array[0]
|
23
23
|
end
|
24
24
|
def test_boolean
|
@@ -115,11 +115,11 @@ class NewRelic::Agent::CollectionHelperTest < Test::Unit::TestCase
|
|
115
115
|
#puts e.backtrace.join("\n")
|
116
116
|
#puts "\n\n"
|
117
117
|
clean_trace = strip_nr_from_backtrace(e.backtrace)
|
118
|
-
assert_equal 0, clean_trace.grep(/newrelic_rpm/).size, clean_trace.
|
119
|
-
assert_equal 0, clean_trace.grep(/trace/).size, clean_trace.
|
118
|
+
assert_equal 0, clean_trace.grep(/newrelic_rpm/).size, clean_trace.inspect
|
119
|
+
assert_equal 0, clean_trace.grep(/trace/).size, clean_trace.inspect
|
120
120
|
assert_equal 3, clean_trace.grep(/find/).size, "should see three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
|
121
121
|
ensure
|
122
122
|
ActiveRecordFixtures.teardown
|
123
123
|
end
|
124
|
-
end
|
124
|
+
end if defined?(::ActiveRecord)
|
125
125
|
end
|
@@ -1,17 +1,6 @@
|
|
1
|
+
# Run faster standalone
|
2
|
+
ENV['SKIP_RAILS'] = 'true'
|
1
3
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class FakeRequest
|
5
|
-
attr_reader :path
|
6
|
-
|
7
|
-
def initialize(path)
|
8
|
-
@path = path
|
9
|
-
end
|
10
|
-
|
11
|
-
def referer
|
12
|
-
"test_referer"
|
13
|
-
end
|
14
|
-
end
|
15
4
|
|
16
5
|
class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
17
6
|
|
@@ -25,15 +14,18 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
25
14
|
@error_collector.notice_error(nil, :metric=> 'path', :request_params => {:x => 'y'})
|
26
15
|
errors = @error_collector.harvest_errors([])
|
27
16
|
|
28
|
-
assert_equal errors.length
|
17
|
+
assert_equal 0, errors.length
|
18
|
+
|
19
|
+
@error_collector.notice_error('Some error message', :metric=> 'path', :request_params => {:x => 'y'})
|
20
|
+
errors = @error_collector.harvest_errors([])
|
29
21
|
|
30
22
|
err = errors.first
|
31
|
-
assert_equal '
|
23
|
+
assert_equal 'Some error message', err.message
|
32
24
|
assert_equal 'y', err.params[:request_params][:x]
|
33
25
|
assert_equal '', err.params[:request_uri]
|
34
26
|
assert_equal '', err.params[:request_referer]
|
35
27
|
assert_equal 'path', err.path
|
36
|
-
assert_equal '
|
28
|
+
assert_equal 'Error', err.exception_class
|
37
29
|
|
38
30
|
end
|
39
31
|
def test_simple
|
@@ -102,7 +94,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
102
94
|
|
103
95
|
max_q_length = 20 # for some reason I can't read the constant in ErrorCollector
|
104
96
|
|
105
|
-
silence_stream(::
|
97
|
+
silence_stream(::STDOUT) do
|
106
98
|
(max_q_length + 5).times do |n|
|
107
99
|
@error_collector.notice_error(Exception.new("exception #{n}"), :metric => "path", :request_params => {:x => n})
|
108
100
|
end
|
@@ -143,9 +135,9 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
143
135
|
|
144
136
|
|
145
137
|
def test_exclude
|
146
|
-
@error_collector.ignore(["
|
138
|
+
@error_collector.ignore(["IOError"])
|
147
139
|
|
148
|
-
@error_collector.notice_error(
|
140
|
+
@error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
|
149
141
|
|
150
142
|
errors = @error_collector.harvest_errors([])
|
151
143
|
|
@@ -154,14 +146,14 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
|
|
154
146
|
|
155
147
|
def test_exclude_block
|
156
148
|
@error_collector.ignore_error_filter do |e|
|
157
|
-
if e.is_a?
|
149
|
+
if e.is_a? IOError
|
158
150
|
nil
|
159
151
|
else
|
160
152
|
e
|
161
153
|
end
|
162
154
|
end
|
163
155
|
|
164
|
-
@error_collector.notice_error(
|
156
|
+
@error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
|
165
157
|
|
166
158
|
errors = @error_collector.harvest_errors([])
|
167
159
|
|
@@ -1,27 +1,24 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
2
|
|
5
3
|
class NewRelic::Agent::MetricDataTest < Test::Unit::TestCase
|
6
4
|
|
7
|
-
|
8
5
|
# test to make sure the MetricData class can serialize to json
|
9
6
|
def test_json
|
10
7
|
spec = NewRelic::MetricSpec.new("controller", "metric#find")
|
11
8
|
|
12
|
-
import = ActiveSupport::JSON.decode(spec.to_json)
|
9
|
+
import = ::ActiveSupport::JSON.decode(spec.to_json)
|
13
10
|
|
14
11
|
compare_spec(spec, import)
|
15
12
|
|
16
13
|
stats = NewRelic::MethodTraceStats.new
|
17
14
|
|
18
|
-
import = ActiveSupport::JSON.decode(stats.to_json)
|
15
|
+
import = ::ActiveSupport::JSON.decode(stats.to_json)
|
19
16
|
|
20
17
|
compare_stat(stats, import)
|
21
18
|
|
22
19
|
metric_data = NewRelic::MetricData.new(spec, stats, 10)
|
23
20
|
|
24
|
-
import = ActiveSupport::JSON.decode(metric_data.to_json)
|
21
|
+
import = ::ActiveSupport::JSON.decode(metric_data.to_json)
|
25
22
|
|
26
23
|
compare_metric_data(metric_data, import)
|
27
24
|
end
|
@@ -1,138 +1,142 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
##require 'new_relic/local_environment'
|
1
|
+
ENV['SKIP_RAILS'] = 'true'
|
2
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
4
3
|
|
5
|
-
class RpmAgentTest < ActiveSupport::TestCase
|
4
|
+
class RpmAgentTest < Test::Unit::TestCase # ActiveSupport::TestCase
|
5
|
+
extend TestContexts
|
6
6
|
|
7
7
|
attr_reader :agent
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
NewRelic::Control.instance['app_name']=nil
|
18
|
-
NewRelic::Control.instance['dispatcher']=nil
|
19
|
-
NewRelic::Control.instance['dispatcher_instance_id']=nil
|
20
|
-
end
|
21
|
-
def test_agent_setup
|
22
|
-
assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
|
23
|
-
assert_raise RuntimeError do
|
24
|
-
NewRelic::Control.instance.init_plugin :agent_enabled => false
|
9
|
+
with_running_agent do
|
10
|
+
# Fake out the agent to think mongrel is running
|
11
|
+
|
12
|
+
should "agent_setup" do
|
13
|
+
assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
|
14
|
+
assert_raise RuntimeError do
|
15
|
+
NewRelic::Control.instance.init_plugin :agent_enabled => false
|
16
|
+
end
|
25
17
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
18
|
+
|
19
|
+
should "public_apis" do
|
20
|
+
assert_raise RuntimeError do
|
21
|
+
NewRelic::Agent.set_sql_obfuscator(:unknown) do |sql|
|
22
|
+
puts sql
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ignore_called = false
|
27
|
+
NewRelic::Agent.ignore_error_filter do |e|
|
28
|
+
ignore_called = true
|
29
|
+
nil
|
32
30
|
end
|
31
|
+
NewRelic::Agent.notice_error(StandardError.new("message"), :request_params => {:x => "y"})
|
32
|
+
assert ignore_called
|
33
|
+
NewRelic::Agent.instance.error_collector.instance_variable_set '@ignore_filter', nil
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
should "startup_shutdown" do
|
37
|
+
@agent = NewRelic::Agent::ShimAgent.instance
|
38
|
+
@agent.shutdown
|
39
|
+
assert (not @agent.started?)
|
40
|
+
@agent.start
|
41
|
+
assert !@agent.started?
|
42
|
+
# this installs the real agent:
|
43
|
+
NewRelic::Agent.manual_start
|
44
|
+
@agent = NewRelic::Agent.instance
|
45
|
+
assert @agent != NewRelic::Agent::ShimAgent.instance
|
46
|
+
assert @agent.started?
|
47
|
+
@agent.shutdown
|
48
|
+
assert !@agent.started?
|
49
|
+
@agent.start
|
50
|
+
assert @agent.started?
|
39
51
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
76
|
-
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
77
|
-
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
78
|
-
end
|
79
|
-
def test_restart
|
80
|
-
NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
|
81
|
-
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
82
|
-
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
83
|
-
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_send_timeslice_data
|
87
|
-
@agent.expects(:invoke_remote).returns({NewRelic::MetricSpec.new("/A/b/c") => 1, NewRelic::MetricSpec.new("/A/b/c", "/X") => 2, NewRelic::MetricSpec.new("/A/b/d") => 3 }.to_a)
|
88
|
-
@agent.send :harvest_and_send_timeslice_data
|
89
|
-
assert_equal 3, @agent.metric_ids.size
|
90
|
-
assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
|
91
|
-
end
|
92
|
-
def test_set_record_sql
|
93
|
-
@agent.set_record_sql(false)
|
94
|
-
assert !Thread::current[:record_sql]
|
95
|
-
NewRelic::Agent.disable_sql_recording do
|
96
|
-
assert_equal false, Thread::current[:record_sql]
|
52
|
+
|
53
|
+
should "manual_start" do
|
54
|
+
NewRelic::Agent.instance.expects(:connect).once
|
55
|
+
NewRelic::Agent.instance.expects(:start_worker_thread).once
|
56
|
+
NewRelic::Agent.instance.instance_variable_set '@started', nil
|
57
|
+
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "post_fork_handler" do
|
61
|
+
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
62
|
+
NewRelic::Agent.after_fork
|
63
|
+
NewRelic::Agent.after_fork
|
64
|
+
end
|
65
|
+
should "manual_overrides" do
|
66
|
+
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
67
|
+
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
68
|
+
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
69
|
+
end
|
70
|
+
|
71
|
+
should "restart" do
|
72
|
+
NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
|
73
|
+
NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
|
74
|
+
assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
|
75
|
+
assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
|
76
|
+
end
|
77
|
+
|
78
|
+
should "send_timeslice_data" do
|
79
|
+
@agent.expects(:invoke_remote).returns({NewRelic::MetricSpec.new("/A/b/c") => 1, NewRelic::MetricSpec.new("/A/b/c", "/X") => 2, NewRelic::MetricSpec.new("/A/b/d") => 3 }.to_a)
|
80
|
+
@agent.send :harvest_and_send_timeslice_data
|
81
|
+
assert_equal 3, @agent.metric_ids.size
|
82
|
+
assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
|
83
|
+
end
|
84
|
+
should "set_record_sql" do
|
85
|
+
@agent.set_record_sql(false)
|
86
|
+
assert !Thread::current[:record_sql]
|
97
87
|
NewRelic::Agent.disable_sql_recording do
|
98
88
|
assert_equal false, Thread::current[:record_sql]
|
89
|
+
NewRelic::Agent.disable_sql_recording do
|
90
|
+
assert_equal false, Thread::current[:record_sql]
|
91
|
+
end
|
92
|
+
assert_equal false, Thread::current[:record_sql]
|
99
93
|
end
|
100
|
-
|
94
|
+
assert !Thread::current[:record_sql], Thread::current[:record_sql]
|
95
|
+
@agent.set_record_sql(nil)
|
101
96
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_version
|
108
|
-
assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_invoke_remote__ignore_non_200_results
|
112
|
-
NewRelic::Agent::Agent.class_eval do
|
113
|
-
public :invoke_remote
|
97
|
+
|
98
|
+
should "version" do
|
99
|
+
assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
|
114
100
|
end
|
115
|
-
response_mock = mock()
|
116
|
-
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
117
|
-
response_mock.stubs(:message).returns("bogus error")
|
118
101
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
102
|
+
should "invoke_remote__ignore_non_200_results" do
|
103
|
+
NewRelic::Agent::Agent.class_eval do
|
104
|
+
public :invoke_remote
|
105
|
+
end
|
106
|
+
response_mock = mock()
|
107
|
+
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
108
|
+
response_mock.stubs(:message).returns("bogus error")
|
109
|
+
|
110
|
+
for code in %w[500 504 400 302 503] do
|
111
|
+
assert_raise NewRelic::Agent::ServerConnectionException, "Ignore #{code}" do
|
112
|
+
response_mock.stubs(:code).returns(code)
|
113
|
+
NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0
|
114
|
+
end
|
123
115
|
end
|
124
116
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
117
|
+
should "invoke_remote__throw_other_errors" do
|
118
|
+
NewRelic::Agent::Agent.class_eval do
|
119
|
+
public :invoke_remote
|
120
|
+
end
|
121
|
+
response_mock = Net::HTTPSuccess.new nil, nil, nil
|
122
|
+
response_mock.stubs(:body).returns("")
|
123
|
+
Marshal.stubs(:load).raises(RuntimeError, "marshal issue")
|
124
|
+
Net::HTTP.any_instance.stubs(:request).returns(response_mock)
|
125
|
+
assert_raise RuntimeError do
|
126
|
+
NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0xFEFE
|
127
|
+
end
|
129
128
|
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
129
|
+
|
130
|
+
context "with transaction api" do
|
131
|
+
should "reject empty arguments" do
|
132
|
+
assert_raises RuntimeError do
|
133
|
+
NewRelic::Agent.record_transaction 0.5
|
134
|
+
end
|
135
|
+
end
|
136
|
+
should "record a transaction" do
|
137
|
+
NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
|
138
|
+
end
|
139
|
+
|
136
140
|
end
|
137
141
|
end
|
138
142
|
end
|
@@ -1,165 +1,160 @@
|
|
1
|
-
|
1
|
+
# Run faster standalone
|
2
|
+
ENV['SKIP_RAILS'] = 'true'
|
3
|
+
|
4
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
5
|
|
3
6
|
class TaskInstrumentationTest < Test::Unit::TestCase
|
4
7
|
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
8
|
+
extend TestContexts
|
5
9
|
attr_accessor :agent
|
6
|
-
def setup
|
7
|
-
super
|
8
|
-
NewRelic::Agent.manual_start
|
9
|
-
@agent = NewRelic::Agent.instance
|
10
|
-
@agent.transaction_sampler.send :clear_builder
|
11
|
-
@agent.transaction_sampler.reset!
|
12
|
-
@agent.stats_engine.clear_stats
|
13
|
-
end
|
14
|
-
def teardown
|
15
|
-
NewRelic::Agent.shutdown
|
16
|
-
super
|
17
|
-
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
with_running_agent do
|
12
|
+
|
13
|
+
should "run" do
|
14
|
+
run_task_inner 0
|
15
|
+
stat_names = %w[Controller/TaskInstrumentationTest/inner_task_0
|
22
16
|
HttpDispatcher
|
23
17
|
Apdex Apdex/TaskInstrumentationTest/inner_task_0].sort
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
expected_but_missing = stat_names - @agent.stats_engine.metrics
|
19
|
+
assert_equal 0, expected_but_missing.size, @agent.stats_engine.metrics.map { |n|
|
20
|
+
stat = @agent.stats_engine.get_stats_no_scope(n)
|
27
21
|
"#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
}.join("\n ") + "\nmissing: #{expected_but_missing.inspect}"
|
23
|
+
assert_equal 0, @agent.stats_engine.get_stats_no_scope('Controller').call_count
|
24
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
|
25
|
+
end
|
26
|
+
|
27
|
+
should "run_recursive" do
|
28
|
+
run_task_inner(3)
|
29
|
+
assert_equal 1, @agent.stats_engine.lookup_stats(
|
36
30
|
'Controller/TaskInstrumentationTest/inner_task_0',
|
37
31
|
'Controller/TaskInstrumentationTest/inner_task_1').call_count
|
38
|
-
|
32
|
+
assert_equal 1, @agent.stats_engine.lookup_stats(
|
39
33
|
'Controller/TaskInstrumentationTest/inner_task_1',
|
40
34
|
'Controller/TaskInstrumentationTest/inner_task_2').call_count
|
41
|
-
|
35
|
+
assert_equal 1, @agent.stats_engine.lookup_stats(
|
42
36
|
'Controller/TaskInstrumentationTest/inner_task_2',
|
43
37
|
'Controller/TaskInstrumentationTest/inner_task_3').call_count
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_run_nested
|
52
|
-
run_task_outer(3)
|
53
|
-
@agent.stats_engine.metrics.sort.each do |n|
|
54
|
-
stat = @agent.stats_engine.get_stats_no_scope(n)
|
55
|
-
# puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
38
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
|
39
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_1').call_count
|
40
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_2').call_count
|
41
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_3').call_count
|
42
|
+
assert_equal 0, @agent.stats_engine.get_stats_no_scope('Controller').call_count
|
56
43
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
44
|
+
|
45
|
+
should "run_nested" do
|
46
|
+
run_task_outer(3)
|
47
|
+
@agent.stats_engine.metrics.sort.each do |n|
|
48
|
+
stat = @agent.stats_engine.get_stats_no_scope(n)
|
49
|
+
# puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
50
|
+
end
|
51
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/outer_task').call_count
|
52
|
+
assert_equal 2, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
|
53
|
+
end
|
54
|
+
|
55
|
+
should "reentrancy" do
|
56
|
+
assert_equal 0, NewRelic::Agent::BusyCalculator.busy_count
|
57
|
+
run_task_inner(1)
|
58
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
|
59
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_1').call_count
|
60
|
+
compare_metrics %w[
|
67
61
|
Controller/TaskInstrumentationTest/inner_task_0:Controller/TaskInstrumentationTest/inner_task_1
|
68
62
|
Controller/TaskInstrumentationTest/inner_task_0
|
69
63
|
Controller/TaskInstrumentationTest/inner_task_1
|
70
64
|
], @agent.stats_engine.metrics.grep(/^Controller/)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_transaction
|
74
|
-
assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
|
75
|
-
assert_nil @agent.transaction_sampler.last_sample
|
76
|
-
assert_equal @agent.transaction_sampler, @agent.stats_engine.instance_variable_get("@transaction_sampler")
|
77
|
-
run_task_outer(10)
|
78
|
-
assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
|
79
|
-
@agent.stats_engine.metrics.sort.each do |n|
|
80
|
-
stat = @agent.stats_engine.get_stats_no_scope(n)
|
81
|
-
# puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
82
65
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
66
|
+
|
67
|
+
should "transaction" do
|
68
|
+
assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
|
69
|
+
assert_nil @agent.transaction_sampler.last_sample
|
70
|
+
assert_equal @agent.transaction_sampler, @agent.stats_engine.instance_variable_get("@transaction_sampler")
|
71
|
+
run_task_outer(10)
|
72
|
+
assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
|
73
|
+
@agent.stats_engine.metrics.sort.each do |n|
|
74
|
+
stat = @agent.stats_engine.get_stats_no_scope(n)
|
75
|
+
# puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
76
|
+
end
|
77
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/outer_task').call_count
|
78
|
+
assert_equal 0, @agent.stats_engine.get_stats_no_scope('Controller').call_count
|
79
|
+
assert_equal 2, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/inner_task_0').call_count
|
80
|
+
assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
|
81
|
+
sample = @agent.transaction_sampler.last_sample
|
82
|
+
assert_not_nil sample
|
83
|
+
assert_not_nil sample.params[:cpu_time], "cpu time nil: \n#{sample}"
|
84
|
+
assert sample.params[:cpu_time] >= 0, "cpu time: #{sample.params[:cpu_time]},\n#{sample}"
|
85
|
+
assert_equal '10', sample.params[:request_params][:level]
|
99
86
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
87
|
+
|
88
|
+
should "abort" do
|
89
|
+
@acct = 'Redrocks'
|
90
|
+
perform_action_with_newrelic_trace(:name => 'hello', :force => true, :params => { :account => @acct}) do
|
91
|
+
self.class.inspect
|
92
|
+
NewRelic::Agent.abort_transaction!
|
93
|
+
end
|
94
|
+
# We record the controller metric still, but abort any transaction recording.
|
95
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/hello').call_count
|
96
|
+
assert_nil @agent.transaction_sampler.last_sample
|
110
97
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
98
|
+
should "block" do
|
99
|
+
assert_equal @agent, NewRelic::Agent.instance
|
100
|
+
@acct = 'Redrocks'
|
101
|
+
perform_action_with_newrelic_trace(:name => 'hello', :force => true, :params => { :account => @acct}) do
|
102
|
+
self.class.inspect
|
103
|
+
end
|
104
|
+
@agent.stats_engine.metrics.sort.each do |n|
|
105
|
+
stat = @agent.stats_engine.get_stats_no_scope(n)
|
106
|
+
#puts "#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
107
|
+
end
|
108
|
+
assert_equal @agent, NewRelic::Agent.instance
|
109
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/hello').call_count
|
110
|
+
sample = @agent.transaction_sampler.last_sample
|
111
|
+
assert_not_nil sample
|
112
|
+
assert_equal 'Redrocks', sample.params[:request_params][:account]
|
113
|
+
|
114
114
|
end
|
115
|
-
assert_equal @agent, NewRelic::Agent.instance
|
116
|
-
assert_equal 1, @agent.stats_engine.get_stats_no_scope('Controller/TaskInstrumentationTest/hello').call_count
|
117
|
-
sample = @agent.transaction_sampler.last_sample
|
118
|
-
assert_not_nil sample
|
119
|
-
assert_equal 'Redrocks', sample.params[:request_params][:account]
|
120
115
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
run_task_exception
|
116
|
+
should "error_handling" do
|
117
|
+
@agent.error_collector.ignore_error_filter
|
118
|
+
@agent.error_collector.harvest_errors([])
|
119
|
+
@agent.error_collector.expects(:notice_error).once
|
120
|
+
assert_equal @agent.error_collector, NewRelic::Agent.instance.error_collector
|
121
|
+
assert_raise RuntimeError do
|
122
|
+
run_task_exception
|
123
|
+
end
|
130
124
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
125
|
+
|
126
|
+
should "custom_params" do
|
127
|
+
@agent.error_collector.stubs(:enabled).returns(true)
|
128
|
+
@agent.error_collector.ignore_error_filter
|
129
|
+
@agent.error_collector.harvest_errors([])
|
130
|
+
assert_equal @agent.error_collector, NewRelic::Agent.instance.error_collector
|
131
|
+
assert_raise RuntimeError do
|
132
|
+
run_task_exception
|
133
|
+
end
|
134
|
+
errors = @agent.error_collector.harvest_errors([])
|
135
|
+
assert_equal 1, errors.size
|
136
|
+
error = errors.first
|
137
|
+
assert_equal "Controller/TaskInstrumentationTest/run_task_exception", error.path
|
138
|
+
assert_not_nil error.params[:stack_trace]
|
139
|
+
assert_not_nil error.params[:custom_params]
|
140
140
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
assert_not_nil error.params[:stack_trace]
|
146
|
-
assert_not_nil error.params[:custom_params]
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_instrument_bg
|
150
|
-
run_background_job
|
151
|
-
stat_names = %w[OtherTransaction/Background/TaskInstrumentationTest/run_background_job
|
141
|
+
|
142
|
+
should "instrument_bg" do
|
143
|
+
run_background_job
|
144
|
+
stat_names = %w[OtherTransaction/Background/TaskInstrumentationTest/run_background_job
|
152
145
|
OtherTransaction/Background/all
|
153
146
|
OtherTransaction/all].sort
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
147
|
+
|
148
|
+
expected_but_missing = stat_names - @agent.stats_engine.metrics
|
149
|
+
assert_equal 0, expected_but_missing.size, @agent.stats_engine.metrics.map { |n|
|
150
|
+
stat = @agent.stats_engine.get_stats_no_scope(n)
|
158
151
|
"#{'%-26s' % n}: #{stat.call_count} calls @ #{stat.average_call_time} sec/call"
|
159
|
-
|
160
|
-
|
161
|
-
|
152
|
+
}.join("\n ") + "\nmissing: #{expected_but_missing.inspect}"
|
153
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('OtherTransaction/all').call_count
|
154
|
+
assert_equal 1, @agent.stats_engine.get_stats_no_scope('OtherTransaction/Background/all').call_count
|
155
|
+
end
|
162
156
|
end
|
157
|
+
|
163
158
|
private
|
164
159
|
|
165
160
|
def run_task_inner(n)
|
@@ -190,4 +185,4 @@ class TaskInstrumentationTest < Test::Unit::TestCase
|
|
190
185
|
add_transaction_tracer :run_task_outer, :name => 'outer_task', :params => '{ :level => args[0] }'
|
191
186
|
# Eventually we need th change this to :category => :task
|
192
187
|
add_transaction_tracer :run_background_job, :category => 'OtherTransaction/Background'
|
193
|
-
end
|
188
|
+
end
|