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
@@ -5,11 +5,15 @@ require 'fileutils'
|
|
5
5
|
class BaseLoggingMethods
|
6
6
|
# stub class to enable testing of the module
|
7
7
|
include NewRelic::Control::LoggingMethods
|
8
|
+
include NewRelic::Control::Configuration
|
9
|
+
def root; "."; end
|
8
10
|
end
|
9
11
|
|
10
12
|
class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
|
11
13
|
def setup
|
12
14
|
@base = BaseLoggingMethods.new
|
15
|
+
@base.settings['log_file_path'] = 'log/'
|
16
|
+
@base.settings['log_file_name'] = 'newrelic_agent.log'
|
13
17
|
super
|
14
18
|
end
|
15
19
|
|
@@ -36,6 +40,7 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
|
|
36
40
|
|
37
41
|
def test_logbang_should_not_log
|
38
42
|
@base.expects(:should_log?).returns(false)
|
43
|
+
@base.stubs(:to_stdout)
|
39
44
|
assert_equal nil, @base.log!('whee')
|
40
45
|
end
|
41
46
|
|
@@ -89,20 +94,10 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
|
|
89
94
|
assert fake_logger.respond_to?(:format_message)
|
90
95
|
end
|
91
96
|
|
92
|
-
def test_setup_log_file_not_exist
|
93
|
-
@base.expects(:log_path).returns('logpath')
|
94
|
-
@base.expects(:log_file_name).returns('logfilename')
|
95
|
-
fake_logger = mock('logger')
|
96
|
-
@base.expects(:log).returns(fake_logger)
|
97
|
-
@base.setup_log
|
98
|
-
assert_equal nil, @base.instance_eval { @log }
|
99
|
-
assert_equal 'logpath/logfilename', @base.instance_eval { @log_file }
|
100
|
-
end
|
101
|
-
|
102
97
|
def test_setup_log_existing_file
|
103
98
|
fake_logger = mock('logger')
|
104
99
|
Logger.expects(:new).with('logpath/logfilename').returns(fake_logger)
|
105
|
-
@base.expects(:log_path).returns('logpath')
|
100
|
+
@base.expects(:log_path).returns('logpath').at_least_once
|
106
101
|
@base.expects(:log_file_name).returns('logfilename')
|
107
102
|
@base.expects(:set_log_format!).with(fake_logger)
|
108
103
|
@base.expects(:set_log_level!).with(fake_logger)
|
@@ -122,16 +117,15 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
|
|
122
117
|
end
|
123
118
|
|
124
119
|
def test_log_path_path_exists
|
125
|
-
@base.
|
126
|
-
|
127
|
-
|
128
|
-
assert_equal File.expand_path('log/'), @base.log_path
|
120
|
+
@base.settings['log_file_path'] = 'log'
|
121
|
+
assert File.directory?('log')
|
122
|
+
assert_equal File.expand_path('log'), @base.log_path
|
129
123
|
end
|
130
124
|
|
131
125
|
def test_log_path_path_created
|
132
126
|
path = File.expand_path('tmp/log_path_test')
|
133
127
|
@base.instance_eval { @log_path = nil }
|
134
|
-
@base.
|
128
|
+
@base.settings['log_file_path'] = 'tmp/log_path_test'
|
135
129
|
assert !File.directory?(path) || FileUtils.rmdir(path)
|
136
130
|
@base.expects(:log!).never
|
137
131
|
assert_equal path, @base.log_path
|
@@ -141,17 +135,51 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
|
|
141
135
|
def test_log_path_path_unable_to_create
|
142
136
|
path = File.expand_path('tmp/log_path_test')
|
143
137
|
@base.instance_eval { @log_path = nil }
|
144
|
-
@base.
|
138
|
+
@base.settings['log_file_path'] = 'tmp/log_path_test'
|
145
139
|
assert !File.directory?(path) || FileUtils.rmdir(path)
|
146
|
-
@base.expects(:log!).with("Error creating
|
147
|
-
Dir.expects(:mkdir).with(path).raises('cannot make directory bro!')
|
148
|
-
|
140
|
+
@base.expects(:log!).with("Error creating log directory tmp/log_path_test, using standard out for logging.", :warn)
|
141
|
+
Dir.expects(:mkdir).with(path).raises('cannot make directory bro!').twice # once for the relative directory, once for the directory relative to Rails.root
|
142
|
+
assert_nil @base.log_path
|
149
143
|
assert !File.directory?(path)
|
144
|
+
assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
|
150
145
|
end
|
151
146
|
|
152
147
|
def test_log_file_name
|
153
148
|
@base.expects(:fetch).with('log_file_name', 'newrelic_agent.log').returns('log_file_name')
|
154
149
|
assert_equal 'log_file_name', @base.log_file_name
|
155
150
|
end
|
156
|
-
end
|
157
151
|
|
152
|
+
def test_log_to_stdout_when_log_file_path_set_to_STDOUT
|
153
|
+
@base.stubs(:fetch).returns('whatever')
|
154
|
+
@base.expects(:fetch).with('log_file_path', 'log').returns('STDOUT')
|
155
|
+
Dir.expects(:mkdir).never
|
156
|
+
@base.setup_log
|
157
|
+
assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_logs_to_stdout_include_newrelic_prefix
|
161
|
+
@base.stubs(:fetch).returns('whatever')
|
162
|
+
@base.expects(:fetch).with('log_file_path', 'log').returns('STDOUT')
|
163
|
+
STDOUT.expects(:write).with(regexp_matches(/\*\* \[NewRelic\].*whee/))
|
164
|
+
@base.setup_log
|
165
|
+
@base.log.info('whee')
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_set_stdout_destination_from_NEW_RELIC_LOG_env_var
|
169
|
+
@base.stubs(:fetch).returns('whatever')
|
170
|
+
ENV['NEW_RELIC_LOG'] = 'stdout'
|
171
|
+
Dir.expects(:mkdir).never
|
172
|
+
@base.setup_log
|
173
|
+
assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
|
174
|
+
ENV['NEW_RELIC_LOG'] = nil
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_set_file_destination_from_NEW_RELIC_LOG_env_var
|
178
|
+
@base.stubs(:fetch).returns('whatever')
|
179
|
+
ENV['NEW_RELIC_LOG'] = 'log/file.log'
|
180
|
+
@base.setup_log
|
181
|
+
assert_equal 'log', File.basename(@base.log_path)
|
182
|
+
assert_equal 'file.log', @base.log_file_name
|
183
|
+
ENV['NEW_RELIC_LOG'] = nil
|
184
|
+
end
|
185
|
+
end
|
@@ -1,33 +1,34 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
|
2
|
-
class NewRelic::ControlTest < Test::Unit::TestCase
|
3
2
|
|
4
|
-
|
3
|
+
class NewRelic::ControlTest < Test::Unit::TestCase
|
4
|
+
attr_reader :control
|
5
5
|
|
6
6
|
def setup
|
7
|
-
|
8
7
|
NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
|
9
|
-
@
|
8
|
+
@control = NewRelic::Control.instance
|
10
9
|
raise 'oh geez, wrong class' unless NewRelic::Control.instance.is_a?(::NewRelic::Control::Frameworks::Test)
|
11
10
|
end
|
11
|
+
|
12
12
|
def shutdown
|
13
13
|
NewRelic::Agent.shutdown
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_cert_file_path
|
17
|
-
assert @
|
18
|
-
assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @
|
17
|
+
assert @control.cert_file_path
|
18
|
+
assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @control.cert_file_path
|
19
19
|
end
|
20
20
|
|
21
21
|
# This test does not actually use the ruby agent in any way - it's
|
22
22
|
# testing that the CA file we ship actually validates our server's
|
23
23
|
# certificate. It's used for customers who enable verify_certificate
|
24
24
|
def test_cert_file
|
25
|
+
return if ::RUBY_VERSION == '1.9.3'
|
25
26
|
require 'socket'
|
26
27
|
require 'openssl'
|
27
28
|
|
28
29
|
s = TCPSocket.new 'collector.newrelic.com', 443
|
29
30
|
ctx = OpenSSL::SSL::SSLContext.new
|
30
|
-
ctx.ca_file = @
|
31
|
+
ctx.ca_file = @control.cert_file_path
|
31
32
|
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
32
33
|
s = OpenSSL::SSL::SSLSocket.new s, ctx
|
33
34
|
s.connect
|
@@ -38,12 +39,13 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
38
39
|
# certificates in a non-customer-facing place before setting them
|
39
40
|
# live.
|
40
41
|
def test_staging_cert_file
|
42
|
+
return if ::RUBY_VERSION == '1.9.3'
|
41
43
|
require 'socket'
|
42
44
|
require 'openssl'
|
43
45
|
|
44
46
|
s = TCPSocket.new 'staging-collector.newrelic.com', 443
|
45
47
|
ctx = OpenSSL::SSL::SSLContext.new
|
46
|
-
ctx.ca_file = @
|
48
|
+
ctx.ca_file = @control.cert_file_path
|
47
49
|
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
48
50
|
s = OpenSSL::SSL::SSLSocket.new s, ctx
|
49
51
|
s.connect
|
@@ -51,39 +53,39 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
51
53
|
end
|
52
54
|
|
53
55
|
def test_monitor_mode
|
54
|
-
assert ! @
|
55
|
-
@
|
56
|
-
@
|
57
|
-
assert !@
|
58
|
-
@
|
59
|
-
assert ! @
|
60
|
-
@
|
61
|
-
assert @
|
62
|
-
@
|
63
|
-
assert !@
|
64
|
-
@
|
65
|
-
assert !@
|
66
|
-
@
|
67
|
-
assert @
|
56
|
+
assert ! @control.monitor_mode?
|
57
|
+
@control.settings.delete 'enabled'
|
58
|
+
@control.settings.delete 'monitor_mode'
|
59
|
+
assert !@control.monitor_mode?
|
60
|
+
@control['enabled'] = false
|
61
|
+
assert ! @control.monitor_mode?
|
62
|
+
@control['enabled'] = true
|
63
|
+
assert @control.monitor_mode?
|
64
|
+
@control['monitor_mode'] = nil
|
65
|
+
assert !@control.monitor_mode?
|
66
|
+
@control['monitor_mode'] = false
|
67
|
+
assert !@control.monitor_mode?
|
68
|
+
@control['monitor_mode'] = true
|
69
|
+
assert @control.monitor_mode?
|
68
70
|
ensure
|
69
|
-
@
|
70
|
-
@
|
71
|
+
@control['enabled'] = false
|
72
|
+
@control['monitor_mode'] = false
|
71
73
|
end
|
72
74
|
|
73
75
|
def test_test_config
|
74
76
|
if defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
|
75
|
-
assert_equal :rails3,
|
77
|
+
assert_equal :rails3, control.app
|
76
78
|
elsif defined?(Rails)
|
77
|
-
assert_equal :rails,
|
79
|
+
assert_equal :rails, control.app
|
78
80
|
else
|
79
|
-
assert_equal :test,
|
81
|
+
assert_equal :test, control.app
|
80
82
|
end
|
81
|
-
assert_equal :test,
|
82
|
-
assert_match /test/i,
|
83
|
-
assert("" ==
|
84
|
-
assert !
|
85
|
-
assert_equal false,
|
86
|
-
|
83
|
+
assert_equal :test, control.framework
|
84
|
+
assert_match /test/i, control.dispatcher_instance_id
|
85
|
+
assert("" == control.dispatcher.to_s, "Expected dispatcher to be empty, but was #{control.dispatcher.to_s}")
|
86
|
+
assert !control['enabled']
|
87
|
+
assert_equal false, control['monitor_mode']
|
88
|
+
control.local_env
|
87
89
|
end
|
88
90
|
|
89
91
|
def test_root
|
@@ -101,10 +103,10 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def test_resolve_ip
|
104
|
-
assert_equal nil,
|
105
|
-
assert_equal nil,
|
106
|
+
assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
|
107
|
+
assert_equal nil, control.send(:convert_to_ip_address, 'q1239988737.us')
|
106
108
|
# This will fail if you don't have a valid, accessible, DNS server
|
107
|
-
assert_equal '204.93.223.153',
|
109
|
+
assert_equal '204.93.223.153', control.send(:convert_to_ip_address, 'collector.newrelic.com')
|
108
110
|
end
|
109
111
|
|
110
112
|
class FakeResolv
|
@@ -120,7 +122,7 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
120
122
|
old_ipsocket = IPSocket
|
121
123
|
Object.instance_eval { remove_const :Resolv}
|
122
124
|
Object.instance_eval {remove_const:'IPSocket' }
|
123
|
-
assert_equal(nil,
|
125
|
+
assert_equal(nil, control.send(:convert_to_ip_address, 'collector.newrelic.com'), "DNS is down, should be no IP for server")
|
124
126
|
|
125
127
|
Object.instance_eval {const_set('Resolv', old_resolv); const_set('IPSocket', old_ipsocket)}
|
126
128
|
# these are here to make sure that the constant tomfoolery above
|
@@ -129,12 +131,10 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
129
131
|
assert_equal old_ipsocket, IPSocket
|
130
132
|
end
|
131
133
|
|
132
|
-
|
133
|
-
|
134
134
|
def test_config_yaml_erb
|
135
|
-
assert_equal 'heyheyhey',
|
136
|
-
assert_equal '',
|
137
|
-
assert_equal '',
|
135
|
+
assert_equal 'heyheyhey', control['erb_value']
|
136
|
+
assert_equal '', control['message']
|
137
|
+
assert_equal '', control['license_key']
|
138
138
|
end
|
139
139
|
|
140
140
|
def test_appnames
|
@@ -142,22 +142,25 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def test_config_booleans
|
145
|
-
assert_equal
|
146
|
-
assert_equal
|
147
|
-
assert_nil
|
148
|
-
assert_equal
|
149
|
-
assert_equal
|
145
|
+
assert_equal control['tval'], true
|
146
|
+
assert_equal control['fval'], false
|
147
|
+
assert_nil control['not_in_yaml_val']
|
148
|
+
assert_equal control['yval'], true
|
149
|
+
assert_equal control['sval'], 'sure'
|
150
150
|
end
|
151
|
+
|
151
152
|
def test_config_apdex
|
152
|
-
assert_equal 1.1,
|
153
|
+
assert_equal 1.1, control.apdex_t
|
153
154
|
end
|
155
|
+
|
154
156
|
# def test_transaction_threshold
|
155
157
|
# assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
|
156
158
|
# assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
157
159
|
# end
|
160
|
+
|
158
161
|
def test_log_file_name
|
159
162
|
NewRelic::Control.instance.setup_log
|
160
|
-
assert_match /newrelic_agent.log$/,
|
163
|
+
assert_match /newrelic_agent.log$/, control.instance_variable_get('@log_file')
|
161
164
|
end
|
162
165
|
|
163
166
|
# def test_transaction_threshold__apdex
|
@@ -167,26 +170,84 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
167
170
|
# end
|
168
171
|
|
169
172
|
def test_transaction_threshold__default
|
170
|
-
|
171
173
|
forced_start :transaction_tracer => { :transaction_threshold => nil}
|
172
|
-
assert_nil
|
174
|
+
assert_nil control['transaction_tracer']['transaction_threshold']
|
173
175
|
assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
174
176
|
end
|
175
177
|
|
176
178
|
def test_transaction_threshold__override
|
177
179
|
forced_start :transaction_tracer => { :transaction_threshold => 1}
|
178
|
-
assert_equal 1,
|
180
|
+
assert_equal 1, control['transaction_tracer']['transaction_threshold']
|
179
181
|
assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
|
180
182
|
end
|
183
|
+
|
184
|
+
def test_transaction_tracer_disabled
|
185
|
+
forced_start(:transaction_tracer => { :enabled => false },
|
186
|
+
:developer_mode => false, :monitor_mode => true)
|
187
|
+
NewRelic::Agent::Agent.instance.check_transaction_sampler_status
|
188
|
+
|
189
|
+
assert(!NewRelic::Agent::Agent.instance.transaction_sampler.enabled?,
|
190
|
+
'transaction tracer enabled when config calls for disabled')
|
191
|
+
|
192
|
+
@control['developer_mode'] = true
|
193
|
+
@control['monitor_mode'] = false
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_sql_tracer_disabled
|
197
|
+
forced_start(:slow_sql => { :enabled => false }, :monitor_mode => true)
|
198
|
+
NewRelic::Agent::Agent.instance.check_sql_sampler_status
|
199
|
+
|
200
|
+
assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
|
201
|
+
'sql tracer enabled when config calls for disabled')
|
202
|
+
|
203
|
+
@control['monitor_mode'] = false
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_sql_tracer_disabled_with_record_sql_false
|
207
|
+
forced_start(:slow_sql => { :enabled => true, :record_sql => 'off' })
|
208
|
+
NewRelic::Agent::Agent.instance.check_sql_sampler_status
|
209
|
+
|
210
|
+
assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
|
211
|
+
'sql tracer enabled when config calls for disabled')
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_sql_tracer_disabled_when_tt_disabled
|
215
|
+
forced_start(:transaction_tracer => { :enabled => false },
|
216
|
+
:slow_sql => { :enabled => true },
|
217
|
+
:developer_mode => false, :monitor_mode => true)
|
218
|
+
NewRelic::Agent::Agent.instance.check_sql_sampler_status
|
219
|
+
|
220
|
+
assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
|
221
|
+
'sql enabled when transaction tracer disabled')
|
222
|
+
|
223
|
+
@control['developer_mode'] = true
|
224
|
+
@control['monitor_mode'] = false
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_sql_tracer_disabled_when_tt_disabled_by_server
|
228
|
+
forced_start(:slow_sql => { :enabled => true },
|
229
|
+
:transaction_tracer => { :enabled => true },
|
230
|
+
:monitor_mode => true)
|
231
|
+
NewRelic::Agent::Agent.instance.check_sql_sampler_status
|
232
|
+
NewRelic::Agent::Agent.instance.finish_setup('collect_traces' => false)
|
233
|
+
|
234
|
+
assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
|
235
|
+
'sql enabled when tracing disabled by server')
|
236
|
+
|
237
|
+
@control['monitor_mode'] = false
|
238
|
+
end
|
239
|
+
|
181
240
|
def test_merging_options
|
182
241
|
NewRelic::Control.send :public, :merge_options
|
183
|
-
@
|
242
|
+
@control.merge_options :api_port => 66, :transaction_tracer => { :explain_threshold => 2.0 }
|
184
243
|
assert_equal 66, NewRelic::Control.instance['api_port']
|
185
244
|
assert_equal 2.0, NewRelic::Control.instance['transaction_tracer']['explain_threshold']
|
186
245
|
assert_equal 'raw', NewRelic::Control.instance['transaction_tracer']['record_sql']
|
187
246
|
end
|
247
|
+
|
188
248
|
private
|
189
|
-
|
249
|
+
|
250
|
+
def forced_start(overrides={})
|
190
251
|
NewRelic::Agent.manual_start overrides
|
191
252
|
# This is to force the agent to start again.
|
192
253
|
NewRelic::Agent.instance.stubs(:started?).returns(nil)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::DelayedJobInstrumentationTest < Test::Unit::TestCase
|
4
|
+
def test_skip_logging_if_no_logger_found
|
5
|
+
Object.const_set('Delayed', Module.new) unless defined?(Delayed)
|
6
|
+
::Delayed.const_set('Worker', Class.new) unless defined?(::Delayed::Worker)
|
7
|
+
|
8
|
+
# on JRuby we need to make sure the worker isn't running, it might
|
9
|
+
# try to log
|
10
|
+
worker = NewRelic::Agent.agent.instance_variable_get(:@worker_loop)
|
11
|
+
worker.stop if worker
|
12
|
+
|
13
|
+
NewRelic::Agent.stubs(:logger).raises(NoMethodError,
|
14
|
+
'temporarily not allowed')
|
15
|
+
NewRelic::Agent.stubs(:respond_to?).with(:logger).returns(false)
|
16
|
+
|
17
|
+
assert DependencyDetection.detect!
|
18
|
+
|
19
|
+
Object.class_eval { remove_const('Delayed') }
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack'
|
3
|
+
require 'uri'
|
4
|
+
require 'socket'
|
5
|
+
require 'timeout'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
module NewRelic
|
9
|
+
class FakeCollector
|
10
|
+
attr_accessor :agent_data, :mock
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@id_counter = 0
|
14
|
+
@base_expectations = {
|
15
|
+
'get_redirect_host' => 'localhost',
|
16
|
+
'connect' => { 'agent_run_id' => agent_run_id },
|
17
|
+
'metric_data' => { 'Some/Metric/Spec' => 1 },
|
18
|
+
'sql_trace_data' => nil,
|
19
|
+
'transaction_sample_data' => nil,
|
20
|
+
'error_data' => nil,
|
21
|
+
'shutdown' => nil,
|
22
|
+
}
|
23
|
+
reset
|
24
|
+
end
|
25
|
+
|
26
|
+
def agent_run_id
|
27
|
+
@id_counter += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
req = ::Rack::Request.new(env)
|
32
|
+
res = ::Rack::Response.new
|
33
|
+
uri = URI.parse(req.url)
|
34
|
+
if uri.path =~ /agent_listener\/\d+\/.+\/(\w+)/
|
35
|
+
method = $1
|
36
|
+
if @mock.keys.include? method
|
37
|
+
res.write Marshal.dump(@mock[method])
|
38
|
+
else
|
39
|
+
res.status = 500
|
40
|
+
res.write "Method not found"
|
41
|
+
end
|
42
|
+
run_id = uri.query =~ /run_id=(\d+)/ ? $1 : nil
|
43
|
+
req.body.rewind
|
44
|
+
@agent_data << OpenStruct.new(:action => method,
|
45
|
+
:body => Marshal.load(req.body.read),
|
46
|
+
:run_id => run_id)
|
47
|
+
end
|
48
|
+
res.finish
|
49
|
+
end
|
50
|
+
|
51
|
+
def run(port=30303)
|
52
|
+
if is_port_available?('127.0.0.1', port)
|
53
|
+
@thread = Thread.new do
|
54
|
+
::Rack::Handler::WEBrick.run(self, :Port => port)
|
55
|
+
end
|
56
|
+
loop do
|
57
|
+
break if !is_port_available?('127.0.0.1', port)
|
58
|
+
sleep 0.01
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def stop
|
64
|
+
::Rack::Handler::WEBrick.shutdown
|
65
|
+
@thread.join
|
66
|
+
end
|
67
|
+
|
68
|
+
def reset
|
69
|
+
@mock = @base_expectations.dup
|
70
|
+
@id_counter = 0
|
71
|
+
@agent_data = []
|
72
|
+
end
|
73
|
+
|
74
|
+
def is_port_available?(ip, port)
|
75
|
+
begin
|
76
|
+
Timeout::timeout(1) do
|
77
|
+
begin
|
78
|
+
s = TCPSocket.new(ip, port)
|
79
|
+
s.close
|
80
|
+
return false
|
81
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
82
|
+
return true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
rescue Timeout::Error
|
86
|
+
end
|
87
|
+
|
88
|
+
return true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if $0 == __FILE__
|
94
|
+
require 'test/unit'
|
95
|
+
require 'net/http'
|
96
|
+
|
97
|
+
class FakeCollectorTest < Test::Unit::TestCase
|
98
|
+
def setup
|
99
|
+
@collector = NewRelic::FakeCollector.new
|
100
|
+
@collector.run
|
101
|
+
end
|
102
|
+
|
103
|
+
def teardown
|
104
|
+
@collector.stop
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_get_redirect
|
108
|
+
@collector.mock['get_redirect_host'] = 'test.example.com'
|
109
|
+
response = invoke('get_redirect_host')
|
110
|
+
|
111
|
+
assert_equal 'test.example.com', response
|
112
|
+
assert_equal 'get_redirect_host', @collector.agent_data[0].action
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_connect
|
116
|
+
response = invoke('connect')
|
117
|
+
|
118
|
+
assert_equal 1, response['agent_run_id']
|
119
|
+
assert_equal 'connect', @collector.agent_data[0].action
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_metric_data
|
123
|
+
response = invoke('metric_data?run_id=1',
|
124
|
+
{'Foo/Bar' => [1,2,3], 'Baz/Cux' => [4,5,6]})
|
125
|
+
|
126
|
+
assert_equal 1, response['Some/Metric/Spec']
|
127
|
+
post = @collector.agent_data[0]
|
128
|
+
assert_equal 'metric_data', post.action
|
129
|
+
assert_equal({'Foo/Bar' => [1,2,3], 'Baz/Cux' => [4,5,6]}, post.body)
|
130
|
+
assert_equal 1, post.run_id.to_i
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_sql_trace_data
|
134
|
+
response = invoke('sql_trace_data?run_id=2',
|
135
|
+
['trace', 'trace', 'trace'])
|
136
|
+
|
137
|
+
assert_nil response
|
138
|
+
post = @collector.agent_data[0]
|
139
|
+
assert_equal 'sql_trace_data', post.action
|
140
|
+
assert_equal ['trace', 'trace', 'trace'], post.body
|
141
|
+
assert_equal 2, post.run_id.to_i
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_transaction_sample_data
|
145
|
+
response = invoke('transaction_sample_data?run_id=3',
|
146
|
+
['node', ['node', 'node'], 'node'])
|
147
|
+
|
148
|
+
assert_nil response
|
149
|
+
post = @collector.agent_data[0]
|
150
|
+
assert_equal 'transaction_sample_data', post.action
|
151
|
+
assert_equal ['node', ['node', 'node'], 'node'], post.body
|
152
|
+
assert_equal 3, post.run_id.to_i
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_error_data
|
156
|
+
response = invoke('error_data?run_id=4', ['error'])
|
157
|
+
|
158
|
+
assert_nil response
|
159
|
+
post = @collector.agent_data[0]
|
160
|
+
assert_equal 'error_data', post.action
|
161
|
+
assert_equal ['error'], post.body
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_shutdown
|
165
|
+
response = invoke('shutdown?run_id=1')
|
166
|
+
|
167
|
+
assert_nil response
|
168
|
+
assert_equal 'shutdown', @collector.agent_data[0].action
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_multiple_invokations
|
172
|
+
pid = Process.fork do
|
173
|
+
invoke('get_redirect_host')
|
174
|
+
invoke('connect')
|
175
|
+
invoke('metric_data?run_id=1')
|
176
|
+
invoke('transaction_sample_data?run_id=1')
|
177
|
+
invoke('shutdown?run_id=1')
|
178
|
+
end
|
179
|
+
invoke('get_redirect_host')
|
180
|
+
invoke('connect')
|
181
|
+
invoke('metric_data?run_id=2')
|
182
|
+
invoke('transaction_sample_data?run_id=2')
|
183
|
+
invoke('shutdown?run_id=2')
|
184
|
+
|
185
|
+
Process.wait(pid)
|
186
|
+
|
187
|
+
expected = ['get_redirect_host', 'connect', 'metric_data',
|
188
|
+
'transaction_sample_data', 'shutdown',
|
189
|
+
'get_redirect_host', 'connect', 'metric_data',
|
190
|
+
'transaction_sample_data', 'shutdown']
|
191
|
+
assert_equal expected.sort, @collector.agent_data.map(&:action).sort
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_reset
|
195
|
+
@collector.mock['get_redirect_host'] = 'never!'
|
196
|
+
@collector.reset
|
197
|
+
assert_equal 'localhost', @collector.mock['get_redirect_host']
|
198
|
+
end
|
199
|
+
|
200
|
+
def invoke(method, post={}, code=200)
|
201
|
+
uri = URI.parse("http://127.0.0.1:30303/agent_listener/8/12345/#{method}")
|
202
|
+
request = Net::HTTP::Post.new("#{uri.path}?#{uri.query}")
|
203
|
+
request.body = Marshal.dump(post)
|
204
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
205
|
+
http.request(request)
|
206
|
+
end
|
207
|
+
Marshal.load(response.body)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|