wd_newrelic_rpm 3.3.4.1 → 3.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.project +23 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +317 -39
- data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
- data/Gemfile +16 -0
- data/LICENSE +1 -1
- data/{README.rdoc → README.md} +71 -55
- data/Rakefile +62 -0
- data/bin/mongrel_rpm +1 -1
- data/config.dot +290 -0
- data/config/database.yml +5 -0
- data/init.rb +31 -0
- data/lib/new_relic/agent.rb +31 -60
- data/lib/new_relic/agent/agent.rb +277 -502
- data/lib/new_relic/agent/agent_logger.rb +165 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +36 -50
- data/lib/new_relic/agent/browser_monitoring.rb +114 -61
- data/lib/new_relic/agent/busy_calculator.rb +14 -6
- data/lib/new_relic/agent/configuration.rb +74 -0
- data/lib/new_relic/agent/configuration/defaults.rb +126 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
- data/lib/new_relic/agent/configuration/manager.rb +136 -0
- data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
- data/lib/new_relic/agent/configuration/server_source.rb +27 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
- data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
- data/lib/new_relic/agent/database.rb +39 -26
- data/lib/new_relic/agent/error_collector.rb +48 -49
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
- data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
- data/lib/new_relic/agent/instrumentation/net.rb +1 -1
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
- data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
- data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
- data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
- data/lib/new_relic/agent/method_tracer.rb +11 -9
- data/lib/new_relic/agent/new_relic_service.rb +379 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
- data/lib/new_relic/agent/pipe_service.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
- data/lib/new_relic/agent/sql_sampler.rb +31 -74
- data/lib/new_relic/agent/stats_engine.rb +0 -5
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
- data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
- data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
- data/lib/new_relic/agent/thread.rb +32 -0
- data/lib/new_relic/agent/thread_profiler.rb +306 -0
- data/lib/new_relic/agent/transaction_info.rb +24 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
- data/lib/new_relic/agent/transaction_sampler.rb +49 -65
- data/lib/new_relic/agent/worker_loop.rb +31 -25
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +19 -10
- data/lib/new_relic/control.rb +1 -3
- data/lib/new_relic/control/class_methods.rb +10 -5
- data/lib/new_relic/control/frameworks/merb.rb +0 -6
- data/lib/new_relic/control/frameworks/rails.rb +30 -45
- data/lib/new_relic/control/frameworks/rails3.rb +23 -18
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +2 -23
- data/lib/new_relic/control/instance_methods.rb +35 -73
- data/lib/new_relic/control/instrumentation.rb +7 -12
- data/lib/new_relic/control/server_methods.rb +17 -19
- data/lib/new_relic/delayed_job_injection.rb +2 -2
- data/lib/new_relic/helper.rb +34 -0
- data/lib/new_relic/language_support.rb +56 -37
- data/lib/new_relic/local_environment.rb +32 -67
- data/lib/new_relic/metric_data.rb +10 -2
- data/lib/new_relic/metric_spec.rb +7 -3
- data/lib/new_relic/noticed_error.rb +32 -9
- data/lib/new_relic/rack.rb +4 -0
- data/lib/new_relic/rack/browser_monitoring.rb +34 -25
- data/lib/new_relic/rack/developer_mode.rb +3 -0
- data/lib/new_relic/rack/error_collector.rb +56 -0
- data/lib/new_relic/stats.rb +9 -7
- data/lib/new_relic/transaction_sample.rb +19 -18
- data/lib/new_relic/transaction_sample/segment.rb +13 -15
- data/lib/new_relic/version.rb +19 -3
- data/lib/newrelic_rpm.rb +1 -1
- data/lib/tasks/tests.rake +6 -8
- data/newrelic.yml +15 -32
- data/newrelic_rpm.gemspec +224 -43
- data/newrelic_rpm.gemspec.erb +54 -0
- data/test/config/newrelic.yml +4 -3
- data/test/config/test_control.rb +18 -18
- data/test/fixtures/gemspec_no_build.rb +442 -0
- data/test/fixtures/gemspec_with_build.rb +442 -0
- data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
- data/test/intentional_fail.rb +10 -0
- data/test/multiverse/.gitignore +10 -0
- data/test/multiverse/README.md +85 -0
- data/test/multiverse/lib/multiverse/color.rb +13 -0
- data/test/multiverse/lib/multiverse/envfile.rb +66 -0
- data/test/multiverse/lib/multiverse/environment.rb +16 -0
- data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
- data/test/multiverse/lib/multiverse/runner.rb +44 -0
- data/test/multiverse/lib/multiverse/suite.rb +162 -0
- data/test/multiverse/script/run_one +3 -0
- data/test/multiverse/script/runner +9 -0
- data/test/multiverse/suites/active_record/Envfile +13 -0
- data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
- data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
- data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
- data/test/multiverse/suites/agent_only/Envfile +4 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
- data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
- data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
- data/test/multiverse/suites/config_file_loading/Envfile +7 -0
- data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
- data/test/multiverse/suites/datamapper/Envfile +8 -0
- data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
- data/test/multiverse/suites/logging/Envfile +4 -0
- data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
- data/test/multiverse/suites/logging/logging_test.rb +143 -0
- data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
- data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
- data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
- data/test/multiverse/suites/no_load/Envfile +2 -0
- data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
- data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
- data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
- data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
- data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
- data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
- data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
- data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
- data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
- data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
- data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
- data/test/multiverse/suites/rails_3_views/Envfile +16 -0
- data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
- data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
- data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
- data/test/multiverse/suites/resque/Envfile +21 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/dump.rdb +0 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
- data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
- data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
- data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
- data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
- data/test/multiverse/suites/sinatra/Envfile +13 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
- data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
- data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
- data/test/multiverse/test/multiverse_test.rb +55 -0
- data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
- data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
- data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
- data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
- data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
- data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
- data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
- data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
- data/test/new_relic/agent/agent/connect_test.rb +151 -227
- data/test/new_relic/agent/agent/start_test.rb +68 -118
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +116 -30
- data/test/new_relic/agent/agent_test_controller.rb +1 -1
- data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
- data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
- data/test/new_relic/agent/busy_calculator_test.rb +7 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
- data/test/new_relic/agent/configuration/manager_test.rb +204 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
- data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
- data/test/new_relic/agent/database_test.rb +12 -11
- data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
- data/test/new_relic/agent/error_collector_test.rb +33 -19
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
- data/test/new_relic/agent/method_tracer_test.rb +7 -6
- data/test/new_relic/agent/mock_scope_listener.rb +3 -0
- data/test/new_relic/agent/new_relic_service_test.rb +376 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
- data/test/new_relic/agent/pipe_service_test.rb +113 -0
- data/test/new_relic/agent/rpm_agent_test.rb +27 -50
- data/test/new_relic/agent/sql_sampler_test.rb +81 -56
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
- data/test/new_relic/agent/stats_engine_test.rb +17 -8
- data/test/new_relic/agent/thread_profiler_test.rb +537 -0
- data/test/new_relic/agent/thread_test.rb +89 -0
- data/test/new_relic/agent/threaded_test.rb +65 -0
- data/test/new_relic/agent/transaction_info_test.rb +45 -4
- data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
- data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
- data/test/new_relic/agent/worker_loop_test.rb +26 -11
- data/test/new_relic/agent_test.rb +113 -33
- data/test/new_relic/collection_helper_test.rb +7 -8
- data/test/new_relic/command/deployments_test.rb +18 -2
- data/test/new_relic/control/class_methods_test.rb +0 -18
- data/test/new_relic/control/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control_test.rb +96 -137
- data/test/new_relic/delayed_job_injection_test.rb +6 -1
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +283 -0
- data/test/new_relic/fake_service.rb +53 -0
- data/test/new_relic/fakes_sending_data.rb +30 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/load_test.rb +13 -0
- data/test/new_relic/local_environment_test.rb +11 -11
- data/test/new_relic/metric_data_test.rb +45 -16
- data/test/new_relic/noticed_error_test.rb +24 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
- data/test/new_relic/rack/developer_mode_test.rb +13 -7
- data/test/new_relic/rack/error_collector_test.rb +74 -0
- data/test/new_relic/stats_test.rb +10 -0
- data/test/new_relic/transaction_sample/segment_test.rb +23 -4
- data/test/new_relic/transaction_sample_test.rb +47 -2
- data/test/new_relic/version_number_test.rb +32 -0
- data/test/script/build_test_gem.sh +9 -3
- data/test/script/ci.sh +108 -35
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +1 -0
- data/test/test_helper.rb +68 -18
- data/ui/helpers/developer_mode_helper.rb +21 -11
- data/ui/views/layouts/newrelic_default.rhtml +1 -0
- data/ui/views/newrelic/file/images/arrow-close.png +0 -0
- data/ui/views/newrelic/file/images/arrow-open.png +0 -0
- data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
- data/ui/views/newrelic/file/images/file_icon.png +0 -0
- data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
- data/ui/views/newrelic/show_sample.rhtml +1 -1
- data/ui/views/newrelic/threads.rhtml +2 -10
- data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
- metadata +191 -65
- data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
- data/lib/new_relic/control/configuration.rb +0 -206
- data/lib/new_relic/control/logging_methods.rb +0 -143
- data/lib/new_relic/data_serialization.rb +0 -151
- data/test/new_relic/control/configuration_test.rb +0 -84
- data/test/new_relic/control/logging_methods_test.rb +0 -185
- data/test/new_relic/data_serialization_test.rb +0 -208
@@ -3,9 +3,18 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
3
3
|
require 'new_relic/agent/agent'
|
4
4
|
include NewRelic::Agent::Agent::Start
|
5
5
|
|
6
|
+
def setup
|
7
|
+
ENV['NEW_RELIC_APP_NAME'] = 'start_test'
|
8
|
+
NewRelic::Agent.reset_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
ENV['NEW_RELIC_APP_NAME'] = nil
|
13
|
+
NewRelic::Agent.reset_config
|
14
|
+
end
|
15
|
+
|
6
16
|
def test_already_started_positive
|
7
|
-
|
8
|
-
control.expects(:log!).with("Agent Started Already!", :error)
|
17
|
+
::Logger.any_instance.expects(:error).with("Agent Started Already!")
|
9
18
|
self.expects(:started?).returns(true)
|
10
19
|
assert already_started?, "should have already started"
|
11
20
|
end
|
@@ -16,39 +25,15 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
16
25
|
end
|
17
26
|
|
18
27
|
def test_disabled_positive
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
with_config(:agent_enabled => false) do
|
29
|
+
assert disabled?
|
30
|
+
end
|
22
31
|
end
|
23
32
|
|
24
33
|
def test_disabled_negative
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_log_dispatcher_positive
|
31
|
-
control = mocked_control
|
32
|
-
log = mocked_log
|
33
|
-
control.expects(:dispatcher).returns('Y U NO SERVE WEBPAGE')
|
34
|
-
log.expects(:info).with("Dispatcher: Y U NO SERVE WEBPAGE")
|
35
|
-
log_dispatcher
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_log_dispatcher_negative
|
39
|
-
control = mocked_control
|
40
|
-
log = mocked_log
|
41
|
-
control.expects(:dispatcher).returns('')
|
42
|
-
log.expects(:info).with("No dispatcher detected.")
|
43
|
-
log_dispatcher
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_log_app_names
|
47
|
-
control = mocked_control
|
48
|
-
log = mocked_log
|
49
|
-
control.expects(:app_names).returns(%w(zam zam zabam))
|
50
|
-
log.expects(:info).with("Application: zam, zam, zabam")
|
51
|
-
log_app_names
|
34
|
+
with_config(:agent_enabled => true) do
|
35
|
+
assert !disabled?
|
36
|
+
end
|
52
37
|
end
|
53
38
|
|
54
39
|
def test_check_config_and_start_agent_disabled
|
@@ -70,26 +55,20 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
70
55
|
end
|
71
56
|
|
72
57
|
def test_check_config_and_start_agent_normal
|
73
|
-
self.expects(:monitoring?).returns(true)
|
74
|
-
self.expects(:has_correct_license_key?).returns(true)
|
75
|
-
self.expects(:using_forking_dispatcher?).returns(false)
|
76
|
-
control = mocked_control
|
77
|
-
control.expects(:sync_startup).returns(false)
|
78
58
|
self.expects(:start_worker_thread)
|
79
59
|
self.expects(:install_exit_handler)
|
80
|
-
|
60
|
+
with_config(:sync_startup => false, :monitor_mode => true, :license_key => 'a' * 40) do
|
61
|
+
check_config_and_start_agent
|
62
|
+
end
|
81
63
|
end
|
82
64
|
|
83
65
|
def test_check_config_and_start_agent_sync
|
84
|
-
self.expects(:monitoring?).returns(true)
|
85
|
-
self.expects(:has_correct_license_key?).returns(true)
|
86
|
-
self.expects(:using_forking_dispatcher?).returns(false)
|
87
|
-
control = mocked_control
|
88
|
-
control.expects(:sync_startup).returns(true)
|
89
66
|
self.expects(:connect_in_foreground)
|
90
67
|
self.expects(:start_worker_thread)
|
91
68
|
self.expects(:install_exit_handler)
|
92
|
-
|
69
|
+
with_config(:sync_startup => true, :monitor_mode => true, :license_key => 'a' * 40) do
|
70
|
+
check_config_and_start_agent
|
71
|
+
end
|
93
72
|
end
|
94
73
|
|
95
74
|
def test_connect_in_foreground
|
@@ -103,8 +82,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
103
82
|
private :at_exit
|
104
83
|
|
105
84
|
def test_install_exit_handler_positive
|
106
|
-
control = mocked_control
|
107
|
-
control.expects(:send_data_on_exit).returns(true)
|
108
85
|
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
109
86
|
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
110
87
|
self.expects(:using_sinatra?).returns(false)
|
@@ -112,69 +89,54 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
112
89
|
# test the shutdown logic. It's somewhat unfortunate, but we can't
|
113
90
|
# kill the interpreter during a test.
|
114
91
|
self.expects(:shutdown)
|
115
|
-
|
92
|
+
with_config(:send_data_on_exit => true) do
|
93
|
+
install_exit_handler
|
94
|
+
end
|
116
95
|
end
|
117
96
|
|
118
97
|
def test_install_exit_handler_negative
|
119
|
-
|
120
|
-
|
121
|
-
|
98
|
+
with_config(:send_data_on_exit => false) do
|
99
|
+
install_exit_handler
|
100
|
+
end
|
101
|
+
# should not raise excpetion
|
122
102
|
end
|
123
103
|
|
124
104
|
def test_install_exit_handler_weird_ruby
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_notify_log_file_location_positive
|
139
|
-
log = mocked_log
|
140
|
-
NewRelic::Control.instance.expects(:log_file).returns('./')
|
141
|
-
log.expects(:send).with(:info, "Agent Log at ./")
|
142
|
-
notify_log_file_location
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_notify_log_file_location_negative
|
146
|
-
log = mocked_log
|
147
|
-
NewRelic::Control.instance.expects(:log_file).returns(nil)
|
148
|
-
notify_log_file_location
|
105
|
+
with_config(:send_data_one_exit => true) do
|
106
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
107
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(false)
|
108
|
+
self.expects(:using_sinatra?).returns(true)
|
109
|
+
install_exit_handler
|
110
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(false)
|
111
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('jruby').returns(true)
|
112
|
+
install_exit_handler
|
113
|
+
NewRelic::LanguageSupport.expects(:using_engine?).with('rbx').returns(true)
|
114
|
+
install_exit_handler
|
115
|
+
end
|
149
116
|
end
|
150
117
|
|
151
118
|
def test_monitoring_positive
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
assert monitoring?
|
119
|
+
with_config(:monitor_mode => true) do
|
120
|
+
assert monitoring?
|
121
|
+
end
|
156
122
|
end
|
157
123
|
|
158
124
|
def test_monitoring_negative
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
log.expects(:send).with(:warn, "Agent configured not to send data in this environment - edit newrelic.yml to change this")
|
163
|
-
assert !monitoring?
|
125
|
+
with_config(:monitor_mode => false) do
|
126
|
+
assert !monitoring?
|
127
|
+
end
|
164
128
|
end
|
165
129
|
|
166
130
|
def test_has_license_key_positive
|
167
|
-
|
168
|
-
|
169
|
-
|
131
|
+
with_config(:license_key => 'a' * 40) do
|
132
|
+
assert has_license_key?
|
133
|
+
end
|
170
134
|
end
|
171
135
|
|
172
136
|
def test_has_license_key_negative
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
log.expects(:send).with(:error, 'No license key found. Please edit your newrelic.yml file and insert your license key.')
|
177
|
-
assert !has_license_key?
|
137
|
+
with_config(:license_key => false) do
|
138
|
+
assert !has_license_key?
|
139
|
+
end
|
178
140
|
end
|
179
141
|
|
180
142
|
def test_has_correct_license_key_positive
|
@@ -189,47 +151,42 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
189
151
|
end
|
190
152
|
|
191
153
|
def test_correct_license_length_positive
|
192
|
-
|
193
|
-
|
194
|
-
|
154
|
+
with_config(:license_key => 'a' * 40) do
|
155
|
+
assert correct_license_length
|
156
|
+
end
|
195
157
|
end
|
196
158
|
|
197
159
|
def test_correct_license_length_negative
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
log.expects(:send).with(:error, "Invalid license key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
202
|
-
assert !correct_license_length
|
160
|
+
with_config(:license_key => 'a' * 30) do
|
161
|
+
assert !correct_license_length
|
162
|
+
end
|
203
163
|
end
|
204
164
|
|
205
165
|
def test_using_forking_dispatcher_positive
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
log.expects(:send).with(:info, "Connecting workers after forking.")
|
210
|
-
assert using_forking_dispatcher?
|
166
|
+
with_config(:dispatcher => :passenger) do
|
167
|
+
assert using_forking_dispatcher?
|
168
|
+
end
|
211
169
|
end
|
212
170
|
|
213
171
|
def test_using_forking_dispatcher_negative
|
214
|
-
|
215
|
-
|
216
|
-
|
172
|
+
with_config(:dispatcher => :frobnitz) do
|
173
|
+
assert !using_forking_dispatcher?
|
174
|
+
end
|
217
175
|
end
|
218
176
|
|
219
177
|
def test_log_unless_positive
|
220
178
|
# should not log
|
221
179
|
assert log_unless(true, :warn, "DURRR")
|
222
180
|
end
|
181
|
+
|
223
182
|
def test_log_unless_negative
|
224
183
|
# should log
|
225
|
-
|
226
|
-
log.expects(:send).with(:warn, "DURRR")
|
184
|
+
expects_logging(:warn, "DURRR")
|
227
185
|
assert !log_unless(false, :warn, "DURRR")
|
228
186
|
end
|
229
187
|
|
230
188
|
def test_log_if_positive
|
231
|
-
|
232
|
-
log.expects(:send).with(:warn, "WHEE")
|
189
|
+
expects_logging(:warn, "WHEE")
|
233
190
|
assert log_if(true, :warn, "WHEE")
|
234
191
|
end
|
235
192
|
|
@@ -239,13 +196,6 @@ class NewRelic::Agent::Agent::StartTest < Test::Unit::TestCase
|
|
239
196
|
|
240
197
|
private
|
241
198
|
|
242
|
-
def mocked_log
|
243
|
-
fake_log = mock('log')
|
244
|
-
self.stubs(:log).returns(fake_log)
|
245
|
-
fake_log
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
199
|
def mocked_control
|
250
200
|
fake_control = mock('control')
|
251
201
|
self.stubs(:control).returns(fake_control)
|
@@ -7,8 +7,6 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
7
7
|
self.expects(:catch_errors).yields
|
8
8
|
self.expects(:connect).with('connection_options')
|
9
9
|
@connected = true
|
10
|
-
self.expects(:check_transaction_sampler_status)
|
11
|
-
self.expects(:check_sql_sampler_status)
|
12
10
|
self.expects(:log_worker_loop_start)
|
13
11
|
self.expects(:create_and_run_worker_loop)
|
14
12
|
deferred_work!('connection_options')
|
@@ -18,62 +16,24 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
18
16
|
self.expects(:catch_errors).yields
|
19
17
|
self.expects(:connect).with('connection_options')
|
20
18
|
@connected = false
|
21
|
-
fake_log = mocked_log
|
22
|
-
fake_log.expects(:debug).with("No connection. Worker thread ending.")
|
23
19
|
deferred_work!('connection_options')
|
24
20
|
end
|
25
21
|
|
26
|
-
def test_check_transaction_sampler_status_enabled
|
27
|
-
control = mocked_control
|
28
|
-
control.expects(:developer_mode?).returns(false)
|
29
|
-
@should_send_samples = true
|
30
|
-
@transaction_sampler = mock('transaction_sampler')
|
31
|
-
@transaction_sampler.expects(:enable)
|
32
|
-
check_transaction_sampler_status
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_check_transaction_sampler_status_devmode
|
36
|
-
control = mocked_control
|
37
|
-
control.expects(:developer_mode?).returns(true)
|
38
|
-
@should_send_samples = false
|
39
|
-
@transaction_sampler = mock('transaction_sampler')
|
40
|
-
@transaction_sampler.expects(:enable)
|
41
|
-
check_transaction_sampler_status
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_check_transaction_sampler_status_disabled
|
45
|
-
control = mocked_control
|
46
|
-
control.expects(:developer_mode?).returns(false)
|
47
|
-
@should_send_samples = false
|
48
|
-
@transaction_sampler = mock('transaction_sampler')
|
49
|
-
@transaction_sampler.expects(:disable)
|
50
|
-
check_transaction_sampler_status
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_log_worker_loop_start
|
54
|
-
@report_period = 30
|
55
|
-
log = mocked_log
|
56
|
-
log.expects(:info).with("Reporting performance data every 30 seconds.")
|
57
|
-
log.expects(:debug).with("Running worker loop")
|
58
|
-
log_worker_loop_start
|
59
|
-
end
|
60
|
-
|
61
22
|
def test_create_and_run_worker_loop
|
62
|
-
@report_period = 30
|
63
23
|
@should_send_samples = true
|
64
24
|
wl = mock('worker loop')
|
65
25
|
NewRelic::Agent::WorkerLoop.expects(:new).returns(wl)
|
66
26
|
wl.expects(:run).with(30).yields
|
67
|
-
self.expects(:
|
68
|
-
|
27
|
+
self.expects(:transmit_data)
|
28
|
+
with_config(:data_report_period => 30) do
|
29
|
+
create_and_run_worker_loop
|
30
|
+
end
|
69
31
|
end
|
70
32
|
|
71
33
|
def test_handle_force_restart
|
72
34
|
# hooray for methods with no branches
|
73
|
-
error = mock('
|
74
|
-
|
75
|
-
error.expects(:message).returns('a message')
|
76
|
-
log.expects(:info).with('a message')
|
35
|
+
error = mock(:message => 'a message')
|
36
|
+
|
77
37
|
self.expects(:reset_stats)
|
78
38
|
self.expects(:sleep).with(30)
|
79
39
|
|
@@ -87,37 +47,22 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
87
47
|
end
|
88
48
|
|
89
49
|
def test_handle_force_disconnect
|
90
|
-
error = mock('
|
91
|
-
|
92
|
-
log = mocked_log
|
93
|
-
log.expects(:error).with("New Relic forced this agent to disconnect (a message)")
|
50
|
+
error = mock(:message => 'a message')
|
51
|
+
|
94
52
|
self.expects(:disconnect)
|
95
53
|
handle_force_disconnect(error)
|
96
54
|
end
|
97
55
|
|
98
56
|
def test_handle_server_connection_problem
|
99
|
-
|
100
|
-
|
101
|
-
log = mocked_log
|
102
|
-
log.expects(:error).with('Unable to establish connection with the server. Run with log level set to debug for more information.')
|
103
|
-
error.expects(:class).returns(error_class)
|
104
|
-
error_class.expects(:name).returns('an error class')
|
105
|
-
error.expects(:message).returns('a message')
|
106
|
-
error.expects(:backtrace).returns(['first line', 'second line'])
|
107
|
-
log.expects(:debug).with("an error class: a message\nfirst line")
|
57
|
+
error = StandardError.new('a message')
|
58
|
+
|
108
59
|
self.expects(:disconnect)
|
109
60
|
handle_server_connection_problem(error)
|
110
61
|
end
|
111
62
|
|
112
63
|
def test_handle_other_error
|
113
|
-
|
114
|
-
|
115
|
-
log = mocked_log
|
116
|
-
error.expects(:class).returns(error_class)
|
117
|
-
error_class.expects(:name).returns('an error class')
|
118
|
-
error.expects(:message).returns('a message')
|
119
|
-
error.expects(:backtrace).returns(['first line', 'second line'])
|
120
|
-
log.expects(:error).with("Terminating worker loop: an error class: a message\n first line\n second line")
|
64
|
+
error = StandardError.new('a message')
|
65
|
+
|
121
66
|
self.expects(:disconnect)
|
122
67
|
handle_other_error(error)
|
123
68
|
end
|
@@ -137,13 +82,6 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
137
82
|
|
138
83
|
private
|
139
84
|
|
140
|
-
def mocked_log
|
141
|
-
fake_log = mock('log')
|
142
|
-
self.stubs(:log).returns(fake_log)
|
143
|
-
fake_log
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
85
|
def mocked_control
|
148
86
|
fake_control = mock('control')
|
149
87
|
self.stubs(:control).returns(fake_control)
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/agent_logger'
|
3
|
+
|
4
|
+
class AgentLoggerTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@config = {
|
7
|
+
:log_file_path => "log/",
|
8
|
+
:log_file_name => "testlog.log",
|
9
|
+
:log_level => :info,
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initalizes_from_config
|
14
|
+
override_logger = stub(:level=)
|
15
|
+
::Logger.stubs(:new).with(any_parameters).returns(override_logger)
|
16
|
+
|
17
|
+
logger = NewRelic::Agent::AgentLogger.new(@config)
|
18
|
+
assert_equal(override_logger, logger.instance_variable_get(:@log))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_initalizes_from_override
|
22
|
+
override_logger = stub(:level=)
|
23
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
24
|
+
assert_equal override_logger, logger.instance_variable_get(:@log)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_forwards_calls_to_logger
|
28
|
+
[:fatal, :error, :warn, :info, :debug].each do |level|
|
29
|
+
override_logger = stub(:level=)
|
30
|
+
override_logger.expects(level).with(any_parameters)
|
31
|
+
|
32
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
33
|
+
|
34
|
+
logger.send(level, "Boo!")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def test_forwards_calls_to_logger_with_multiple_arguments
|
40
|
+
[:fatal, :error, :warn, :info, :debug].each do |level|
|
41
|
+
override_logger = stub(:level=)
|
42
|
+
override_logger.expects(level).with("What\nup?")
|
43
|
+
|
44
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
45
|
+
|
46
|
+
logger.send(level, "What", "up?")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_passing_exceptions_gets_pretty_formatting
|
51
|
+
caught = nil
|
52
|
+
begin
|
53
|
+
raise Exception.new("Boo!")
|
54
|
+
rescue Exception => e
|
55
|
+
caught = e
|
56
|
+
end
|
57
|
+
|
58
|
+
# Checking if it looks like message includes backtrace
|
59
|
+
override_logger = stub(:level=)
|
60
|
+
override_logger.expects(:debug).with {|msg| msg.include?("test_") }
|
61
|
+
|
62
|
+
NewRelic::Agent::AgentLogger.new(@config, "", override_logger).debug(e)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_wont_log_if_agent_not_enabled
|
66
|
+
::Logger.stubs(:new).with("/dev/null").returns(stub(:level=)).at_least_once
|
67
|
+
|
68
|
+
@config[:agent_enabled] = false
|
69
|
+
logger = NewRelic::Agent::AgentLogger.new(@config)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_logs_to_nul_if_dev_null_not_there
|
73
|
+
File.stubs(:exists?).with("/dev/null").returns(false)
|
74
|
+
File.stubs(:exists?).with("NUL").returns(true)
|
75
|
+
|
76
|
+
::Logger.stubs(:new).with("NUL").returns(stub(:level=)).once
|
77
|
+
|
78
|
+
@config[:agent_enabled] = false
|
79
|
+
logger = NewRelic::Agent::AgentLogger.new(@config)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_maps_log_levels
|
83
|
+
assert_equal Logger::FATAL, NewRelic::Agent::AgentLogger.log_level_for(:fatal)
|
84
|
+
assert_equal Logger::ERROR, NewRelic::Agent::AgentLogger.log_level_for(:error)
|
85
|
+
assert_equal Logger::WARN, NewRelic::Agent::AgentLogger.log_level_for(:warn)
|
86
|
+
assert_equal Logger::INFO, NewRelic::Agent::AgentLogger.log_level_for(:info)
|
87
|
+
assert_equal Logger::DEBUG, NewRelic::Agent::AgentLogger.log_level_for(:debug)
|
88
|
+
|
89
|
+
assert_equal Logger::INFO, NewRelic::Agent::AgentLogger.log_level_for("")
|
90
|
+
assert_equal Logger::INFO, NewRelic::Agent::AgentLogger.log_level_for(:unknown)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_sets_log_level
|
94
|
+
override_logger = mock()
|
95
|
+
override_logger.expects(:level=).with(Logger::DEBUG)
|
96
|
+
@config[:log_level] = :debug
|
97
|
+
|
98
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_log_to_stdout_and_warns_if_failed_on_create
|
102
|
+
NewRelic::Agent::AgentLogger.any_instance.stubs(:find_or_create_file_path).returns(nil)
|
103
|
+
|
104
|
+
stdout = stub(:level=)
|
105
|
+
stdout.expects(:warn)
|
106
|
+
::Logger.stubs(:new).with(STDOUT).returns(stdout)
|
107
|
+
|
108
|
+
logger = NewRelic::Agent::AgentLogger.new(@config)
|
109
|
+
assert_equal stdout, logger.instance_variable_get(:@log)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_log_to_stdout_based_on_config
|
113
|
+
@config[:log_file_path] = "STDOUT"
|
114
|
+
|
115
|
+
stdout = stub(:level=)
|
116
|
+
stdout.expects(:warn).never
|
117
|
+
::Logger.stubs(:new).with(STDOUT).returns(stdout)
|
118
|
+
|
119
|
+
logger = NewRelic::Agent::AgentLogger.new(@config)
|
120
|
+
assert_equal stdout, logger.instance_variable_get(:@log)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_startup_purges_memory_logger
|
124
|
+
[:fatal, :error, :warn, :info, :debug].each do |level|
|
125
|
+
::NewRelic::Agent::StartupLogger.instance.send(level, "boo!")
|
126
|
+
|
127
|
+
override_logger = stub(:level=)
|
128
|
+
override_logger.expects(level).with("boo!")
|
129
|
+
|
130
|
+
NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_format_message_allows_nil_backtrace
|
135
|
+
override_logger = stub(:level=)
|
136
|
+
override_logger.expects(:debug)
|
137
|
+
|
138
|
+
logger = ::NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
139
|
+
|
140
|
+
logger.debug(Exception.new("Look Ma, no backtrace!"))
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
def test_logs_to_stdout_if_fails_on_file
|
145
|
+
stdout = stub_everything()
|
146
|
+
::Logger.stubs(:new).with(STDOUT).returns(stdout)
|
147
|
+
::Logger.stubs(:new).with(instance_of(String)).raises(Errno::EACCES)
|
148
|
+
|
149
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "")
|
150
|
+
|
151
|
+
assert_equal stdout, logger.instance_variable_get(:@log)
|
152
|
+
end
|
153
|
+
end
|