wd_newrelic_rpm 3.3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +591 -0
- data/LICENSE +64 -0
- data/README.rdoc +179 -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/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 +467 -0
- data/lib/new_relic/agent/agent.rb +1325 -0
- data/lib/new_relic/agent/beacon_configuration.rb +121 -0
- data/lib/new_relic/agent/browser_monitoring.rb +142 -0
- data/lib/new_relic/agent/busy_calculator.rb +99 -0
- data/lib/new_relic/agent/chained_call.rb +13 -0
- data/lib/new_relic/agent/database.rb +223 -0
- data/lib/new_relic/agent/error_collector.rb +251 -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 +137 -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/controller_instrumentation.rb +443 -0
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -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 +353 -0
- data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
- data/lib/new_relic/agent/instrumentation/net.rb +29 -0
- data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
- data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -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 +37 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
- data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
- data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
- data/lib/new_relic/agent/method_tracer.rb +528 -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_lock_sampler.rb +40 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
- data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
- data/lib/new_relic/agent/shim_agent.rb +29 -0
- data/lib/new_relic/agent/sql_sampler.rb +286 -0
- data/lib/new_relic/agent/stats_engine.rb +26 -0
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
- data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
- data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
- data/lib/new_relic/agent/transaction_info.rb +74 -0
- data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
- data/lib/new_relic/agent/transaction_sampler.rb +468 -0
- data/lib/new_relic/agent/worker_loop.rb +89 -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 +105 -0
- data/lib/new_relic/commands/install.rb +80 -0
- data/lib/new_relic/control.rb +46 -0
- data/lib/new_relic/control/class_methods.rb +53 -0
- data/lib/new_relic/control/configuration.rb +206 -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 +31 -0
- data/lib/new_relic/control/frameworks/rails.rb +164 -0
- data/lib/new_relic/control/frameworks/rails3.rb +75 -0
- data/lib/new_relic/control/frameworks/ruby.rb +42 -0
- data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
- data/lib/new_relic/control/instance_methods.rb +179 -0
- data/lib/new_relic/control/instrumentation.rb +100 -0
- data/lib/new_relic/control/logging_methods.rb +143 -0
- data/lib/new_relic/control/profiling.rb +25 -0
- data/lib/new_relic/control/server_methods.rb +114 -0
- data/lib/new_relic/data_serialization.rb +151 -0
- data/lib/new_relic/delayed_job_injection.rb +51 -0
- data/lib/new_relic/language_support.rb +73 -0
- data/lib/new_relic/local_environment.rb +428 -0
- data/lib/new_relic/merbtasks.rb +6 -0
- data/lib/new_relic/metric_data.rb +51 -0
- data/lib/new_relic/metric_spec.rb +76 -0
- data/lib/new_relic/metrics.rb +9 -0
- data/lib/new_relic/noticed_error.rb +29 -0
- data/lib/new_relic/rack/browser_monitoring.rb +76 -0
- data/lib/new_relic/rack/developer_mode.rb +268 -0
- data/lib/new_relic/recipes.rb +77 -0
- data/lib/new_relic/stats.rb +335 -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 +261 -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 +203 -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 +55 -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 +19 -0
- data/newrelic.yml +265 -0
- data/newrelic_rpm.gemspec +312 -0
- data/recipes/newrelic.rb +6 -0
- data/test/active_record_fixtures.rb +77 -0
- data/test/config/newrelic.yml +48 -0
- data/test/config/test_control.rb +48 -0
- data/test/fixtures/proc_cpuinfo.txt +575 -0
- data/test/new_relic/agent/agent/connect_test.rb +403 -0
- data/test/new_relic/agent/agent/start_test.rb +255 -0
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
- data/test/new_relic/agent/agent_test.rb +140 -0
- data/test/new_relic/agent/agent_test_controller.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
- data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
- data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
- data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
- data/test/new_relic/agent/busy_calculator_test.rb +81 -0
- data/test/new_relic/agent/database_test.rb +149 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
- data/test/new_relic/agent/error_collector_test.rb +192 -0
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -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 +50 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
- data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
- data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -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 +164 -0
- data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
- data/test/new_relic/agent/method_tracer_test.rb +386 -0
- data/test/new_relic/agent/mock_scope_listener.rb +23 -0
- data/test/new_relic/agent/rpm_agent_test.rb +149 -0
- data/test/new_relic/agent/sampler_test.rb +19 -0
- data/test/new_relic/agent/shim_agent_test.rb +20 -0
- data/test/new_relic/agent/sql_sampler_test.rb +192 -0
- data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
- data/test/new_relic/agent/stats_engine_test.rb +220 -0
- data/test/new_relic/agent/transaction_info_test.rb +13 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
- data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
- data/test/new_relic/agent/worker_loop_test.rb +66 -0
- data/test/new_relic/agent_test.rb +187 -0
- data/test/new_relic/collection_helper_test.rb +149 -0
- data/test/new_relic/command/deployments_test.rb +68 -0
- data/test/new_relic/control/class_methods_test.rb +62 -0
- data/test/new_relic/control/configuration_test.rb +84 -0
- data/test/new_relic/control/logging_methods_test.rb +185 -0
- data/test/new_relic/control_test.rb +256 -0
- data/test/new_relic/data_serialization_test.rb +208 -0
- data/test/new_relic/delayed_job_injection_test.rb +16 -0
- data/test/new_relic/local_environment_test.rb +85 -0
- data/test/new_relic/metric_data_test.rb +125 -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/rack/all_test.rb +11 -0
- data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
- data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
- data/test/new_relic/rack/developer_mode_test.rb +74 -0
- data/test/new_relic/stats_test.rb +411 -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 +389 -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 +177 -0
- data/test/new_relic/version_number_test.rb +89 -0
- data/test/script/build_test_gem.sh +51 -0
- data/test/script/ci.sh +94 -0
- data/test/script/ci_bench.sh +52 -0
- data/test/test_contexts.rb +29 -0
- data/test/test_helper.rb +155 -0
- data/ui/helpers/developer_mode_helper.rb +357 -0
- data/ui/helpers/google_pie_chart.rb +48 -0
- data/ui/views/layouts/newrelic_default.rhtml +47 -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 +53 -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/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/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 +376 -0
@@ -0,0 +1,576 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
|
3
|
+
class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::Unit::TestCase
|
4
|
+
require 'active_record_fixtures'
|
5
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
6
|
+
|
7
|
+
def setup
|
8
|
+
super
|
9
|
+
NewRelic::Agent.manual_start
|
10
|
+
ActiveRecordFixtures.setup
|
11
|
+
NewRelic::Agent.instance.transaction_sampler.reset!
|
12
|
+
NewRelic::Agent.instance.stats_engine.clear_stats
|
13
|
+
rescue => e
|
14
|
+
puts e
|
15
|
+
puts e.backtrace.join("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
super
|
20
|
+
NewRelic::Agent.shutdown
|
21
|
+
end
|
22
|
+
|
23
|
+
#####################################################################
|
24
|
+
# Note: If these tests are failing, most likely the problem is that #
|
25
|
+
# the active record instrumentation is not loading for whichever #
|
26
|
+
# version of rails you're testing at the moment. #
|
27
|
+
#####################################################################
|
28
|
+
|
29
|
+
def test_agent_setup
|
30
|
+
assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_finder
|
34
|
+
ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
35
|
+
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
36
|
+
|
37
|
+
assert_calls_metrics(find_metric) do
|
38
|
+
ActiveRecordFixtures::Order.find(:all)
|
39
|
+
check_metric_count(find_metric, 1)
|
40
|
+
ActiveRecordFixtures::Order.find_all_by_name "jeff"
|
41
|
+
check_metric_count(find_metric, 2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_exists
|
46
|
+
return if NewRelic::Control.instance.rails_version < "2.3.4" ||
|
47
|
+
NewRelic::Control.instance.rails_version >= "3.0.7"
|
48
|
+
|
49
|
+
ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
50
|
+
|
51
|
+
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
52
|
+
|
53
|
+
assert_calls_metrics(find_metric) do
|
54
|
+
ActiveRecordFixtures::Order.exists?(["name=?", 'jeff'])
|
55
|
+
check_metric_count(find_metric, 1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# multiple duplicate find calls should only cause metric trigger on the first
|
60
|
+
# call. the others are ignored.
|
61
|
+
def test_query_cache
|
62
|
+
# Not sure why we get a transaction error with sqlite
|
63
|
+
return if isSqlite?
|
64
|
+
|
65
|
+
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
66
|
+
ActiveRecordFixtures::Order.cache do
|
67
|
+
m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
68
|
+
assert_calls_metrics(find_metric) do
|
69
|
+
ActiveRecordFixtures::Order.find(:all)
|
70
|
+
end
|
71
|
+
|
72
|
+
check_metric_count(find_metric, 1)
|
73
|
+
|
74
|
+
assert_calls_metrics(find_metric) do
|
75
|
+
10.times { ActiveRecordFixtures::Order.find m.id }
|
76
|
+
end
|
77
|
+
check_metric_count(find_metric, 2)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_metric_names_jruby
|
82
|
+
# fails due to a bug in rails 3 - log does not provide the correct
|
83
|
+
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
84
|
+
return if rails3? || !defined?(JRuby)
|
85
|
+
expected = %W[
|
86
|
+
ActiveRecord/all
|
87
|
+
ActiveRecord/find
|
88
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
89
|
+
Database/SQL/insert
|
90
|
+
RemoteService/sql/mysql/localhost
|
91
|
+
]
|
92
|
+
|
93
|
+
if NewRelic::Control.instance.rails_version < '2.1.0'
|
94
|
+
expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_calls_metrics(*expected) do
|
98
|
+
m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
99
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
100
|
+
m.id = 999
|
101
|
+
m.save!
|
102
|
+
end
|
103
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
104
|
+
|
105
|
+
compare_metrics expected, metrics
|
106
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
107
|
+
# zero because jruby uses a different mysql adapter
|
108
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 0)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_metric_names_sqlite
|
112
|
+
# fails due to a bug in rails 3 - log does not provide the correct
|
113
|
+
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
114
|
+
return if rails3? || !isSqlite? || defined?(JRuby)
|
115
|
+
|
116
|
+
expected = %W[
|
117
|
+
ActiveRecord/all
|
118
|
+
ActiveRecord/find
|
119
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
120
|
+
ActiveRecord/create
|
121
|
+
ActiveRecord/ActiveRecordFixtures::Order/create]
|
122
|
+
|
123
|
+
if NewRelic::Control.instance.rails_version < '2.1.0'
|
124
|
+
expected += %W[ActiveRecord/save ActiveRecord/ActiveRecordFixtures::Order/save]
|
125
|
+
end
|
126
|
+
|
127
|
+
assert_calls_metrics(*expected) do
|
128
|
+
m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
|
129
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
130
|
+
m.id = 999
|
131
|
+
m.save!
|
132
|
+
end
|
133
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
134
|
+
|
135
|
+
compare_metrics expected, metrics
|
136
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
137
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_metric_names_standard
|
141
|
+
# fails due to a bug in rails 3 - log does not provide the correct
|
142
|
+
# transaction type - it returns 'SQL' instead of 'Foo Create', for example.
|
143
|
+
return if defined?(JRuby) || isSqlite?
|
144
|
+
|
145
|
+
expected = %W[
|
146
|
+
ActiveRecord/all
|
147
|
+
ActiveRecord/find
|
148
|
+
ActiveRecord/create
|
149
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
150
|
+
ActiveRecord/ActiveRecordFixtures::Order/create
|
151
|
+
Database/SQL/other
|
152
|
+
RemoteService/sql/mysql/localhost]
|
153
|
+
|
154
|
+
if NewRelic::Control.instance.rails_version < '2.1.0'
|
155
|
+
expected += ['ActiveRecord/save',
|
156
|
+
'ActiveRecord/ActiveRecordFixtures::Order/save']
|
157
|
+
elsif NewRelic::Control.instance.rails_version >= '3.0.0'
|
158
|
+
expected << 'Database/SQL/insert'
|
159
|
+
end
|
160
|
+
|
161
|
+
assert_calls_metrics(*expected) do
|
162
|
+
m = ActiveRecordFixtures::Order.create :id => 0, :name => 'donkey'
|
163
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
164
|
+
m.id = 999
|
165
|
+
m.save!
|
166
|
+
end
|
167
|
+
|
168
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
169
|
+
|
170
|
+
compare_metrics expected, metrics
|
171
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
172
|
+
if NewRelic::Control.instance.rails_version < '3.0.0'
|
173
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/create", 1)
|
174
|
+
else
|
175
|
+
check_metric_count("Database/SQL/insert", 1)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_join_metrics_jruby
|
180
|
+
return unless defined?(JRuby)
|
181
|
+
return if rails3?
|
182
|
+
|
183
|
+
expected_metrics = %W[
|
184
|
+
ActiveRecord/all
|
185
|
+
ActiveRecord/destroy
|
186
|
+
ActiveRecord/ActiveRecordFixtures::Order/destroy
|
187
|
+
Database/SQL/insert
|
188
|
+
Database/SQL/delete
|
189
|
+
Database/SQL/show
|
190
|
+
ActiveRecord/find
|
191
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
192
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/find
|
193
|
+
RemoteService/sql/mysql/localhost
|
194
|
+
]
|
195
|
+
|
196
|
+
assert_calls_metrics(*expected_metrics) do
|
197
|
+
m = ActiveRecordFixtures::Order.create :name => 'jeff'
|
198
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
199
|
+
s = m.shipments.create
|
200
|
+
m.shipments.to_a
|
201
|
+
m.destroy
|
202
|
+
end
|
203
|
+
|
204
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
205
|
+
|
206
|
+
compare_metrics expected_metrics, metrics
|
207
|
+
|
208
|
+
check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
|
209
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
210
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
|
211
|
+
check_metric_count("Database/SQL/insert", 3)
|
212
|
+
check_metric_count("Database/SQL/delete", 1)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_join_metrics_sqlite
|
216
|
+
return if (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3)
|
217
|
+
return if defined?(JRuby)
|
218
|
+
return unless isSqlite?
|
219
|
+
|
220
|
+
expected_metrics = %W[
|
221
|
+
ActiveRecord/all
|
222
|
+
ActiveRecord/destroy
|
223
|
+
ActiveRecord/ActiveRecordFixtures::Order/destroy
|
224
|
+
Database/SQL/insert
|
225
|
+
Database/SQL/delete
|
226
|
+
ActiveRecord/find
|
227
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
228
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/find
|
229
|
+
ActiveRecord/create
|
230
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/create
|
231
|
+
ActiveRecord/ActiveRecordFixtures::Order/create
|
232
|
+
]
|
233
|
+
|
234
|
+
assert_calls_metrics(*expected_metrics) do
|
235
|
+
m = ActiveRecordFixtures::Order.create :name => 'jeff'
|
236
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
237
|
+
s = m.shipments.create
|
238
|
+
m.shipments.to_a
|
239
|
+
m.destroy
|
240
|
+
end
|
241
|
+
|
242
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
243
|
+
compare_metrics expected_metrics, metrics
|
244
|
+
if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
|
245
|
+
check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
|
246
|
+
end
|
247
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
248
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
|
249
|
+
check_metric_count("Database/SQL/insert", 3)
|
250
|
+
check_metric_count("Database/SQL/delete", 1)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_join_metrics_standard
|
254
|
+
return if (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3)
|
255
|
+
return if defined?(JRuby) || isSqlite?
|
256
|
+
|
257
|
+
expected_metrics = %W[
|
258
|
+
ActiveRecord/all
|
259
|
+
RemoteService/sql/mysql/localhost
|
260
|
+
ActiveRecord/destroy
|
261
|
+
ActiveRecord/ActiveRecordFixtures::Order/destroy
|
262
|
+
Database/SQL/insert
|
263
|
+
Database/SQL/delete
|
264
|
+
ActiveRecord/find
|
265
|
+
ActiveRecord/ActiveRecordFixtures::Order/find
|
266
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/find
|
267
|
+
Database/SQL/other
|
268
|
+
Database/SQL/show
|
269
|
+
ActiveRecord/create
|
270
|
+
ActiveRecord/ActiveRecordFixtures::Shipment/create
|
271
|
+
ActiveRecord/ActiveRecordFixtures::Order/create
|
272
|
+
]
|
273
|
+
|
274
|
+
assert_calls_metrics(*expected_metrics) do
|
275
|
+
m = ActiveRecordFixtures::Order.create :name => 'jeff'
|
276
|
+
m = ActiveRecordFixtures::Order.find(m.id)
|
277
|
+
s = m.shipments.create
|
278
|
+
m.shipments.to_a
|
279
|
+
m.destroy
|
280
|
+
end
|
281
|
+
|
282
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
283
|
+
|
284
|
+
compare_metrics expected_metrics, metrics
|
285
|
+
if !(defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise Edition/)
|
286
|
+
check_metric_time('ActiveRecord/all', NewRelic::Agent.get_stats("ActiveRecord/all").total_exclusive_time, 0)
|
287
|
+
end
|
288
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
|
289
|
+
check_metric_count("ActiveRecord/ActiveRecordFixtures::Shipment/find", 1)
|
290
|
+
check_metric_count("Database/SQL/insert", 1)
|
291
|
+
check_metric_count("Database/SQL/delete", 1)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_direct_sql
|
295
|
+
assert_nil NewRelic::Agent::Instrumentation::MetricFrame.current
|
296
|
+
assert_nil NewRelic::Agent.instance.stats_engine.scope_name
|
297
|
+
assert_equal 0, NewRelic::Agent.instance.stats_engine.metrics.size, NewRelic::Agent.instance.stats_engine.metrics.inspect
|
298
|
+
|
299
|
+
expected_metrics = %W[
|
300
|
+
ActiveRecord/all
|
301
|
+
Database/SQL/select
|
302
|
+
RemoteService/sql/mysql/localhost
|
303
|
+
]
|
304
|
+
|
305
|
+
assert_calls_unscoped_metrics(*expected_metrics) do
|
306
|
+
ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
|
307
|
+
end
|
308
|
+
|
309
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
310
|
+
compare_metrics(expected_metrics, metrics)
|
311
|
+
|
312
|
+
check_unscoped_metric_count('Database/SQL/select', 1)
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
def test_other_sql
|
317
|
+
expected_metrics = %W[
|
318
|
+
ActiveRecord/all
|
319
|
+
Database/SQL/other
|
320
|
+
RemoteService/sql/mysql/localhost
|
321
|
+
]
|
322
|
+
assert_calls_unscoped_metrics(*expected_metrics) do
|
323
|
+
ActiveRecordFixtures::Order.connection.execute "begin"
|
324
|
+
end
|
325
|
+
|
326
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
327
|
+
|
328
|
+
compare_metrics expected_metrics, metrics
|
329
|
+
check_unscoped_metric_count('Database/SQL/other', 1)
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_show_sql
|
333
|
+
return if isSqlite?
|
334
|
+
return if isPostgres?
|
335
|
+
|
336
|
+
expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/mysql/localhost]
|
337
|
+
|
338
|
+
assert_calls_metrics(*expected_metrics) do
|
339
|
+
ActiveRecordFixtures::Order.connection.execute "show tables"
|
340
|
+
end
|
341
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
342
|
+
compare_metrics expected_metrics, metrics
|
343
|
+
check_unscoped_metric_count('Database/SQL/show', 1)
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_blocked_instrumentation
|
347
|
+
ActiveRecordFixtures::Order.add_delay
|
348
|
+
NewRelic::Agent.disable_all_tracing do
|
349
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
350
|
+
ActiveRecordFixtures::Order.find(:all)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
|
354
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
355
|
+
compare_metrics [], metrics
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_run_explains
|
359
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
360
|
+
ActiveRecordFixtures::Order.add_delay
|
361
|
+
ActiveRecordFixtures::Order.find(:all)
|
362
|
+
end
|
363
|
+
|
364
|
+
# that's a mouthful. perhaps we should ponder our API.
|
365
|
+
segment = NewRelic::Agent.instance.transaction_sampler.last_sample \
|
366
|
+
.root_segment.called_segments[0].called_segments[0].called_segments[0]
|
367
|
+
regex = /^SELECT (["`]?#{ActiveRecordFixtures::Order.table_name}["`]?.)?\* FROM ["`]?#{ActiveRecordFixtures::Order.table_name}["`]?$/
|
368
|
+
assert_match regex, segment.params[:sql].strip
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_prepare_to_send
|
372
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
373
|
+
ActiveRecordFixtures::Order.add_delay
|
374
|
+
ActiveRecordFixtures::Order.find(:all)
|
375
|
+
end
|
376
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
377
|
+
assert_not_nil sample
|
378
|
+
|
379
|
+
includes_gc = false
|
380
|
+
sample.each_segment {|s| includes_gc ||= s.metric_name =~ /GC/ }
|
381
|
+
|
382
|
+
assert_equal (includes_gc ? 4 : 3), sample.count_segments, sample.to_s
|
383
|
+
|
384
|
+
sql_segment = sample.root_segment.called_segments.first.called_segments.first.called_segments.first
|
385
|
+
assert_not_nil sql_segment, sample.to_s
|
386
|
+
assert_match /^SELECT /, sql_segment.params[:sql]
|
387
|
+
assert sql_segment.duration > 0.0, "Segment duration must be greater than zero."
|
388
|
+
sample = sample.prepare_to_send(:record_sql => :raw, :explain_sql => 0.0)
|
389
|
+
sql_segment = sample.root_segment.called_segments.first.called_segments.first.called_segments.first
|
390
|
+
assert_match /^SELECT /, sql_segment.params[:sql]
|
391
|
+
explanations = sql_segment.params[:explain_plan]
|
392
|
+
if isMysql? || isPostgres?
|
393
|
+
assert_not_nil explanations, "No explains in segment: #{sql_segment}"
|
394
|
+
assert_equal(2, explanations.size,
|
395
|
+
"No explains in segment: #{sql_segment}")
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_transaction_mysql
|
400
|
+
return unless isMysql? && !defined?(JRuby)
|
401
|
+
ActiveRecordFixtures.setup
|
402
|
+
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
403
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
404
|
+
ActiveRecordFixtures::Order.add_delay
|
405
|
+
ActiveRecordFixtures::Order.find(:all)
|
406
|
+
end
|
407
|
+
|
408
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
409
|
+
|
410
|
+
sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
|
411
|
+
segment = sample.root_segment.called_segments.first.called_segments.first.called_segments.first
|
412
|
+
explanation = segment.params[:explain_plan]
|
413
|
+
assert_not_nil explanation, "No explains in segment: #{segment}"
|
414
|
+
assert_equal 2, explanation.size,"No explains in segment: #{segment}"
|
415
|
+
|
416
|
+
assert_equal 10, explanation[0].size
|
417
|
+
['id', 'select_type', 'table'].each do |c|
|
418
|
+
assert explanation[0].include?(c)
|
419
|
+
end
|
420
|
+
['1', 'SIMPLE', ActiveRecordFixtures::Order.table_name].each do |c|
|
421
|
+
assert explanation[1][0].include?(c)
|
422
|
+
end
|
423
|
+
|
424
|
+
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
425
|
+
assert_equal 1, s.call_count
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_transaction_postgres
|
429
|
+
return unless isPostgres?
|
430
|
+
# note that our current test builds do not use postgres, this is
|
431
|
+
# here strictly for troubleshooting, not CI builds
|
432
|
+
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
433
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
434
|
+
ActiveRecordFixtures::Order.add_delay
|
435
|
+
ActiveRecordFixtures::Order.find(:all)
|
436
|
+
end
|
437
|
+
|
438
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
439
|
+
|
440
|
+
sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
|
441
|
+
segment = sample.root_segment.called_segments.first.called_segments.first.called_segments.first
|
442
|
+
explanations = segment.params[:explain_plan]
|
443
|
+
|
444
|
+
assert_not_nil explanations, "No explains in segment: #{segment}"
|
445
|
+
assert_equal 1, explanations.size,"No explains in segment: #{segment}"
|
446
|
+
assert_equal 1, explanations.first.size
|
447
|
+
|
448
|
+
assert_equal("Explain Plan", explanations[0][0])
|
449
|
+
assert_match /Seq Scan on test_data/, explanations[0][1].join(";")
|
450
|
+
|
451
|
+
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
452
|
+
assert_equal 1, s.call_count
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_transaction_other
|
456
|
+
return if isMysql? || isPostgres?
|
457
|
+
sample = NewRelic::Agent.instance.transaction_sampler.reset!
|
458
|
+
perform_action_with_newrelic_trace :name => 'bogosity' do
|
459
|
+
ActiveRecordFixtures::Order.add_delay
|
460
|
+
ActiveRecordFixtures::Order.find(:all)
|
461
|
+
end
|
462
|
+
|
463
|
+
sample = NewRelic::Agent.instance.transaction_sampler.last_sample
|
464
|
+
|
465
|
+
sample = sample.prepare_to_send(:record_sql => :obfuscated, :explain_sql => 0.0)
|
466
|
+
segment = sample.root_segment.called_segments.first.called_segments.first.called_segments.first
|
467
|
+
|
468
|
+
s = NewRelic::Agent.get_stats("ActiveRecord/ActiveRecordFixtures::Order/find")
|
469
|
+
assert_equal 1, s.call_count
|
470
|
+
end
|
471
|
+
|
472
|
+
# These are only valid for rails 2.1 and later
|
473
|
+
if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
|
474
|
+
ActiveRecordFixtures::Order.class_eval do
|
475
|
+
if NewRelic::Control.instance.rails_version < NewRelic::VersionNumber.new("3.1")
|
476
|
+
named_scope :jeffs, :conditions => { :name => 'Jeff' }
|
477
|
+
else
|
478
|
+
scope :jeffs, :conditions => { :name => 'Jeff' }
|
479
|
+
end
|
480
|
+
end
|
481
|
+
def test_named_scope
|
482
|
+
ActiveRecordFixtures::Order.create :name => 'Jeff'
|
483
|
+
|
484
|
+
find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
|
485
|
+
|
486
|
+
check_metric_count(find_metric, 0)
|
487
|
+
assert_calls_metrics(find_metric) do
|
488
|
+
x = ActiveRecordFixtures::Order.jeffs.find(:all)
|
489
|
+
end
|
490
|
+
check_metric_count(find_metric, 1)
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
# This is to make sure the all metric is recorded for exceptional cases
|
495
|
+
def test_error_handling
|
496
|
+
# have the AR select throw an error
|
497
|
+
ActiveRecordFixtures::Order.connection.stubs(:log_info).with do | sql, x, y |
|
498
|
+
raise "Error" if sql =~ /select/
|
499
|
+
true
|
500
|
+
end
|
501
|
+
|
502
|
+
expected_metrics = %W[ActiveRecord/all Database/SQL/select RemoteService/sql/mysql/localhost]
|
503
|
+
|
504
|
+
assert_calls_metrics(*expected_metrics) do
|
505
|
+
begin
|
506
|
+
ActiveRecordFixtures::Order.connection.select_rows "select * from #{ActiveRecordFixtures::Order.table_name}"
|
507
|
+
rescue RuntimeError => e
|
508
|
+
# catch only the error we raise above
|
509
|
+
raise unless e.message == 'Error'
|
510
|
+
end
|
511
|
+
end
|
512
|
+
metrics = NewRelic::Agent.instance.stats_engine.metrics
|
513
|
+
compare_metrics expected_metrics, metrics
|
514
|
+
check_metric_count('Database/SQL/select', 1)
|
515
|
+
check_metric_count('ActiveRecord/all', 1)
|
516
|
+
check_metric_count('RemoteService/sql/mysql/localhost', 1)
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_rescue_handling
|
520
|
+
# Not sure why we get a transaction error with sqlite
|
521
|
+
return if isSqlite?
|
522
|
+
|
523
|
+
begin
|
524
|
+
ActiveRecordFixtures::Order.transaction do
|
525
|
+
raise ActiveRecord::ActiveRecordError.new('preserve-me!')
|
526
|
+
end
|
527
|
+
rescue ActiveRecord::ActiveRecordError => e
|
528
|
+
assert_equal 'preserve-me!', e.message
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_remote_service_metric_respects_dynamic_connection_config
|
533
|
+
return unless isMysql?
|
534
|
+
|
535
|
+
# puts NewRelic::Agent::Database.config.inspect
|
536
|
+
|
537
|
+
ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
|
538
|
+
assert(NewRelic::Agent.get_stats('RemoteService/sql/mysql/localhost').call_count != 0)
|
539
|
+
|
540
|
+
config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
|
541
|
+
config[:host] = '127.0.0.1'
|
542
|
+
connection = ActiveRecordFixtures::Shipment.establish_connection(config)
|
543
|
+
|
544
|
+
# puts ActiveRecord::Base.connection.instance_eval { @config }.inspect
|
545
|
+
# puts NewRelic::Agent::Database.config.inspect
|
546
|
+
|
547
|
+
ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
|
548
|
+
assert(NewRelic::Agent.get_stats('RemoteService/sql/mysql/127.0.0.1').call_count != 0)
|
549
|
+
|
550
|
+
config[:host] = 'localhost'
|
551
|
+
ActiveRecordFixtures::Shipment.establish_connection(config)
|
552
|
+
|
553
|
+
# raise NewRelic::Agent.instance.stats_engine.inspect
|
554
|
+
end
|
555
|
+
|
556
|
+
private
|
557
|
+
|
558
|
+
def rails3?
|
559
|
+
(defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3)
|
560
|
+
end
|
561
|
+
|
562
|
+
def rails_env
|
563
|
+
rails3? ? ::Rails.env : RAILS_ENV
|
564
|
+
end
|
565
|
+
|
566
|
+
def isPostgres?
|
567
|
+
ActiveRecordFixtures::Order.configurations[rails_env]['adapter'] =~ /postgres/i
|
568
|
+
end
|
569
|
+
def isMysql?
|
570
|
+
ActiveRecordFixtures::Order.connection.class.name =~ /mysql/i
|
571
|
+
end
|
572
|
+
|
573
|
+
def isSqlite?
|
574
|
+
ActiveRecord::Base.configurations[rails_env]['adapter'] =~ /sqlite/i
|
575
|
+
end
|
576
|
+
end
|