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
@@ -5,8 +5,13 @@ class NewRelic::DelayedJobInstrumentationTest < Test::Unit::TestCase
|
|
5
5
|
Object.const_set('Delayed', Module.new) unless defined?(Delayed)
|
6
6
|
::Delayed.const_set('Worker', Class.new) unless defined?(::Delayed::Worker)
|
7
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
|
+
|
8
13
|
NewRelic::Agent.stubs(:logger).raises(NoMethodError,
|
9
|
-
|
14
|
+
'temporarily not allowed')
|
10
15
|
NewRelic::Agent.stubs(:respond_to?).with(:logger).returns(false)
|
11
16
|
|
12
17
|
assert DependencyDetection.detect!
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
|
3
|
+
# Test logic around detecting or configuring dispatcher
|
4
|
+
class DispatcherTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
NewRelic::Agent.shutdown
|
8
|
+
NewRelic::Agent.reset_config
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_dispatcher_reported_to_environment_report(dispatcher)
|
12
|
+
NewRelic::Control.instance.local_env.gather_environment_info
|
13
|
+
key, value = NewRelic::Control.instance.local_env.snapshot.detect do |(k, v)|
|
14
|
+
k == "Dispatcher"
|
15
|
+
end
|
16
|
+
assert_equal dispatcher.to_s, value
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_detects_dispatcher_via_loaded_libraries
|
20
|
+
class << self
|
21
|
+
module ::PhusionPassenger
|
22
|
+
end
|
23
|
+
end
|
24
|
+
assert_equal :passenger, NewRelic::Agent.config[:dispatcher]
|
25
|
+
assert_dispatcher_reported_to_environment_report :passenger
|
26
|
+
ensure
|
27
|
+
Object.send(:remove_const, :PhusionPassenger)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_detects_dispatcher_via_ENV_NEW_RELIC_DISPATCHER
|
31
|
+
ENV['NEW_RELIC_DISPATCHER'] = "foobared"
|
32
|
+
NewRelic::Agent.reset_config
|
33
|
+
assert_equal :foobared, NewRelic::Agent.config[:dispatcher]
|
34
|
+
assert_dispatcher_reported_to_environment_report :foobared
|
35
|
+
ensure
|
36
|
+
ENV['NEW_RELIC_DISPATCHER'] = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_detects_dispatcher_via_ENV_NEWRELIC_DISPATCHER
|
40
|
+
ENV['NEWRELIC_DISPATCHER'] = "bazbang"
|
41
|
+
NewRelic::Agent.reset_config
|
42
|
+
assert_equal :bazbang, NewRelic::Agent.config[:dispatcher]
|
43
|
+
assert_dispatcher_reported_to_environment_report :bazbang
|
44
|
+
ensure
|
45
|
+
ENV['NEWRELIC_DISPATCHER'] = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_detects_dispatcher_based_on_arguments_to_manual_start
|
49
|
+
NewRelic::Agent.manual_start(:dispatcher => :resque)
|
50
|
+
assert_equal :resque, NewRelic::Agent.config[:dispatcher]
|
51
|
+
assert_dispatcher_reported_to_environment_report :resque
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack'
|
3
|
+
require 'uri'
|
4
|
+
require 'socket'
|
5
|
+
require 'timeout'
|
6
|
+
require 'ostruct'
|
7
|
+
require File.join(File.dirname(__FILE__), 'fakes_sending_data')
|
8
|
+
|
9
|
+
require 'json' if RUBY_VERSION >= '1.9'
|
10
|
+
|
11
|
+
module NewRelic
|
12
|
+
class FakeCollector
|
13
|
+
attr_accessor :agent_data, :mock
|
14
|
+
|
15
|
+
include FakesSendingData
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@id_counter = 0
|
19
|
+
@base_expectations = {
|
20
|
+
'get_redirect_host' => [200, {'return_value' => 'localhost'}],
|
21
|
+
'connect' => [200, {'return_value' => {"agent_run_id" => agent_run_id}}],
|
22
|
+
'get_agent_commands' => [200, {'return_value' => []}],
|
23
|
+
'metric_data' => [200, {'return_value' => [[{'name' => 'Some/Metric/Spec'}, 1]]}],
|
24
|
+
'sql_trace_data' => [200, {'return_value' => nil}],
|
25
|
+
'transaction_sample_data' => [200, {'return_value' => nil}],
|
26
|
+
'error_data' => [200, {'return_value' => nil}],
|
27
|
+
'shutdown' => [200, {'return_value' => nil}]
|
28
|
+
}
|
29
|
+
reset
|
30
|
+
end
|
31
|
+
|
32
|
+
def agent_run_id
|
33
|
+
@id_counter += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def call(env)
|
37
|
+
req = ::Rack::Request.new(env)
|
38
|
+
res = ::Rack::Response.new
|
39
|
+
uri = URI.parse(req.url)
|
40
|
+
if uri.path =~ /agent_listener\/\d+\/.+\/(\w+)/
|
41
|
+
method = $1
|
42
|
+
format = json_format?(uri) && RUBY_VERSION >= '1.9' ? :json : :pruby
|
43
|
+
if @mock.keys.include? method
|
44
|
+
res.status = @mock[method][0]
|
45
|
+
if format == :json
|
46
|
+
res.write JSON.dump(@mock[method][1])
|
47
|
+
else
|
48
|
+
res.write Marshal.dump(@mock[method][1])
|
49
|
+
end
|
50
|
+
else
|
51
|
+
res.status = 500
|
52
|
+
res.write "Method not found"
|
53
|
+
end
|
54
|
+
run_id = uri.query =~ /run_id=(\d+)/ ? $1 : nil
|
55
|
+
req.body.rewind
|
56
|
+
|
57
|
+
body = if format == :json
|
58
|
+
body = JSON.load(req.body.read)
|
59
|
+
else
|
60
|
+
body = Marshal.load(req.body.read)
|
61
|
+
end
|
62
|
+
@agent_data << OpenStruct.new(:action => method,
|
63
|
+
:body => body,
|
64
|
+
:run_id => run_id,
|
65
|
+
:format => format)
|
66
|
+
end
|
67
|
+
res.finish
|
68
|
+
end
|
69
|
+
|
70
|
+
def json_format?(uri)
|
71
|
+
uri.query && uri.query.include?('marshal_format=json')
|
72
|
+
end
|
73
|
+
|
74
|
+
def run(port=30303)
|
75
|
+
return if @thread && @thread.alive?
|
76
|
+
serve_on_port(port) do
|
77
|
+
@thread = Thread.new do
|
78
|
+
::Rack::Handler::WEBrick.run(self,
|
79
|
+
:Port => port,
|
80
|
+
:Logger => WEBrick::Log.new("/dev/null"),
|
81
|
+
:AccessLog => [nil, nil])
|
82
|
+
end
|
83
|
+
@thread.abort_on_exception = true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def serve_on_port(port)
|
88
|
+
if is_port_available?('127.0.0.1', port)
|
89
|
+
yield
|
90
|
+
loop do
|
91
|
+
break if !is_port_available?('127.0.0.1', port)
|
92
|
+
sleep 0.01
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def stop
|
98
|
+
return unless @thread.alive?
|
99
|
+
::Rack::Handler::WEBrick.shutdown
|
100
|
+
@thread.join
|
101
|
+
reset
|
102
|
+
end
|
103
|
+
|
104
|
+
def reset
|
105
|
+
@mock = @base_expectations.dup
|
106
|
+
@id_counter = 0
|
107
|
+
@agent_data = []
|
108
|
+
end
|
109
|
+
|
110
|
+
def is_port_available?(ip, port)
|
111
|
+
begin
|
112
|
+
Timeout::timeout(1) do
|
113
|
+
begin
|
114
|
+
s = TCPSocket.new(ip, port)
|
115
|
+
s.close
|
116
|
+
return false
|
117
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
118
|
+
return true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
rescue Timeout::Error
|
122
|
+
end
|
123
|
+
|
124
|
+
return true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# might we need this? I'll just leave it here for now
|
129
|
+
class FakeCollectorProcess < FakeCollector
|
130
|
+
def run(port=30303)
|
131
|
+
serve_on_port(port) do
|
132
|
+
@pid = Process.fork do
|
133
|
+
::Rack::Handler::WEBrick.run(self, :Port => port)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def stop
|
139
|
+
return unless @pid
|
140
|
+
Process.kill('QUIT', @pid)
|
141
|
+
Process.wait(@pid)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if $0 == __FILE__
|
147
|
+
require 'test/unit'
|
148
|
+
require 'net/http'
|
149
|
+
|
150
|
+
class FakeCollectorTest < Test::Unit::TestCase
|
151
|
+
def setup
|
152
|
+
@collector = NewRelic::FakeCollector.new
|
153
|
+
@collector.run
|
154
|
+
end
|
155
|
+
|
156
|
+
def teardown
|
157
|
+
@collector.stop
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_get_redirect
|
161
|
+
@collector.mock['get_redirect_host'] = [200, 'test.example.com']
|
162
|
+
response = invoke('get_redirect_host')
|
163
|
+
|
164
|
+
assert_equal 'test.example.com', response
|
165
|
+
assert_equal 'get_redirect_host', @collector.agent_data[0].action
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_connect
|
169
|
+
response = invoke('connect')
|
170
|
+
|
171
|
+
assert_equal 1, response['agent_run_id']
|
172
|
+
assert_equal 'connect', @collector.agent_data[0].action
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_metric_data
|
176
|
+
response = invoke('metric_data?run_id=1',
|
177
|
+
{'Foo/Bar' => [1,2,3], 'Baz/Cux' => [4,5,6]})
|
178
|
+
|
179
|
+
assert_equal 1, response['Some/Metric/Spec']
|
180
|
+
post = @collector.agent_data[0]
|
181
|
+
assert_equal 'metric_data', post.action
|
182
|
+
assert_equal({'Foo/Bar' => [1,2,3], 'Baz/Cux' => [4,5,6]}, post.body)
|
183
|
+
assert_equal 1, post.run_id.to_i
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_sql_trace_data
|
187
|
+
response = invoke('sql_trace_data?run_id=2',
|
188
|
+
['trace', 'trace', 'trace'])
|
189
|
+
|
190
|
+
assert_nil response
|
191
|
+
post = @collector.agent_data[0]
|
192
|
+
assert_equal 'sql_trace_data', post.action
|
193
|
+
assert_equal ['trace', 'trace', 'trace'], post.body
|
194
|
+
assert_equal 2, post.run_id.to_i
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_transaction_sample_data
|
198
|
+
response = invoke('transaction_sample_data?run_id=3',
|
199
|
+
['node', ['node', 'node'], 'node'])
|
200
|
+
|
201
|
+
assert_nil response
|
202
|
+
post = @collector.agent_data[0]
|
203
|
+
assert_equal 'transaction_sample_data', post.action
|
204
|
+
assert_equal ['node', ['node', 'node'], 'node'], post.body
|
205
|
+
assert_equal 3, post.run_id.to_i
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_transaction_sample_data_json
|
209
|
+
response = invoke('transaction_sample_data?run_id=3&marshal_format=json',
|
210
|
+
'["node",["node","node"],"node"]')
|
211
|
+
|
212
|
+
assert_equal '', response
|
213
|
+
post = @collector.agent_data[0]
|
214
|
+
assert_equal 'transaction_sample_data', post.action
|
215
|
+
assert_equal '["node",["node","node"],"node"]', post.body
|
216
|
+
assert_equal 3, post.run_id.to_i
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_error_data
|
220
|
+
response = invoke('error_data?run_id=4', ['error'])
|
221
|
+
|
222
|
+
assert_nil response
|
223
|
+
post = @collector.agent_data[0]
|
224
|
+
assert_equal 'error_data', post.action
|
225
|
+
assert_equal ['error'], post.body
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_shutdown
|
229
|
+
response = invoke('shutdown?run_id=1')
|
230
|
+
|
231
|
+
assert_nil response
|
232
|
+
assert_equal 'shutdown', @collector.agent_data[0].action
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_multiple_invokations
|
236
|
+
pid = Process.fork do
|
237
|
+
invoke('get_redirect_host')
|
238
|
+
invoke('connect')
|
239
|
+
invoke('metric_data?run_id=1')
|
240
|
+
invoke('transaction_sample_data?run_id=1')
|
241
|
+
invoke('shutdown?run_id=1')
|
242
|
+
end
|
243
|
+
invoke('get_redirect_host')
|
244
|
+
invoke('connect')
|
245
|
+
invoke('metric_data?run_id=2')
|
246
|
+
invoke('transaction_sample_data?run_id=2')
|
247
|
+
invoke('shutdown?run_id=2')
|
248
|
+
|
249
|
+
Process.wait(pid)
|
250
|
+
|
251
|
+
expected = ['get_redirect_host', 'connect', 'metric_data',
|
252
|
+
'transaction_sample_data', 'shutdown',
|
253
|
+
'get_redirect_host', 'connect', 'metric_data',
|
254
|
+
'transaction_sample_data', 'shutdown']
|
255
|
+
assert_equal expected.sort, @collector.agent_data.map(&:action).sort
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_reset
|
259
|
+
@collector.mock['get_redirect_host'] = [200, 'never!']
|
260
|
+
@collector.reset
|
261
|
+
assert_equal [200, 'localhost'], @collector.mock['get_redirect_host']
|
262
|
+
end
|
263
|
+
|
264
|
+
def invoke(method, post={}, code=200)
|
265
|
+
uri = URI.parse("http://127.0.0.1:30303/agent_listener/8/12345/#{method}")
|
266
|
+
request = Net::HTTP::Post.new("#{uri.path}?#{uri.query}")
|
267
|
+
if uri.query && uri.query.include?('marsha_format=json')
|
268
|
+
request.body = JSON.dump(post)
|
269
|
+
else
|
270
|
+
request.body = Marshal.dump(post)
|
271
|
+
end
|
272
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
273
|
+
http.request(request)
|
274
|
+
end
|
275
|
+
if uri.query && uri.query.include?('marshal_format=json')
|
276
|
+
JSON.load(response.body)
|
277
|
+
else
|
278
|
+
Marshal.load(response.body)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require File.join(File.dirname(__FILE__), 'fakes_sending_data')
|
3
|
+
|
4
|
+
module NewRelic
|
5
|
+
class FakeService
|
6
|
+
attr_accessor :request_timeout, :agent_id, :agent_data, :collector, :mock
|
7
|
+
|
8
|
+
include FakesSendingData
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@agent_data = []
|
12
|
+
@supported_methods = [ :connect, :metric_data, :transaction_sample_data,
|
13
|
+
:error_data, :sql_trace_data, :profile_data,
|
14
|
+
:get_agent_commands, :shutdown ]
|
15
|
+
@collector = NewRelic::Control::Server.new(:name => 'fakehost', :port => 0)
|
16
|
+
@id_counter = 0
|
17
|
+
@base_expectations = {
|
18
|
+
'get_redirect_host' => 'localhost',
|
19
|
+
'connect' => { 'agent_run_id' => agent_run_id },
|
20
|
+
'get_agent_commands' => [],
|
21
|
+
'metric_data' => [[{ 'name' => 'Some/Metric/Spec' }, 1]],
|
22
|
+
'sql_trace_data' => nil,
|
23
|
+
'transaction_sample_data' => nil,
|
24
|
+
'error_data' => nil,
|
25
|
+
'shutdown' => nil,
|
26
|
+
}
|
27
|
+
reset
|
28
|
+
end
|
29
|
+
|
30
|
+
def agent_run_id
|
31
|
+
@id_counter += 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset
|
35
|
+
@mock = @base_expectations.dup
|
36
|
+
@id_counter = 0
|
37
|
+
@agent_data = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_service(method, value)
|
41
|
+
@mock[method.to_s] = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(method, *args)
|
45
|
+
if @supported_methods.include?(method)
|
46
|
+
@agent_data << OpenStruct.new(:action => method, :params => args)
|
47
|
+
@mock[method.to_s]
|
48
|
+
else
|
49
|
+
super
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module FakesSendingData
|
3
|
+
def calls_for(method)
|
4
|
+
@agent_data. \
|
5
|
+
select { |d| d.action == method }. \
|
6
|
+
map { |d| d.body }
|
7
|
+
end
|
8
|
+
|
9
|
+
# Unpeel the inner layers of encoding applied by the JSON marshaller.
|
10
|
+
# I'm sorry.
|
11
|
+
def unpack_inner_blobs(req)
|
12
|
+
body = req.body
|
13
|
+
if req.format == :json
|
14
|
+
case req.action
|
15
|
+
when 'profile_data' then
|
16
|
+
body[0][4] = unpack(body[0][4])
|
17
|
+
when 'sql_trace_data' then
|
18
|
+
body[0][0][9] = unpack(body[0][0][9])
|
19
|
+
when 'transaction_sample_data' then
|
20
|
+
body[4] = unpack(body[4])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
body
|
24
|
+
end
|
25
|
+
|
26
|
+
def unpack(blob)
|
27
|
+
JSON.load(Zlib::Inflate.inflate(Base64.decode64(blob)))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..', 'test_helper'))
|
2
|
+
|
3
|
+
# Test logic around detecting or configuring framework
|
4
|
+
class FrameworkTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
|
8
|
+
# muck with this constant which forces the agent to load the
|
9
|
+
# NewRelic::Control::Frameworks::Test control so we can test the logic used
|
10
|
+
# to load the appropriate control object.
|
11
|
+
@old_newrelic_test_const = ::NewRelic::TEST
|
12
|
+
::NewRelic.send(:remove_const, :TEST)
|
13
|
+
|
14
|
+
NewRelic::Agent.shutdown
|
15
|
+
NewRelic::Agent.reset_config
|
16
|
+
|
17
|
+
# don't bomb out trying to load frameworks that don't exist.
|
18
|
+
NewRelic::Control.stubs(:new_instance).returns(stub :init_plugin => nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
# Put things back how we found them
|
23
|
+
::NewRelic.send(:const_set, :TEST, @old_newrelic_test_const)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_detects_framework_via_loaded_libraries
|
27
|
+
class << self
|
28
|
+
module ::Merb
|
29
|
+
module Plugins
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
assert_equal :merb, NewRelic::Agent.config[:framework]
|
34
|
+
ensure
|
35
|
+
Object.send(:remove_const, :Merb)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_detects_framework_via_ENV_NEW_RELIC_FRAMEWORK
|
39
|
+
ENV['NEW_RELIC_FRAMEWORK'] = "foobared"
|
40
|
+
NewRelic::Agent.reset_config
|
41
|
+
assert_equal :foobared, NewRelic::Agent.config[:framework]
|
42
|
+
ensure
|
43
|
+
ENV['NEW_RELIC_FRAMEWORK'] = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_detects_framework_via_ENV_NEWRELIC_FRAMEWORK
|
47
|
+
ENV['NEWRELIC_FRAMEWORK'] = "bazbang"
|
48
|
+
NewRelic::Agent.reset_config
|
49
|
+
assert_equal :bazbang, NewRelic::Agent.config[:framework]
|
50
|
+
ensure
|
51
|
+
ENV['NEWRELIC_FRAMEWORK'] = nil
|
52
|
+
end
|
53
|
+
end
|