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,89 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/thread'
|
3
|
+
|
4
|
+
class ThreadTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_sets_label
|
7
|
+
t = NewRelic::Agent::AgentThread.new("labelled") {}
|
8
|
+
assert_equal "labelled", t[:newrelic_label]
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_bucket_thread_as_agent_when_profiling
|
12
|
+
t = NewRelic::Agent::AgentThread.new("labelled") {}
|
13
|
+
assert_equal :agent, NewRelic::Agent::AgentThread.bucket_thread(t, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_bucket_thread_as_agent_when_not_profiling
|
17
|
+
t = NewRelic::Agent::AgentThread.new("labelled") {}
|
18
|
+
assert_equal :ignore, NewRelic::Agent::AgentThread.bucket_thread(t, false)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_bucket_thread_as_request
|
22
|
+
t = ::Thread.new {}
|
23
|
+
frame = NewRelic::Agent::Instrumentation::MetricFrame.new
|
24
|
+
frame.request = "has a request"
|
25
|
+
t[:newrelic_metric_frame] = frame
|
26
|
+
|
27
|
+
assert_equal :request, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_bucket_thread_as_background
|
31
|
+
t = ::Thread.new {}
|
32
|
+
frame = NewRelic::Agent::Instrumentation::MetricFrame.new
|
33
|
+
t[:newrelic_metric_frame] = frame
|
34
|
+
|
35
|
+
assert_equal :background, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_bucket_thread_as_other_if_nil_frame
|
39
|
+
t = ::Thread.new {}
|
40
|
+
t[:newrelic_metric_frame] = nil
|
41
|
+
|
42
|
+
assert_equal :other, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_bucket_thread_as_other
|
46
|
+
t = ::Thread.new {}
|
47
|
+
assert_equal :other, NewRelic::Agent::AgentThread.bucket_thread(t, DONT_CARE)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_runs_block
|
51
|
+
called = false
|
52
|
+
|
53
|
+
t = NewRelic::Agent::AgentThread.new("labelled") { called = true }
|
54
|
+
t.join
|
55
|
+
|
56
|
+
assert called
|
57
|
+
end
|
58
|
+
|
59
|
+
TRACE = [
|
60
|
+
"/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:100:in `catch'",
|
61
|
+
"/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/newrelic_rpm-3.5.3.452.dev/lib/new_relic/agent/agent.rb:200:in `start_worker_thread'",
|
62
|
+
"/Users/jclark/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.5.0/lib/thin/backends/base.rb:300:in `block (3 levels) in run'",
|
63
|
+
]
|
64
|
+
|
65
|
+
def test_scrubs_backtrace_when_not_profiling_agent_code
|
66
|
+
result = NewRelic::Agent::AgentThread.scrub_backtrace(stub(:backtrace => TRACE), false)
|
67
|
+
assert_equal [TRACE[0], TRACE[2]], result
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_doesnt_scrub_backtrace_when_profiling_agent_code
|
71
|
+
result = NewRelic::Agent::AgentThread.scrub_backtrace(stub(:backtrace => TRACE), true)
|
72
|
+
assert_equal TRACE, result
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_scrub_backtrace_handles_errors_during_backtrace
|
76
|
+
dummy_thread = stub
|
77
|
+
dummy_thread.stubs(:backtrace).raises(StandardError.new('nah'))
|
78
|
+
assert_nothing_raised do
|
79
|
+
NewRelic::Agent::AgentThread.scrub_backtrace(dummy_thread, true)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_scrub_backtrace_handles_nil_backtrace
|
84
|
+
bt = NewRelic::Agent::AgentThread.scrub_backtrace(stub(:backtrace => nil), false)
|
85
|
+
assert_nil(bt)
|
86
|
+
end
|
87
|
+
|
88
|
+
DONT_CARE = true
|
89
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class ThreadedTest < Test::Unit::TestCase
|
2
|
+
def setup
|
3
|
+
@original_thread_class = NewRelic::Agent::AgentThread
|
4
|
+
swap_thread_class(FakeThread)
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
swap_thread_class(@original_thread_class)
|
9
|
+
@original_thread_class = nil
|
10
|
+
|
11
|
+
FakeThread.list.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_test
|
15
|
+
# no-op to keep quiet....
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def swap_thread_class(klass)
|
21
|
+
NewRelic::Agent.send(:remove_const, "AgentThread") if NewRelic::Agent.const_defined?("AgentThread")
|
22
|
+
NewRelic::Agent.const_set("AgentThread", klass)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class FakeThread
|
27
|
+
@@list = []
|
28
|
+
|
29
|
+
def initialize(locals={}, &block)
|
30
|
+
@locals = locals
|
31
|
+
yield if block_given?
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.current
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.list
|
39
|
+
@@list
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.bucket_thread(thread, _)
|
43
|
+
thread[:bucket]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.scrub_backtrace(thread, _)
|
47
|
+
thread[:scrubbed_backtrace] || thread.backtrace
|
48
|
+
end
|
49
|
+
|
50
|
+
def key?(key)
|
51
|
+
@locals.key?(key)
|
52
|
+
end
|
53
|
+
|
54
|
+
def [](key)
|
55
|
+
@locals[key]
|
56
|
+
end
|
57
|
+
|
58
|
+
def backtrace
|
59
|
+
@locals[:backtrace] || []
|
60
|
+
end
|
61
|
+
|
62
|
+
def join
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -3,11 +3,52 @@ require 'ostruct'
|
|
3
3
|
|
4
4
|
class NewRelic::Agent::TransactionInfoTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@request = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=
|
6
|
+
@request = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=12345678'})
|
7
|
+
@request_with_embedded_tag = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=1234<tag>evil</tag>5678'})
|
8
|
+
@request_with_embedded_utf8_encoded_js = OpenStruct.new(:cookies => {'NRAGENT' => "tk=1234"])򑛞"})
|
9
|
+
@request_with_double_quotes = OpenStruct.new(:cookies => {'NRAGENT' => 'tk="""deadbeef"""'})
|
10
|
+
@request_with_single_quotes = OpenStruct.new(:cookies => {'NRAGENT' => "tk='''deadbeef'''"})
|
11
|
+
@request_with_multi_lt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=<<<deadbeef'})
|
12
|
+
@request_with_multi_gt = OpenStruct.new(:cookies => {'NRAGENT' => 'tk=>>>deadbeef'})
|
13
|
+
@request_with_bare_token = OpenStruct.new(:cookies => {'NRAGENT' => 0xdeadbeef})
|
14
|
+
@request_with_nil_token = OpenStruct.new(:cookies => {'NRAGENT' => nil})
|
7
15
|
end
|
8
16
|
|
9
|
-
def
|
10
|
-
assert_equal(
|
11
|
-
NewRelic::Agent::TransactionInfo.get_token(@request))
|
17
|
+
def test_get_token_safe_token_returned_untouched
|
18
|
+
assert_equal("12345678", NewRelic::Agent::TransactionInfo.get_token(@request))
|
12
19
|
end
|
20
|
+
|
21
|
+
def test_get_token_with_embedded_tags_sanitized
|
22
|
+
assert_equal("",NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_tag))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_get_token_with_embedded_utf8_js_sanitized
|
26
|
+
assert_equal("1234&#34&#93&#41&#595678",
|
27
|
+
NewRelic::Agent::TransactionInfo.get_token(@request_with_embedded_utf8_encoded_js))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_get_token_replaces_double_quoted_token_with_empty_string
|
31
|
+
assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_double_quotes))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_token_replaces_single_quoted_toket_with_empty_string
|
35
|
+
assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_single_quotes))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_token_replaces_token_started_with_multiple_Lt_with_empty_string
|
39
|
+
assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_lt))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_get_token_replaces_token_started_with_multiple_gt_with_empty_string
|
43
|
+
assert_equal("", NewRelic::Agent::TransactionInfo.get_token(@request_with_multi_gt))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_get_token_bare_value_replaced_with_nil
|
47
|
+
assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_bare_token))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_get_token_nil_token_returns_nil_token
|
51
|
+
assert_equal(nil,NewRelic::Agent::TransactionInfo.get_token(@request_with_ni_token))
|
52
|
+
end
|
53
|
+
|
13
54
|
end
|
@@ -171,19 +171,20 @@ class NewRelic::Agent::TransationSampleBuilderTest < Test::Unit::TestCase
|
|
171
171
|
end
|
172
172
|
|
173
173
|
def test_trace_should_not_record_more_than_segment_limit
|
174
|
-
|
175
|
-
|
176
|
-
|
174
|
+
with_config(:'transaction_tracer.limit_segments' => 3) do
|
175
|
+
8.times {|i| build_segment i.to_s }
|
176
|
+
assert_equal 3, @builder.sample.count_segments
|
177
|
+
end
|
177
178
|
end
|
178
179
|
|
179
180
|
# regression
|
180
181
|
def test_trace_should_log_segment_reached_once
|
181
|
-
|
182
|
-
|
183
|
-
|
182
|
+
with_config(:'transaction_tracer.limit_segments' => 3) do
|
183
|
+
expects_logging(:debug, includes("Segment limit"))
|
184
|
+
8.times {|i| build_segment i.to_s }
|
185
|
+
end
|
184
186
|
end
|
185
187
|
|
186
|
-
|
187
188
|
def validate_builder(check_names = true)
|
188
189
|
validate_segment @builder.sample.root_segment, check_names
|
189
190
|
end
|
@@ -27,11 +27,14 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
27
27
|
agent.stubs(:stats_engine).returns(stats_engine)
|
28
28
|
@sampler = NewRelic::Agent::TransactionSampler.new
|
29
29
|
stats_engine.transaction_sampler = @sampler
|
30
|
+
@test_config = { :'transaction_tracer.enabled' => true }
|
31
|
+
NewRelic::Agent.config.apply_config(@test_config)
|
30
32
|
end
|
31
33
|
|
32
34
|
def teardown
|
33
35
|
super
|
34
36
|
Thread.current[:transaction_sample_builder] = nil
|
37
|
+
NewRelic::Agent.config.remove_config(@test_config)
|
35
38
|
end
|
36
39
|
|
37
40
|
def test_initialize
|
@@ -45,27 +48,10 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
45
48
|
assert_equal(default_value, @sampler.instance_variable_get('@' + variable.to_s))
|
46
49
|
end
|
47
50
|
|
48
|
-
segment_limit = @sampler.instance_variable_get('@segment_limit')
|
49
|
-
assert(segment_limit.is_a?(Numeric), "Segment limit should be numeric")
|
50
|
-
assert(segment_limit > 0, "Segment limit should be above zero")
|
51
|
-
|
52
|
-
stack_trace_threshold = @sampler.instance_variable_get('@stack_trace_threshold')
|
53
|
-
assert(stack_trace_threshold.is_a?((0.1).class), "Stack trace threshold should be a #{(0.1).class.inspect}, but is #{stack_trace_threshold.inspect}")
|
54
|
-
assert(stack_trace_threshold > 0.0, "Stack trace threshold should be above zero")
|
55
|
-
|
56
51
|
lock = @sampler.instance_variable_get('@samples_lock')
|
57
52
|
assert(lock.is_a?(Mutex), "Samples lock should be a mutex, is: #{lock.inspect}")
|
58
53
|
end
|
59
54
|
|
60
|
-
def test_configure
|
61
|
-
control = NewRelic::Control.instance
|
62
|
-
control.merge_options('transaction_tracer' => {'stack_trace_threshold' => 5.0, 'limit_segments' => 20, 'explain_threshold' => 4.0})
|
63
|
-
@sampler.configure!
|
64
|
-
assert_equal 20, @sampler.instance_variable_get('@segment_limit')
|
65
|
-
assert_equal 5.0, @sampler.instance_variable_get('@stack_trace_threshold')
|
66
|
-
assert_equal 4.0, @sampler.instance_variable_get('@explain_threshold')
|
67
|
-
end
|
68
|
-
|
69
55
|
def test_current_sample_id_default
|
70
56
|
builder = mock('builder')
|
71
57
|
builder.expects(:sample_id).returns(11111)
|
@@ -78,20 +64,6 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
78
64
|
assert_equal(nil, @sampler.current_sample_id)
|
79
65
|
end
|
80
66
|
|
81
|
-
def test_enable
|
82
|
-
assert_equal(nil, @sampler.instance_variable_get('@disabled'))
|
83
|
-
@sampler.enable
|
84
|
-
assert_equal(false, @sampler.instance_variable_get('@disabled'))
|
85
|
-
assert_equal(@sampler, NewRelic::Agent.instance.stats_engine.instance_variable_get('@transaction_sampler'))
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_disable
|
89
|
-
assert_nil @sampler.instance_variable_get('@disabled')
|
90
|
-
@sampler.disable
|
91
|
-
assert @sampler.instance_variable_get('@disabled')
|
92
|
-
assert_nil NewRelic::Agent.instance.stats_engine.instance_variable_get('@transaction_sampler')
|
93
|
-
end
|
94
|
-
|
95
67
|
def test_sampling_rate_equals_default
|
96
68
|
@sampler.sampling_rate = 1
|
97
69
|
assert_equal(1, @sampler.instance_variable_get('@sampling_rate'))
|
@@ -107,15 +79,16 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
107
79
|
end
|
108
80
|
|
109
81
|
def test_notice_first_scope_push_default
|
110
|
-
@sampler.expects(:disabled).returns(false)
|
111
82
|
@sampler.expects(:start_builder).with(100.0)
|
112
83
|
@sampler.notice_first_scope_push(Time.at(100))
|
113
84
|
end
|
114
85
|
|
115
86
|
def test_notice_first_scope_push_disabled
|
116
|
-
|
117
|
-
|
118
|
-
|
87
|
+
with_config(:'transaction_tracer.enabled' => false,
|
88
|
+
:developer_mode => false) do
|
89
|
+
@sampler.expects(:start_builder).never
|
90
|
+
@sampler.notice_first_scope_push(Time.at(100))
|
91
|
+
end
|
119
92
|
end
|
120
93
|
|
121
94
|
def test_notice_push_scope_no_builder
|
@@ -124,17 +97,15 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
124
97
|
end
|
125
98
|
|
126
99
|
def test_notice_push_scope_with_builder
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
100
|
+
with_config(:developer_mode => false) do
|
101
|
+
builder = mock('builder')
|
102
|
+
builder.expects(:trace_entry).with('a scope', 100.0)
|
103
|
+
@sampler.expects(:builder).returns(builder).twice
|
104
|
+
@sampler.notice_push_scope('a scope', Time.at(100))
|
105
|
+
end
|
133
106
|
end
|
134
107
|
|
135
108
|
def test_notice_push_scope_in_dev_mode
|
136
|
-
NewRelic::Control.instance.expects(:developer_mode?).returns(true)
|
137
|
-
|
138
109
|
builder = mock('builder')
|
139
110
|
builder.expects(:trace_entry).with('a scope', 100.0)
|
140
111
|
@sampler.expects(:builder).returns(builder).twice
|
@@ -224,22 +195,23 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
224
195
|
end
|
225
196
|
|
226
197
|
def test_store_random_sample_no_random_sampling
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
198
|
+
with_config(:'transaction_tracer.random_sample' => false) do
|
199
|
+
assert_equal(nil, @sampler.instance_variable_get('@random_sample'))
|
200
|
+
@sampler.store_random_sample(mock('sample'))
|
201
|
+
assert_equal(nil, @sampler.instance_variable_get('@random_sample'))
|
202
|
+
end
|
231
203
|
end
|
232
204
|
|
233
205
|
def test_store_random_sample_random_sampling
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
206
|
+
with_config(:'transaction_tracer.random_sample' => true) do
|
207
|
+
sample = mock('sample')
|
208
|
+
assert_equal(nil, @sampler.instance_variable_get('@random_sample'))
|
209
|
+
@sampler.store_random_sample(sample)
|
210
|
+
assert_equal(sample, @sampler.instance_variable_get('@random_sample'))
|
211
|
+
end
|
239
212
|
end
|
240
213
|
|
241
214
|
def test_store_sample_for_developer_mode_in_dev_mode
|
242
|
-
NewRelic::Control.instance.expects(:developer_mode?).returns(true)
|
243
215
|
sample = mock('sample')
|
244
216
|
@sampler.expects(:truncate_samples)
|
245
217
|
@sampler.store_sample_for_developer_mode(sample)
|
@@ -247,11 +219,11 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
247
219
|
end
|
248
220
|
|
249
221
|
def test_store_sample_for_developer_mode_no_dev
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
222
|
+
with_config(:developer_mode => false) do
|
223
|
+
sample = mock('sample')
|
224
|
+
@sampler.store_sample_for_developer_mode(sample)
|
225
|
+
assert_equal([], @sampler.instance_variable_get('@samples'))
|
226
|
+
end
|
255
227
|
end
|
256
228
|
|
257
229
|
def test_store_slowest_sample_new_is_slowest
|
@@ -320,13 +292,16 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
320
292
|
end
|
321
293
|
|
322
294
|
def test_notice_transaction_disabled
|
323
|
-
|
324
|
-
|
325
|
-
@sampler.
|
295
|
+
builder = mock('builder')
|
296
|
+
builder.expects(:set_transaction_info).never # since we're disabled
|
297
|
+
@sampler.stubs(:builder).returns(builder)
|
298
|
+
with_config(:'transaction_tracer.enabled' => false,
|
299
|
+
:developer_mode => false) do
|
300
|
+
@sampler.notice_transaction('foo')
|
301
|
+
end
|
326
302
|
end
|
327
303
|
|
328
304
|
def test_notice_transaction_no_builder
|
329
|
-
@sampler.expects(:disabled).returns(false)
|
330
305
|
@sampler.expects(:builder).returns(nil).once
|
331
306
|
@sampler.notice_transaction('foo')
|
332
307
|
end
|
@@ -335,7 +310,6 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
335
310
|
builder = mock('builder')
|
336
311
|
builder.expects(:set_transaction_info).with('a path', 'a uri', {:some => :params})
|
337
312
|
@sampler.expects(:builder).returns(builder).twice
|
338
|
-
@sampler.expects(:disabled).returns(false)
|
339
313
|
@sampler.notice_transaction('a path', 'a uri', {:some => :params})
|
340
314
|
end
|
341
315
|
|
@@ -430,19 +404,21 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
430
404
|
end
|
431
405
|
|
432
406
|
def test_append_backtrace_under_duration
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
407
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 2.0) do
|
408
|
+
segment = mock('segment')
|
409
|
+
segment.expects(:[]=).with(:backtrace, any_parameters).never
|
410
|
+
@sampler.append_backtrace(mock('segment'), 1.0)
|
411
|
+
end
|
437
412
|
end
|
438
413
|
|
439
414
|
def test_append_backtrace_over_duration
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
415
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 2.0) do
|
416
|
+
segment = mock('segment')
|
417
|
+
# note the mocha expectation matcher - you can't hardcode a
|
418
|
+
# backtrace so we match on any string, which should be okay.
|
419
|
+
segment.expects(:[]=).with(:backtrace, instance_of(String))
|
420
|
+
@sampler.append_backtrace(segment, 2.5)
|
421
|
+
end
|
446
422
|
end
|
447
423
|
|
448
424
|
def test_notice_sql_recording_sql
|
@@ -463,8 +439,10 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
463
439
|
end
|
464
440
|
|
465
441
|
def test_harvest_when_disabled
|
466
|
-
|
467
|
-
|
442
|
+
with_config(:'transaction_tracer.enabled' => false,
|
443
|
+
:developer_mode => false) do
|
444
|
+
assert_equal([], @sampler.harvest)
|
445
|
+
end
|
468
446
|
end
|
469
447
|
|
470
448
|
def test_harvest_defaults
|
@@ -475,8 +453,7 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
475
453
|
@last_sample = 'a sample'
|
476
454
|
end
|
477
455
|
|
478
|
-
@sampler.expects(:
|
479
|
-
@sampler.expects(:add_samples_to).with([], 2.0).returns([])
|
456
|
+
@sampler.expects(:add_samples_to).with([]).returns([])
|
480
457
|
|
481
458
|
assert_equal([], @sampler.harvest)
|
482
459
|
|
@@ -487,12 +464,12 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
487
464
|
end
|
488
465
|
|
489
466
|
def test_harvest_with_previous_samples
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
467
|
+
with_config(:'transaction_tracer.limit_segments' => 2000) do
|
468
|
+
sample = mock('sample')
|
469
|
+
@sampler.expects(:add_samples_to).with([sample]).returns([sample])
|
470
|
+
sample.expects(:truncate).with(2000)
|
471
|
+
assert_equal([sample], @sampler.harvest([sample]))
|
472
|
+
end
|
496
473
|
end
|
497
474
|
|
498
475
|
def test_add_random_sample_to_not_random_sampling
|
@@ -528,16 +505,16 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
528
505
|
end
|
529
506
|
|
530
507
|
def test_add_random_sample_to_activated
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
508
|
+
with_config(:'transaction_tracer.random_sample' => true, :sample_rate => 1) do
|
509
|
+
sample = mock('sample')
|
510
|
+
@sampler.instance_eval {
|
511
|
+
@harvest_count = 3
|
512
|
+
@random_sample = sample
|
513
|
+
}
|
514
|
+
result = []
|
515
|
+
@sampler.add_random_sample_to(result)
|
516
|
+
assert_equal([sample], result, "should add the random sample to the array")
|
517
|
+
end
|
541
518
|
end
|
542
519
|
|
543
520
|
def test_add_random_sample_to_sampling_rate_zero
|
@@ -555,10 +532,9 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
555
532
|
|
556
533
|
def test_add_samples_to_no_data
|
557
534
|
result = []
|
558
|
-
slow_threshold = 2.0
|
559
535
|
@sampler.instance_eval { @slowest_sample = nil }
|
560
536
|
@sampler.expects(:add_random_sample_to).with([])
|
561
|
-
assert_equal([], @sampler.add_samples_to(result
|
537
|
+
assert_equal([], @sampler.add_samples_to(result))
|
562
538
|
end
|
563
539
|
|
564
540
|
def test_add_samples_to_one_result
|
@@ -566,30 +542,31 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
566
542
|
sample.expects(:duration).returns(1).at_least_once
|
567
543
|
sample.stubs(:force_persist).returns(false)
|
568
544
|
result = [sample]
|
569
|
-
slow_threshold = 2.0
|
570
545
|
@sampler.instance_eval { @slowest_sample = nil }
|
571
546
|
@sampler.expects(:add_random_sample_to).with([sample])
|
572
|
-
assert_equal([sample], @sampler.add_samples_to(result
|
547
|
+
assert_equal([sample], @sampler.add_samples_to(result))
|
573
548
|
end
|
574
549
|
|
575
550
|
def test_add_samples_to_adding_slowest
|
576
551
|
sample = mock('sample')
|
577
552
|
sample.expects(:duration).returns(2.5).at_least_once
|
578
553
|
result = []
|
579
|
-
|
580
|
-
@sampler.instance_eval { @slowest_sample = sample }
|
554
|
+
@sampler.instance_variable_set(:@slowest_sample, sample)
|
581
555
|
@sampler.expects(:add_random_sample_to).with([sample])
|
582
|
-
|
556
|
+
with_config(:'transaction_tracer.transaction_threshold' => 2) do
|
557
|
+
assert_equal([sample], @sampler.add_samples_to(result))
|
558
|
+
end
|
583
559
|
end
|
584
560
|
|
585
561
|
def test_add_samples_to_under_threshold
|
586
562
|
result = []
|
587
|
-
slow_threshold = 2.0
|
588
563
|
sample = mock('sample')
|
589
564
|
sample.expects(:duration).returns(1.0).at_least_once
|
590
565
|
@sampler.instance_eval { @slowest_sample = sample }
|
591
566
|
@sampler.expects(:add_random_sample_to).with([])
|
592
|
-
|
567
|
+
with_config(:'transaction_tracer.transaction_threshold' => 2.0) do
|
568
|
+
assert_equal([], @sampler.add_samples_to(result))
|
569
|
+
end
|
593
570
|
end
|
594
571
|
|
595
572
|
def test_add_samples_to_two_sample_enter_one_sample_leave
|
@@ -599,69 +576,72 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
599
576
|
faster_sample.expects(:duration).returns(5.0).at_least_once
|
600
577
|
faster_sample.stubs(:force_persist).returns(false)
|
601
578
|
result = [faster_sample]
|
602
|
-
slow_threshold = 2.0
|
603
579
|
@sampler.instance_eval { @slowest_sample = slower_sample }
|
604
580
|
@sampler.expects(:add_random_sample_to).with([slower_sample])
|
605
|
-
assert_equal([slower_sample], @sampler.add_samples_to(result
|
581
|
+
assert_equal([slower_sample], @sampler.add_samples_to(result))
|
606
582
|
end
|
607
583
|
|
608
584
|
def test_add_samples_to_keep_older_slower_sample
|
609
585
|
slower_sample = mock('slower')
|
610
586
|
slower_sample.expects(:duration).returns(10.0).at_least_once
|
611
587
|
slower_sample.stubs(:force_persist).returns(false)
|
612
|
-
|
588
|
+
|
613
589
|
faster_sample = mock('faster')
|
614
590
|
faster_sample.expects(:duration).returns(5.0).at_least_once
|
615
591
|
result = [slower_sample]
|
616
|
-
slow_threshold = 2.0
|
617
592
|
@sampler.instance_eval { @slowest_sample = faster_sample }
|
618
593
|
@sampler.expects(:add_random_sample_to).with([slower_sample])
|
619
|
-
assert_equal([slower_sample], @sampler.add_samples_to(result
|
594
|
+
assert_equal([slower_sample], @sampler.add_samples_to(result))
|
620
595
|
end
|
621
|
-
|
596
|
+
|
622
597
|
def test_keep_force_persist
|
623
598
|
sample1 = mock('regular')
|
624
599
|
sample1.stubs(:duration).returns(10)
|
625
600
|
sample1.stubs(:force_persist).returns(false)
|
626
|
-
|
601
|
+
|
627
602
|
sample2 = mock('force_persist')
|
628
603
|
sample2.stubs(:duration).returns(1)
|
629
604
|
sample2.stubs(:force_persist).returns(true)
|
630
|
-
|
631
|
-
result = @sampler.add_samples_to([sample1,sample2]
|
632
|
-
|
605
|
+
|
606
|
+
result = @sampler.add_samples_to([sample1,sample2])
|
607
|
+
|
633
608
|
assert_equal 2, result.length
|
634
609
|
assert_equal sample1, result[0]
|
635
610
|
assert_equal sample2, result[1]
|
636
|
-
end
|
611
|
+
end
|
637
612
|
|
638
613
|
def test_start_builder_default
|
639
614
|
Thread.current[:record_tt] = true
|
640
|
-
@sampler.expects(:disabled).returns(false)
|
641
615
|
NewRelic::Agent.expects(:is_execution_traced?).returns(true)
|
642
616
|
@sampler.send(:start_builder)
|
643
|
-
assert(Thread.current[:transaction_sample_builder]
|
617
|
+
assert(Thread.current[:transaction_sample_builder] \
|
618
|
+
.is_a?(NewRelic::Agent::TransactionSampleBuilder),
|
619
|
+
"should set up a new builder by default")
|
644
620
|
end
|
645
621
|
|
646
622
|
def test_start_builder_disabled
|
647
623
|
Thread.current[:transaction_sample_builder] = 'not nil.'
|
648
|
-
|
649
|
-
|
650
|
-
|
624
|
+
with_config(:'transaction_tracer.enabled' => false,
|
625
|
+
:developer_mode => false) do
|
626
|
+
@sampler.send(:start_builder)
|
627
|
+
assert_equal(nil, Thread.current[:transaction_sample_builder],
|
628
|
+
"should clear the transaction builder when disabled")
|
629
|
+
end
|
651
630
|
end
|
652
631
|
|
653
632
|
def test_start_builder_dont_replace_existing_builder
|
654
633
|
fake_builder = mock('transaction sample builder')
|
655
634
|
Thread.current[:transaction_sample_builder] = fake_builder
|
656
|
-
@sampler.expects(:disabled).returns(false)
|
657
635
|
@sampler.send(:start_builder)
|
658
|
-
assert_equal(fake_builder, Thread.current[:transaction_sample_builder],
|
636
|
+
assert_equal(fake_builder, Thread.current[:transaction_sample_builder],
|
637
|
+
"should not overwrite an existing transaction sample builder")
|
659
638
|
Thread.current[:transaction_sample_builder] = nil
|
660
639
|
end
|
661
640
|
|
662
641
|
def test_builder
|
663
642
|
Thread.current[:transaction_sample_builder] = 'shamalamadingdong, brother.'
|
664
|
-
assert_equal('shamalamadingdong, brother.', @sampler.send(:builder),
|
643
|
+
assert_equal('shamalamadingdong, brother.', @sampler.send(:builder),
|
644
|
+
'should return the value from the thread local variable')
|
665
645
|
Thread.current[:transaction_sample_builder] = nil
|
666
646
|
end
|
667
647
|
|
@@ -703,9 +683,10 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
703
683
|
|
704
684
|
@sampler.notice_pop_scope "a"
|
705
685
|
@sampler.notice_scope_empty
|
706
|
-
|
707
|
-
|
708
|
-
|
686
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
687
|
+
sample = @sampler.harvest([]).first
|
688
|
+
assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
|
689
|
+
end
|
709
690
|
end
|
710
691
|
|
711
692
|
def test_sample__gc_stats
|
@@ -730,8 +711,10 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
730
711
|
@sampler.notice_pop_scope "a"
|
731
712
|
@sampler.notice_scope_empty
|
732
713
|
|
733
|
-
|
734
|
-
|
714
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
715
|
+
sample = @sampler.harvest([]).first
|
716
|
+
assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
|
717
|
+
end
|
735
718
|
ensure
|
736
719
|
MockGCStats.mock_values = []
|
737
720
|
end
|
@@ -747,31 +730,38 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
747
730
|
# sample traces, for example. It's unfortunate, but we can't
|
748
731
|
# reliably turn off GC on all versions of ruby under test
|
749
732
|
def test_harvest_slowest
|
750
|
-
run_sample_trace
|
751
|
-
run_sample_trace
|
752
|
-
|
753
|
-
run_sample_trace
|
754
|
-
run_sample_trace
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
733
|
+
run_sample_trace(0,0.1)
|
734
|
+
run_sample_trace(0,0.1)
|
735
|
+
# two second duration
|
736
|
+
run_sample_trace(0,2)
|
737
|
+
run_sample_trace(0,0.1)
|
738
|
+
run_sample_trace(0,0.1)
|
739
|
+
|
740
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
741
|
+
|
742
|
+
slowest = @sampler.harvest(nil)[0]
|
743
|
+
first_duration = slowest.duration
|
744
|
+
assert((first_duration.round >= 2),
|
745
|
+
"expected sample duration = 2, but was: #{slowest.duration.inspect}")
|
746
|
+
|
747
|
+
# 1 second duration
|
748
|
+
run_sample_trace(0,1)
|
749
|
+
not_as_slow = @sampler.harvest(slowest)[0]
|
750
|
+
assert((not_as_slow == slowest), "Should re-harvest the same transaction since it should be slower than the new transaction - expected #{slowest.inspect} but got #{not_as_slow.inspect}")
|
751
|
+
|
752
|
+
run_sample_trace(0,10)
|
753
|
+
|
754
|
+
new_slowest = @sampler.harvest(slowest)[0]
|
755
|
+
assert((new_slowest != slowest), "Should not harvest the same trace since the new one should be slower")
|
756
|
+
assert_equal(new_slowest.duration.round, 10, "Slowest duration must be = 10, but was: #{new_slowest.duration.inspect}")
|
757
|
+
end
|
770
758
|
end
|
771
759
|
|
772
760
|
def test_prepare_to_send
|
773
761
|
run_sample_trace { sleep 0.002 }
|
774
|
-
sample =
|
762
|
+
sample = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
763
|
+
@sampler.harvest(nil)[0]
|
764
|
+
end
|
775
765
|
|
776
766
|
ready_to_send = sample.prepare_to_send
|
777
767
|
assert sample.duration == ready_to_send.duration
|
@@ -816,8 +806,10 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
816
806
|
@sampler.notice_scope_empty
|
817
807
|
|
818
808
|
assert_equal 0, @sampler.scope_depth
|
819
|
-
|
820
|
-
|
809
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
810
|
+
sample = @sampler.harvest(nil).first
|
811
|
+
assert_equal "ROOT{a}", sample.to_s_compact
|
812
|
+
end
|
821
813
|
end
|
822
814
|
|
823
815
|
def test_double_scope_stack_empty
|
@@ -830,7 +822,9 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
830
822
|
@sampler.notice_scope_empty
|
831
823
|
@sampler.notice_scope_empty
|
832
824
|
|
833
|
-
|
825
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
826
|
+
assert_not_nil @sampler.harvest(nil)[0]
|
827
|
+
end
|
834
828
|
end
|
835
829
|
|
836
830
|
|
@@ -847,39 +841,36 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
847
841
|
end
|
848
842
|
|
849
843
|
def test_stack_trace__sql
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
@sampler.notice_sql("test", nil, 1)
|
855
|
-
|
856
|
-
segment = @sampler.send(:builder).current_segment
|
844
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
|
845
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
846
|
+
@sampler.notice_sql("test", nil, 1)
|
847
|
+
segment = @sampler.send(:builder).current_segment
|
857
848
|
|
858
|
-
|
859
|
-
|
849
|
+
assert segment[:sql]
|
850
|
+
assert segment[:backtrace]
|
851
|
+
end
|
860
852
|
end
|
861
|
-
|
853
|
+
|
862
854
|
def test_stack_trace__scope
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
855
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
|
856
|
+
t = Time.now
|
857
|
+
@sampler.notice_first_scope_push t.to_f
|
858
|
+
@sampler.notice_push_scope 'Bill', (t+1).to_f
|
867
859
|
|
868
|
-
|
869
|
-
|
860
|
+
segment = @sampler.send(:builder).current_segment
|
861
|
+
assert segment[:backtrace]
|
862
|
+
end
|
870
863
|
end
|
871
864
|
|
872
865
|
def test_nil_stacktrace
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
@sampler.notice_sql("test", nil, 1)
|
878
|
-
|
879
|
-
segment = @sampler.send(:builder).current_segment
|
866
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 2) do
|
867
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
868
|
+
@sampler.notice_sql("test", nil, 1)
|
869
|
+
segment = @sampler.send(:builder).current_segment
|
880
870
|
|
881
|
-
|
882
|
-
|
871
|
+
assert segment[:sql]
|
872
|
+
assert_nil segment[:backtrace]
|
873
|
+
end
|
883
874
|
end
|
884
875
|
|
885
876
|
def test_big_sql
|
@@ -917,40 +908,38 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
917
908
|
|
918
909
|
def test_param_capture
|
919
910
|
[true, false].each do |capture|
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
911
|
+
with_config(:capture_params => capture) do
|
912
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
913
|
+
@sampler.notice_transaction('/path', nil, {:param => 'hi'})
|
914
|
+
@sampler.notice_scope_empty
|
924
915
|
|
925
|
-
|
916
|
+
tt = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
917
|
+
@sampler.harvest(nil)[0]
|
918
|
+
end
|
926
919
|
|
927
|
-
|
920
|
+
assert_equal (capture) ? 1 : 0, tt.params[:request_params].length
|
921
|
+
end
|
928
922
|
end
|
929
923
|
end
|
930
|
-
|
924
|
+
|
931
925
|
def test_should_not_collect_segments_beyond_limit
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
@sampler.
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
NewRelic::Control.instance.merge_options('transaction_tracer' => {
|
946
|
-
'limit_segments' => 4000,
|
947
|
-
})
|
948
|
-
end
|
949
|
-
|
926
|
+
with_config(:'transaction_tracer.limit_segments' => 3) do
|
927
|
+
run_sample_trace do
|
928
|
+
@sampler.notice_push_scope 'a1'
|
929
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'hallah'", nil, 0)
|
930
|
+
@sampler.notice_push_scope 'a11'
|
931
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", nil, 0)
|
932
|
+
@sampler.notice_pop_scope "a11"
|
933
|
+
@sampler.notice_pop_scope "a1"
|
934
|
+
end
|
935
|
+
assert_equal 3, @sampler.samples[0].count_segments
|
936
|
+
end
|
937
|
+
end
|
938
|
+
|
950
939
|
private
|
951
|
-
|
952
|
-
def run_sample_trace
|
953
|
-
@sampler.notice_first_scope_push
|
940
|
+
|
941
|
+
def run_sample_trace(start = Time.now.to_f, stop = nil)
|
942
|
+
@sampler.notice_first_scope_push start
|
954
943
|
@sampler.notice_transaction '/path', nil, {}
|
955
944
|
@sampler.notice_push_scope "a"
|
956
945
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", nil, 0)
|
@@ -962,6 +951,6 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
962
951
|
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", nil, 0)
|
963
952
|
@sampler.notice_pop_scope "ac"
|
964
953
|
@sampler.notice_pop_scope "a"
|
965
|
-
@sampler.notice_scope_empty
|
954
|
+
@sampler.notice_scope_empty stop || Time.now.to_f
|
966
955
|
end
|
967
956
|
end
|