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
@@ -0,0 +1,13 @@
1
+ # require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+ require 'test/unit'
3
+ require 'resolv'
4
+ require 'mocha'
5
+
6
+ class LoadTest < Test::Unit::TestCase
7
+ def test_loading_agent_when_disabled_does_not_resolv_addresses
8
+ ::Resolv.expects(:getaddress).never
9
+ ::IPSocket.expects(:getaddress).never
10
+
11
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
12
+ end
13
+ end
@@ -28,25 +28,25 @@ class NewRelic::LocalEnvironmentTest < Test::Unit::TestCase
28
28
 
29
29
  def test_passenger
30
30
  class << self
31
- module ::Passenger
32
- const_set "AbstractServer", 0
31
+ module ::PhusionPassenger
33
32
  end
34
33
  end
34
+ NewRelic::Agent.reset_config
35
35
  e = NewRelic::LocalEnvironment.new
36
- assert_equal :passenger, e.environment
36
+ assert_equal :passenger, e.discovered_dispatcher
37
+ assert_equal :passenger, NewRelic::Agent.config[:dispatcher]
37
38
  assert_nil e.dispatcher_instance_id, "dispatcher instance id should be nil: #{e.dispatcher_instance_id}"
38
39
 
39
- NewRelic::Control.instance.instance_eval do
40
- @settings['app_name'] = 'myapp'
40
+ with_config(:app_name => 'myapp') do
41
+ e = NewRelic::LocalEnvironment.new
42
+ assert_equal :passenger, e.discovered_dispatcher
43
+ assert_nil e.dispatcher_instance_id
41
44
  end
42
45
 
43
- e = NewRelic::LocalEnvironment.new
44
- assert_equal :passenger, e.environment
45
- assert_nil e.dispatcher_instance_id
46
-
47
- ::Passenger.class_eval { remove_const :AbstractServer }
46
+ ensure
47
+ Object.send(:remove_const, :PhusionPassenger)
48
48
  end
49
-
49
+
50
50
  def test_snapshot
51
51
  e = NewRelic::LocalEnvironment.new
52
52
  s = e.snapshot
@@ -14,50 +14,49 @@ class NewRelic::MetricDataTest < Test::Unit::TestCase
14
14
  def test_eql_basic
15
15
  spec = mock('metric_spec')
16
16
  stats = mock('stats')
17
- metric_id = mock('metric_id')
17
+ metric_id = mock('metric_id')
18
18
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
19
19
  md2 = NewRelic::MetricData.new(spec, stats, metric_id)
20
20
  assert(md1.eql?(md2), "The example metric data objects should be eql?: #{md1.inspect} #{md2.inspect}")
21
- assert(md2.eql?(md1), "The example metric data objects should be eql?: #{md1.inspect} #{md2.inspect}")
21
+ assert(md2.eql?(md1), "The example metric data objects should be eql?: #{md1.inspect} #{md2.inspect}")
22
22
  end
23
23
 
24
24
  def test_eql_unequal_specs
25
-
26
25
  spec = mock('metric_spec')
27
26
  other_spec = mock('other_spec')
28
27
  stats = mock('stats')
29
- metric_id = mock('metric_id')
28
+ metric_id = mock('metric_id')
30
29
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
31
30
  md2 = NewRelic::MetricData.new(other_spec, stats, metric_id)
32
31
  assert(!md1.eql?(md2), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
33
- assert(!md2.eql?(md1), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
32
+ assert(!md2.eql?(md1), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
34
33
  end
35
34
  def test_eql_unequal_stats
36
35
  spec = mock('metric_spec')
37
36
  stats = mock('stats')
38
37
  other_stats = mock('other_stats')
39
- metric_id = mock('metric_id')
38
+ metric_id = mock('metric_id')
40
39
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
41
40
  md2 = NewRelic::MetricData.new(spec, other_stats, metric_id)
42
41
  assert(!md1.eql?(md2), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
43
- assert(!md2.eql?(md1), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
42
+ assert(!md2.eql?(md1), "The example metric data objects should not be eql?: #{md1.inspect} #{md2.inspect}")
44
43
  end
45
44
 
46
45
  def test_eql_unequal_metric_ids_dont_matter
47
46
  spec = mock('metric_spec')
48
47
  stats = mock('stats')
49
48
  metric_id = mock('metric_id')
50
- other_metric_id = mock('other_metric_id')
49
+ other_metric_id = mock('other_metric_id')
51
50
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
52
51
  md2 = NewRelic::MetricData.new(spec, stats, other_metric_id)
53
52
  assert(md1.eql?(md2), "The example metric data objects should be eql? with different metric_ids: #{md1.inspect} #{md2.inspect}")
54
- assert(md2.eql?(md1), "The example metric data objects should be eql? with different metric_ids: #{md1.inspect} #{md2.inspect}")
53
+ assert(md2.eql?(md1), "The example metric data objects should be eql? with different metric_ids: #{md1.inspect} #{md2.inspect}")
55
54
  end
56
55
 
57
56
  def test_original_spec_basic
58
57
  spec = mock('metric_spec')
59
58
  stats = mock('stats')
60
- metric_id = mock('metric_id')
59
+ metric_id = mock('metric_id')
61
60
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
62
61
  original_spec = md1.instance_variable_get('@original_spec')
63
62
  assert_equal(nil, original_spec, "should start with a nil original spec, but was #{original_spec.inspect}")
@@ -66,26 +65,26 @@ class NewRelic::MetricDataTest < Test::Unit::TestCase
66
65
 
67
66
  def test_metric_spec_equal_should_not_set_original_spec_with_no_metric_spec
68
67
  stats = mock('stats')
69
- metric_id = mock('metric_id')
68
+ metric_id = mock('metric_id')
70
69
  md1 = NewRelic::MetricData.new(nil, stats, metric_id)
71
70
  original_spec = md1.instance_variable_get('@original_spec')
72
71
  assert_equal(nil, original_spec, "should start with a nil original spec, but was #{original_spec.inspect}")
73
-
72
+
74
73
  new_spec = mock('new metric_spec')
75
74
  assert_equal(new_spec, md1.metric_spec=(new_spec), "should return the new spec")
76
75
 
77
76
  new_original_spec = md1.instance_variable_get('@original_spec')
78
77
  assert_equal(nil, new_original_spec, "should not set @original_spec but was #{new_original_spec.inspect}")
79
78
  end
80
-
79
+
81
80
  def test_metric_spec_equal_should_set_original_spec_with_existing_metric_spec
82
81
  spec = mock('metric_spec')
83
82
  stats = mock('stats')
84
- metric_id = mock('metric_id')
83
+ metric_id = mock('metric_id')
85
84
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
86
85
  original_spec = md1.instance_variable_get('@original_spec')
87
86
  assert_equal(nil, original_spec, "should start with a nil original spec, but was #{original_spec.inspect}")
88
-
87
+
89
88
  new_spec = mock('new metric_spec')
90
89
  assert_equal(new_spec, md1.metric_spec=(new_spec), "should return the new spec")
91
90
 
@@ -96,7 +95,7 @@ class NewRelic::MetricDataTest < Test::Unit::TestCase
96
95
  def test_hash
97
96
  spec = mock('metric_spec')
98
97
  stats = mock('stats')
99
- metric_id = mock('metric_id')
98
+ metric_id = mock('metric_id')
100
99
  md1 = NewRelic::MetricData.new(spec, stats, metric_id)
101
100
  assert((spec.hash ^ stats.hash) == md1.hash, "expected #{spec.hash ^ stats.hash} to equal #{md1.hash}")
102
101
  end
@@ -122,4 +121,34 @@ class NewRelic::MetricDataTest < Test::Unit::TestCase
122
121
  md = NewRelic::MetricData.new(nil, NewRelic::MethodTraceStats.new, 12345)
123
122
  assert_equal('12345: [01/01/70 12:00AM UTC, 0.000s; 0 calls 0s]', md.to_s, "should include the metric id and not have a metric spec")
124
123
  end
124
+
125
+ def test_to_collector_array_with_spec
126
+ stats = NewRelic::MethodTraceStats.new
127
+ stats.record_data_point(1.0)
128
+ stats.record_data_point(2.0, 1.0)
129
+ md = NewRelic::MetricData.new(NewRelic::MetricSpec.new('Custom/test/method', 'scope'),
130
+ stats, nil)
131
+ expected = [ {'name' => 'Custom/test/method', 'scope' => 'scope'},
132
+ [2, 3.0, 2.0, 1.0, 2.0, 5.0] ]
133
+ assert_equal expected, md.to_collector_array
134
+ end
135
+
136
+ def test_to_collector_array_with_spec_and_id
137
+ stats = NewRelic::MethodTraceStats.new
138
+ stats.record_data_point(1.0)
139
+ stats.record_data_point(2.0, 1.0)
140
+ md = NewRelic::MetricData.new(NewRelic::MetricSpec.new('Custom/test/method', 'scope'),
141
+ stats, 1234)
142
+ expected = [ 1234, [2, 3.0, 2.0, 1.0, 2.0, 5.0] ]
143
+ assert_equal expected, md.to_collector_array
144
+ end
145
+
146
+ def test_to_collector_array_with_id
147
+ stats = NewRelic::MethodTraceStats.new
148
+ stats.record_data_point(1.0)
149
+ stats.record_data_point(2.0, 1.0)
150
+ md = NewRelic::MetricData.new(nil, stats, 1234)
151
+ expected = [ 1234, [2, 3.0, 2.0, 1.0, 2.0, 5.0] ]
152
+ assert_equal expected, md.to_collector_array
153
+ end
125
154
  end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
2
+
3
+ class NewRelic::Agent::NoticedErrorTest < Test::Unit::TestCase
4
+ def setup
5
+ @path = 'foo/bar/baz'
6
+ @params = { 'key' => 'val' }
7
+ @time = Time.now
8
+ end
9
+
10
+ def test_to_collector_array
11
+ e = Exception.new('test exception')
12
+ error = NewRelic::NoticedError.new(@path, @params, e, @time)
13
+ expected = [
14
+ (@time.to_f * 1000).round, @path, 'test exception', 'Exception', @params
15
+ ]
16
+ assert_equal expected, error.to_collector_array
17
+ end
18
+
19
+ def test_handles_non_string_exception_messages
20
+ e = Exception.new({ :non => :string })
21
+ error = NewRelic::NoticedError.new(@path, @params, e, @time)
22
+ assert_equal(String, error.message.class)
23
+ end
24
+ end
@@ -9,7 +9,7 @@ ENV['RACK_ENV'] = 'test'
9
9
  # benefit from auto-rum, but the truth of the matter is that atm
10
10
  # we only support Rails >= 2.3
11
11
  def middleware_supported?
12
- ::Rails::VERSION::MAJOR >= 2 && ::Rails::VERSION::MINOR >= 3
12
+ ::Rails::VERSION::STRING >= '2.3'
13
13
  end
14
14
 
15
15
  if middleware_supported?
@@ -46,11 +46,17 @@ EOL
46
46
  def setup
47
47
  super
48
48
  clear_cookies
49
+ @config = {
50
+ :browser_key => 'some browser key',
51
+ :beacon => 'beacon',
52
+ :application_id => 5,
53
+ :'rum.enabled' => true,
54
+ :episodes_file => 'this_is_my_file',
55
+ :license_key => 'a' * 40
56
+ }
57
+ NewRelic::Agent.config.apply_config(@config)
49
58
  NewRelic::Agent.manual_start
50
- config = NewRelic::Agent::BeaconConfiguration.new("browser_key" => "browserKey",
51
- "application_id" => "apId",
52
- "beacon"=>"beacon",
53
- "episodes_url"=>"this_is_my_file")
59
+ config = NewRelic::Agent::BeaconConfiguration.new
54
60
  NewRelic::Agent.instance.stubs(:beacon_configuration).returns(config)
55
61
  NewRelic::Agent.stubs(:is_transaction_traced?).returns(true)
56
62
  end
@@ -60,6 +66,7 @@ EOL
60
66
  clear_cookies
61
67
  mocha_teardown
62
68
  TestApp.doc = nil
69
+ NewRelic::Agent.config.remove_config(@config)
63
70
  end
64
71
 
65
72
  def test_make_sure_header_is_set
@@ -110,7 +117,7 @@ EOL
110
117
  def test_insert_timing_footer_right_before_html_body_close
111
118
  get '/'
112
119
 
113
- assert_match(/.*NREUMQ\.push.*new Date\(\)\.getTime\(\),"","","","",""\]\)<\/script><\/body>/,
120
+ assert_match(/.*NREUMQ\.push.*new Date\(\)\.getTime\(\),"","","","",""\]\);<\/script><\/body>/,
114
121
  last_response.body)
115
122
  end
116
123
 
@@ -132,11 +139,14 @@ EOL
132
139
  def test_guid_is_set_in_footer_when_token_is_set
133
140
  guid = 'abcdefgfedcba'
134
141
  NewRelic::TransactionSample.any_instance.stubs(:generate_guid).returns(guid)
135
- NewRelic::Control.instance.stubs(:apdex_t).returns(0.0001)
136
142
  set_cookie "NRAGENT=tk=token"
137
- get '/'
138
-
139
- assert(last_response.body.include?(guid), last_response.body)
143
+ with_config(:apdex_t => 0.0001) do
144
+ get '/'
145
+ assert(last_response.body.include?(guid), last_response.body)
146
+ end
140
147
  end
141
148
  end
149
+ else
150
+ warn "Skipping rum auto instrumentation tests"
142
151
  end
152
+
@@ -14,32 +14,38 @@ class DeveloperModeTest < Test::Unit::TestCase
14
14
  mock_app = lambda { |env| [500, {}, "Don't touch me!"] }
15
15
  NewRelic::Rack::DeveloperMode.new(mock_app)
16
16
  end
17
-
17
+
18
18
  def setup
19
+ @test_config = { :developer_mode => true }
20
+ NewRelic::Agent.config.apply_config(@test_config)
19
21
  @sampler = NewRelic::Agent::TransactionSampler.new
20
22
  run_sample_trace_on(@sampler, '/here')
21
23
  run_sample_trace_on(@sampler, '/there')
22
24
  run_sample_trace_on(@sampler, '/somewhere')
23
25
  NewRelic::Agent.instance.stubs(:transaction_sampler).returns(@sampler)
24
26
  end
25
-
27
+
28
+ def teardown
29
+ NewRelic::Agent.config.remove_config(@test_config)
30
+ end
31
+
26
32
  def test_index_displays_all_samples
27
33
  get '/newrelic'
28
-
34
+
29
35
  assert last_response.ok?
30
36
  assert last_response.body.include?('/here')
31
37
  assert last_response.body.include?('/there')
32
- assert last_response.body.include?('/somewhere')
38
+ assert last_response.body.include?('/somewhere')
33
39
  end
34
40
 
35
41
  def test_show_sample_summary_displays_sample_details
36
42
  get "/newrelic/show_sample_summary?id=#{@sampler.samples[0].sample_id}"
37
-
43
+
38
44
  assert last_response.ok?
39
45
  assert last_response.body.include?('/here')
40
46
  assert last_response.body.include?('SandwichesController')
41
- assert last_response.body.include?('index')
42
- end
47
+ assert last_response.body.include?('index')
48
+ end
43
49
 
44
50
  def test_explain_sql_displays_query_plan
45
51
  sample = @sampler.samples[0]
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', '..',
2
+ 'test_helper'))
3
+ require 'rack/test'
4
+ require 'new_relic/rack/error_collector'
5
+
6
+ module NewRelic::Rack
7
+ class ErrorCollectorTest < Test::Unit::TestCase
8
+ include Rack::Test::Methods
9
+
10
+ class TestApp
11
+ def call(env)
12
+ if env['PATH_INFO'] == '/ignored'
13
+ env['action_dispatch.request.parameters'] = {
14
+ 'controller' => 'test_ignore',
15
+ 'action' => 'ignored'
16
+ }
17
+ end
18
+ raise 'unhandled error'
19
+ end
20
+ end
21
+
22
+ def app
23
+ NewRelic::Rack::ErrorCollector.new(TestApp.new)
24
+ end
25
+
26
+ def setup
27
+ NewRelic::Agent.reset_config
28
+ NewRelic::Agent.manual_start
29
+ NewRelic::Agent.instance.error_collector
30
+ NewRelic::Agent.instance.error_collector.errors = []
31
+
32
+ # sanity checks
33
+ assert NewRelic::Agent.instance.error_collector.enabled?
34
+ NewRelic::Agent.instance.error_collector \
35
+ .instance_variable_set(:@ignore_filter, nil)
36
+ assert !NewRelic::Agent.instance.error_collector.ignore_error_filter
37
+ end
38
+
39
+ def test_notice_and_reraise_errors
40
+ assert_raise RuntimeError do
41
+ get '/'
42
+ end
43
+
44
+ assert_equal('unhandled error',
45
+ NewRelic::Agent.instance.error_collector.errors[0].message)
46
+ end
47
+
48
+ def test_ignore_filtered_errors
49
+ NewRelic::Agent.instance.error_collector.ignore_error_filter do |error|
50
+ !error.kind_of?(RuntimeError)
51
+ end
52
+
53
+ assert_raise RuntimeError do
54
+ get '/'
55
+ end
56
+
57
+ assert(NewRelic::Agent.instance.error_collector.errors.empty?,
58
+ 'noticed an error that should have been ignored')
59
+ end
60
+
61
+ def test_ignore_errors_from_ignored_actions
62
+ assert_raise RuntimeError do
63
+ get '/ignored'
64
+ end
65
+
66
+ assert(NewRelic::Agent.instance.error_collector.errors.empty?,
67
+ 'noticed an error that should have been ignored')
68
+ end
69
+ end
70
+ end
71
+
72
+ class TestIgnoreController
73
+ @do_not_trace = { :only => :ignored }
74
+ end
@@ -399,6 +399,16 @@ class NewRelic::StatsTest < Test::Unit::TestCase
399
399
  assert_in_delta(s3.standard_deviation, 4.743, 0.01)
400
400
  end
401
401
 
402
+ if RUBY_VERSION >= '1.9'
403
+ def test_to_json_enforces_float_values
404
+ s1 = NewRelic::MethodTraceStats.new
405
+ s1.trace_call 3.to_r
406
+ s1.trace_call 7.to_r
407
+
408
+ assert_equal 3.0, JSON.load(s1.to_json)['min_call_time']
409
+ end
410
+ end
411
+
402
412
  private
403
413
  def validate (stats, count, total, min, max, exclusive = nil)
404
414
  assert_equal stats.call_count, count
@@ -39,10 +39,29 @@ class NewRelic::TransactionSample::SegmentTest < Test::Unit::TestCase
39
39
  s.to_s
40
40
  end
41
41
 
42
- def test_to_json
43
- t = Time.now
44
- s = NewRelic::TransactionSample::Segment.new(t, 'Custom/test/metric', nil)
45
- assert_equal({ :entry_timestamp => t, :exit_timestamp => nil, :metric_name => 'Custom/test/metric', :segment_id => s.object_id }.to_json, s.to_json)
42
+ def test_to_array
43
+ parent = NewRelic::TransactionSample::Segment.new(1, 'Custom/test/parent', 1)
44
+ parent.params[:test] = 'value'
45
+ child = NewRelic::TransactionSample::Segment.new(2, 'Custom/test/child', 2)
46
+ child.end_trace(3)
47
+ parent.add_called_segment(child)
48
+ parent.end_trace(4)
49
+ expected_array = [1000, 4000, 'Custom/test/parent', {:test => 'value'},
50
+ [[2000, 3000, 'Custom/test/child', {}, []]]]
51
+ assert_equal(expected_array, parent.to_array)
52
+ end
53
+
54
+ if RUBY_VERSION >= '1.9.2'
55
+ def test_to_json
56
+ parent = NewRelic::TransactionSample::Segment.new(1, 'Custom/test/parent', 1)
57
+ parent.params[:test] = 'value'
58
+ child = NewRelic::TransactionSample::Segment.new(2, 'Custom/test/child', 2)
59
+ child.end_trace(3)
60
+ parent.add_called_segment(child)
61
+ parent.end_trace(4)
62
+ expected_string = "[1000,4000,\"Custom/test/parent\",{\"test\":\"value\"},[[2000,3000,\"Custom/test/child\",{},[]]]]"
63
+ assert_equal(expected_string, parent.to_json)
64
+ end
46
65
  end
47
66
 
48
67
  def test_path_string