wd_newrelic_rpm 3.3.4.1 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. data/.gitignore +20 -0
  2. data/.project +23 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +317 -39
  5. data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE +1 -1
  8. data/{README.rdoc → README.md} +71 -55
  9. data/Rakefile +62 -0
  10. data/bin/mongrel_rpm +1 -1
  11. data/config.dot +290 -0
  12. data/config/database.yml +5 -0
  13. data/init.rb +31 -0
  14. data/lib/new_relic/agent.rb +31 -60
  15. data/lib/new_relic/agent/agent.rb +277 -502
  16. data/lib/new_relic/agent/agent_logger.rb +165 -0
  17. data/lib/new_relic/agent/audit_logger.rb +72 -0
  18. data/lib/new_relic/agent/beacon_configuration.rb +36 -50
  19. data/lib/new_relic/agent/browser_monitoring.rb +114 -61
  20. data/lib/new_relic/agent/busy_calculator.rb +14 -6
  21. data/lib/new_relic/agent/configuration.rb +74 -0
  22. data/lib/new_relic/agent/configuration/defaults.rb +126 -0
  23. data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
  24. data/lib/new_relic/agent/configuration/manager.rb +136 -0
  25. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  26. data/lib/new_relic/agent/configuration/server_source.rb +27 -0
  27. data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
  28. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  29. data/lib/new_relic/agent/database.rb +39 -26
  30. data/lib/new_relic/agent/error_collector.rb +48 -49
  31. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
  33. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  36. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
  37. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
  38. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  39. data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
  40. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  42. data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
  43. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
  46. data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
  47. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  48. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
  49. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  50. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  51. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  52. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
  53. data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
  54. data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
  55. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  56. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
  57. data/lib/new_relic/agent/method_tracer.rb +11 -9
  58. data/lib/new_relic/agent/new_relic_service.rb +379 -0
  59. data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
  60. data/lib/new_relic/agent/pipe_service.rb +58 -0
  61. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
  62. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
  63. data/lib/new_relic/agent/sql_sampler.rb +31 -74
  64. data/lib/new_relic/agent/stats_engine.rb +0 -5
  65. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
  66. data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
  67. data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
  68. data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
  69. data/lib/new_relic/agent/thread.rb +32 -0
  70. data/lib/new_relic/agent/thread_profiler.rb +306 -0
  71. data/lib/new_relic/agent/transaction_info.rb +24 -4
  72. data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
  73. data/lib/new_relic/agent/transaction_sampler.rb +49 -65
  74. data/lib/new_relic/agent/worker_loop.rb +31 -25
  75. data/lib/new_relic/collection_helper.rb +1 -1
  76. data/lib/new_relic/commands/deployments.rb +19 -10
  77. data/lib/new_relic/control.rb +1 -3
  78. data/lib/new_relic/control/class_methods.rb +10 -5
  79. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  80. data/lib/new_relic/control/frameworks/rails.rb +30 -45
  81. data/lib/new_relic/control/frameworks/rails3.rb +23 -18
  82. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  83. data/lib/new_relic/control/frameworks/ruby.rb +2 -23
  84. data/lib/new_relic/control/instance_methods.rb +35 -73
  85. data/lib/new_relic/control/instrumentation.rb +7 -12
  86. data/lib/new_relic/control/server_methods.rb +17 -19
  87. data/lib/new_relic/delayed_job_injection.rb +2 -2
  88. data/lib/new_relic/helper.rb +34 -0
  89. data/lib/new_relic/language_support.rb +56 -37
  90. data/lib/new_relic/local_environment.rb +32 -67
  91. data/lib/new_relic/metric_data.rb +10 -2
  92. data/lib/new_relic/metric_spec.rb +7 -3
  93. data/lib/new_relic/noticed_error.rb +32 -9
  94. data/lib/new_relic/rack.rb +4 -0
  95. data/lib/new_relic/rack/browser_monitoring.rb +34 -25
  96. data/lib/new_relic/rack/developer_mode.rb +3 -0
  97. data/lib/new_relic/rack/error_collector.rb +56 -0
  98. data/lib/new_relic/stats.rb +9 -7
  99. data/lib/new_relic/transaction_sample.rb +19 -18
  100. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  101. data/lib/new_relic/version.rb +19 -3
  102. data/lib/newrelic_rpm.rb +1 -1
  103. data/lib/tasks/tests.rake +6 -8
  104. data/newrelic.yml +15 -32
  105. data/newrelic_rpm.gemspec +224 -43
  106. data/newrelic_rpm.gemspec.erb +54 -0
  107. data/test/config/newrelic.yml +4 -3
  108. data/test/config/test_control.rb +18 -18
  109. data/test/fixtures/gemspec_no_build.rb +442 -0
  110. data/test/fixtures/gemspec_with_build.rb +442 -0
  111. data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
  112. data/test/intentional_fail.rb +10 -0
  113. data/test/multiverse/.gitignore +10 -0
  114. data/test/multiverse/README.md +85 -0
  115. data/test/multiverse/lib/multiverse/color.rb +13 -0
  116. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  117. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  118. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  119. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  120. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  121. data/test/multiverse/script/run_one +3 -0
  122. data/test/multiverse/script/runner +9 -0
  123. data/test/multiverse/suites/active_record/Envfile +13 -0
  124. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  125. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  126. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  127. data/test/multiverse/suites/agent_only/Envfile +4 -0
  128. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  129. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  130. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  131. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  132. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  133. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  134. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  135. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  136. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  137. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  138. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  139. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  140. data/test/multiverse/suites/datamapper/Envfile +8 -0
  141. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  142. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  143. data/test/multiverse/suites/logging/Envfile +4 -0
  144. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  145. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  146. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  147. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  148. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  149. data/test/multiverse/suites/no_load/Envfile +2 -0
  150. data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
  151. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  152. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  153. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  154. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  155. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  156. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  157. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  158. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  159. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  160. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  161. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  162. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  163. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  164. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  165. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  166. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  167. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  168. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  169. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  170. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  171. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  172. data/test/multiverse/suites/resque/Envfile +21 -0
  173. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  174. data/test/multiverse/suites/resque/dump.rdb +0 -0
  175. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  176. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  177. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  178. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  179. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
  180. data/test/multiverse/suites/sinatra/Envfile +13 -0
  181. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  182. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
  183. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  184. data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
  185. data/test/multiverse/test/multiverse_test.rb +55 -0
  186. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  187. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  188. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  189. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  190. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  191. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  192. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  193. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  194. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  195. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  196. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  197. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  198. data/test/new_relic/agent/agent/connect_test.rb +151 -227
  199. data/test/new_relic/agent/agent/start_test.rb +68 -118
  200. data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
  201. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  202. data/test/new_relic/agent/agent_test.rb +116 -30
  203. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  204. data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
  205. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  206. data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
  207. data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
  208. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  209. data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
  210. data/test/new_relic/agent/configuration/manager_test.rb +204 -0
  211. data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
  212. data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
  213. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  214. data/test/new_relic/agent/database_test.rb +12 -11
  215. data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
  216. data/test/new_relic/agent/error_collector_test.rb +33 -19
  217. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
  218. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  219. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  220. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
  221. data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
  222. data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
  223. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  224. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
  225. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  226. data/test/new_relic/agent/method_tracer_test.rb +7 -6
  227. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  228. data/test/new_relic/agent/new_relic_service_test.rb +376 -0
  229. data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
  230. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  231. data/test/new_relic/agent/rpm_agent_test.rb +27 -50
  232. data/test/new_relic/agent/sql_sampler_test.rb +81 -56
  233. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
  234. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
  235. data/test/new_relic/agent/stats_engine_test.rb +17 -8
  236. data/test/new_relic/agent/thread_profiler_test.rb +537 -0
  237. data/test/new_relic/agent/thread_test.rb +89 -0
  238. data/test/new_relic/agent/threaded_test.rb +65 -0
  239. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  240. data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
  241. data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
  242. data/test/new_relic/agent/worker_loop_test.rb +26 -11
  243. data/test/new_relic/agent_test.rb +113 -33
  244. data/test/new_relic/collection_helper_test.rb +7 -8
  245. data/test/new_relic/command/deployments_test.rb +18 -2
  246. data/test/new_relic/control/class_methods_test.rb +0 -18
  247. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  248. data/test/new_relic/control_test.rb +96 -137
  249. data/test/new_relic/delayed_job_injection_test.rb +6 -1
  250. data/test/new_relic/dispatcher_test.rb +54 -0
  251. data/test/new_relic/fake_collector.rb +283 -0
  252. data/test/new_relic/fake_service.rb +53 -0
  253. data/test/new_relic/fakes_sending_data.rb +30 -0
  254. data/test/new_relic/framework_test.rb +53 -0
  255. data/test/new_relic/load_test.rb +13 -0
  256. data/test/new_relic/local_environment_test.rb +11 -11
  257. data/test/new_relic/metric_data_test.rb +45 -16
  258. data/test/new_relic/noticed_error_test.rb +24 -0
  259. data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
  260. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  261. data/test/new_relic/rack/error_collector_test.rb +74 -0
  262. data/test/new_relic/stats_test.rb +10 -0
  263. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  264. data/test/new_relic/transaction_sample_test.rb +47 -2
  265. data/test/new_relic/version_number_test.rb +32 -0
  266. data/test/script/build_test_gem.sh +9 -3
  267. data/test/script/ci.sh +108 -35
  268. data/test/script/ci_agent-tests_runner.sh +82 -0
  269. data/test/script/ci_multiverse_runner.sh +63 -0
  270. data/test/test_contexts.rb +1 -0
  271. data/test/test_helper.rb +68 -18
  272. data/ui/helpers/developer_mode_helper.rb +21 -11
  273. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  274. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  275. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  276. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  277. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  278. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  279. data/ui/views/newrelic/show_sample.rhtml +1 -1
  280. data/ui/views/newrelic/threads.rhtml +2 -10
  281. data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
  282. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
  283. metadata +191 -65
  284. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  285. data/lib/new_relic/control/configuration.rb +0 -206
  286. data/lib/new_relic/control/logging_methods.rb +0 -143
  287. data/lib/new_relic/data_serialization.rb +0 -151
  288. data/test/new_relic/control/configuration_test.rb +0 -84
  289. data/test/new_relic/control/logging_methods_test.rb +0 -185
  290. data/test/new_relic/data_serialization_test.rb +0 -208
@@ -5,10 +5,17 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
5
5
  class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
6
6
  def setup
7
7
  super
8
+ @test_config = { :capture_params => true }
9
+ NewRelic::Agent.config.apply_config(@test_config)
8
10
  @error_collector = NewRelic::Agent::ErrorCollector.new
9
11
  @error_collector.stubs(:enabled).returns(true)
10
12
  end
11
-
13
+
14
+ def teardown
15
+ super
16
+ NewRelic::Agent.config.remove_config(@test_config)
17
+ end
18
+
12
19
  def test_empty
13
20
  @error_collector.harvest_errors([])
14
21
  @error_collector.notice_error(nil, :metric=> 'path', :request_params => {:x => 'y'})
@@ -27,7 +34,7 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
27
34
  assert_equal 'path', err.path
28
35
  assert_equal 'Error', err.exception_class
29
36
  end
30
-
37
+
31
38
  def test_simple
32
39
  @error_collector.notice_error(StandardError.new("message"), :uri => '/myurl/', :metric => 'path', :referer => 'test_referer', :request_params => {:x => 'y'})
33
40
 
@@ -115,7 +122,6 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
115
122
 
116
123
 
117
124
  def test_supported_param_types
118
-
119
125
  types = [[1, '1'],
120
126
  [1.1, '1.1'],
121
127
  ['hi', 'hi'],
@@ -124,10 +130,9 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
124
130
  [TestClass.new, "#<NewRelic::Agent::ErrorCollectorTest::TestClass>"]
125
131
  ]
126
132
 
127
-
128
133
  types.each do |test|
129
- @error_collector.notice_error(StandardError.new("message"), :metric => 'path', :request_params => {:x => test[0]})
130
-
134
+ @error_collector.notice_error(StandardError.new("message"), :metric => 'path',
135
+ :request_params => {:x => test[0]})
131
136
  assert_equal test[1], @error_collector.harvest_errors([])[0].params[:request_params][:x]
132
137
  end
133
138
  end
@@ -143,8 +148,19 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
143
148
  assert_equal 0, errors.length
144
149
  end
145
150
 
151
+ def test_exclude_later_config_changes
152
+ @error_collector.notice_error(IOError.new("message"))
153
+
154
+ NewRelic::Agent.config.apply_config(:'error_collector.ignore_errors' => "IOError")
155
+ @error_collector.notice_error(IOError.new("message"))
156
+
157
+ errors = @error_collector.harvest_errors([])
158
+
159
+ assert_equal 1, errors.length
160
+
161
+ end
162
+
146
163
  def test_exclude_block
147
- NewRelic::Agent.logger.expects(:error).never
148
164
  @error_collector.ignore_error_filter &wrapped_filter_proc
149
165
 
150
166
  @error_collector.notice_error(IOError.new("message"), :metric => 'path', :request_params => {:x => 'y'})
@@ -156,20 +172,18 @@ class NewRelic::Agent::ErrorCollectorTest < Test::Unit::TestCase
156
172
  end
157
173
 
158
174
  def test_obfuscates_error_messages_when_high_security_is_set
159
- NewRelic::Control.instance['high_security'] = true
160
-
161
- @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo = 'bar'"))
162
- @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo in (1,2,3,4,5)"))
175
+ with_config(:high_security => true) do
176
+ @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo = 'bar'"))
177
+ @error_collector.notice_error(StandardError.new("YO SQL BAD: serect * flom test where foo in (1,2,3,4,5)"))
163
178
 
164
- old_errors = []
165
- errors = @error_collector.harvest_errors([])
179
+ old_errors = []
180
+ errors = @error_collector.harvest_errors([])
166
181
 
167
- assert_equal('YO SQL BAD: serect * flom test where foo = ?',
168
- errors[0].message)
169
- assert_equal('YO SQL BAD: serect * flom test where foo in (?,?,?,?,?)',
170
- errors[1].message)
171
-
172
- NewRelic::Control.instance['high_security'] = nil
182
+ assert_equal('YO SQL BAD: serect * flom test where foo = ?',
183
+ errors[0].message)
184
+ assert_equal('YO SQL BAD: serect * flom test where foo in (?,?,?,?,?)',
185
+ errors[1].message)
186
+ end
173
187
  end
174
188
 
175
189
  private
@@ -4,6 +4,16 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
4
4
  require 'active_record_fixtures'
5
5
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
6
6
 
7
+ # the db adapter library the tests are running under (e.g. sqlite3)
8
+ def adapter
9
+ if ActiveRecord::Base.respond_to?(:connection_config)
10
+ ActiveRecord::Base.connection_config[:adapter]
11
+ else
12
+ # old versions of rails are usually tested against mysql
13
+ 'mysql'
14
+ end
15
+ end
16
+
7
17
  def setup
8
18
  super
9
19
  NewRelic::Agent.manual_start
@@ -35,9 +45,13 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
35
45
  find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
36
46
 
37
47
  assert_calls_metrics(find_metric) do
38
- ActiveRecordFixtures::Order.find(:all)
48
+ all_finder(ActiveRecordFixtures::Order)
39
49
  check_metric_count(find_metric, 1)
40
- ActiveRecordFixtures::Order.find_all_by_name "jeff"
50
+ if NewRelic::Control.instance.rails_version >= "4"
51
+ ActiveRecordFixtures::Order.where(:name => "jeff").load
52
+ else
53
+ ActiveRecordFixtures::Order.find_all_by_name "jeff"
54
+ end
41
55
  check_metric_count(find_metric, 2)
42
56
  end
43
57
  end
@@ -64,9 +78,9 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
64
78
 
65
79
  find_metric = "ActiveRecord/ActiveRecordFixtures::Order/find"
66
80
  ActiveRecordFixtures::Order.cache do
67
- m = ActiveRecordFixtures::Order.create :id => 0, :name => 'jeff'
81
+ m = ActiveRecordFixtures::Order.create :id => 1, :name => 'jeff'
68
82
  assert_calls_metrics(find_metric) do
69
- ActiveRecordFixtures::Order.find(:all)
83
+ all_finder(ActiveRecordFixtures::Order)
70
84
  end
71
85
 
72
86
  check_metric_count(find_metric, 1)
@@ -87,7 +101,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
87
101
  ActiveRecord/find
88
102
  ActiveRecord/ActiveRecordFixtures::Order/find
89
103
  Database/SQL/insert
90
- RemoteService/sql/mysql/localhost
104
+ RemoteService/sql/#{adapter}/localhost
91
105
  ]
92
106
 
93
107
  if NewRelic::Control.instance.rails_version < '2.1.0'
@@ -141,7 +155,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
141
155
  # fails due to a bug in rails 3 - log does not provide the correct
142
156
  # transaction type - it returns 'SQL' instead of 'Foo Create', for example.
143
157
  return if defined?(JRuby) || isSqlite?
144
-
158
+
145
159
  expected = %W[
146
160
  ActiveRecord/all
147
161
  ActiveRecord/find
@@ -149,7 +163,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
149
163
  ActiveRecord/ActiveRecordFixtures::Order/find
150
164
  ActiveRecord/ActiveRecordFixtures::Order/create
151
165
  Database/SQL/other
152
- RemoteService/sql/mysql/localhost]
166
+ RemoteService/sql/#{adapter}/localhost]
153
167
 
154
168
  if NewRelic::Control.instance.rails_version < '2.1.0'
155
169
  expected += ['ActiveRecord/save',
@@ -159,14 +173,14 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
159
173
  end
160
174
 
161
175
  assert_calls_metrics(*expected) do
162
- m = ActiveRecordFixtures::Order.create :id => 0, :name => 'donkey'
176
+ m = ActiveRecordFixtures::Order.create :id => 1, :name => 'donkey'
163
177
  m = ActiveRecordFixtures::Order.find(m.id)
164
178
  m.id = 999
165
179
  m.save!
166
180
  end
167
181
 
168
182
  metrics = NewRelic::Agent.instance.stats_engine.metrics
169
-
183
+
170
184
  compare_metrics expected, metrics
171
185
  check_metric_count("ActiveRecord/ActiveRecordFixtures::Order/find", 1)
172
186
  if NewRelic::Control.instance.rails_version < '3.0.0'
@@ -190,7 +204,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
190
204
  ActiveRecord/find
191
205
  ActiveRecord/ActiveRecordFixtures::Order/find
192
206
  ActiveRecord/ActiveRecordFixtures::Shipment/find
193
- RemoteService/sql/mysql/localhost
207
+ RemoteService/sql/#{adapter}/localhost
194
208
  ]
195
209
 
196
210
  assert_calls_metrics(*expected_metrics) do
@@ -251,12 +265,12 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
251
265
  end
252
266
 
253
267
  def test_join_metrics_standard
254
- return if (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3)
268
+ return if (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i >= 3)
255
269
  return if defined?(JRuby) || isSqlite?
256
270
 
257
271
  expected_metrics = %W[
258
272
  ActiveRecord/all
259
- RemoteService/sql/mysql/localhost
273
+ RemoteService/sql/#{adapter}/localhost
260
274
  ActiveRecord/destroy
261
275
  ActiveRecord/ActiveRecordFixtures::Order/destroy
262
276
  Database/SQL/insert
@@ -299,7 +313,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
299
313
  expected_metrics = %W[
300
314
  ActiveRecord/all
301
315
  Database/SQL/select
302
- RemoteService/sql/mysql/localhost
316
+ RemoteService/sql/#{adapter}/localhost
303
317
  ]
304
318
 
305
319
  assert_calls_unscoped_metrics(*expected_metrics) do
@@ -317,7 +331,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
317
331
  expected_metrics = %W[
318
332
  ActiveRecord/all
319
333
  Database/SQL/other
320
- RemoteService/sql/mysql/localhost
334
+ RemoteService/sql/#{adapter}/localhost
321
335
  ]
322
336
  assert_calls_unscoped_metrics(*expected_metrics) do
323
337
  ActiveRecordFixtures::Order.connection.execute "begin"
@@ -333,7 +347,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
333
347
  return if isSqlite?
334
348
  return if isPostgres?
335
349
 
336
- expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/mysql/localhost]
350
+ expected_metrics = %W[ActiveRecord/all Database/SQL/show RemoteService/sql/#{adapter}/localhost]
337
351
 
338
352
  assert_calls_metrics(*expected_metrics) do
339
353
  ActiveRecordFixtures::Order.connection.execute "show tables"
@@ -347,7 +361,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
347
361
  ActiveRecordFixtures::Order.add_delay
348
362
  NewRelic::Agent.disable_all_tracing do
349
363
  perform_action_with_newrelic_trace :name => 'bogosity' do
350
- ActiveRecordFixtures::Order.find(:all)
364
+ all_finder(ActiveRecordFixtures::Order)
351
365
  end
352
366
  end
353
367
  assert_nil NewRelic::Agent.instance.transaction_sampler.last_sample
@@ -358,7 +372,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
358
372
  def test_run_explains
359
373
  perform_action_with_newrelic_trace :name => 'bogosity' do
360
374
  ActiveRecordFixtures::Order.add_delay
361
- ActiveRecordFixtures::Order.find(:all)
375
+ all_finder(ActiveRecordFixtures::Order)
362
376
  end
363
377
 
364
378
  # that's a mouthful. perhaps we should ponder our API.
@@ -371,7 +385,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
371
385
  def test_prepare_to_send
372
386
  perform_action_with_newrelic_trace :name => 'bogosity' do
373
387
  ActiveRecordFixtures::Order.add_delay
374
- ActiveRecordFixtures::Order.find(:all)
388
+ all_finder(ActiveRecordFixtures::Order)
375
389
  end
376
390
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
377
391
  assert_not_nil sample
@@ -402,7 +416,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
402
416
  sample = NewRelic::Agent.instance.transaction_sampler.reset!
403
417
  perform_action_with_newrelic_trace :name => 'bogosity' do
404
418
  ActiveRecordFixtures::Order.add_delay
405
- ActiveRecordFixtures::Order.find(:all)
419
+ all_finder(ActiveRecordFixtures::Order)
406
420
  end
407
421
 
408
422
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
@@ -432,7 +446,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
432
446
  sample = NewRelic::Agent.instance.transaction_sampler.reset!
433
447
  perform_action_with_newrelic_trace :name => 'bogosity' do
434
448
  ActiveRecordFixtures::Order.add_delay
435
- ActiveRecordFixtures::Order.find(:all)
449
+ all_finder(ActiveRecordFixtures::Order)
436
450
  end
437
451
 
438
452
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
@@ -457,7 +471,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
457
471
  sample = NewRelic::Agent.instance.transaction_sampler.reset!
458
472
  perform_action_with_newrelic_trace :name => 'bogosity' do
459
473
  ActiveRecordFixtures::Order.add_delay
460
- ActiveRecordFixtures::Order.find(:all)
474
+ all_finder(ActiveRecordFixtures::Order)
461
475
  end
462
476
 
463
477
  sample = NewRelic::Agent.instance.transaction_sampler.last_sample
@@ -472,10 +486,12 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
472
486
  # These are only valid for rails 2.1 and later
473
487
  if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("2.1.0")
474
488
  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
489
+ if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4")
490
+ scope :jeffs, lambda { where(:name => 'Jeff') }
491
+ elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.1")
478
492
  scope :jeffs, :conditions => { :name => 'Jeff' }
493
+ else
494
+ named_scope :jeffs, :conditions => { :name => 'Jeff' }
479
495
  end
480
496
  end
481
497
  def test_named_scope
@@ -485,7 +501,11 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
485
501
 
486
502
  check_metric_count(find_metric, 0)
487
503
  assert_calls_metrics(find_metric) do
488
- x = ActiveRecordFixtures::Order.jeffs.find(:all)
504
+ if NewRelic::Control.instance.rails_version >= "4"
505
+ x = ActiveRecordFixtures::Order.jeffs.load
506
+ else
507
+ x = ActiveRecordFixtures::Order.jeffs.find(:all)
508
+ end
489
509
  end
490
510
  check_metric_count(find_metric, 1)
491
511
  end
@@ -499,7 +519,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
499
519
  true
500
520
  end
501
521
 
502
- expected_metrics = %W[ActiveRecord/all Database/SQL/select RemoteService/sql/mysql/localhost]
522
+ expected_metrics = %W[ActiveRecord/all Database/SQL/select RemoteService/sql/#{adapter}/localhost]
503
523
 
504
524
  assert_calls_metrics(*expected_metrics) do
505
525
  begin
@@ -513,7 +533,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
513
533
  compare_metrics expected_metrics, metrics
514
534
  check_metric_count('Database/SQL/select', 1)
515
535
  check_metric_count('ActiveRecord/all', 1)
516
- check_metric_count('RemoteService/sql/mysql/localhost', 1)
536
+ check_metric_count("RemoteService/sql/#{adapter}/localhost", 1)
517
537
  end
518
538
 
519
539
  def test_rescue_handling
@@ -535,7 +555,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
535
555
  # puts NewRelic::Agent::Database.config.inspect
536
556
 
537
557
  ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
538
- assert(NewRelic::Agent.get_stats('RemoteService/sql/mysql/localhost').call_count != 0)
558
+ assert(NewRelic::Agent.get_stats("RemoteService/sql/#{adapter}/localhost").call_count != 0)
539
559
 
540
560
  config = ActiveRecordFixtures::Shipment.connection.instance_eval { @config }
541
561
  config[:host] = '127.0.0.1'
@@ -545,7 +565,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
545
565
  # puts NewRelic::Agent::Database.config.inspect
546
566
 
547
567
  ActiveRecordFixtures::Shipment.connection.execute('SHOW TABLES');
548
- assert(NewRelic::Agent.get_stats('RemoteService/sql/mysql/127.0.0.1').call_count != 0)
568
+ assert(NewRelic::Agent.get_stats("RemoteService/sql/#{adapter}/127.0.0.1").call_count != 0)
549
569
 
550
570
  config[:host] = 'localhost'
551
571
  ActiveRecordFixtures::Shipment.establish_connection(config)
@@ -556,7 +576,7 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
556
576
  private
557
577
 
558
578
  def rails3?
559
- (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i == 3)
579
+ (defined?(Rails) && Rails.respond_to?(:version) && Rails.version.to_i >= 3)
560
580
  end
561
581
 
562
582
  def rails_env
@@ -573,4 +593,14 @@ class NewRelic::Agent::Instrumentation::ActiveRecordInstrumentationTest < Test::
573
593
  def isSqlite?
574
594
  ActiveRecord::Base.configurations[rails_env]['adapter'] =~ /sqlite/i
575
595
  end
596
+
597
+ def all_finder(relation)
598
+ if NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("4.0")
599
+ relation.all.load
600
+ elsif NewRelic::Control.instance.rails_version >= NewRelic::VersionNumber.new("3.0")
601
+ relation.all
602
+ else
603
+ relation.find(:all)
604
+ end
605
+ end
576
606
  end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+
3
+ class NewRelic::Agent::Instrumentation::BrowserMonitoringTimingsTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Time.stubs(:now).returns(2000)
7
+ @transaction = stub(
8
+ :transaction_name => "Name",
9
+ :start_time => 0
10
+ )
11
+ end
12
+
13
+ def test_queue_time
14
+ t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(1000.1234, @transaction)
15
+ assert_equal 1_000_123, t.queue_time_in_millis
16
+ end
17
+
18
+ def test_queue_time_clamps_to_positive
19
+ t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(-1000, @transaction)
20
+ assert_equal 0, t.queue_time_in_millis
21
+ end
22
+
23
+ def test_app_time
24
+ t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(nil, @transaction)
25
+ assert_equal 2_000_000, t.app_time_in_millis
26
+ end
27
+
28
+ def test_transaction_name
29
+ t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(nil, @transaction)
30
+ assert_equal "Name", t.transaction_name
31
+ end
32
+
33
+ def test_defaults_to_transaction_info
34
+ t = NewRelic::Agent::Instrumentation::BrowserMonitoringTimings.new(1000, nil)
35
+ assert_equal nil, t.transaction_name
36
+ assert_equal 0.0, t.start_time_in_millis
37
+ end
38
+
39
+ end
@@ -34,7 +34,7 @@ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestC
34
34
  end
35
35
 
36
36
  def test_log_underflow
37
- NewRelic::Agent.logger.expects(:error).with(regexp_matches(/Underflow in metric frames: /))
37
+ expects_logging(:error, regexp_matches(/Underflow in metric frames: /))
38
38
  log_underflow
39
39
  end
40
40
 
@@ -47,4 +47,10 @@ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
47
47
  assert_equal "/", f.uri
48
48
  assert_nil f.referer
49
49
  end
50
+
51
+ def test_queue_time
52
+ f.apdex_start = 1000
53
+ f.start = 1500
54
+ assert_equal 500, f.queue_time
55
+ end
50
56
  end
@@ -118,6 +118,20 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
118
118
  check_metric_time('WebFrontend/WebServer/serverb', 1.0, 0.1)
119
119
  end
120
120
 
121
+ def test_parse_server_time_accepting_milliseconds_resolution_separator_char
122
+ env = {'HTTP_X_REQUEST_START' => "t=1000.000000"}
123
+ create_test_start_time(env)
124
+ env['HTTP_X_QUEUE_START'] = "t=1001.000000"
125
+ assert_calls_metrics('WebFrontend/WebServer/all') do
126
+ assert_equal(Time.at(1000), parse_server_time_from(env))
127
+ end
128
+ assert_calls_metrics('WebFrontend/QueueTime') do
129
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
130
+ end
131
+ check_metric_time('WebFrontend/WebServer/all', 2.0, 0.1)
132
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.1)
133
+ end
134
+
121
135
  # test for backwards compatibility with old header
122
136
  def test_parse_server_time_from_with_no_server_name
123
137
  env = {'HTTP_X_REQUEST_START' => "t=#{convert_to_microseconds(Time.at(1001))}"}