factorylabs-newrelic_rpm 2.10.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +354 -0
- data/LICENSE +37 -0
- data/README-2.10.2.2 +10 -0
- data/README.md +138 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic_cmd +4 -0
- data/cert/cacert.pem +34 -0
- data/install.rb +45 -0
- data/lib/new_relic/agent.rb +315 -0
- data/lib/new_relic/agent/agent.rb +647 -0
- data/lib/new_relic/agent/busy_calculator.rb +86 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/collection_helper.rb +66 -0
- data/lib/new_relic/agent/error_collector.rb +117 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +91 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +389 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +12 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +24 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +8 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +199 -0
- data/lib/new_relic/agent/instrumentation/net.rb +21 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +20 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +109 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +24 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +39 -0
- data/lib/new_relic/agent/method_tracer.rb +348 -0
- data/lib/new_relic/agent/patch_const_missing.rb +125 -0
- data/lib/new_relic/agent/sampler.rb +46 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +141 -0
- data/lib/new_relic/agent/samplers/mongrel_sampler.rb +23 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +24 -0
- data/lib/new_relic/agent/shim_agent.rb +21 -0
- data/lib/new_relic/agent/stats_engine.rb +22 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +116 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +74 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +154 -0
- data/lib/new_relic/agent/transaction_sampler.rb +315 -0
- data/lib/new_relic/agent/worker_loop.rb +118 -0
- data/lib/new_relic/commands/deployments.rb +145 -0
- data/lib/new_relic/commands/new_relic_commands.rb +30 -0
- data/lib/new_relic/control.rb +484 -0
- data/lib/new_relic/control/external.rb +13 -0
- data/lib/new_relic/control/merb.rb +24 -0
- data/lib/new_relic/control/rails.rb +151 -0
- data/lib/new_relic/control/ruby.rb +36 -0
- data/lib/new_relic/control/sinatra.rb +14 -0
- data/lib/new_relic/histogram.rb +89 -0
- data/lib/new_relic/local_environment.rb +299 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +42 -0
- data/lib/new_relic/metric_parser.rb +124 -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 +25 -0
- data/lib/new_relic/metric_parser/controller.rb +54 -0
- data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
- data/lib/new_relic/metric_parser/errors.rb +6 -0
- data/lib/new_relic/metric_parser/external.rb +50 -0
- data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
- data/lib/new_relic/metric_parser/other_transaction.rb +15 -0
- data/lib/new_relic/metric_parser/view.rb +61 -0
- data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
- data/lib/new_relic/metric_parser/web_service.rb +9 -0
- data/lib/new_relic/metric_spec.rb +67 -0
- data/lib/new_relic/metrics.rb +7 -0
- data/lib/new_relic/noticed_error.rb +23 -0
- data/lib/new_relic/rack/metric_app.rb +56 -0
- data/lib/new_relic/rack/mongrel_rpm.ru +25 -0
- data/lib/new_relic/rack/newrelic.yml +26 -0
- data/lib/new_relic/rack_app.rb +5 -0
- data/lib/new_relic/recipes.rb +82 -0
- data/lib/new_relic/stats.rb +362 -0
- data/lib/new_relic/transaction_analysis.rb +121 -0
- data/lib/new_relic/transaction_sample.rb +671 -0
- data/lib/new_relic/version.rb +54 -0
- data/lib/new_relic_api.rb +276 -0
- data/lib/newrelic_rpm.rb +45 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +15 -0
- data/newrelic.yml +227 -0
- data/newrelic_rpm.gemspec +214 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +46 -0
- data/test/config/test_control.rb +38 -0
- data/test/new_relic/agent/active_record_instrumentation_test.rb +268 -0
- data/test/new_relic/agent/agent_controller_test.rb +254 -0
- data/test/new_relic/agent/agent_test_controller.rb +78 -0
- data/test/new_relic/agent/busy_calculator_test.rb +79 -0
- data/test/new_relic/agent/classloader_patch_test.rb +56 -0
- data/test/new_relic/agent/collection_helper_test.rb +125 -0
- data/test/new_relic/agent/error_collector_test.rb +173 -0
- data/test/new_relic/agent/method_tracer_test.rb +340 -0
- data/test/new_relic/agent/metric_data_test.rb +56 -0
- data/test/new_relic/agent/mock_ar_connection.rb +40 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/net_instrumentation_test.rb +63 -0
- data/test/new_relic/agent/rpm_agent_test.rb +125 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +88 -0
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/task_instrumentation_test.rb +177 -0
- data/test/new_relic/agent/testable_agent.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
- data/test/new_relic/agent/transaction_sample_test.rb +186 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +404 -0
- data/test/new_relic/agent/worker_loop_test.rb +103 -0
- data/test/new_relic/control_test.rb +110 -0
- data/test/new_relic/delayed_job_test.rb +108 -0
- data/test/new_relic/deployments_api_test.rb +68 -0
- data/test/new_relic/environment_test.rb +75 -0
- data/test/new_relic/metric_parser_test.rb +172 -0
- data/test/new_relic/metric_spec_test.rb +177 -0
- data/test/new_relic/shim_agent_test.rb +9 -0
- data/test/new_relic/stats_test.rb +291 -0
- data/test/new_relic/version_number_test.rb +76 -0
- data/test/test_helper.rb +53 -0
- data/test/ui/newrelic_controller_test.rb +14 -0
- data/test/ui/newrelic_helper_test.rb +53 -0
- data/ui/controllers/newrelic_controller.rb +220 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/helpers/newrelic_helper.rb +320 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +19 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +14 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +11 -0
- data/ui/views/newrelic/_stack_trace.rhtml +30 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +42 -0
- data/ui/views/newrelic/images/arrow-close.png +0 -0
- data/ui/views/newrelic/images/arrow-open.png +0 -0
- data/ui/views/newrelic/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/images/file_icon.png +0 -0
- data/ui/views/newrelic/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/images/textmate.png +0 -0
- data/ui/views/newrelic/index.rhtml +57 -0
- data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
- data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/stylesheets/style.css +484 -0
- data/ui/views/newrelic/threads.rhtml +52 -0
- metadata +238 -0
@@ -0,0 +1,254 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'action_controller/base'
|
3
|
+
require 'new_relic/agent/agent_test_controller'
|
4
|
+
|
5
|
+
class AgentControllerTest < ActionController::TestCase
|
6
|
+
|
7
|
+
self.controller_class = NewRelic::Agent::AgentTestController
|
8
|
+
|
9
|
+
attr_accessor :agent, :engine
|
10
|
+
|
11
|
+
# Normally you can do this with #setup but for some reason in rails 2.0.2
|
12
|
+
# setup is not called.
|
13
|
+
def initialize name
|
14
|
+
super name
|
15
|
+
Thread.current[:newrelic_ignore_controller] = nil
|
16
|
+
NewRelic::Agent.manual_start
|
17
|
+
@agent = NewRelic::Agent.instance
|
18
|
+
# @agent.instrument_app
|
19
|
+
agent.transaction_sampler.harvest
|
20
|
+
NewRelic::Agent::AgentTestController.class_eval do
|
21
|
+
newrelic_ignore :only => [:action_to_ignore, :entry_action, :base_action]
|
22
|
+
newrelic_ignore_apdex :only => :action_to_ignore_apdex
|
23
|
+
end
|
24
|
+
@engine = @agent.stats_engine
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
Thread.current[:newrelic_ignore_controller] = nil
|
29
|
+
super
|
30
|
+
NewRelic::Agent.shutdown
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_metric__ignore
|
34
|
+
engine.clear_stats
|
35
|
+
compare_metrics [], engine.metrics
|
36
|
+
get :action_to_ignore
|
37
|
+
compare_metrics [], engine.metrics
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_controller_rescued_error
|
41
|
+
engine.clear_stats
|
42
|
+
assert_raise RuntimeError do
|
43
|
+
get :action_with_error
|
44
|
+
end
|
45
|
+
metrics = ['Apdex',
|
46
|
+
'Apdex/new_relic/agent/agent_test/action_with_error',
|
47
|
+
'HttpDispatcher',
|
48
|
+
'Controller',
|
49
|
+
'Controller/new_relic/agent/agent_test/action_with_error',
|
50
|
+
'Errors/all']
|
51
|
+
|
52
|
+
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
53
|
+
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
|
54
|
+
assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
|
55
|
+
apdex = engine.get_stats_no_scope("Apdex")
|
56
|
+
score = apdex.get_apdex
|
57
|
+
assert_equal 1, score[2], 'failing'
|
58
|
+
assert_equal 0, score[1], 'tol'
|
59
|
+
assert_equal 0, score[0], 'satisfied'
|
60
|
+
|
61
|
+
end
|
62
|
+
def test_controller_error
|
63
|
+
engine.clear_stats
|
64
|
+
assert_raise RuntimeError do
|
65
|
+
get :action_with_error
|
66
|
+
end
|
67
|
+
metrics = ['Apdex',
|
68
|
+
'Apdex/new_relic/agent/agent_test/action_with_error',
|
69
|
+
'HttpDispatcher',
|
70
|
+
'Controller',
|
71
|
+
'Controller/new_relic/agent/agent_test/action_with_error',
|
72
|
+
'Errors/all']
|
73
|
+
|
74
|
+
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
75
|
+
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
|
76
|
+
assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
|
77
|
+
apdex = engine.get_stats_no_scope("Apdex")
|
78
|
+
score = apdex.get_apdex
|
79
|
+
assert_equal 1, score[2], 'failing'
|
80
|
+
assert_equal 0, score[1], 'tol'
|
81
|
+
assert_equal 0, score[0], 'satisfied'
|
82
|
+
|
83
|
+
end
|
84
|
+
def test_filter_error
|
85
|
+
engine.clear_stats
|
86
|
+
assert_raise RuntimeError do
|
87
|
+
get :action_with_before_filter_error
|
88
|
+
end
|
89
|
+
metrics = ['Apdex',
|
90
|
+
'Apdex/new_relic/agent/agent_test/action_with_before_filter_error',
|
91
|
+
'HttpDispatcher',
|
92
|
+
'Controller',
|
93
|
+
'Controller/new_relic/agent/agent_test/action_with_before_filter_error',
|
94
|
+
'Errors/all']
|
95
|
+
|
96
|
+
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
97
|
+
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_before_filter_error").call_count
|
98
|
+
assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
|
99
|
+
apdex = engine.get_stats_no_scope("Apdex")
|
100
|
+
score = apdex.get_apdex
|
101
|
+
assert_equal 1, score[2], 'failing'
|
102
|
+
assert_equal 0, score[1], 'tol'
|
103
|
+
assert_equal 0, score[0], 'satisfied'
|
104
|
+
end
|
105
|
+
def test_metric__ignore_base
|
106
|
+
engine.clear_stats
|
107
|
+
get :base_action
|
108
|
+
compare_metrics [], engine.metrics
|
109
|
+
end
|
110
|
+
def test_metric__no_ignore
|
111
|
+
path = 'new_relic/agent/agent_test/index'
|
112
|
+
index_stats = stats("Controller/#{path}")
|
113
|
+
index_apdex_stats = engine.get_custom_stats("Apdex/#{path}", NewRelic::ApdexStats)
|
114
|
+
assert_difference 'index_stats.call_count' do
|
115
|
+
assert_difference 'index_apdex_stats.call_count' do
|
116
|
+
get :index
|
117
|
+
end
|
118
|
+
end
|
119
|
+
assert_nil Thread.current[:newrelic_ignore_controller]
|
120
|
+
end
|
121
|
+
def test_metric__ignore_apdex
|
122
|
+
engine = @agent.stats_engine
|
123
|
+
path = 'new_relic/agent/agent_test/action_to_ignore_apdex'
|
124
|
+
cpu_stats = stats("ControllerCPU/#{path}")
|
125
|
+
index_stats = stats("Controller/#{path}")
|
126
|
+
index_apdex_stats = engine.get_custom_stats("Apdex/#{path}", NewRelic::ApdexStats)
|
127
|
+
assert_difference 'index_stats.call_count' do
|
128
|
+
assert_no_difference 'index_apdex_stats.call_count' do
|
129
|
+
get :action_to_ignore_apdex
|
130
|
+
end
|
131
|
+
end
|
132
|
+
assert_nil Thread.current[:newrelic_ignore_controller]
|
133
|
+
|
134
|
+
end
|
135
|
+
def test_metric__dispatched
|
136
|
+
engine = @agent.stats_engine
|
137
|
+
get :entry_action
|
138
|
+
assert_nil Thread.current[:newrelic_ignore_controller]
|
139
|
+
assert_nil engine.lookup_stat('Controller/agent_test/entry_action')
|
140
|
+
assert_nil engine.lookup_stat('Controller/agent_test_controller/entry_action')
|
141
|
+
assert_nil engine.lookup_stat('Controller/AgentTestController/entry_action')
|
142
|
+
assert_nil engine.lookup_stat('Controller/NewRelic::Agent::AgentTestController/internal_action')
|
143
|
+
assert_nil engine.lookup_stat('Controller/NewRelic::Agent::AgentTestController_controller/internal_action')
|
144
|
+
assert_not_nil engine.lookup_stat('Controller/NewRelic::Agent::AgentTestController/internal_traced_action')
|
145
|
+
end
|
146
|
+
def test_action_instrumentation
|
147
|
+
begin
|
148
|
+
get :index, :foo => 'bar'
|
149
|
+
assert_match /bar/, @response.body
|
150
|
+
#rescue ActionController::RoutingError
|
151
|
+
# you might get here if you don't have the default route installed.
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_controller_params
|
156
|
+
assert agent.transaction_sampler
|
157
|
+
num_samples = NewRelic::Agent.instance.transaction_sampler.samples.length
|
158
|
+
assert_equal "[FILTERED]", @controller._filter_parameters({'social_security_number' => 'test'})['social_security_number']
|
159
|
+
get :index, 'social_security_number' => "001-555-1212"
|
160
|
+
samples = agent.transaction_sampler.samples
|
161
|
+
assert_equal num_samples + 1, samples.length
|
162
|
+
assert_equal "[FILTERED]", samples.last.params[:request_params]["social_security_number"]
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_controller_params
|
166
|
+
agent.transaction_sampler.reset!
|
167
|
+
get :index, 'number' => "001-555-1212"
|
168
|
+
s = agent.transaction_sampler.harvest(nil, 0.0)
|
169
|
+
assert_equal 1, s.size
|
170
|
+
assert_equal 5, s.first.params.size
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
def test_busycalculation
|
175
|
+
engine.clear_stats
|
176
|
+
|
177
|
+
assert_equal 0, NewRelic::Agent::BusyCalculator.busy_count
|
178
|
+
get :index, 'social_security_number' => "001-555-1212", 'wait' => '1.0'
|
179
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
180
|
+
|
181
|
+
assert_equal 1, stats('Instance/Busy').call_count
|
182
|
+
assert_equal 1, stats('HttpDispatcher').call_count
|
183
|
+
# We are probably busy about 99% of the time, but lets make sure it's at least 50
|
184
|
+
assert stats('Instance/Busy').total_call_time > 0.5, stats('Instance/Busy')
|
185
|
+
assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_histogram
|
189
|
+
engine.clear_stats
|
190
|
+
get :index, 'social_security_number' => "001-555-1212"
|
191
|
+
bucket = NewRelic::Agent.instance.stats_engine.metrics.find { | m | m =~ /^Response Times/ }
|
192
|
+
assert_not_nil bucket
|
193
|
+
bucket_stats = stats(bucket)
|
194
|
+
assert_equal 1, bucket_stats.call_count
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_queue_headers
|
198
|
+
engine.clear_stats
|
199
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
200
|
+
queue_time_stat = stats('WebFrontend/Mongrel/Average Queue Time')
|
201
|
+
|
202
|
+
# no request start header
|
203
|
+
get :index
|
204
|
+
assert_equal 0, queue_length_stat.call_count
|
205
|
+
|
206
|
+
# apache version of header
|
207
|
+
request_start = ((Time.now.to_f - 0.2) * 1e6).to_i.to_s
|
208
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_REQUEST_START' => "t=#{request_start}"})
|
209
|
+
get :index
|
210
|
+
assert_equal(0, queue_length_stat.call_count, 'We should not be seeing a queue length yet')
|
211
|
+
assert_equal(1, queue_time_stat.call_count, 'We should have seen the queue header once')
|
212
|
+
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
213
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
214
|
+
|
215
|
+
engine.clear_stats
|
216
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
217
|
+
|
218
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
219
|
+
queue_time_stat = stats('WebFrontend/Mongrel/Average Queue Time')
|
220
|
+
|
221
|
+
# heroku version
|
222
|
+
request_start = ((Time.now.to_f - 0.2) * 1e3).to_i.to_s
|
223
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_REQUEST_START' => request_start, 'HTTP_X_HEROKU_QUEUE_DEPTH' => '0'})
|
224
|
+
get :index
|
225
|
+
assert_equal(0, queue_length_stat.total_call_time, 'queue should be empty')
|
226
|
+
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
227
|
+
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
228
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
229
|
+
engine.clear_stats
|
230
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
231
|
+
|
232
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
233
|
+
queue_time_stat = stats('WebFrontend/Mongrel/Average Queue Time')
|
234
|
+
|
235
|
+
# heroku version with queue length > 0
|
236
|
+
request_start = ((Time.now.to_f - 0.2) * 1e3).to_i.to_s
|
237
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_REQUEST_START' => request_start, 'HTTP_X_HEROKU_QUEUE_DEPTH' => '3'})
|
238
|
+
get :index
|
239
|
+
|
240
|
+
assert_equal(1, queue_length_stat.call_count, 'queue should have been seen once')
|
241
|
+
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
242
|
+
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
243
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
244
|
+
assert_equal(3, queue_length_stat.total_call_time, 'queue should be 3 long')
|
245
|
+
|
246
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
247
|
+
end
|
248
|
+
|
249
|
+
private
|
250
|
+
def stats(name)
|
251
|
+
engine.get_stats_no_scope(name)
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Defining a test controller class with a superclass, used to
|
2
|
+
# verify correct attribute inheritence
|
3
|
+
class NewRelic::Agent::SuperclassController < ActionController::Base
|
4
|
+
def base_action
|
5
|
+
render :text => 'none'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
# This is a controller class used in testing controller instrumentation
|
9
|
+
class NewRelic::Agent::AgentTestController < NewRelic::Agent::SuperclassController
|
10
|
+
filter_parameter_logging :social_security_number
|
11
|
+
|
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
|
19
|
+
def index
|
20
|
+
sleep params['wait'].to_i if params['wait']
|
21
|
+
render :text => params.inspect
|
22
|
+
end
|
23
|
+
def _filter_parameters(params)
|
24
|
+
filter_parameters params
|
25
|
+
end
|
26
|
+
def action_to_render
|
27
|
+
render :text => params.inspect
|
28
|
+
end
|
29
|
+
def action_to_ignore
|
30
|
+
render :text => 'unmeasured'
|
31
|
+
end
|
32
|
+
def action_to_ignore_apdex
|
33
|
+
render :text => 'unmeasured'
|
34
|
+
end
|
35
|
+
before_filter :oops, :only => :action_with_before_filter_error
|
36
|
+
def action_with_before_filter_error
|
37
|
+
render :text => 'nothing'
|
38
|
+
end
|
39
|
+
def oops
|
40
|
+
raise "error in before filter"
|
41
|
+
end
|
42
|
+
class TestException < RuntimeError
|
43
|
+
end
|
44
|
+
|
45
|
+
def rescue_action_locally(exception)
|
46
|
+
if exception.is_a? TestException
|
47
|
+
raise "error in the handler"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def action_with_error
|
51
|
+
raise "error in action"
|
52
|
+
end
|
53
|
+
def entry_action
|
54
|
+
perform_action_with_newrelic_trace('internal_action') do
|
55
|
+
internal_action
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.set_some_headers(hash_of_headers)
|
60
|
+
@@headers_to_add ||= {}
|
61
|
+
@@headers_to_add.merge!(hash_of_headers)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.clear_headers
|
65
|
+
@@headers_to_add = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def newrelic_request_headers
|
69
|
+
@@headers_to_add
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def internal_action
|
74
|
+
perform_action_with_newrelic_trace(:name => 'internal_traced_action', :force => true) do
|
75
|
+
render :text => 'internal action'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
class NewRelic::Agent::BusyCalculatorTest < Test::Unit::TestCase
|
3
|
+
attr_reader :now
|
4
|
+
def setup
|
5
|
+
@now = Time.now.to_f
|
6
|
+
NewRelic::Agent::BusyCalculator.reset
|
7
|
+
@instance_busy = NewRelic::MethodTraceStats.new
|
8
|
+
NewRelic::Agent::BusyCalculator.stubs(:instance_busy_stats).returns(@instance_busy)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_normal
|
12
|
+
# start the timewindow 10 seconds ago
|
13
|
+
# start a request at 10 seconds, 5 seconds long
|
14
|
+
NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
|
15
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 10.0)
|
16
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 5.0)
|
17
|
+
assert_equal 5, NewRelic::Agent::BusyCalculator.accumulator
|
18
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
19
|
+
|
20
|
+
assert_equal 1, @instance_busy.call_count
|
21
|
+
assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
|
22
|
+
end
|
23
|
+
def test_split
|
24
|
+
# start the timewindow 10 seconds ago
|
25
|
+
# start a request at 5 seconds, don't finish
|
26
|
+
NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
|
27
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
|
28
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
29
|
+
|
30
|
+
assert_equal 1, @instance_busy.call_count, @instance_busy
|
31
|
+
assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
|
32
|
+
end
|
33
|
+
def test_reentrancy
|
34
|
+
# start the timewindow 10 seconds ago
|
35
|
+
# start a request at 5 seconds, don't finish, but make two more
|
36
|
+
# complete calls, which should be ignored.
|
37
|
+
NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
|
38
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
|
39
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 4.5)
|
40
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 4.0)
|
41
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 3.5)
|
42
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 3.0)
|
43
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 2.0)
|
44
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 1.0)
|
45
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
46
|
+
|
47
|
+
assert_equal 1, @instance_busy.call_count
|
48
|
+
assert_in_delta 0.50, @instance_busy.total_call_time, 0.05
|
49
|
+
end
|
50
|
+
def test_concurrency
|
51
|
+
# start the timewindow 10 seconds ago
|
52
|
+
# start a request at 10 seconds, 5 seconds long
|
53
|
+
NewRelic::Agent::BusyCalculator.stubs(:harvest_start).returns(now - 10.0)
|
54
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 8.0)
|
55
|
+
worker = Thread.new do
|
56
|
+
# Get busy for 6 - 3 seconds
|
57
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 6.0)
|
58
|
+
NewRelic::Agent::BusyCalculator.dispatcher_start(now - 5.0)
|
59
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 4.0)
|
60
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 3.0)
|
61
|
+
end
|
62
|
+
# Get busy for 8 - 2 seconds
|
63
|
+
NewRelic::Agent::BusyCalculator.dispatcher_finish(now - 2.0)
|
64
|
+
worker.join
|
65
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
66
|
+
|
67
|
+
assert_equal 1, @instance_busy.call_count
|
68
|
+
# 3 + 6 = 9, or 90%
|
69
|
+
assert_in_delta 0.90, @instance_busy.total_call_time, 0.025
|
70
|
+
|
71
|
+
end
|
72
|
+
def test_dont_ignore_zero_counts
|
73
|
+
assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
|
74
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
75
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
76
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
77
|
+
assert_equal 3, @instance_busy.call_count
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class ClassLoaderPatchTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_const_undefined
|
6
|
+
require 'new_relic/agent/patch_const_missing'
|
7
|
+
ClassLoadingWatcher.background_thread = Thread.current
|
8
|
+
|
9
|
+
# try loading some non-existent class
|
10
|
+
NewRelic::Control.instance.log.expects(:error).at_least_once.with{|args| args =~ /Agent background thread.*:FooBar/}
|
11
|
+
NewRelic::Control.instance.log.expects(:error).with{|args| args =~ /Agent background thread.*:FooBaz/}.never
|
12
|
+
|
13
|
+
ClassLoadingWatcher.enable_warning
|
14
|
+
assert_raise NameError do
|
15
|
+
FooBar::Bat
|
16
|
+
end
|
17
|
+
|
18
|
+
ClassLoadingWatcher.disable_warning
|
19
|
+
assert_raise NameError do
|
20
|
+
FooBaz::Bat
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_require
|
25
|
+
require 'new_relic/agent/patch_const_missing'
|
26
|
+
ClassLoadingWatcher.background_thread = Thread.current
|
27
|
+
|
28
|
+
# try loading some non-existent class
|
29
|
+
NewRelic::Control.instance.log.expects(:error).at_least_once.with{|args| args =~ /Agent background thread.*rational/}
|
30
|
+
NewRelic::Control.instance.log.expects(:error).with{|args| args =~ /Agent background thread.*pstore/}.never
|
31
|
+
|
32
|
+
ClassLoadingWatcher.enable_warning
|
33
|
+
require('rational') # standard library probably not loaded yet
|
34
|
+
|
35
|
+
ClassLoadingWatcher.disable_warning
|
36
|
+
|
37
|
+
require 'pstore' # standard library probably not loaded yet
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_load
|
41
|
+
require 'new_relic/agent/patch_const_missing'
|
42
|
+
ClassLoadingWatcher.background_thread = Thread.current
|
43
|
+
|
44
|
+
# try loading some non-existent class
|
45
|
+
NewRelic::Control.instance.log.expects(:error).with{|args| args =~ /Agent background thread.*tsort/}.at_least_once
|
46
|
+
NewRelic::Control.instance.log.expects(:error).with{|args| args =~ /Agent background thread.*getoptlong/}.never
|
47
|
+
|
48
|
+
ClassLoadingWatcher.enable_warning
|
49
|
+
|
50
|
+
load 'tsort.rb' # standard library probably not loaded yet
|
51
|
+
|
52
|
+
ClassLoadingWatcher.disable_warning
|
53
|
+
|
54
|
+
load 'getoptlong.rb' # standard library probably not loaded yet
|
55
|
+
end
|
56
|
+
end
|