sundawg_newrelic_rpm 3.5.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.project +23 -0
- data/.travis.yml +9 -0
- data/CHANGELOG +969 -0
- data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
- data/Gemfile +20 -0
- data/LICENSE +87 -0
- data/README.md +195 -0
- data/Rakefile +58 -0
- data/bin/mongrel_rpm +33 -0
- data/bin/newrelic +13 -0
- data/bin/newrelic_cmd +5 -0
- data/cert/cacert.pem +118 -0
- data/cert/oldsite.pem +28 -0
- data/cert/site.pem +27 -0
- data/config.dot +290 -0
- data/config/database.yml +5 -0
- data/gem-public_cert.pem +20 -0
- data/init.rb +31 -0
- data/install.rb +9 -0
- data/lib/conditional_vendored_dependency_detection.rb +3 -0
- data/lib/conditional_vendored_metric_parser.rb +5 -0
- data/lib/new_relic/agent.rb +488 -0
- data/lib/new_relic/agent/agent.rb +1069 -0
- data/lib/new_relic/agent/agent_logger.rb +173 -0
- data/lib/new_relic/agent/audit_logger.rb +72 -0
- data/lib/new_relic/agent/beacon_configuration.rb +107 -0
- data/lib/new_relic/agent/browser_monitoring.rb +195 -0
- data/lib/new_relic/agent/busy_calculator.rb +112 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/configuration.rb +74 -0
- data/lib/new_relic/agent/configuration/defaults.rb +132 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
- data/lib/new_relic/agent/configuration/manager.rb +148 -0
- data/lib/new_relic/agent/configuration/mask_defaults.rb +11 -0
- data/lib/new_relic/agent/configuration/server_source.rb +31 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +67 -0
- data/lib/new_relic/agent/cross_app_monitor.rb +239 -0
- data/lib/new_relic/agent/cross_app_tracing.rb +281 -0
- data/lib/new_relic/agent/database.rb +254 -0
- data/lib/new_relic/agent/error_collector.rb +266 -0
- data/lib/new_relic/agent/event_listener.rb +43 -0
- data/lib/new_relic/agent/instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
- data/lib/new_relic/agent/instrumentation/active_record.rb +134 -0
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
- data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +51 -0
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +485 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +230 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +356 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/net.rb +31 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +23 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +68 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
- data/lib/new_relic/agent/instrumentation/rails3/errors.rb +41 -0
- data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +145 -0
- data/lib/new_relic/agent/instrumentation/rails4/errors.rb +45 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +107 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +22 -0
- data/lib/new_relic/agent/method_tracer.rb +530 -0
- data/lib/new_relic/agent/new_relic_service.rb +513 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
- data/lib/new_relic/agent/pipe_service.rb +63 -0
- data/lib/new_relic/agent/rules_engine.rb +72 -0
- data/lib/new_relic/agent/sampler.rb +50 -0
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +141 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +28 -0
- data/lib/new_relic/agent/sql_sampler.rb +251 -0
- data/lib/new_relic/agent/stats.rb +149 -0
- data/lib/new_relic/agent/stats_engine.rb +30 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +116 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +161 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +97 -0
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +58 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +145 -0
- data/lib/new_relic/agent/thread.rb +32 -0
- data/lib/new_relic/agent/thread_profiler.rb +319 -0
- data/lib/new_relic/agent/transaction_info.rb +119 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +126 -0
- data/lib/new_relic/agent/transaction_sampler.rb +459 -0
- data/lib/new_relic/agent/worker_loop.rb +96 -0
- data/lib/new_relic/coerce.rb +37 -0
- data/lib/new_relic/collection_helper.rb +77 -0
- data/lib/new_relic/command.rb +85 -0
- data/lib/new_relic/commands/deployments.rb +114 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control.rb +44 -0
- data/lib/new_relic/control/class_methods.rb +58 -0
- data/lib/new_relic/control/frameworks.rb +10 -0
- data/lib/new_relic/control/frameworks/external.rb +16 -0
- data/lib/new_relic/control/frameworks/merb.rb +25 -0
- data/lib/new_relic/control/frameworks/rails.rb +173 -0
- data/lib/new_relic/control/frameworks/rails3.rb +71 -0
- data/lib/new_relic/control/frameworks/rails4.rb +23 -0
- data/lib/new_relic/control/frameworks/ruby.rb +21 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/instance_methods.rb +145 -0
- data/lib/new_relic/control/instrumentation.rb +95 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +80 -0
- data/lib/new_relic/delayed_job_injection.rb +51 -0
- data/lib/new_relic/helper.rb +66 -0
- data/lib/new_relic/language_support.rb +92 -0
- data/lib/new_relic/latest_changes.rb +31 -0
- data/lib/new_relic/local_environment.rb +385 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +70 -0
- data/lib/new_relic/metric_spec.rb +80 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +59 -0
- data/lib/new_relic/okjson.rb +599 -0
- data/lib/new_relic/rack.rb +4 -0
- data/lib/new_relic/rack/agent_hooks.rb +20 -0
- data/lib/new_relic/rack/browser_monitoring.rb +85 -0
- data/lib/new_relic/rack/developer_mode.rb +271 -0
- data/lib/new_relic/rack/error_collector.rb +66 -0
- data/lib/new_relic/recipes.rb +99 -0
- data/lib/new_relic/timer_lib.rb +27 -0
- data/lib/new_relic/transaction_analysis.rb +77 -0
- data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
- data/lib/new_relic/transaction_sample.rb +272 -0
- data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
- data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
- data/lib/new_relic/transaction_sample/segment.rb +205 -0
- data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
- data/lib/new_relic/url_rule.rb +14 -0
- data/lib/new_relic/version.rb +66 -0
- data/lib/newrelic_rpm.rb +49 -0
- data/lib/tasks/all.rb +4 -0
- data/lib/tasks/install.rake +7 -0
- data/lib/tasks/tests.rake +17 -0
- data/newrelic.yml +227 -0
- data/newrelic_rpm.gemspec +50 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +49 -0
- data/test/config/test_control.rb +48 -0
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/intentional_fail.rb +10 -0
- data/test/multiverse/.gitignore +11 -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 +164 -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 +9 -0
- data/test/multiverse/suites/agent_only/audit_log_test.rb +97 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +23 -0
- data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +56 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +66 -0
- data/test/multiverse/suites/agent_only/logging_test.rb +163 -0
- data/test/multiverse/suites/agent_only/marshaling_test.rb +96 -0
- data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
- data/test/multiverse/suites/agent_only/no_dns_resolv.rb +17 -0
- data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +57 -0
- data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +81 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +32 -0
- data/test/multiverse/suites/agent_only/ssl_test.rb +22 -0
- data/test/multiverse/suites/agent_only/start_up_test.rb +21 -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/testing_app.rb +17 -0
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +92 -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/rails/Envfile +18 -0
- data/test/multiverse/suites/rails/app.rb +49 -0
- data/test/multiverse/suites/rails/app/views/foos/_foo.html.haml +1 -0
- data/test/multiverse/suites/rails/app/views/views/_a_partial.html.erb +1 -0
- data/test/multiverse/suites/rails/app/views/views/_mid_partial.html.erb +1 -0
- data/test/multiverse/suites/rails/app/views/views/_top_partial.html.erb +3 -0
- data/test/multiverse/suites/rails/app/views/views/deep_partial.html.erb +3 -0
- data/test/multiverse/suites/rails/app/views/views/haml_view.html.haml +6 -0
- data/test/multiverse/suites/rails/app/views/views/index.html.erb +4 -0
- data/test/multiverse/suites/rails/config/newrelic.yml +32 -0
- data/test/multiverse/suites/rails/error_tracing_test.rb +211 -0
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +79 -0
- data/test/multiverse/suites/rails/queue_time_test.rb +55 -0
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +205 -0
- data/test/multiverse/suites/resque/Envfile +24 -0
- data/test/multiverse/suites/resque/Rakefile +8 -0
- data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +151 -0
- data/test/multiverse/suites/resque/resque_setup.rb +15 -0
- data/test/multiverse/suites/sinatra/Envfile +15 -0
- data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +38 -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 +139 -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 +295 -0
- data/test/new_relic/agent/agent/start_test.rb +205 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +88 -0
- data/test/new_relic/agent/agent_logger_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +301 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +381 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/audit_logger_test.rb +105 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +107 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +395 -0
- data/test/new_relic/agent/busy_calculator_test.rb +96 -0
- data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
- data/test/new_relic/agent/configuration/manager_test.rb +232 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +50 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +85 -0
- data/test/new_relic/agent/cross_app_monitor_test.rb +237 -0
- data/test/new_relic/agent/database_test.rb +194 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +268 -0
- data/test/new_relic/agent/error_collector_test.rb +246 -0
- data/test/new_relic/agent/event_listener_test.rb +67 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +606 -0
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +66 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +107 -0
- data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
- data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
- data/test/new_relic/agent/instrumentation/metric_frame_test.rb +151 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +461 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +97 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +182 -0
- data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
- data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +158 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +222 -0
- data/test/new_relic/agent/method_tracer_test.rb +389 -0
- data/test/new_relic/agent/mock_scope_listener.rb +26 -0
- data/test/new_relic/agent/new_relic_service_test.rb +571 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
- data/test/new_relic/agent/pipe_service_test.rb +133 -0
- data/test/new_relic/agent/rpm_agent_test.rb +115 -0
- data/test/new_relic/agent/rules_engine_test.rb +82 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +16 -0
- data/test/new_relic/agent/sql_sampler_test.rb +244 -0
- data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +85 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +180 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +184 -0
- data/test/new_relic/agent/stats_hash_test.rb +93 -0
- data/test/new_relic/agent/stats_test.rb +197 -0
- data/test/new_relic/agent/thread_profiler_test.rb +582 -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 +106 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +227 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +968 -0
- data/test/new_relic/agent/worker_loop_test.rb +84 -0
- data/test/new_relic/agent_test.rb +296 -0
- data/test/new_relic/coerce_test.rb +65 -0
- data/test/new_relic/collection_helper_test.rb +148 -0
- data/test/new_relic/command/deployments_test.rb +84 -0
- data/test/new_relic/control/class_methods_test.rb +44 -0
- data/test/new_relic/control/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control_test.rb +194 -0
- data/test/new_relic/delayed_job_injection_test.rb +21 -0
- data/test/new_relic/dispatcher_test.rb +54 -0
- data/test/new_relic/fake_collector.rb +389 -0
- data/test/new_relic/framework_test.rb +53 -0
- data/test/new_relic/helper_test.rb +24 -0
- data/test/new_relic/load_test.rb +13 -0
- data/test/new_relic/local_environment_test.rb +85 -0
- data/test/new_relic/metric_data_test.rb +183 -0
- data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
- data/test/new_relic/metric_spec_test.rb +95 -0
- data/test/new_relic/noticed_error_test.rb +32 -0
- data/test/new_relic/rack/agent_hooks_test.rb +30 -0
- data/test/new_relic/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +152 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +80 -0
- data/test/new_relic/rack/error_collector_test.rb +90 -0
- data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
- data/test/new_relic/transaction_analysis_test.rb +121 -0
- data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
- data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
- data/test/new_relic/transaction_sample/segment_test.rb +415 -0
- data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
- data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
- data/test/new_relic/transaction_sample_test.rb +250 -0
- data/test/new_relic/version_number_test.rb +97 -0
- data/test/script/build_test_gem.sh +57 -0
- data/test/script/ci.sh +168 -0
- data/test/script/ci_agent-tests_runner.sh +82 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/script/ci_multiverse_runner.sh +63 -0
- data/test/test_contexts.rb +30 -0
- data/test/test_helper.rb +240 -0
- data/ui/helpers/developer_mode_helper.rb +367 -0
- data/ui/helpers/google_pie_chart.rb +49 -0
- data/ui/views/layouts/newrelic_default.rhtml +48 -0
- data/ui/views/newrelic/_explain_plans.rhtml +27 -0
- data/ui/views/newrelic/_sample.rhtml +20 -0
- data/ui/views/newrelic/_segment.rhtml +28 -0
- data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
- data/ui/views/newrelic/_segment_row.rhtml +12 -0
- data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
- data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
- data/ui/views/newrelic/_sql_row.rhtml +16 -0
- data/ui/views/newrelic/_stack_trace.rhtml +15 -0
- data/ui/views/newrelic/_table.rhtml +12 -0
- data/ui/views/newrelic/explain_sql.rhtml +43 -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/file/images/new-relic-rpm-desktop.gif +0 -0
- data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
- data/ui/views/newrelic/file/images/textmate.png +0 -0
- data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
- data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
- data/ui/views/newrelic/file/stylesheets/style.css +490 -0
- data/ui/views/newrelic/index.rhtml +71 -0
- data/ui/views/newrelic/sample_not_found.rhtml +2 -0
- data/ui/views/newrelic/show_sample.rhtml +80 -0
- data/ui/views/newrelic/show_source.rhtml +3 -0
- data/ui/views/newrelic/threads.rhtml +45 -0
- data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
- data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
- metadata +494 -0
@@ -0,0 +1,968 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
module MockGCStats
|
6
|
+
|
7
|
+
def time
|
8
|
+
return 0 if @@values.empty?
|
9
|
+
raise "too many calls" if @@index >= @@values.size
|
10
|
+
@@curtime ||= 0
|
11
|
+
@@curtime += (@@values[@@index] * 1e09).to_i
|
12
|
+
@@index += 1
|
13
|
+
@@curtime
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.mock_values= array
|
17
|
+
@@values = array
|
18
|
+
@@index = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup
|
24
|
+
Thread::current[:record_sql] = nil
|
25
|
+
agent = NewRelic::Agent.instance
|
26
|
+
stats_engine = NewRelic::Agent::StatsEngine.new
|
27
|
+
agent.stubs(:stats_engine).returns(stats_engine)
|
28
|
+
@sampler = NewRelic::Agent::TransactionSampler.new
|
29
|
+
stats_engine.transaction_sampler = @sampler
|
30
|
+
@test_config = { :'transaction_tracer.enabled' => true }
|
31
|
+
NewRelic::Agent.config.apply_config(@test_config)
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
super
|
36
|
+
Thread.current[:transaction_sample_builder] = nil
|
37
|
+
NewRelic::Agent.config.remove_config(@test_config)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_initialize
|
41
|
+
defaults = {
|
42
|
+
:samples => [],
|
43
|
+
:harvest_count => 0,
|
44
|
+
:max_samples => 100,
|
45
|
+
:random_sample => nil,
|
46
|
+
}
|
47
|
+
defaults.each do |variable, default_value|
|
48
|
+
assert_equal(default_value, @sampler.instance_variable_get('@' + variable.to_s))
|
49
|
+
end
|
50
|
+
|
51
|
+
lock = @sampler.instance_variable_get('@samples_lock')
|
52
|
+
assert(lock.is_a?(Mutex), "Samples lock should be a mutex, is: #{lock.inspect}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_current_sample_id_default
|
56
|
+
builder = mock('builder')
|
57
|
+
builder.expects(:sample_id).returns(11111)
|
58
|
+
@sampler.expects(:builder).returns(builder)
|
59
|
+
assert_equal(11111, @sampler.current_sample_id)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_current_sample_id_no_builder
|
63
|
+
@sampler.expects(:builder).returns(nil)
|
64
|
+
assert_equal(nil, @sampler.current_sample_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_sampling_rate_equals_default
|
68
|
+
@sampler.sampling_rate = 1
|
69
|
+
assert_equal(1, @sampler.instance_variable_get('@sampling_rate'))
|
70
|
+
# rand(1) is always zero, so we can be sure here
|
71
|
+
assert_equal(0, @sampler.instance_variable_get('@harvest_count'))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_sampling_rate_equals_with_a_float
|
75
|
+
@sampler.sampling_rate = 5.5
|
76
|
+
assert_equal(5, @sampler.instance_variable_get('@sampling_rate'))
|
77
|
+
harvest_count = @sampler.instance_variable_get('@harvest_count')
|
78
|
+
assert((0..4).include?(harvest_count), "should be in the range 0..4")
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_notice_first_scope_push_default
|
82
|
+
@sampler.expects(:start_builder).with(100.0)
|
83
|
+
@sampler.notice_first_scope_push(Time.at(100))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_notice_first_scope_push_disabled
|
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
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_notice_push_scope_no_builder
|
95
|
+
@sampler.expects(:builder)
|
96
|
+
assert_equal(nil, @sampler.notice_push_scope('a scope'))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_notice_push_scope_with_builder
|
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
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_notice_push_scope_in_dev_mode
|
109
|
+
builder = mock('builder')
|
110
|
+
builder.expects(:trace_entry).with('a scope', 100.0)
|
111
|
+
@sampler.expects(:builder).returns(builder).twice
|
112
|
+
@sampler.expects(:capture_segment_trace)
|
113
|
+
|
114
|
+
@sampler.notice_push_scope('a scope', Time.at(100))
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_scope_depth_no_builder
|
118
|
+
@sampler.expects(:builder).returns(nil)
|
119
|
+
assert_equal(0, @sampler.scope_depth, "should default to zero with no builder")
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_scope_depth_with_builder
|
123
|
+
builder = mock('builder')
|
124
|
+
builder.expects(:scope_depth).returns('scope_depth')
|
125
|
+
@sampler.expects(:builder).returns(builder).twice
|
126
|
+
|
127
|
+
assert_equal('scope_depth', @sampler.scope_depth, "should delegate scope depth to the builder")
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_notice_pop_scope_no_builder
|
131
|
+
@sampler.expects(:builder).returns(nil)
|
132
|
+
assert_equal(nil, @sampler.notice_pop_scope('a scope', Time.at(100)))
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_notice_pop_scope_with_frozen_sample
|
136
|
+
builder = mock('builder')
|
137
|
+
sample = mock('sample')
|
138
|
+
builder.expects(:sample).returns(sample)
|
139
|
+
sample.expects(:frozen?).returns(true)
|
140
|
+
@sampler.expects(:builder).returns(builder).twice
|
141
|
+
|
142
|
+
assert_raise(RuntimeError) do
|
143
|
+
@sampler.notice_pop_scope('a scope', Time.at(100))
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_notice_pop_scope_builder_delegation
|
148
|
+
builder = mock('builder')
|
149
|
+
builder.expects(:trace_exit).with('a scope', 100.0)
|
150
|
+
sample = mock('sample')
|
151
|
+
builder.expects(:sample).returns(sample)
|
152
|
+
sample.expects(:frozen?).returns(false)
|
153
|
+
@sampler.expects(:builder).returns(builder).times(3)
|
154
|
+
|
155
|
+
@sampler.notice_pop_scope('a scope', Time.at(100))
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_notice_scope_empty_no_builder
|
159
|
+
@sampler.expects(:builder).returns(nil)
|
160
|
+
assert_equal(nil, @sampler.notice_scope_empty)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_notice_scope_empty_ignored_transaction
|
164
|
+
builder = mock('builder')
|
165
|
+
# the builder should be cached, so only called once
|
166
|
+
@sampler.expects(:builder).returns(builder).once
|
167
|
+
|
168
|
+
builder.expects(:finish_trace).with(100.0)
|
169
|
+
|
170
|
+
@sampler.expects(:clear_builder)
|
171
|
+
|
172
|
+
builder.expects(:ignored?).returns(true)
|
173
|
+
|
174
|
+
assert_equal(nil, @sampler.notice_scope_empty(Time.at(100)))
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_notice_scope_empty_with_builder
|
178
|
+
builder = mock('builder')
|
179
|
+
# the builder should be cached, so only called once
|
180
|
+
@sampler.expects(:builder).returns(builder).once
|
181
|
+
|
182
|
+
|
183
|
+
builder.expects(:finish_trace).with(100.0)
|
184
|
+
@sampler.expects(:clear_builder)
|
185
|
+
|
186
|
+
builder.expects(:ignored?).returns(false)
|
187
|
+
|
188
|
+
sample = mock('sample')
|
189
|
+
builder.expects(:sample).returns(sample)
|
190
|
+
@sampler.expects(:store_sample).with(sample)
|
191
|
+
|
192
|
+
@sampler.notice_scope_empty(Time.at(100))
|
193
|
+
|
194
|
+
assert_equal(sample, @sampler.instance_variable_get('@last_sample'))
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_store_random_sample_no_random_sampling
|
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
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_store_random_sample_random_sampling
|
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
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_store_sample_for_developer_mode_in_dev_mode
|
215
|
+
sample = mock('sample')
|
216
|
+
@sampler.expects(:truncate_samples)
|
217
|
+
@sampler.store_sample_for_developer_mode(sample)
|
218
|
+
assert_equal([sample], @sampler.instance_variable_get('@samples'))
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_store_sample_for_developer_mode_no_dev
|
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
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_store_slowest_sample_new_is_slowest
|
230
|
+
old_sample = stub('old_sample', :duration => 3.0, :threshold => 1.0)
|
231
|
+
new_sample = stub('new_sample', :duration => 4.0, :threshold => 1.0)
|
232
|
+
@sampler.instance_eval { @slowest_sample = old_sample }
|
233
|
+
|
234
|
+
@sampler.store_slowest_sample(new_sample)
|
235
|
+
|
236
|
+
assert_equal(new_sample, @sampler.instance_variable_get('@slowest_sample'))
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_store_slowest_sample_not_slowest
|
240
|
+
old_sample = mock('old_sample')
|
241
|
+
new_sample = mock('new_sample')
|
242
|
+
@sampler.instance_eval { @slowest_sample = old_sample }
|
243
|
+
@sampler.expects(:slowest_sample?).with(old_sample, new_sample).returns(false)
|
244
|
+
|
245
|
+
@sampler.store_slowest_sample(new_sample)
|
246
|
+
|
247
|
+
assert_equal(old_sample, @sampler.instance_variable_get('@slowest_sample'))
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_store_slowest_sample_does_not_store_if_faster_than_threshold
|
251
|
+
old_sample = stub('old_sample', :duration => 1.0, :threshold => 0.5)
|
252
|
+
new_sample = stub('new_sample', :duration => 2.0, :threshold => 4.0)
|
253
|
+
@sampler.instance_eval { @slowest_sample = old_sample }
|
254
|
+
@sampler.store_slowest_sample(new_sample)
|
255
|
+
|
256
|
+
assert_equal(old_sample, @sampler.instance_variable_get('@slowest_sample'))
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_slowest_sample_no_sample
|
260
|
+
old_sample = nil
|
261
|
+
new_sample = mock('new_sample')
|
262
|
+
assert_equal(true, @sampler.slowest_sample?(old_sample, new_sample))
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_slowest_sample_faster_sample
|
266
|
+
old_sample = mock('old_sample')
|
267
|
+
new_sample = mock('new_sample')
|
268
|
+
old_sample.expects(:duration).returns(1.0)
|
269
|
+
new_sample.expects(:duration).returns(0.5)
|
270
|
+
assert_equal(false, @sampler.slowest_sample?(old_sample, new_sample))
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_slowest_sample_slower_sample
|
274
|
+
old_sample = mock('old_sample')
|
275
|
+
new_sample = mock('new_sample')
|
276
|
+
old_sample.expects(:duration).returns(0.5)
|
277
|
+
new_sample.expects(:duration).returns(1.0)
|
278
|
+
assert_equal(true, @sampler.slowest_sample?(old_sample, new_sample))
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_truncate_samples_no_samples
|
282
|
+
@sampler.instance_eval { @max_samples = 10 }
|
283
|
+
@sampler.instance_eval { @samples = [] }
|
284
|
+
@sampler.truncate_samples
|
285
|
+
assert_equal([], @sampler.instance_variable_get('@samples'))
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_truncate_samples_equal_samples
|
289
|
+
@sampler.instance_eval { @max_samples = 2 }
|
290
|
+
@sampler.instance_eval { @samples = [1, 2] }
|
291
|
+
@sampler.truncate_samples
|
292
|
+
assert_equal([1, 2], @sampler.instance_variable_get('@samples'))
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_truncate_samples_extra_samples
|
296
|
+
@sampler.instance_eval { @max_samples = 2 }
|
297
|
+
@sampler.instance_eval { @samples = [1, 2, 3] }
|
298
|
+
@sampler.truncate_samples
|
299
|
+
assert_equal([2, 3], @sampler.instance_variable_get('@samples'))
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_notice_transaction_disabled
|
303
|
+
builder = mock('builder')
|
304
|
+
builder.expects(:set_transaction_info).never # since we're disabled
|
305
|
+
@sampler.stubs(:builder).returns(builder)
|
306
|
+
with_config(:'transaction_tracer.enabled' => false,
|
307
|
+
:developer_mode => false) do
|
308
|
+
@sampler.notice_transaction('foo')
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_notice_transaction_no_builder
|
313
|
+
@sampler.expects(:builder).returns(nil).once
|
314
|
+
@sampler.notice_transaction('foo')
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_notice_transaction_with_builder
|
318
|
+
builder = mock('builder')
|
319
|
+
builder.expects(:set_transaction_info).with('a path', 'a uri', {:some => :params})
|
320
|
+
@sampler.expects(:builder).returns(builder).twice
|
321
|
+
@sampler.notice_transaction('a path', 'a uri', {:some => :params})
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_ignore_transaction_no_builder
|
325
|
+
@sampler.expects(:builder).returns(nil).once
|
326
|
+
@sampler.ignore_transaction
|
327
|
+
end
|
328
|
+
|
329
|
+
def test_ignore_transaction_with_builder
|
330
|
+
builder = mock('builder')
|
331
|
+
builder.expects(:ignore_transaction)
|
332
|
+
@sampler.expects(:builder).returns(builder).twice
|
333
|
+
@sampler.ignore_transaction
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_notice_profile_no_builder
|
337
|
+
@sampler.expects(:builder).returns(nil).once
|
338
|
+
@sampler.notice_profile(nil)
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_notice_profile_with_builder
|
342
|
+
profile = mock('profile')
|
343
|
+
builder = mock('builder')
|
344
|
+
@sampler.expects(:builder).returns(builder).twice
|
345
|
+
builder.expects(:set_profile).with(profile)
|
346
|
+
|
347
|
+
@sampler.notice_profile(profile)
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_notice_transaction_cpu_time_no_builder
|
351
|
+
@sampler.expects(:builder).returns(nil).once
|
352
|
+
@sampler.notice_transaction_cpu_time(0.0)
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_notice_transaction_cpu_time_with_builder
|
356
|
+
cpu_time = mock('cpu_time')
|
357
|
+
builder = mock('builder')
|
358
|
+
@sampler.expects(:builder).returns(builder).twice
|
359
|
+
builder.expects(:set_transaction_cpu_time).with(cpu_time)
|
360
|
+
|
361
|
+
@sampler.notice_transaction_cpu_time(cpu_time)
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_notice_extra_data_no_builder
|
365
|
+
@sampler.expects(:builder).returns(nil).once
|
366
|
+
@sampler.send(:notice_extra_data, nil, nil, nil)
|
367
|
+
end
|
368
|
+
|
369
|
+
def test_notice_extra_data_no_builder
|
370
|
+
builder = mock('builder')
|
371
|
+
@sampler.expects(:builder).returns(builder).twice
|
372
|
+
builder.expects(:current_segment).returns(nil)
|
373
|
+
@sampler.send(:notice_extra_data, nil, nil, nil)
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_notice_extra_data_with_segment_no_old_message_no_config_key
|
377
|
+
key = :a_key
|
378
|
+
builder = mock('builder')
|
379
|
+
segment = mock('segment')
|
380
|
+
@sampler.expects(:builder).returns(builder).twice
|
381
|
+
builder.expects(:current_segment).returns(segment)
|
382
|
+
segment.expects(:[]).with(key).returns(nil)
|
383
|
+
@sampler.expects(:append_new_message).with(nil, 'a message').returns('a message')
|
384
|
+
NewRelic::Agent::TransactionSampler.expects(:truncate_message) \
|
385
|
+
.with('a message').returns('truncated_message')
|
386
|
+
segment.expects(:[]=).with(key, 'truncated_message')
|
387
|
+
@sampler.expects(:append_backtrace).with(segment, 1.0)
|
388
|
+
@sampler.send(:notice_extra_data, 'a message', 1.0, key)
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_truncate_message_short_message
|
392
|
+
message = 'a message'
|
393
|
+
assert_equal(message, NewRelic::Agent::TransactionSampler.truncate_message(message))
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_truncate_message_long_message
|
397
|
+
message = 'a' * 16384
|
398
|
+
truncated_message = NewRelic::Agent::TransactionSampler.truncate_message(message)
|
399
|
+
assert_equal(16384, truncated_message.length)
|
400
|
+
assert_equal('a' * 16381 + '...', truncated_message)
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_append_new_message_no_old_message
|
404
|
+
old_message = nil
|
405
|
+
new_message = 'a message'
|
406
|
+
assert_equal(new_message, @sampler.append_new_message(old_message, new_message))
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_append_new_message_with_old_message
|
410
|
+
old_message = 'old message'
|
411
|
+
new_message = ' a message'
|
412
|
+
assert_equal("old message;\n a message", @sampler.append_new_message(old_message, new_message))
|
413
|
+
end
|
414
|
+
|
415
|
+
def test_append_backtrace_under_duration
|
416
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 2.0) do
|
417
|
+
segment = mock('segment')
|
418
|
+
segment.expects(:[]=).with(:backtrace, any_parameters).never
|
419
|
+
@sampler.append_backtrace(mock('segment'), 1.0)
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_append_backtrace_over_duration
|
424
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 2.0) do
|
425
|
+
segment = mock('segment')
|
426
|
+
# note the mocha expectation matcher - you can't hardcode a
|
427
|
+
# backtrace so we match on any string, which should be okay.
|
428
|
+
segment.expects(:[]=).with(:backtrace, instance_of(String))
|
429
|
+
@sampler.append_backtrace(segment, 2.5)
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_notice_sql_recording_sql
|
434
|
+
Thread.current[:record_sql] = true
|
435
|
+
@sampler.expects(:notice_extra_data).with('some sql', 1.0, :sql, 'a config', :connection_config)
|
436
|
+
@sampler.notice_sql('some sql', 'a config', 1.0)
|
437
|
+
end
|
438
|
+
|
439
|
+
def test_notice_sql_not_recording
|
440
|
+
Thread.current[:record_sql] = false
|
441
|
+
@sampler.expects(:notice_extra_data).with('some sql', 1.0, :sql, 'a config', :connection_config).never # <--- important
|
442
|
+
@sampler.notice_sql('some sql', 'a config', 1.0)
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_notice_nosql
|
446
|
+
@sampler.expects(:notice_extra_data).with('a key', 1.0, :key)
|
447
|
+
@sampler.notice_nosql('a key', 1.0)
|
448
|
+
end
|
449
|
+
|
450
|
+
def test_harvest_when_disabled
|
451
|
+
with_config(:'transaction_tracer.enabled' => false,
|
452
|
+
:developer_mode => false) do
|
453
|
+
assert_equal([], @sampler.harvest)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_harvest_defaults
|
458
|
+
# making sure the sampler clears out the old samples
|
459
|
+
@sampler.instance_eval do
|
460
|
+
@slowest_sample = 'a sample'
|
461
|
+
@random_sample = 'a sample'
|
462
|
+
@last_sample = 'a sample'
|
463
|
+
end
|
464
|
+
|
465
|
+
@sampler.expects(:add_samples_to).with([]).returns([])
|
466
|
+
|
467
|
+
assert_equal([], @sampler.harvest)
|
468
|
+
|
469
|
+
# make sure the samples have been cleared
|
470
|
+
assert_equal(nil, @sampler.instance_variable_get('@slowest_sample'))
|
471
|
+
assert_equal(nil, @sampler.instance_variable_get('@random_sample'))
|
472
|
+
assert_equal(nil, @sampler.instance_variable_get('@last_sample'))
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_harvest_with_previous_samples
|
476
|
+
with_config(:'transaction_tracer.limit_segments' => 2000) do
|
477
|
+
sample = mock('sample')
|
478
|
+
@sampler.expects(:add_samples_to).with([sample]).returns([sample])
|
479
|
+
sample.expects(:truncate).with(2000)
|
480
|
+
assert_equal([sample], @sampler.harvest([sample]))
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_add_random_sample_to_not_random_sampling
|
485
|
+
@sampler.instance_eval { @random_sampling = false }
|
486
|
+
result = []
|
487
|
+
@sampler.add_random_sample_to(result)
|
488
|
+
assert_equal([], result, "should not add anything to the array if we are not random sampling")
|
489
|
+
end
|
490
|
+
|
491
|
+
def test_add_random_sample_to_no_random_sample
|
492
|
+
@sampler.instance_eval { @random_sampling = true }
|
493
|
+
@sampler.instance_eval {
|
494
|
+
@harvest_count = 1
|
495
|
+
@sampling_rate = 2
|
496
|
+
@random_sample = nil
|
497
|
+
}
|
498
|
+
result = []
|
499
|
+
@sampler.add_random_sample_to(result)
|
500
|
+
assert_equal([], result, "should not add sample to the array when it is nil")
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_add_random_sample_to_not_active
|
504
|
+
@sampler.instance_eval { @random_sampling = true }
|
505
|
+
sample = mock('sample')
|
506
|
+
@sampler.instance_eval {
|
507
|
+
@harvest_count = 4
|
508
|
+
@sampling_rate = 40 # 4 % 40 = 4, so the sample should not be added
|
509
|
+
@random_sample = sample
|
510
|
+
}
|
511
|
+
result = []
|
512
|
+
@sampler.add_random_sample_to(result)
|
513
|
+
assert_equal([], result, "should not add samples to the array when harvest count is not moduli sampling rate")
|
514
|
+
end
|
515
|
+
|
516
|
+
def test_add_random_sample_to_activated
|
517
|
+
with_config(:'transaction_tracer.random_sample' => true, :sample_rate => 1) do
|
518
|
+
sample = mock('sample')
|
519
|
+
@sampler.instance_eval {
|
520
|
+
@harvest_count = 3
|
521
|
+
@random_sample = sample
|
522
|
+
}
|
523
|
+
result = []
|
524
|
+
@sampler.add_random_sample_to(result)
|
525
|
+
assert_equal([sample], result, "should add the random sample to the array")
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_add_random_sample_to_sampling_rate_zero
|
530
|
+
@sampler.instance_eval { @random_sampling = true }
|
531
|
+
sample = mock('sample')
|
532
|
+
@sampler.instance_eval {
|
533
|
+
@harvest_count = 3
|
534
|
+
@sampling_rate = 0
|
535
|
+
@random_sample = sample
|
536
|
+
}
|
537
|
+
result = []
|
538
|
+
@sampler.add_random_sample_to(result)
|
539
|
+
assert_equal([], result, "should not add the sample to the array")
|
540
|
+
end
|
541
|
+
|
542
|
+
def test_add_samples_to_no_data
|
543
|
+
result = []
|
544
|
+
@sampler.instance_eval { @slowest_sample = nil }
|
545
|
+
@sampler.expects(:add_random_sample_to).with([])
|
546
|
+
assert_equal([], @sampler.add_samples_to(result))
|
547
|
+
end
|
548
|
+
|
549
|
+
def test_add_samples_to_one_result
|
550
|
+
sample = mock('sample')
|
551
|
+
sample.expects(:duration).returns(1).at_least_once
|
552
|
+
sample.stubs(:force_persist).returns(false)
|
553
|
+
result = [sample]
|
554
|
+
@sampler.instance_eval { @slowest_sample = nil }
|
555
|
+
@sampler.expects(:add_random_sample_to).with([sample])
|
556
|
+
assert_equal([sample], @sampler.add_samples_to(result))
|
557
|
+
end
|
558
|
+
|
559
|
+
def test_add_samples_to_adding_slowest
|
560
|
+
sample = mock('sample')
|
561
|
+
sample.expects(:duration).returns(2.5).at_least_once
|
562
|
+
result = []
|
563
|
+
@sampler.instance_variable_set(:@slowest_sample, sample)
|
564
|
+
@sampler.expects(:add_random_sample_to).with([sample])
|
565
|
+
with_config(:'transaction_tracer.transaction_threshold' => 2) do
|
566
|
+
assert_equal([sample], @sampler.add_samples_to(result))
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_add_samples_to_two_sample_enter_one_sample_leave
|
571
|
+
slower_sample = mock('slower')
|
572
|
+
slower_sample.expects(:duration).returns(10.0).at_least_once
|
573
|
+
faster_sample = mock('faster')
|
574
|
+
faster_sample.expects(:duration).returns(5.0).at_least_once
|
575
|
+
faster_sample.stubs(:force_persist).returns(false)
|
576
|
+
result = [faster_sample]
|
577
|
+
@sampler.instance_eval { @slowest_sample = slower_sample }
|
578
|
+
@sampler.expects(:add_random_sample_to).with([slower_sample])
|
579
|
+
assert_equal([slower_sample], @sampler.add_samples_to(result))
|
580
|
+
end
|
581
|
+
|
582
|
+
def test_add_samples_to_keep_older_slower_sample
|
583
|
+
slower_sample = mock('slower')
|
584
|
+
slower_sample.expects(:duration).returns(10.0).at_least_once
|
585
|
+
slower_sample.stubs(:force_persist).returns(false)
|
586
|
+
|
587
|
+
faster_sample = mock('faster')
|
588
|
+
faster_sample.expects(:duration).returns(5.0).at_least_once
|
589
|
+
result = [slower_sample]
|
590
|
+
@sampler.instance_eval { @slowest_sample = faster_sample }
|
591
|
+
@sampler.expects(:add_random_sample_to).with([slower_sample])
|
592
|
+
assert_equal([slower_sample], @sampler.add_samples_to(result))
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_keep_force_persist
|
596
|
+
sample1 = mock('regular')
|
597
|
+
sample1.stubs(:duration).returns(10)
|
598
|
+
sample1.stubs(:force_persist).returns(false)
|
599
|
+
|
600
|
+
sample2 = mock('force_persist')
|
601
|
+
sample2.stubs(:duration).returns(1)
|
602
|
+
sample2.stubs(:force_persist).returns(true)
|
603
|
+
|
604
|
+
result = @sampler.add_samples_to([sample1,sample2])
|
605
|
+
|
606
|
+
assert_equal 2, result.length
|
607
|
+
assert_equal sample1, result[0]
|
608
|
+
assert_equal sample2, result[1]
|
609
|
+
end
|
610
|
+
|
611
|
+
def test_start_builder_default
|
612
|
+
Thread.current[:record_tt] = true
|
613
|
+
NewRelic::Agent.expects(:is_execution_traced?).returns(true)
|
614
|
+
@sampler.send(:start_builder)
|
615
|
+
assert(Thread.current[:transaction_sample_builder] \
|
616
|
+
.is_a?(NewRelic::Agent::TransactionSampleBuilder),
|
617
|
+
"should set up a new builder by default")
|
618
|
+
end
|
619
|
+
|
620
|
+
def test_start_builder_disabled
|
621
|
+
Thread.current[:transaction_sample_builder] = 'not nil.'
|
622
|
+
with_config(:'transaction_tracer.enabled' => false,
|
623
|
+
:developer_mode => false) do
|
624
|
+
@sampler.send(:start_builder)
|
625
|
+
assert_equal(nil, Thread.current[:transaction_sample_builder],
|
626
|
+
"should clear the transaction builder when disabled")
|
627
|
+
end
|
628
|
+
end
|
629
|
+
|
630
|
+
def test_start_builder_dont_replace_existing_builder
|
631
|
+
fake_builder = mock('transaction sample builder')
|
632
|
+
Thread.current[:transaction_sample_builder] = fake_builder
|
633
|
+
@sampler.send(:start_builder)
|
634
|
+
assert_equal(fake_builder, Thread.current[:transaction_sample_builder],
|
635
|
+
"should not overwrite an existing transaction sample builder")
|
636
|
+
Thread.current[:transaction_sample_builder] = nil
|
637
|
+
end
|
638
|
+
|
639
|
+
def test_builder
|
640
|
+
Thread.current[:transaction_sample_builder] = 'shamalamadingdong, brother.'
|
641
|
+
assert_equal('shamalamadingdong, brother.', @sampler.send(:builder),
|
642
|
+
'should return the value from the thread local variable')
|
643
|
+
Thread.current[:transaction_sample_builder] = nil
|
644
|
+
end
|
645
|
+
|
646
|
+
def test_clear_builder
|
647
|
+
Thread.current[:transaction_sample_builder] = 'shamalamadingdong, brother.'
|
648
|
+
assert_equal(nil, @sampler.send(:clear_builder), 'should clear the thread local variable')
|
649
|
+
end
|
650
|
+
|
651
|
+
# Tests below this line are functional tests for the sampler, not
|
652
|
+
# unit tests per se - some overlap with the tests above, but
|
653
|
+
# generally usefully so
|
654
|
+
|
655
|
+
def test_multiple_samples
|
656
|
+
run_sample_trace
|
657
|
+
run_sample_trace
|
658
|
+
run_sample_trace
|
659
|
+
run_sample_trace
|
660
|
+
|
661
|
+
samples = @sampler.samples
|
662
|
+
assert_equal 4, samples.length
|
663
|
+
assert_equal "a", samples.first.root_segment.called_segments[0].metric_name
|
664
|
+
assert_equal "a", samples.last.root_segment.called_segments[0].metric_name
|
665
|
+
end
|
666
|
+
|
667
|
+
def test_sample_tree
|
668
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
669
|
+
assert_equal 0, @sampler.scope_depth
|
670
|
+
|
671
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
672
|
+
@sampler.notice_transaction "/path", nil, {}
|
673
|
+
@sampler.notice_push_scope "a"
|
674
|
+
|
675
|
+
@sampler.notice_push_scope "b"
|
676
|
+
@sampler.notice_pop_scope "b"
|
677
|
+
|
678
|
+
@sampler.notice_push_scope "c"
|
679
|
+
@sampler.notice_push_scope "d"
|
680
|
+
@sampler.notice_pop_scope "d"
|
681
|
+
@sampler.notice_pop_scope "c"
|
682
|
+
|
683
|
+
@sampler.notice_pop_scope "a"
|
684
|
+
@sampler.notice_scope_empty
|
685
|
+
sample = @sampler.harvest([]).first
|
686
|
+
assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
def test_sample__gc_stats
|
691
|
+
GC.extend MockGCStats
|
692
|
+
# These are effectively Garbage Collects, detected each time GC.time is
|
693
|
+
# called by the transaction sampler. One time value in seconds for each call.
|
694
|
+
MockGCStats.mock_values = [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0]
|
695
|
+
assert_equal 0, @sampler.scope_depth
|
696
|
+
|
697
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
698
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
699
|
+
@sampler.notice_transaction "/path", nil, {}
|
700
|
+
@sampler.notice_push_scope "a"
|
701
|
+
|
702
|
+
@sampler.notice_push_scope "b"
|
703
|
+
@sampler.notice_pop_scope "b"
|
704
|
+
|
705
|
+
@sampler.notice_push_scope "c"
|
706
|
+
@sampler.notice_push_scope "d"
|
707
|
+
@sampler.notice_pop_scope "d"
|
708
|
+
@sampler.notice_pop_scope "c"
|
709
|
+
|
710
|
+
@sampler.notice_pop_scope "a"
|
711
|
+
@sampler.notice_scope_empty
|
712
|
+
|
713
|
+
sample = @sampler.harvest([]).first
|
714
|
+
assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
|
715
|
+
end
|
716
|
+
ensure
|
717
|
+
MockGCStats.mock_values = []
|
718
|
+
end
|
719
|
+
|
720
|
+
def test_sample_id
|
721
|
+
run_sample_trace do
|
722
|
+
assert((@sampler.current_sample_id && @sampler.current_sample_id != 0), @sampler.current_sample_id.to_s + ' should not be zero')
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
|
727
|
+
# NB this test occasionally fails due to a GC during one of the
|
728
|
+
# sample traces, for example. It's unfortunate, but we can't
|
729
|
+
# reliably turn off GC on all versions of ruby under test
|
730
|
+
def test_harvest_slowest
|
731
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
732
|
+
run_sample_trace(0,0.1)
|
733
|
+
run_sample_trace(0,0.1)
|
734
|
+
# two second duration
|
735
|
+
run_sample_trace(0,2)
|
736
|
+
run_sample_trace(0,0.1)
|
737
|
+
run_sample_trace(0,0.1)
|
738
|
+
|
739
|
+
slowest = @sampler.harvest(nil)[0]
|
740
|
+
first_duration = slowest.duration
|
741
|
+
assert((first_duration.round >= 2),
|
742
|
+
"expected sample duration = 2, but was: #{slowest.duration.inspect}")
|
743
|
+
|
744
|
+
# 1 second duration
|
745
|
+
run_sample_trace(0,1)
|
746
|
+
not_as_slow = @sampler.harvest(slowest)[0]
|
747
|
+
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}")
|
748
|
+
|
749
|
+
run_sample_trace(0,10)
|
750
|
+
|
751
|
+
new_slowest = @sampler.harvest(slowest)[0]
|
752
|
+
assert((new_slowest != slowest), "Should not harvest the same trace since the new one should be slower")
|
753
|
+
assert_equal(new_slowest.duration.round, 10, "Slowest duration must be = 10, but was: #{new_slowest.duration.inspect}")
|
754
|
+
end
|
755
|
+
end
|
756
|
+
|
757
|
+
def test_prepare_to_send
|
758
|
+
sample = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
759
|
+
run_sample_trace { sleep 0.002 }
|
760
|
+
@sampler.harvest(nil)[0]
|
761
|
+
end
|
762
|
+
|
763
|
+
ready_to_send = sample.prepare_to_send
|
764
|
+
assert sample.duration == ready_to_send.duration
|
765
|
+
|
766
|
+
assert ready_to_send.start_time.is_a?(Time)
|
767
|
+
end
|
768
|
+
|
769
|
+
def test_multithread
|
770
|
+
threads = []
|
771
|
+
|
772
|
+
5.times do
|
773
|
+
t = Thread.new(@sampler) do |the_sampler|
|
774
|
+
@sampler = the_sampler
|
775
|
+
10.times do
|
776
|
+
run_sample_trace { sleep 0.0001 }
|
777
|
+
end
|
778
|
+
end
|
779
|
+
|
780
|
+
threads << t
|
781
|
+
end
|
782
|
+
threads.each {|t| t.join }
|
783
|
+
end
|
784
|
+
|
785
|
+
def test_sample_with_parallel_paths
|
786
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
787
|
+
assert_equal 0, @sampler.scope_depth
|
788
|
+
|
789
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
790
|
+
@sampler.notice_transaction "/path", nil, {}
|
791
|
+
@sampler.notice_push_scope "a"
|
792
|
+
|
793
|
+
assert_equal 1, @sampler.scope_depth
|
794
|
+
|
795
|
+
@sampler.notice_pop_scope "a"
|
796
|
+
@sampler.notice_scope_empty
|
797
|
+
|
798
|
+
assert_equal 0, @sampler.scope_depth
|
799
|
+
|
800
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
801
|
+
@sampler.notice_transaction "/path", nil, {}
|
802
|
+
@sampler.notice_push_scope "a"
|
803
|
+
@sampler.notice_pop_scope "a"
|
804
|
+
@sampler.notice_scope_empty
|
805
|
+
|
806
|
+
assert_equal 0, @sampler.scope_depth
|
807
|
+
sample = @sampler.harvest(nil).first
|
808
|
+
assert_equal "ROOT{a}", sample.to_s_compact
|
809
|
+
end
|
810
|
+
end
|
811
|
+
|
812
|
+
def test_double_scope_stack_empty
|
813
|
+
with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
814
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
815
|
+
@sampler.notice_transaction "/path", nil, {}
|
816
|
+
@sampler.notice_push_scope "a"
|
817
|
+
@sampler.notice_pop_scope "a"
|
818
|
+
@sampler.notice_scope_empty
|
819
|
+
@sampler.notice_scope_empty
|
820
|
+
@sampler.notice_scope_empty
|
821
|
+
@sampler.notice_scope_empty
|
822
|
+
|
823
|
+
assert_not_nil @sampler.harvest(nil)[0]
|
824
|
+
end
|
825
|
+
end
|
826
|
+
|
827
|
+
|
828
|
+
def test_record_sql_off
|
829
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
830
|
+
|
831
|
+
Thread::current[:record_sql] = false
|
832
|
+
|
833
|
+
@sampler.notice_sql("test", nil, 0)
|
834
|
+
|
835
|
+
segment = @sampler.send(:builder).current_segment
|
836
|
+
|
837
|
+
assert_nil segment[:sql]
|
838
|
+
end
|
839
|
+
|
840
|
+
def test_stack_trace__sql
|
841
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
|
842
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
843
|
+
@sampler.notice_sql("test", nil, 1)
|
844
|
+
segment = @sampler.send(:builder).current_segment
|
845
|
+
|
846
|
+
assert segment[:sql]
|
847
|
+
assert segment[:backtrace]
|
848
|
+
end
|
849
|
+
end
|
850
|
+
|
851
|
+
def test_stack_trace__scope
|
852
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
|
853
|
+
t = Time.now
|
854
|
+
@sampler.notice_first_scope_push t.to_f
|
855
|
+
@sampler.notice_push_scope 'Bill', (t+1).to_f
|
856
|
+
|
857
|
+
segment = @sampler.send(:builder).current_segment
|
858
|
+
assert segment[:backtrace]
|
859
|
+
end
|
860
|
+
end
|
861
|
+
|
862
|
+
def test_nil_stacktrace
|
863
|
+
with_config(:'transaction_tracer.stack_trace_threshold' => 2) do
|
864
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
865
|
+
@sampler.notice_sql("test", nil, 1)
|
866
|
+
segment = @sampler.send(:builder).current_segment
|
867
|
+
|
868
|
+
assert segment[:sql]
|
869
|
+
assert_nil segment[:backtrace]
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
873
|
+
def test_big_sql
|
874
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
875
|
+
|
876
|
+
sql = "SADJKHASDHASD KAJSDH ASKDH ASKDHASDK JASHD KASJDH ASKDJHSAKDJHAS DKJHSADKJSAH DKJASHD SAKJDH SAKDJHS"
|
877
|
+
|
878
|
+
len = 0
|
879
|
+
while len <= 16384
|
880
|
+
@sampler.notice_sql(sql, nil, 0)
|
881
|
+
len += sql.length
|
882
|
+
end
|
883
|
+
|
884
|
+
segment = @sampler.send(:builder).current_segment
|
885
|
+
|
886
|
+
sql = segment[:sql]
|
887
|
+
|
888
|
+
assert sql.length <= 16384
|
889
|
+
end
|
890
|
+
|
891
|
+
def test_segment_obfuscated
|
892
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
893
|
+
@sampler.notice_push_scope "foo"
|
894
|
+
|
895
|
+
orig_sql = "SELECT * from Jim where id=66"
|
896
|
+
|
897
|
+
@sampler.notice_sql(orig_sql, nil, 0)
|
898
|
+
|
899
|
+
segment = @sampler.send(:builder).current_segment
|
900
|
+
|
901
|
+
assert_equal orig_sql, segment[:sql]
|
902
|
+
assert_equal "SELECT * from Jim where id=?", segment.obfuscated_sql
|
903
|
+
@sampler.notice_pop_scope "foo"
|
904
|
+
end
|
905
|
+
|
906
|
+
def test_param_capture
|
907
|
+
[true, false].each do |capture|
|
908
|
+
with_config(:capture_params => capture) do
|
909
|
+
tt = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
|
910
|
+
@sampler.notice_first_scope_push Time.now.to_f
|
911
|
+
@sampler.notice_transaction('/path', nil, {:param => 'hi'})
|
912
|
+
@sampler.notice_scope_empty
|
913
|
+
@sampler.harvest(nil)[0]
|
914
|
+
end
|
915
|
+
|
916
|
+
assert_equal (capture) ? 1 : 0, tt.params[:request_params].length
|
917
|
+
end
|
918
|
+
end
|
919
|
+
end
|
920
|
+
|
921
|
+
def test_should_not_collect_segments_beyond_limit
|
922
|
+
with_config(:'transaction_tracer.limit_segments' => 3) do
|
923
|
+
run_sample_trace do
|
924
|
+
@sampler.notice_push_scope 'a1'
|
925
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'hallah'", nil, 0)
|
926
|
+
@sampler.notice_push_scope 'a11'
|
927
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", nil, 0)
|
928
|
+
@sampler.notice_pop_scope "a11"
|
929
|
+
@sampler.notice_pop_scope "a1"
|
930
|
+
end
|
931
|
+
assert_equal 3, @sampler.samples[0].count_segments
|
932
|
+
end
|
933
|
+
end
|
934
|
+
|
935
|
+
def test_renaming_current_segment_midflight
|
936
|
+
@sampler.start_builder
|
937
|
+
@sampler.notice_push_scope( 'External/www.google.com/all' )
|
938
|
+
@sampler.rename_scope_segment( 'External/www.google.com/Net::HTTP/GET' )
|
939
|
+
assert_nothing_raised do
|
940
|
+
@sampler.notice_pop_scope( 'External/www.google.com/Net::HTTP/GET' )
|
941
|
+
end
|
942
|
+
end
|
943
|
+
|
944
|
+
def test_adding_segment_parameters
|
945
|
+
@sampler.start_builder
|
946
|
+
@sampler.notice_push_scope( 'External/www.google.com/all' )
|
947
|
+
@sampler.add_segment_parameters( :transaction_guid => '97612F92E6194080' )
|
948
|
+
assert_equal '97612F92E6194080', @sampler.builder.current_segment[:transaction_guid]
|
949
|
+
end
|
950
|
+
|
951
|
+
private
|
952
|
+
|
953
|
+
def run_sample_trace(start = Time.now.to_f, stop = nil)
|
954
|
+
@sampler.notice_first_scope_push start
|
955
|
+
@sampler.notice_transaction '/path', nil, {}
|
956
|
+
@sampler.notice_push_scope "a"
|
957
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", nil, 0)
|
958
|
+
@sampler.notice_push_scope "ab"
|
959
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", nil, 0)
|
960
|
+
yield if block_given?
|
961
|
+
@sampler.notice_pop_scope "ab"
|
962
|
+
@sampler.notice_push_scope "ac"
|
963
|
+
@sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", nil, 0)
|
964
|
+
@sampler.notice_pop_scope "ac"
|
965
|
+
@sampler.notice_pop_scope "a"
|
966
|
+
@sampler.notice_scope_empty stop || Time.now.to_f
|
967
|
+
end
|
968
|
+
end
|