onyx_newrelic_rpm 2.12.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +436 -0
- data/LICENSE +37 -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 +46 -0
- data/lib/new_relic/agent/agent.rb +668 -0
- data/lib/new_relic/agent/busy_calculator.rb +91 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/error_collector.rb +128 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
- data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +92 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +45 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +404 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +40 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +9 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +307 -0
- data/lib/new_relic/agent/instrumentation/net.rb +17 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +22 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +112 -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/rails3/action_controller.rb +45 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +21 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +17 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +10 -0
- data/lib/new_relic/agent/method_tracer.rb +350 -0
- data/lib/new_relic/agent/sampler.rb +46 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +37 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +142 -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/metric_stats.rb +118 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +80 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +149 -0
- data/lib/new_relic/agent/stats_engine.rb +24 -0
- data/lib/new_relic/agent/transaction_sampler.rb +315 -0
- data/lib/new_relic/agent/worker_loop.rb +80 -0
- data/lib/new_relic/agent.rb +369 -0
- data/lib/new_relic/collection_helper.rb +69 -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/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/rails3.rb +75 -0
- data/lib/new_relic/control/ruby.rb +36 -0
- data/lib/new_relic/control/sinatra.rb +18 -0
- data/lib/new_relic/control.rb +528 -0
- data/lib/new_relic/delayed_job_injection.rb +27 -0
- data/lib/new_relic/histogram.rb +89 -0
- data/lib/new_relic/local_environment.rb +333 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +42 -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 +50 -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_parser.rb +125 -0
- data/lib/new_relic/metric_spec.rb +67 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +24 -0
- data/lib/new_relic/rack/metric_app.rb +58 -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 +376 -0
- data/lib/new_relic/transaction_analysis.rb +124 -0
- data/lib/new_relic/transaction_sample.rb +654 -0
- data/lib/new_relic/version.rb +55 -0
- data/lib/new_relic_api.rb +276 -0
- data/lib/newrelic_rpm.rb +40 -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 +235 -0
- data/onyx_newrelic_rpm.gemspec +221 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +55 -0
- data/test/config/newrelic.yml +43 -0
- data/test/config/test_control.rb +38 -0
- data/test/new_relic/agent/active_record_instrumentation_test.rb +287 -0
- data/test/new_relic/agent/agent_controller_test.rb +280 -0
- data/test/new_relic/agent/agent_test_controller.rb +82 -0
- data/test/new_relic/agent/busy_calculator_test.rb +79 -0
- data/test/new_relic/agent/collection_helper_test.rb +125 -0
- data/test/new_relic/agent/error_collector_test.rb +171 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +103 -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/metric_frame_test.rb +51 -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 +77 -0
- data/test/new_relic/agent/rpm_agent_test.rb +138 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +72 -0
- data/test/new_relic/agent/stats_engine/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/task_instrumentation_test.rb +193 -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 +385 -0
- data/test/new_relic/agent/worker_loop_test.rb +60 -0
- data/test/new_relic/control_test.rb +117 -0
- data/test/new_relic/deployments_api_test.rb +69 -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 +311 -0
- data/test/new_relic/version_number_test.rb +89 -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 +319 -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 +248 -0
@@ -0,0 +1,280 @@
|
|
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
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_mongrel_queue
|
35
|
+
engine.clear_stats
|
36
|
+
NewRelic::Control.instance.local_env.stubs(:mongrel).returns( stub('mongrel', :workers => stub('workers', :list => stub('list', :length => '10'))))
|
37
|
+
|
38
|
+
get :index
|
39
|
+
assert_equal 1, stats('HttpDispatcher').call_count
|
40
|
+
assert_equal 1, engine.get_stats_no_scope('Mongrel/Queue Length').call_count
|
41
|
+
assert_equal 9, engine.get_stats_no_scope('Mongrel/Queue Length').total_call_time
|
42
|
+
assert_equal 0, engine.get_stats_no_scope('WebFrontend/Mongrel/Average Queue Time').call_count
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_heroku_queue
|
46
|
+
engine.clear_stats
|
47
|
+
NewRelic::Control.instance.local_env.stubs(:mongrel).returns( stub('mongrel', :workers => stub('workers', :list => stub('list', :length => '10'))))
|
48
|
+
NewRelic::Agent::AgentTestController.set_some_headers 'HTTP_X_HEROKU_QUEUE_DEPTH'=>'15'
|
49
|
+
get :index
|
50
|
+
assert_equal 1, stats('HttpDispatcher').call_count
|
51
|
+
assert_equal 1, engine.get_stats_no_scope('Mongrel/Queue Length').call_count
|
52
|
+
assert_equal 15, engine.get_stats_no_scope('Mongrel/Queue Length').total_call_time
|
53
|
+
assert_equal 0, engine.get_stats_no_scope('WebFrontend/Mongrel/Average Queue Time').call_count
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_render_inline
|
57
|
+
engine.clear_stats
|
58
|
+
get :action_inline
|
59
|
+
assert_equal 'foofah', @response.body
|
60
|
+
compare_metrics %w[Controller/new_relic/agent/agent_test/action_inline], engine.metrics.grep(/^Controller/)
|
61
|
+
end
|
62
|
+
def test_metric__ignore
|
63
|
+
engine.clear_stats
|
64
|
+
compare_metrics [], engine.metrics
|
65
|
+
get :action_to_ignore
|
66
|
+
compare_metrics [], engine.metrics
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_controller_rescued_error
|
70
|
+
engine.clear_stats
|
71
|
+
assert_raise RuntimeError do
|
72
|
+
get :action_with_error
|
73
|
+
end
|
74
|
+
metrics = ['Apdex',
|
75
|
+
'Apdex/new_relic/agent/agent_test/action_with_error',
|
76
|
+
'HttpDispatcher',
|
77
|
+
'Controller/new_relic/agent/agent_test/action_with_error',
|
78
|
+
'Errors/all']
|
79
|
+
|
80
|
+
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
81
|
+
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
|
82
|
+
assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
|
83
|
+
apdex = engine.get_stats_no_scope("Apdex")
|
84
|
+
score = apdex.get_apdex
|
85
|
+
assert_equal 1, score[2], 'failing'
|
86
|
+
assert_equal 0, score[1], 'tol'
|
87
|
+
assert_equal 0, score[0], 'satisfied'
|
88
|
+
|
89
|
+
end
|
90
|
+
def test_controller_error
|
91
|
+
engine.clear_stats
|
92
|
+
assert_raise RuntimeError do
|
93
|
+
get :action_with_error
|
94
|
+
end
|
95
|
+
metrics = ['Apdex',
|
96
|
+
'Apdex/new_relic/agent/agent_test/action_with_error',
|
97
|
+
'HttpDispatcher',
|
98
|
+
'Controller/new_relic/agent/agent_test/action_with_error',
|
99
|
+
'Errors/all']
|
100
|
+
|
101
|
+
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
102
|
+
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_error").call_count
|
103
|
+
assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
|
104
|
+
apdex = engine.get_stats_no_scope("Apdex")
|
105
|
+
score = apdex.get_apdex
|
106
|
+
assert_equal 1, score[2], 'failing'
|
107
|
+
assert_equal 0, score[1], 'tol'
|
108
|
+
assert_equal 0, score[0], 'satisfied'
|
109
|
+
|
110
|
+
end
|
111
|
+
def test_filter_error
|
112
|
+
engine.clear_stats
|
113
|
+
assert_raise RuntimeError do
|
114
|
+
get :action_with_before_filter_error
|
115
|
+
end
|
116
|
+
metrics = ['Apdex',
|
117
|
+
'Apdex/new_relic/agent/agent_test/action_with_before_filter_error',
|
118
|
+
'HttpDispatcher',
|
119
|
+
'Controller/new_relic/agent/agent_test/action_with_before_filter_error',
|
120
|
+
'Errors/all']
|
121
|
+
|
122
|
+
compare_metrics metrics, engine.metrics.reject{|m| m.index('Response')==0 || m.index('CPU')==0}
|
123
|
+
assert_equal 1, engine.get_stats_no_scope("Controller/new_relic/agent/agent_test/action_with_before_filter_error").call_count
|
124
|
+
assert_equal 1, engine.get_stats_no_scope("Errors/all").call_count
|
125
|
+
apdex = engine.get_stats_no_scope("Apdex")
|
126
|
+
score = apdex.get_apdex
|
127
|
+
assert_equal 1, score[2], 'failing'
|
128
|
+
assert_equal 0, score[1], 'tol'
|
129
|
+
assert_equal 0, score[0], 'satisfied'
|
130
|
+
end
|
131
|
+
def test_metric__ignore_base
|
132
|
+
engine.clear_stats
|
133
|
+
get :base_action
|
134
|
+
compare_metrics [], engine.metrics
|
135
|
+
end
|
136
|
+
def test_metric__no_ignore
|
137
|
+
path = 'new_relic/agent/agent_test/index'
|
138
|
+
index_stats = stats("Controller/#{path}")
|
139
|
+
index_apdex_stats = engine.get_custom_stats("Apdex/#{path}", NewRelic::ApdexStats)
|
140
|
+
assert_difference 'index_stats.call_count' do
|
141
|
+
assert_difference 'index_apdex_stats.call_count' do
|
142
|
+
get :index
|
143
|
+
end
|
144
|
+
end
|
145
|
+
assert_nil Thread.current[:newrelic_ignore_controller]
|
146
|
+
end
|
147
|
+
def test_metric__ignore_apdex
|
148
|
+
engine = @agent.stats_engine
|
149
|
+
path = 'new_relic/agent/agent_test/action_to_ignore_apdex'
|
150
|
+
cpu_stats = stats("ControllerCPU/#{path}")
|
151
|
+
index_stats = stats("Controller/#{path}")
|
152
|
+
index_apdex_stats = engine.get_custom_stats("Apdex/#{path}", NewRelic::ApdexStats)
|
153
|
+
assert_difference 'index_stats.call_count' do
|
154
|
+
assert_no_difference 'index_apdex_stats.call_count' do
|
155
|
+
get :action_to_ignore_apdex
|
156
|
+
end
|
157
|
+
end
|
158
|
+
assert_nil Thread.current[:newrelic_ignore_controller]
|
159
|
+
|
160
|
+
end
|
161
|
+
def test_metric__dispatched
|
162
|
+
engine = @agent.stats_engine
|
163
|
+
get :entry_action
|
164
|
+
assert_nil Thread.current[:newrelic_ignore_controller]
|
165
|
+
assert_nil engine.lookup_stat('Controller/agent_test/entry_action')
|
166
|
+
assert_nil engine.lookup_stat('Controller/agent_test_controller/entry_action')
|
167
|
+
assert_nil engine.lookup_stat('Controller/AgentTestController/entry_action')
|
168
|
+
assert_nil engine.lookup_stat('Controller/NewRelic::Agent::AgentTestController/internal_action')
|
169
|
+
assert_nil engine.lookup_stat('Controller/NewRelic::Agent::AgentTestController_controller/internal_action')
|
170
|
+
assert_not_nil engine.lookup_stat('Controller/NewRelic::Agent::AgentTestController/internal_traced_action')
|
171
|
+
end
|
172
|
+
def test_action_instrumentation
|
173
|
+
begin
|
174
|
+
get :index, :foo => 'bar'
|
175
|
+
assert_match /bar/, @response.body
|
176
|
+
#rescue ActionController::RoutingError
|
177
|
+
# you might get here if you don't have the default route installed.
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_controller_params
|
182
|
+
assert agent.transaction_sampler
|
183
|
+
num_samples = NewRelic::Agent.instance.transaction_sampler.samples.length
|
184
|
+
assert_equal "[FILTERED]", @controller._filter_parameters({'social_security_number' => 'test'})['social_security_number']
|
185
|
+
get :index, 'social_security_number' => "001-555-1212"
|
186
|
+
samples = agent.transaction_sampler.samples
|
187
|
+
assert_equal num_samples + 1, samples.length
|
188
|
+
assert_equal "[FILTERED]", samples.last.params[:request_params]["social_security_number"]
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_controller_params
|
192
|
+
agent.transaction_sampler.reset!
|
193
|
+
get :index, 'number' => "001-555-1212"
|
194
|
+
s = agent.transaction_sampler.harvest(nil, 0.0)
|
195
|
+
assert_equal 1, s.size
|
196
|
+
assert_equal 5, s.first.params.size
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
def test_busycalculation
|
201
|
+
engine.clear_stats
|
202
|
+
|
203
|
+
assert_equal 0, NewRelic::Agent::BusyCalculator.busy_count
|
204
|
+
get :index, 'social_security_number' => "001-555-1212", 'wait' => '1.0'
|
205
|
+
NewRelic::Agent::BusyCalculator.harvest_busy
|
206
|
+
|
207
|
+
assert_equal 1, stats('Instance/Busy').call_count
|
208
|
+
assert_equal 1, stats('HttpDispatcher').call_count
|
209
|
+
# We are probably busy about 99% of the time, but lets make sure it's at least 50
|
210
|
+
assert stats('Instance/Busy').total_call_time > 0.5, stats('Instance/Busy')
|
211
|
+
assert_equal 0, stats('WebFrontend/Mongrel/Average Queue Time').call_count
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_histogram
|
215
|
+
engine.clear_stats
|
216
|
+
get :index, 'social_security_number' => "001-555-1212"
|
217
|
+
bucket = NewRelic::Agent.instance.stats_engine.metrics.find { | m | m =~ /^Response Times/ }
|
218
|
+
assert_not_nil bucket
|
219
|
+
bucket_stats = stats(bucket)
|
220
|
+
assert_equal 1, bucket_stats.call_count
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_queue_headers
|
224
|
+
engine.clear_stats
|
225
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
226
|
+
queue_time_stat = stats('WebFrontend/Mongrel/Average Queue Time')
|
227
|
+
|
228
|
+
# no request start header
|
229
|
+
get :index
|
230
|
+
assert_equal 0, queue_length_stat.call_count
|
231
|
+
|
232
|
+
# apache version of header
|
233
|
+
request_start = ((Time.now.to_f - 0.2) * 1e6).to_i.to_s
|
234
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_REQUEST_START' => "t=#{request_start}"})
|
235
|
+
get :index
|
236
|
+
assert_equal(0, queue_length_stat.call_count, 'We should not be seeing a queue length yet')
|
237
|
+
assert_equal(1, queue_time_stat.call_count, 'We should have seen the queue header once')
|
238
|
+
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
239
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
240
|
+
|
241
|
+
engine.clear_stats
|
242
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
243
|
+
|
244
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
245
|
+
queue_time_stat = stats('WebFrontend/Mongrel/Average Queue Time')
|
246
|
+
|
247
|
+
# heroku version
|
248
|
+
request_start = ((Time.now.to_f - 0.2) * 1e3).to_i.to_s
|
249
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_REQUEST_START' => request_start, 'HTTP_X_HEROKU_QUEUE_DEPTH' => '0'})
|
250
|
+
get :index
|
251
|
+
assert_equal(0, queue_length_stat.total_call_time, 'queue should be empty')
|
252
|
+
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
253
|
+
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
254
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
255
|
+
engine.clear_stats
|
256
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
257
|
+
|
258
|
+
queue_length_stat = stats('Mongrel/Queue Length')
|
259
|
+
queue_time_stat = stats('WebFrontend/Mongrel/Average Queue Time')
|
260
|
+
|
261
|
+
# heroku version with queue length > 0
|
262
|
+
request_start = ((Time.now.to_f - 0.2) * 1e3).to_i.to_s
|
263
|
+
NewRelic::Agent::AgentTestController.set_some_headers({'HTTP_X_REQUEST_START' => request_start, 'HTTP_X_HEROKU_QUEUE_DEPTH' => '3'})
|
264
|
+
get :index
|
265
|
+
|
266
|
+
assert_equal(1, queue_length_stat.call_count, 'queue should have been seen once')
|
267
|
+
assert_equal(1, queue_time_stat.call_count, 'should have seen the queue header once')
|
268
|
+
assert(queue_time_stat.total_call_time > 0.1, "Queue time should be longer than 100ms")
|
269
|
+
assert(queue_time_stat.total_call_time < 10, "Queue time should be under 10 seconds (sanity check)")
|
270
|
+
assert_equal(3, queue_length_stat.total_call_time, 'queue should be 3 long')
|
271
|
+
|
272
|
+
NewRelic::Agent::AgentTestController.clear_headers
|
273
|
+
end
|
274
|
+
|
275
|
+
private
|
276
|
+
def stats(name)
|
277
|
+
engine.get_stats_no_scope(name)
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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_inline
|
27
|
+
render(:inline => "<%= 'foo' %>fah")
|
28
|
+
end
|
29
|
+
|
30
|
+
def action_to_render
|
31
|
+
render :text => params.inspect
|
32
|
+
end
|
33
|
+
def action_to_ignore
|
34
|
+
render :text => 'unmeasured'
|
35
|
+
end
|
36
|
+
def action_to_ignore_apdex
|
37
|
+
render :text => 'unmeasured'
|
38
|
+
end
|
39
|
+
before_filter :oops, :only => :action_with_before_filter_error
|
40
|
+
def action_with_before_filter_error
|
41
|
+
render :text => 'nothing'
|
42
|
+
end
|
43
|
+
def oops
|
44
|
+
raise "error in before filter"
|
45
|
+
end
|
46
|
+
class TestException < RuntimeError
|
47
|
+
end
|
48
|
+
|
49
|
+
def rescue_action_locally(exception)
|
50
|
+
if exception.is_a? TestException
|
51
|
+
raise "error in the handler"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
def action_with_error
|
55
|
+
raise "error in action"
|
56
|
+
end
|
57
|
+
def entry_action
|
58
|
+
perform_action_with_newrelic_trace('internal_action') do
|
59
|
+
internal_action
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.set_some_headers(hash_of_headers)
|
64
|
+
@@headers_to_add ||= {}
|
65
|
+
@@headers_to_add.merge!(hash_of_headers)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.clear_headers
|
69
|
+
@@headers_to_add = nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def newrelic_request_headers
|
73
|
+
@@headers_to_add ||= {}
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def internal_action
|
78
|
+
perform_action_with_newrelic_trace(:name => 'internal_traced_action', :force => true) do
|
79
|
+
render :text => 'internal action'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
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,125 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'ostruct'
|
3
|
+
require 'active_record_fixtures'
|
4
|
+
class NewRelic::Agent::CollectionHelperTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
NewRelic::Agent.manual_start
|
9
|
+
end
|
10
|
+
def teardown
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
include NewRelic::CollectionHelper
|
15
|
+
def test_string
|
16
|
+
val = (('A'..'Z').to_a.join * 100).to_s
|
17
|
+
assert_equal val[0...256] + "...", normalize_params(val)
|
18
|
+
end
|
19
|
+
def test_array
|
20
|
+
new_array = normalize_params [ 1000 ] * 50
|
21
|
+
assert_equal 20, new_array.size
|
22
|
+
assert_equal '1000', new_array[0]
|
23
|
+
end
|
24
|
+
def test_boolean
|
25
|
+
np = normalize_params(NewRelic::Control.instance.settings)
|
26
|
+
assert_equal false, np['monitor_mode']
|
27
|
+
end
|
28
|
+
def test_string__singleton
|
29
|
+
val = "This String"
|
30
|
+
def val.hello; end
|
31
|
+
assert_equal "This String", normalize_params(val)
|
32
|
+
assert val.respond_to?(:hello)
|
33
|
+
assert !normalize_params(val).respond_to?(:hello)
|
34
|
+
end
|
35
|
+
class MyString < String; end
|
36
|
+
def test_kind_of_string
|
37
|
+
s = MyString.new "This is a string"
|
38
|
+
assert_equal "This is a string", s.to_s
|
39
|
+
assert_equal MyString, s.class
|
40
|
+
assert_equal String, s.to_s.class
|
41
|
+
params = normalize_params(:val => [s])
|
42
|
+
assert_equal String, params[:val][0].class
|
43
|
+
assert_equal String, flatten(s).class
|
44
|
+
assert_equal String, truncate(s, 2).class
|
45
|
+
end
|
46
|
+
def test_number
|
47
|
+
np = normalize_params({ 'one' => 1.0, 'two' => '2'})
|
48
|
+
end
|
49
|
+
def test_nil
|
50
|
+
np = normalize_params({ nil => 1.0, 'two' => nil})
|
51
|
+
assert_equal "1.0", np['']
|
52
|
+
assert_equal nil, np['two']
|
53
|
+
end
|
54
|
+
def test_hash
|
55
|
+
val = ('A'..'Z').to_a.join * 100
|
56
|
+
assert_equal Hash["ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF..." => (("0"*256) + "...")], normalize_params({ val => '0' * 512 })
|
57
|
+
end
|
58
|
+
class MyHash < Hash
|
59
|
+
|
60
|
+
end
|
61
|
+
# Test to ensure that hash subclasses are properly converted
|
62
|
+
def test_hash_subclass
|
63
|
+
h = MyHash.new
|
64
|
+
h[:mine] = 'mine'
|
65
|
+
custom_params = { :one => {:hash => { :a => :b}, :myhash => h }}
|
66
|
+
nh = normalize_params(custom_params)
|
67
|
+
myhash = custom_params[:one][:myhash]
|
68
|
+
assert_equal MyHash, myhash.class
|
69
|
+
myhash = nh[:one][:myhash]
|
70
|
+
assert_equal Hash, myhash.class
|
71
|
+
end
|
72
|
+
|
73
|
+
class MyEnumerable
|
74
|
+
include Enumerable
|
75
|
+
|
76
|
+
def each
|
77
|
+
yield "1"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_enumerable
|
82
|
+
e = MyEnumerable.new
|
83
|
+
custom_params = { :one => {:hash => { :a => :b}, :myenum => e }}
|
84
|
+
nh = normalize_params(custom_params)
|
85
|
+
myenum = nh[:one][:myenum]
|
86
|
+
assert_match /MyEnumerable/, myenum
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_stringio
|
90
|
+
# Verify StringIO works like this normally:
|
91
|
+
s = StringIO.new "start" + ("foo bar bat " * 1000)
|
92
|
+
val = nil
|
93
|
+
s.each { | entry | val = entry; break }
|
94
|
+
assert_match /^startfoo bar/, val
|
95
|
+
|
96
|
+
# make sure stringios aren't affected by calling normalize_params:
|
97
|
+
s = StringIO.new "start" + ("foo bar bat " * 1000)
|
98
|
+
v = normalize_params({ :foo => s.string })
|
99
|
+
s.each { | entry | val = entry; break }
|
100
|
+
assert_match /^startfoo bar/, val
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_object
|
104
|
+
assert_equal ["foo", '#<OpenStruct>'], normalize_params(['foo', OpenStruct.new('z'=>'q')])
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_strip_backtrace
|
108
|
+
begin
|
109
|
+
ActiveRecordFixtures.setup
|
110
|
+
# ActiveRecordFixtures::Order.add_delay
|
111
|
+
ActiveRecordFixtures::Order.find 0
|
112
|
+
flunk "should throw"
|
113
|
+
rescue => e
|
114
|
+
#puts e
|
115
|
+
#puts e.backtrace.join("\n")
|
116
|
+
#puts "\n\n"
|
117
|
+
clean_trace = strip_nr_from_backtrace(e.backtrace)
|
118
|
+
assert_equal 0, clean_trace.grep(/newrelic_rpm/).size, clean_trace.grep(/newrelic_rpm/)
|
119
|
+
assert_equal 0, clean_trace.grep(/trace/).size, clean_trace.grep(/trace/)
|
120
|
+
assert_equal 3, clean_trace.grep(/find/).size, "should see three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
|
121
|
+
ensure
|
122
|
+
ActiveRecordFixtures.teardown
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|