ghazel-newrelic_rpm 3.1.0.1 → 3.4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +120 -35
- data/LICENSE +29 -2
- data/README.rdoc +2 -2
- data/bin/mongrel_rpm +0 -0
- data/bin/newrelic +0 -0
- data/bin/newrelic_cmd +0 -0
- data/lib/new_relic/agent.rb +50 -38
- data/lib/new_relic/agent/agent.rb +459 -337
- data/lib/new_relic/agent/beacon_configuration.rb +71 -11
- data/lib/new_relic/agent/browser_monitoring.rb +73 -14
- data/lib/new_relic/agent/busy_calculator.rb +11 -3
- data/lib/new_relic/agent/chained_call.rb +2 -2
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +231 -183
- data/lib/new_relic/agent/instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +10 -2
- data/lib/new_relic/agent/instrumentation/active_record.rb +138 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +7 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +6 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +46 -14
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +8 -2
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +11 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +49 -25
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +7 -2
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +31 -4
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -5
- data/lib/new_relic/agent/instrumentation/net.rb +8 -2
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -2
- data/lib/new_relic/agent/instrumentation/queue_time.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +66 -35
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +121 -1
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +21 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +80 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +46 -20
- data/lib/new_relic/agent/instrumentation/sunspot.rb +6 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +7 -2
- data/lib/new_relic/agent/method_tracer.rb +205 -99
- data/lib/new_relic/agent/new_relic_service.rb +221 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +161 -0
- data/lib/new_relic/agent/pipe_service.rb +54 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +89 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -7
- data/lib/new_relic/agent/shim_agent.rb +5 -5
- data/lib/new_relic/agent/sql_sampler.rb +282 -0
- data/lib/new_relic/agent/stats_engine.rb +2 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +35 -30
- data/lib/new_relic/agent/stats_engine/samplers.rb +10 -4
- data/lib/new_relic/agent/stats_engine/transactions.rb +28 -87
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +18 -3
- data/lib/new_relic/agent/transaction_sampler.rb +108 -20
- data/lib/new_relic/agent/worker_loop.rb +14 -6
- data/lib/new_relic/collection_helper.rb +19 -11
- data/lib/new_relic/command.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +2 -2
- data/lib/new_relic/commands/install.rb +2 -13
- data/lib/new_relic/control.rb +2 -3
- data/lib/new_relic/control/class_methods.rb +12 -6
- data/lib/new_relic/control/configuration.rb +57 -8
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +4 -4
- data/lib/new_relic/control/frameworks/merb.rb +2 -1
- data/lib/new_relic/control/frameworks/rails.rb +35 -22
- data/lib/new_relic/control/frameworks/rails3.rb +12 -7
- data/lib/new_relic/control/frameworks/ruby.rb +5 -5
- data/lib/new_relic/control/frameworks/sinatra.rb +1 -4
- data/lib/new_relic/control/instance_methods.rb +38 -12
- data/lib/new_relic/control/instrumentation.rb +23 -4
- data/lib/new_relic/control/logging_methods.rb +70 -15
- data/lib/new_relic/control/server_methods.rb +22 -9
- data/lib/new_relic/delayed_job_injection.rb +16 -3
- data/lib/new_relic/helper.rb +21 -0
- data/lib/new_relic/language_support.rb +95 -0
- data/lib/new_relic/local_environment.rb +92 -48
- data/lib/new_relic/metric_data.rb +7 -2
- data/lib/new_relic/metric_spec.rb +12 -9
- data/lib/new_relic/noticed_error.rb +6 -1
- data/lib/new_relic/rack/browser_monitoring.rb +18 -19
- data/lib/new_relic/rack/developer_mode.rb +3 -2
- data/lib/new_relic/recipes.rb +8 -4
- data/lib/new_relic/stats.rb +17 -60
- data/lib/new_relic/transaction_analysis.rb +2 -1
- data/lib/new_relic/transaction_analysis/segment_summary.rb +4 -2
- data/lib/new_relic/transaction_sample.rb +60 -75
- data/lib/new_relic/transaction_sample/segment.rb +31 -79
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +1 -1
- data/newrelic.yml +2 -2
- data/newrelic_rpm.gemspec +46 -54
- data/test/active_record_fixtures.rb +3 -3
- data/test/config/newrelic.yml +1 -1
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +128 -25
- data/test/new_relic/agent/agent/start_test.rb +9 -94
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -4
- data/test/new_relic/agent/agent_test.rb +51 -78
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +49 -33
- data/test/new_relic/agent/beacon_configuration_test.rb +12 -5
- data/test/new_relic/agent/browser_monitoring_test.rb +99 -50
- data/test/new_relic/agent/database_test.rb +161 -0
- data/test/new_relic/agent/error_collector_test.rb +47 -23
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +96 -42
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +0 -2
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +3 -11
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +9 -9
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +6 -11
- data/test/new_relic/agent/memcache_instrumentation_test.rb +54 -18
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +1 -1
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +1 -1
- data/test/new_relic/agent/method_tracer_test.rb +3 -2
- data/test/new_relic/agent/new_relic_service_test.rb +151 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +114 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +4 -31
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +19 -18
- data/test/new_relic/agent/stats_engine_test.rb +41 -6
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +27 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +68 -46
- data/test/new_relic/agent/worker_loop_test.rb +3 -3
- data/test/new_relic/agent_test.rb +242 -0
- data/test/new_relic/collection_helper_test.rb +50 -28
- data/test/new_relic/control/configuration_test.rb +77 -0
- data/test/new_relic/control/logging_methods_test.rb +49 -21
- data/test/new_relic/control_test.rb +115 -54
- data/test/new_relic/delayed_job_injection_test.rb +21 -0
- data/test/new_relic/fake_collector.rb +210 -0
- data/test/new_relic/fake_service.rb +44 -0
- data/test/new_relic/local_environment_test.rb +14 -1
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +84 -23
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +31 -0
- data/test/new_relic/stats_test.rb +3 -18
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +14 -0
- data/test/new_relic/transaction_analysis_test.rb +3 -3
- data/test/new_relic/transaction_sample/segment_test.rb +15 -80
- data/test/new_relic/transaction_sample_test.rb +25 -18
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +140 -0
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +18 -5
- data/ui/helpers/developer_mode_helper.rb +14 -8
- data/ui/helpers/google_pie_chart.rb +0 -1
- data/ui/views/newrelic/index.rhtml +2 -2
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +4 -18
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +10 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +11 -11
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +17 -4
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +4 -0
- metadata +50 -36
- data/lib/new_relic/agent/instrumentation/rails/active_record_instrumentation.rb +0 -108
- data/lib/new_relic/agent/instrumentation/rails3/active_record_instrumentation.rb +0 -112
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/data_serialization.rb +0 -84
- data/lib/new_relic/histogram.rb +0 -91
- data/lib/new_relic/rack/metric_app.rb +0 -65
- data/lib/new_relic/rack/mongrel_rpm.ru +0 -28
- data/lib/new_relic/rack/newrelic.yml +0 -27
- data/lib/new_relic/rack_app.rb +0 -6
- data/test/new_relic/data_serialization_test.rb +0 -70
- data/vendor/gems/dependency_detection-0.0.1.build/README +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/LICENSE +0 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/README +0 -0
@@ -23,7 +23,7 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
|
23
23
|
# This shows how the tasks stay aligned with the period and don't drift.
|
24
24
|
count = 0
|
25
25
|
start = Time.now
|
26
|
-
@worker_loop.run(0.
|
26
|
+
@worker_loop.run(0.03) do
|
27
27
|
count +=1
|
28
28
|
if count == 3
|
29
29
|
@worker_loop.stop
|
@@ -31,7 +31,7 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
elapsed = Time.now - start
|
34
|
-
assert_in_delta 0.
|
34
|
+
assert_in_delta 0.09, elapsed, 0.03
|
35
35
|
end
|
36
36
|
def test_task_error__standard
|
37
37
|
@logger.expects(:debug)
|
@@ -45,7 +45,7 @@ class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
|
|
45
45
|
end
|
46
46
|
assert done
|
47
47
|
end
|
48
|
-
class BadBoy <
|
48
|
+
class BadBoy < StandardError; end
|
49
49
|
|
50
50
|
def test_task_error__exception
|
51
51
|
@logger.expects(:error).once
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module NewRelic
|
5
|
+
class MainAgentTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# mostly this module just passes through to the active agent
|
8
|
+
# through the agent method or the control instance through
|
9
|
+
# NewRelic::Control.instance . But it's nice to make sure.
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
super
|
13
|
+
Thread.current[:newrelic_untraced] = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_shutdown
|
17
|
+
mock_agent = mocked_agent
|
18
|
+
mock_agent.expects(:shutdown).with({})
|
19
|
+
NewRelic::Agent.shutdown
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_after_fork
|
23
|
+
mock_agent = mocked_agent
|
24
|
+
mock_agent.expects(:after_fork).with({})
|
25
|
+
NewRelic::Agent.after_fork
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_after_fork_sets_forked_flag
|
29
|
+
agent = NewRelic::Agent::Agent.new
|
30
|
+
assert !agent.forked?
|
31
|
+
agent.after_fork
|
32
|
+
|
33
|
+
assert agent.forked?
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
if NewRelic::LanguageSupport.can_fork? &&
|
38
|
+
!NewRelic::LanguageSupport.using_version?('1.9.1')
|
39
|
+
def test_timeslice_harvest_with_after_fork_report_to_channel
|
40
|
+
NewRelic::Control.instance.stubs(:agent_enabled?).returns(true)
|
41
|
+
NewRelic::Control.instance.stubs(:monitor_mode?).returns(true)
|
42
|
+
|
43
|
+
NewRelic::Agent::Agent.instance.service = NewRelic::FakeService.new
|
44
|
+
NewRelic::Agent.shutdown # make sure the agent is not already started
|
45
|
+
NewRelic::Agent.manual_start(:license_key => ('1234567890' * 4),
|
46
|
+
:start_channel_listener => true)
|
47
|
+
|
48
|
+
metric = 'Custom/test/method'
|
49
|
+
NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric) \
|
50
|
+
.record_data_point(1.0)
|
51
|
+
|
52
|
+
# ensure that cached metric ids don't interfere with metric merging
|
53
|
+
NewRelic::Agent.agent.instance_variable_set(:@metric_ids,
|
54
|
+
{NewRelic::MetricSpec.new('Instance/Busy') => 1})
|
55
|
+
|
56
|
+
NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
|
57
|
+
NewRelic::Agent.register_report_channel(:agent_test) # before fork
|
58
|
+
pid = Process.fork do
|
59
|
+
NewRelic::Agent.after_fork(:report_to_channel => :agent_test)
|
60
|
+
NewRelic::Agent.agent.stats_engine.get_stats_no_scope(metric) \
|
61
|
+
.record_data_point(2.0)
|
62
|
+
end
|
63
|
+
Process.wait(pid)
|
64
|
+
NewRelic::Agent::PipeChannelManager.listener.stop
|
65
|
+
|
66
|
+
engine = NewRelic::Agent.agent.stats_engine
|
67
|
+
assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
|
68
|
+
assert_equal(2, engine.lookup_stats(metric).call_count)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_reset_stats
|
73
|
+
mock_agent = mocked_agent
|
74
|
+
mock_agent.expects(:reset_stats)
|
75
|
+
NewRelic::Agent.reset_stats
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_manual_start_default
|
79
|
+
mock_control = mocked_control
|
80
|
+
mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => true})
|
81
|
+
NewRelic::Agent.manual_start
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_manual_start_with_opts
|
85
|
+
mock_control = mocked_control
|
86
|
+
mock_control.expects(:init_plugin).with({:agent_enabled => true, :sync_startup => false})
|
87
|
+
NewRelic::Agent.manual_start(:sync_startup => false)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_manual_start_starts_channel_listener
|
91
|
+
NewRelic::Agent::PipeChannelManager.listener.stop
|
92
|
+
NewRelic::Agent.agent.service = NewRelic::FakeService.new
|
93
|
+
NewRelic::Agent.manual_start(:start_channel_listener => true)
|
94
|
+
assert NewRelic::Agent::PipeChannelManager.listener.started?
|
95
|
+
NewRelic::Agent::PipeChannelManager.listener.stop
|
96
|
+
NewRelic::Agent.shutdown
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_logger
|
100
|
+
control = mocked_control
|
101
|
+
control.expects(:log)
|
102
|
+
NewRelic::Agent.logger
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_browser_timing_header
|
106
|
+
agent = mocked_agent
|
107
|
+
agent.expects(:browser_timing_header)
|
108
|
+
NewRelic::Agent.browser_timing_header
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_browser_timing_footer
|
112
|
+
agent = mocked_agent
|
113
|
+
agent.expects(:browser_timing_footer)
|
114
|
+
NewRelic::Agent.browser_timing_footer
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_get_stats
|
118
|
+
agent = mocked_agent
|
119
|
+
mock_stats_engine = mock('stats_engine')
|
120
|
+
agent.expects(:stats_engine).returns(mock_stats_engine)
|
121
|
+
mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
|
122
|
+
NewRelic::Agent.get_stats('Custom/test/metric')
|
123
|
+
end
|
124
|
+
|
125
|
+
# note that this is the same as get_stats above, they're just aliases
|
126
|
+
def test_get_stats_no_scope
|
127
|
+
agent = mocked_agent
|
128
|
+
mock_stats_engine = mock('stats_engine')
|
129
|
+
agent.expects(:stats_engine).returns(mock_stats_engine)
|
130
|
+
mock_stats_engine.expects(:get_stats).with('Custom/test/metric', false)
|
131
|
+
NewRelic::Agent.get_stats_no_scope('Custom/test/metric')
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_agent_not_started
|
135
|
+
old_agent = NewRelic::Agent.agent
|
136
|
+
NewRelic::Agent.instance_eval { @agent = nil }
|
137
|
+
assert_raise(RuntimeError) do
|
138
|
+
NewRelic::Agent.agent
|
139
|
+
end
|
140
|
+
NewRelic::Agent.instance_eval { @agent = old_agent }
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_agent_when_started
|
144
|
+
old_agent = NewRelic::Agent.agent
|
145
|
+
NewRelic::Agent.instance_eval { @agent = 'not nil' }
|
146
|
+
assert_equal('not nil', NewRelic::Agent.agent, "should return the value from @agent")
|
147
|
+
NewRelic::Agent.instance_eval { @agent = old_agent }
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_abort_transaction_bang
|
151
|
+
NewRelic::Agent::Instrumentation::MetricFrame.expects(:abort_transaction!)
|
152
|
+
NewRelic::Agent.abort_transaction!
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_is_transaction_traced_true
|
156
|
+
Thread.current[:record_tt] = true
|
157
|
+
assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is set')
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_is_transaction_traced_blank
|
161
|
+
Thread.current[:record_tt] = nil
|
162
|
+
assert_equal(true, NewRelic::Agent.is_transaction_traced?, 'should be true since the thread local is not set')
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_is_transaction_traced_false
|
166
|
+
Thread.current[:record_tt] = false
|
167
|
+
assert_equal(false, NewRelic::Agent.is_transaction_traced?, 'should be false since the thread local is false')
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_is_sql_recorded_true
|
171
|
+
Thread.current[:record_sql] = true
|
172
|
+
assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is set')
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_is_sql_recorded_blank
|
176
|
+
Thread.current[:record_sql] = nil
|
177
|
+
assert_equal(true, NewRelic::Agent.is_sql_recorded?, 'should be true since the thread local is not set')
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_is_sql_recorded_false
|
181
|
+
Thread.current[:record_sql] = false
|
182
|
+
assert_equal(false, NewRelic::Agent.is_sql_recorded?, 'should be false since the thread local is false')
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_is_execution_traced_true
|
186
|
+
Thread.current[:newrelic_untraced] = [true, true]
|
187
|
+
assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is set')
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_is_execution_traced_blank
|
191
|
+
Thread.current[:newrelic_untraced] = nil
|
192
|
+
assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is not set')
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_is_execution_traced_empty
|
196
|
+
Thread.current[:newrelic_untraced] = []
|
197
|
+
assert_equal(true, NewRelic::Agent.is_execution_traced?, 'should be true since the thread local is an empty array')
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_is_execution_traced_false
|
201
|
+
Thread.current[:newrelic_untraced] = [true, false]
|
202
|
+
assert_equal(false, NewRelic::Agent.is_execution_traced?, 'should be false since the thread local stack has the last element false')
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_instance
|
206
|
+
assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_register_report_channel
|
210
|
+
NewRelic::Agent.register_report_channel(:channel_id)
|
211
|
+
assert NewRelic::Agent::PipeChannelManager.channels[:channel_id] \
|
212
|
+
.kind_of?(NewRelic::Agent::PipeChannelManager::Pipe)
|
213
|
+
NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
|
214
|
+
end
|
215
|
+
|
216
|
+
private
|
217
|
+
|
218
|
+
def mocked_agent
|
219
|
+
agent = mock('agent')
|
220
|
+
NewRelic::Agent.stubs(:agent).returns(agent)
|
221
|
+
agent
|
222
|
+
end
|
223
|
+
|
224
|
+
def mocked_control
|
225
|
+
server = NewRelic::Control::Server.new('localhost', 3000)
|
226
|
+
control = OpenStruct.new(:license_key => 'abcdef',
|
227
|
+
:server => server)
|
228
|
+
control.instance_eval do
|
229
|
+
def [](key)
|
230
|
+
nil
|
231
|
+
end
|
232
|
+
|
233
|
+
def fetch(k,d)
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
NewRelic::Control.stubs(:instance).returns(control)
|
239
|
+
control
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -15,12 +15,12 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
include NewRelic::CollectionHelper
|
17
17
|
def test_string
|
18
|
-
val = (('A'..'Z').to_a.join *
|
19
|
-
assert_equal val[0...
|
18
|
+
val = (('A'..'Z').to_a.join * 1024).to_s
|
19
|
+
assert_equal val[0...16384] + "...", normalize_params(val)
|
20
20
|
end
|
21
21
|
def test_array
|
22
22
|
new_array = normalize_params [ 1000 ] * 2000
|
23
|
-
assert_equal
|
23
|
+
assert_equal 128, new_array.size
|
24
24
|
assert_equal '1000', new_array[0]
|
25
25
|
end
|
26
26
|
def test_boolean
|
@@ -55,7 +55,7 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
def test_hash
|
57
57
|
val = ('A'..'Z').to_a.join * 100
|
58
|
-
assert_equal Hash["
|
58
|
+
assert_equal Hash[(val[0..63] + "...") => (("0"*16384) + "...")], normalize_params({ val => '0' * (16384*2) })
|
59
59
|
end
|
60
60
|
class MyHash < Hash
|
61
61
|
|
@@ -72,13 +72,7 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
|
|
72
72
|
assert_equal Hash, myhash.class
|
73
73
|
end
|
74
74
|
|
75
|
-
class MyEnumerable
|
76
|
-
include Enumerable
|
77
75
|
|
78
|
-
def each
|
79
|
-
yield "1"
|
80
|
-
end
|
81
|
-
end
|
82
76
|
|
83
77
|
def test_enumerable
|
84
78
|
e = MyEnumerable.new
|
@@ -101,27 +95,55 @@ class NewRelic::CollectionHelperTest < Test::Unit::TestCase
|
|
101
95
|
s.each { | entry | val = entry; break }
|
102
96
|
assert_match /^startfoo bar/, val
|
103
97
|
end
|
104
|
-
|
98
|
+
class MyEnumerable
|
99
|
+
include Enumerable
|
100
|
+
|
101
|
+
def each
|
102
|
+
yield "1"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
105
106
|
def test_object
|
106
107
|
assert_equal ["foo", '#<OpenStruct>'], normalize_params(['foo', OpenStruct.new('z'=>'q')])
|
107
108
|
end
|
108
109
|
|
109
110
|
def test_strip_backtrace
|
110
|
-
|
111
|
-
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
111
|
+
clean_trace = strip_nr_from_backtrace(mock_backtrace)
|
112
|
+
assert_equal(0, clean_trace.grep(/newrelic_rpm/).size,
|
113
|
+
"should remove all instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
|
114
|
+
assert_equal(0, clean_trace.grep(/trace/).size,
|
115
|
+
"should remove trace method tags from method names but got: #{clean_trace.join("\n")}")
|
116
|
+
assert((clean_trace.grep(/find/).size >= 3),
|
117
|
+
"should see at least three frames with 'find' in them: \n#{clean_trace.join("\n")}")
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_disabled_strip_backtrace
|
121
|
+
NewRelic::Control.instance['disable_backtrace_cleanup'] = true
|
122
|
+
clean_trace = strip_nr_from_backtrace(mock_backtrace)
|
123
|
+
assert_equal(1, clean_trace.grep(/new_relic/).size,
|
124
|
+
"should not remove instances of new relic from backtrace but got: #{clean_trace.join("\n")}")
|
125
|
+
assert_equal(1, clean_trace.grep(/_trace/).size,
|
126
|
+
"should not remove trace method tags from method names but got: #{clean_trace.join("\n")}")
|
127
|
+
# assert (clean_trace.grep(/find/).size >= 3), "should see at least three frames with 'find' in them (#{e}): \n#{clean_trace.join("\n")}"
|
128
|
+
NewRelic::Control.instance['disable_backtrace_cleanup'] = false
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
def mock_backtrace
|
133
|
+
[
|
134
|
+
%q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1620:in `find_one_without_trace'},
|
135
|
+
%q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1620:in `find_one'},
|
136
|
+
%q{/home/app/gems/activerecord-2.3.12/lib/active_record/base.rb:1603:in `find_from_ids'},
|
137
|
+
%q{./test/new_relic/collection_helper_test.rb:112:in `test_strip_stackdump'},
|
138
|
+
%q{/home/app/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `__send__'},
|
139
|
+
%q{/home/app/gems/mocha-0.9.8/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb:19:in `run'},
|
140
|
+
%q{/home/app/test/unit/testsuite.rb:34:in `run'},
|
141
|
+
%q{/home/app/test/unit/testsuite.rb:33:in `each'},
|
142
|
+
%q{/home/app/test/unit/testsuite.rb:33:in `run'},
|
143
|
+
%q{/home/app/test/unit/testsuite.rb:34:in `run'},
|
144
|
+
%q{/home/app/test/unit/testsuite.rb:33:in `each'},
|
145
|
+
%q{/home/app/test/unit/testsuite.rb:33:in `run'},
|
146
|
+
%q{/home/app/test/unit/ui/testrunnermediator.rb:46:in `run_suite'}
|
147
|
+
]
|
148
|
+
end
|
127
149
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'/../../test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Control::ConfigurationTest < Test::Unit::TestCase
|
4
|
+
require 'new_relic/control/configuration'
|
5
|
+
include NewRelic::Control::Configuration
|
6
|
+
|
7
|
+
def setup
|
8
|
+
# The log stuff is memoized so let's clear it each time.
|
9
|
+
NewRelic::Control.instance.instance_variable_set '@log_path', nil
|
10
|
+
NewRelic::Control.instance.instance_variable_set '@log_file', nil
|
11
|
+
@root = ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
NewRelic::Control.instance.settings.delete('log_file_path')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_license_key_defaults_to_env_variable
|
19
|
+
ENV['NEWRELIC_LICENSE_KEY'] = nil
|
20
|
+
self.expects(:fetch).with('license_key', nil)
|
21
|
+
license_key
|
22
|
+
|
23
|
+
ENV['NEWRELIC_LICENSE_KEY'] = "a string"
|
24
|
+
self.expects(:fetch).with('license_key', 'a string')
|
25
|
+
license_key
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_log_path_uses_default_if_not_set
|
29
|
+
NewRelic::Control.instance.setup_log
|
30
|
+
assert_equal(File.expand_path("log/newrelic_agent.log"),
|
31
|
+
NewRelic::Control.instance.log_file)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_log_file_path_uses_given_value
|
35
|
+
Dir.stubs(:mkdir).returns(true)
|
36
|
+
NewRelic::Control.instance['log_file_path'] = 'lerg'
|
37
|
+
NewRelic::Control.instance.setup_log
|
38
|
+
assert_match(/\/lerg\/newrelic_agent.log/,
|
39
|
+
NewRelic::Control.instance.log_file)
|
40
|
+
NewRelic::Control.instance.settings.delete('log_file_path') # = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_server_side_config_ignores_yaml
|
44
|
+
settings.merge! 'ssl' => false, 'transaction_tracer' => {'enabled' => true, 'stack_trace_threshold' => 1.0}, 'error_collector' => {'enabled' => true, 'ignore_errors' => 'ActiveRecord::RecordNotFound'}, 'capture_params' => false
|
45
|
+
merge_server_side_config 'transaction_tracer.enabled' => false, 'error_collector.enabled' => false
|
46
|
+
assert_equal({'ssl' => false, 'transaction_tracer' => {'enabled' => false}, 'error_collector' => {'enabled' => false}}, settings)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_install_browser_monitoring
|
50
|
+
require(File.expand_path(File.join(File.dirname(__FILE__),
|
51
|
+
'/../../../lib/new_relic/rack/browser_monitoring')))
|
52
|
+
middleware = stub('middleware config')
|
53
|
+
config = stub('rails config', :middleware => middleware)
|
54
|
+
middleware.expects(:use).with(NewRelic::Rack::BrowserMonitoring)
|
55
|
+
NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => true }
|
56
|
+
NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
|
57
|
+
|
58
|
+
NewRelic::Control.instance.install_browser_monitoring(config)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_install_browser_monitoring_should_not_install_when_not_configured
|
62
|
+
middleware = stub('middleware config')
|
63
|
+
config = stub('rails config', :middleware => middleware)
|
64
|
+
middleware.expects(:use).never
|
65
|
+
NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => false }
|
66
|
+
NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
|
67
|
+
|
68
|
+
NewRelic::Control.instance.install_browser_monitoring(config)
|
69
|
+
|
70
|
+
NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => true }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_data_serialization_default_off
|
74
|
+
DependencyDetection.send(:class_variable_set, '@@items', [])
|
75
|
+
assert NewRelic::Control.instance.disable_serialization?
|
76
|
+
end
|
77
|
+
end
|