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
@@ -0,0 +1 @@
|
|
1
|
+
gemfile "#noop"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__),'..', '..', '..','test_helper'))
|
2
|
+
require 'new_relic/agent/agent'
|
3
|
+
require 'ostruct'
|
4
|
+
|
2
5
|
class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
3
|
-
require 'new_relic/agent/agent'
|
4
|
-
|
5
|
-
# I don't like this, we should be testing a third party, not ourselves -Jon
|
6
6
|
include NewRelic::Agent::Agent::Connect
|
7
7
|
|
8
8
|
def setup
|
@@ -11,7 +11,26 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
11
11
|
@connect_attempts = 1
|
12
12
|
@connect_retry_period = 0
|
13
13
|
@transaction_sampler = NewRelic::Agent::TransactionSampler.new
|
14
|
-
@sql_sampler = NewRelic::Agent::SqlSampler.new
|
14
|
+
@sql_sampler = NewRelic::Agent::SqlSampler.new
|
15
|
+
@error_collector = NewRelic::Agent::ErrorCollector.new
|
16
|
+
server = NewRelic::Control::Server.new('localhost', 30303)
|
17
|
+
@service = NewRelic::Agent::NewRelicService.new('abcdef', server)
|
18
|
+
@test_config = { :developer_mode => true }
|
19
|
+
NewRelic::Agent.config.apply_config(@test_config)
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
NewRelic::Agent.config.remove_config(@test_config)
|
24
|
+
end
|
25
|
+
|
26
|
+
def control
|
27
|
+
fake_control = OpenStruct.new('local_env' => OpenStruct.new('snapshot' => []))
|
28
|
+
fake_control.instance_eval do
|
29
|
+
def [](key)
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
fake_control
|
15
34
|
end
|
16
35
|
|
17
36
|
def test_tried_to_connect?
|
@@ -61,7 +80,6 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
61
80
|
def test_should_retry_true
|
62
81
|
@keep_retrying = true
|
63
82
|
@connect_attempts = 1
|
64
|
-
log.expects(:info).once
|
65
83
|
self.expects(:increment_retry_period!).once
|
66
84
|
assert should_retry?, "should retry in this circumstance"
|
67
85
|
assert_equal 2, @connect_attempts, "should be on the second attempt"
|
@@ -86,287 +104,203 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
86
104
|
end
|
87
105
|
|
88
106
|
def test_log_error
|
89
|
-
error =
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
log.expects(:error).with("Error establishing connection with New Relic Service at server: message")
|
96
|
-
log.expects(:debug).with("line\nsecondline")
|
107
|
+
error = StandardError.new("message")
|
108
|
+
|
109
|
+
expects_logging(:error,
|
110
|
+
includes("Error establishing connection with New Relic Service"), \
|
111
|
+
instance_of(StandardError))
|
112
|
+
|
97
113
|
log_error(error)
|
98
114
|
end
|
99
115
|
|
100
116
|
def test_handle_license_error
|
101
|
-
error = mock(
|
117
|
+
error = mock(:message => "error message")
|
102
118
|
self.expects(:disconnect).once
|
103
|
-
log.expects(:error).once.with("error message")
|
104
|
-
log.expects(:info).once.with("Visit NewRelic.com to obtain a valid license key, or to upgrade your account.")
|
105
|
-
error.expects(:message).returns("error message")
|
106
119
|
handle_license_error(error)
|
107
120
|
end
|
108
121
|
|
109
|
-
def test_log_seed_token
|
110
|
-
fake_control = mocked_control
|
111
|
-
fake_control.expects(:validate_seed).times(2).returns("many seeds")
|
112
|
-
fake_control.expects(:validate_token).once.returns("a token, man")
|
113
|
-
log.expects(:debug).with("Connecting with validation seed/token: many seeds/a token, man").once
|
114
|
-
log_seed_token
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_no_seed_token
|
118
|
-
fake_control = mocked_control
|
119
|
-
fake_control.expects(:validate_seed).once.returns(nil)
|
120
|
-
log.expects(:debug).never
|
121
|
-
log_seed_token
|
122
|
-
end
|
123
|
-
|
124
|
-
def mocks_for_positive_environment_for_connect(value_for_control)
|
125
|
-
control = mocked_control
|
126
|
-
control.expects(:'[]').with('send_environment_info').once.returns(value_for_control)
|
127
|
-
fake_env = mock('local_env')
|
128
|
-
fake_env.expects(:snapshot).once.returns("snapshot")
|
129
|
-
control.expects(:local_env).once.returns(fake_env)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_environment_for_connect_nil
|
133
|
-
mocks_for_positive_environment_for_connect(nil)
|
134
|
-
assert_equal 'snapshot', environment_for_connect
|
135
|
-
end
|
136
|
-
|
137
122
|
def test_environment_for_connect_positive
|
138
|
-
|
139
|
-
|
123
|
+
fake_env = stub('local_env', :discovered_dispatcher => nil)
|
124
|
+
fake_env.expects(:snapshot).returns("snapshot")
|
125
|
+
NewRelic::Control.instance.expects(:local_env).at_least_once.returns(fake_env)
|
126
|
+
with_config(:send_environment_info => true) do
|
127
|
+
assert_equal 'snapshot', environment_for_connect
|
128
|
+
end
|
140
129
|
end
|
141
130
|
|
142
131
|
def test_environment_for_connect_negative
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_validate_settings
|
149
|
-
control = mocked_control
|
150
|
-
control.expects(:validate_seed).once
|
151
|
-
control.expects(:validate_token).once
|
152
|
-
assert_equal({:seed => nil, :token => nil}, validate_settings)
|
132
|
+
with_config(:send_environment_info => false) do
|
133
|
+
assert_equal [], environment_for_connect
|
134
|
+
end
|
153
135
|
end
|
154
136
|
|
155
137
|
def test_connect_settings
|
156
138
|
control = mocked_control
|
157
|
-
|
158
|
-
control.expects(:settings)
|
159
|
-
self.expects(:validate_settings)
|
139
|
+
NewRelic::Agent.config.expects(:app_names)
|
160
140
|
self.expects(:environment_for_connect)
|
161
|
-
keys = %w(pid host app_name language agent_version environment settings
|
141
|
+
keys = %w(pid host app_name language agent_version environment settings)
|
162
142
|
value = connect_settings
|
163
143
|
keys.each do |k|
|
164
144
|
assert(value.has_key?(k.to_sym), "should include the key #{k}")
|
165
145
|
end
|
166
146
|
end
|
167
147
|
|
168
|
-
def test_configure_error_collector_base
|
169
|
-
fake_collector = mocked_error_collector
|
170
|
-
fake_collector.expects(:config_enabled).returns(false)
|
171
|
-
fake_collector.expects(:enabled=).with(false)
|
172
|
-
log.expects(:debug).with("Errors will not be sent to the New Relic service.")
|
173
|
-
configure_error_collector!(false)
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_configure_error_collector_enabled
|
177
|
-
fake_collector = mocked_error_collector
|
178
|
-
fake_collector.expects(:config_enabled).returns(true)
|
179
|
-
fake_collector.expects(:enabled=).with(true)
|
180
|
-
log.expects(:debug).with("Errors will be sent to the New Relic service.")
|
181
|
-
configure_error_collector!(true)
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_configure_error_collector_server_disabled
|
185
|
-
fake_collector = mocked_error_collector
|
186
|
-
fake_collector.expects(:config_enabled).returns(true)
|
187
|
-
fake_collector.expects(:enabled=).with(false)
|
188
|
-
log.expects(:debug).with("Errors will not be sent to the New Relic service.")
|
189
|
-
configure_error_collector!(false)
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_enable_random_samples
|
193
|
-
sampling_rate = 10
|
194
|
-
ts = @transaction_sampler = mock('ts')
|
195
|
-
ts.expects(:random_sampling=).with(true)
|
196
|
-
ts.expects(:sampling_rate=).with(sampling_rate)
|
197
|
-
ts.expects(:sampling_rate).returns(sampling_rate)
|
198
|
-
log.expects(:info).with("Transaction sampling enabled, rate = 10")
|
199
|
-
enable_random_samples!(sampling_rate)
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_enable_random_samples_with_no_sampling_rate
|
203
|
-
# testing that we set a sane default for sampling rate
|
204
|
-
sampling_rate = 0
|
205
|
-
ts = @transaction_sampler = mock('ts')
|
206
|
-
ts.expects(:random_sampling=).with(true)
|
207
|
-
ts.expects(:sampling_rate=).with(10)
|
208
|
-
ts.expects(:sampling_rate).returns(10)
|
209
|
-
log.expects(:info).with("Transaction sampling enabled, rate = 10")
|
210
|
-
enable_random_samples!(sampling_rate)
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_config_transaction_tracer
|
214
|
-
NewRelic::Control.instance.settings['transaction_tracer'] = {
|
215
|
-
'enabled' => true,
|
216
|
-
'random_sample' => false,
|
217
|
-
'explain_threshold' => 0.75,
|
218
|
-
'explain_enabled' => true
|
219
|
-
}
|
220
|
-
|
221
|
-
config_transaction_tracer
|
222
|
-
|
223
|
-
assert @transaction_sampler.enabled?
|
224
|
-
assert_equal 0.75, @transaction_sampler.explain_threshold
|
225
|
-
assert @transaction_sampler.explain_enabled
|
226
|
-
# assert_equal 1.5, @transaction_sampler.transaction_threshold
|
227
|
-
end
|
228
|
-
|
229
148
|
def test_configure_transaction_tracer_with_random_sampling
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
149
|
+
with_config(:'transaction_tracer.transaction_threshold' => 5,
|
150
|
+
:'transaction_tracer.random_sample' => true) do
|
151
|
+
sample = TransactionSampleTestHelper.make_sql_transaction
|
152
|
+
@transaction_sampler.store_sample(sample)
|
153
|
+
|
154
|
+
assert_equal sample, @transaction_sampler.instance_variable_get(:@random_sample)
|
155
|
+
end
|
238
156
|
end
|
239
157
|
|
240
158
|
def test_configure_transaction_tracer_positive
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
configure_transaction_tracer!(true, 10)
|
245
|
-
assert @should_send_samples
|
246
|
-
assert_equal 5, @transaction_sampler.slow_capture_threshold
|
159
|
+
with_config(:'transaction_tracer.enabled' => true) do
|
160
|
+
assert @transaction_sampler.enabled?
|
161
|
+
end
|
247
162
|
end
|
248
163
|
|
249
164
|
def test_configure_transaction_tracer_negative
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
assert !@should_send_samples
|
165
|
+
with_config(:'transaction_tracer.enabled' => false) do
|
166
|
+
assert @transaction_sampler.enabled?
|
167
|
+
end
|
254
168
|
end
|
255
169
|
|
256
170
|
def test_configure_transaction_tracer_server_disabled
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
171
|
+
config = NewRelic::Agent::Configuration::ServerSource.new('collect_traces' => false,
|
172
|
+
'developer_mode' => false)
|
173
|
+
with_config(config) do
|
174
|
+
assert !@transaction_sampler.enabled?
|
175
|
+
end
|
261
176
|
end
|
262
177
|
|
263
178
|
def test_apdex_f
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
def test_apdex_f_threshold_positive
|
269
|
-
NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'apdex_f' }
|
270
|
-
assert apdex_f_threshold?
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_apdex_f_threshold_negative
|
274
|
-
NewRelic::Control.instance.settings['transaction_tracer'] = { 'transaction_threshold' => 'WHEE' }
|
275
|
-
assert !apdex_f_threshold?
|
179
|
+
with_config(:apdex_t => 10) do
|
180
|
+
assert_equal 40, apdex_f
|
181
|
+
end
|
276
182
|
end
|
277
183
|
|
278
184
|
def test_set_sql_recording_default
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
185
|
+
with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
|
186
|
+
assert_equal(:obfuscated, NewRelic::Agent::Database.record_sql_method,
|
187
|
+
"should default to :obfuscated, was #{NewRelic::Agent::Database.record_sql_method}")
|
188
|
+
end
|
283
189
|
end
|
284
190
|
|
285
191
|
def test_set_sql_recording_off
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
192
|
+
with_config(:'transaction_tracer.record_sql' => 'off') do
|
193
|
+
assert_equal(:off, NewRelic::Agent::Database.record_sql_method,
|
194
|
+
"should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
|
195
|
+
end
|
290
196
|
end
|
291
197
|
|
292
198
|
def test_set_sql_recording_none
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
199
|
+
with_config(:'transaction_tracer.record_sql' => 'none') do
|
200
|
+
assert_equal(:off, NewRelic::Agent::Database.record_sql_method,
|
201
|
+
"should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
|
202
|
+
end
|
297
203
|
end
|
298
204
|
|
299
205
|
def test_set_sql_recording_raw
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
206
|
+
with_config(:'transaction_tracer.record_sql' => 'raw') do
|
207
|
+
assert_equal(:raw, NewRelic::Agent::Database.record_sql_method,
|
208
|
+
"should be set to :raw, was #{NewRelic::Agent::Database.record_sql_method}")
|
209
|
+
end
|
304
210
|
end
|
305
211
|
|
306
212
|
def test_set_sql_recording_falsy
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
213
|
+
with_config(:'transaction_tracer.record_sql' => false) do
|
214
|
+
assert_equal(:off, NewRelic::Agent::Database.record_sql_method,
|
215
|
+
"should be set to :off, was #{NewRelic::Agent::Database.record_sql_method}")
|
216
|
+
end
|
311
217
|
end
|
312
218
|
|
313
|
-
def
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
log_sql_transmission_warning?
|
219
|
+
def test_query_server_for_configuration
|
220
|
+
self.expects(:connect_to_server).returns("so happy")
|
221
|
+
self.expects(:finish_setup).with("so happy")
|
222
|
+
query_server_for_configuration
|
318
223
|
end
|
319
224
|
|
320
|
-
def
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
end
|
225
|
+
def test_connect_to_server_gets_config_from_collector
|
226
|
+
NewRelic::Agent.manual_start
|
227
|
+
service = NewRelic::FakeService.new
|
228
|
+
NewRelic::Agent::Agent.instance.service = service
|
229
|
+
service.mock['connect'] = {'agent_run_id' => 23, 'config' => 'a lot'}
|
326
230
|
|
327
|
-
|
328
|
-
control = mocked_control
|
329
|
-
self.expects(:invoke_remote).with(:get_redirect_host).returns('collector-deux.newrelic.com')
|
330
|
-
control.expects(:server_from_host).with('collector-deux.newrelic.com').returns('correct')
|
331
|
-
set_collector_host!
|
332
|
-
assert_equal 'correct', @collector
|
333
|
-
end
|
231
|
+
response = NewRelic::Agent.agent.connect_to_server
|
334
232
|
|
335
|
-
|
336
|
-
|
337
|
-
control = mocked_control
|
338
|
-
self.expects(:invoke_remote).with(:get_redirect_host).returns(nil)
|
339
|
-
set_collector_host!
|
340
|
-
assert_equal 'initial value', @collector, "should not modify collector value"
|
341
|
-
end
|
233
|
+
assert_equal 23, response['agent_run_id']
|
234
|
+
assert_equal 'a lot', response['config']
|
342
235
|
|
343
|
-
|
344
|
-
self.expects(:set_collector_host!)
|
345
|
-
self.expects(:connect_to_server).returns("so happy")
|
346
|
-
self.expects(:finish_setup).with("so happy")
|
347
|
-
query_server_for_configuration
|
236
|
+
NewRelic::Agent.shutdown
|
348
237
|
end
|
349
238
|
|
350
239
|
def test_finish_setup
|
351
240
|
config = {
|
352
241
|
'agent_run_id' => 'fishsticks',
|
353
|
-
'data_report_period' => 'pasta sauce',
|
354
|
-
'url_rules' => 'tamales',
|
355
242
|
'collect_traces' => true,
|
356
243
|
'collect_errors' => true,
|
357
|
-
'sample_rate' => 10
|
244
|
+
'sample_rate' => 10,
|
245
|
+
'cross_process_id' => '1#234',
|
246
|
+
'encoding_key' => 'a' * 30,
|
247
|
+
'agent_config' => { 'transaction_tracer.record_sql' => 'raw' }
|
358
248
|
}
|
359
|
-
NewRelic::Control.instance.settings['transaction_tracer'] = {'enabled' => true}
|
360
249
|
self.expects(:log_connection!).with(config)
|
361
|
-
self.expects(:configure_transaction_tracer!).with(true, 10)
|
362
|
-
self.expects(:configure_error_collector!).with(true)
|
363
250
|
@transaction_sampler = stub('transaction sampler', :configure! => true,
|
364
251
|
:config => {})
|
365
|
-
@sql_sampler = stub('sql sampler', :configure! => true)
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
252
|
+
@sql_sampler = stub('sql sampler', :configure! => true)
|
253
|
+
with_config(:'transaction_tracer.enabled' => true) do
|
254
|
+
finish_setup(config)
|
255
|
+
assert_equal 'fishsticks', @service.agent_id
|
256
|
+
assert_equal '1#234', @cross_process_id
|
257
|
+
assert_equal 'a' * 30, @cross_process_encoding_key
|
258
|
+
assert_equal [97] * 30, @cross_process_encoding_bytes
|
259
|
+
assert_equal 'raw', NewRelic::Agent.config[:'transaction_tracer.record_sql']
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_get_bytes_with_nil
|
264
|
+
assert_equal [], get_bytes(nil)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_logging_collector_messages
|
268
|
+
NewRelic::Agent.manual_start
|
269
|
+
service = NewRelic::FakeService.new
|
270
|
+
NewRelic::Agent::Agent.instance.service = service
|
271
|
+
service.mock['connect'] = {
|
272
|
+
'agent_run_id' => 23, 'config' => 'a lot',
|
273
|
+
'messages' => [{ 'message' => 'beep boop', 'level' => 'INFO' },
|
274
|
+
{ 'message' => 'ha cha cha', 'level' => 'WARN' }]
|
275
|
+
}
|
276
|
+
|
277
|
+
expects_logging(:info, 'beep boop')
|
278
|
+
expects_logging(:warn, 'ha cha cha')
|
279
|
+
|
280
|
+
NewRelic::Agent.agent.query_server_for_configuration
|
281
|
+
NewRelic::Agent.shutdown
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_finish_setup_without_config
|
285
|
+
@service.agent_id = 'blah'
|
286
|
+
finish_setup(nil)
|
287
|
+
assert_equal 'blah', @service.agent_id
|
288
|
+
end
|
289
|
+
|
290
|
+
# no idea why this test leaks in Rails 2.0
|
291
|
+
# will be moved to a multiverse test eventually anyway
|
292
|
+
if !Rails::VERSION::STRING =~ /2\.0.*/
|
293
|
+
def test_set_apdex_t_from_server
|
294
|
+
service = NewRelic::FakeService.new
|
295
|
+
NewRelic::Agent::Agent.instance.service = service
|
296
|
+
service.mock['connect'] = { 'apdex_t' => 0.5 }
|
297
|
+
with_config(:sync_startup => true, :monitor_mode => true,
|
298
|
+
:license_key => 'a' * 40) do
|
299
|
+
NewRelic::Agent.manual_start
|
300
|
+
assert_equal 0.5, NewRelic::Agent.config[:apdex_t]
|
301
|
+
NewRelic::Agent.shutdown
|
302
|
+
end
|
303
|
+
end
|
370
304
|
end
|
371
305
|
|
372
306
|
private
|
@@ -377,22 +311,12 @@ class NewRelic::Agent::Agent::ConnectTest < Test::Unit::TestCase
|
|
377
311
|
fake_control
|
378
312
|
end
|
379
313
|
|
380
|
-
def mocked_log
|
381
|
-
fake_log = mock('log')
|
382
|
-
self.stubs(:log).returns(fake_log)
|
383
|
-
fake_log
|
384
|
-
end
|
385
|
-
|
386
314
|
def mocked_error_collector
|
387
315
|
fake_collector = mock('error collector')
|
388
316
|
self.stubs(:error_collector).returns(fake_collector)
|
389
317
|
fake_collector
|
390
318
|
end
|
391
319
|
|
392
|
-
def log
|
393
|
-
@logger ||= Object.new
|
394
|
-
end
|
395
|
-
|
396
320
|
def assert_accessor(sym)
|
397
321
|
var_name = "@#{sym}"
|
398
322
|
instance_variable_set(var_name, 1)
|