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,204 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+ require 'new_relic/agent/configuration/manager'
3
+ require 'new_relic/agent/configuration/mask_defaults'
4
+
5
+ module NewRelic::Agent::Configuration
6
+ class ManagerTest < Test::Unit::TestCase
7
+ def setup
8
+ @manager = NewRelic::Agent::Configuration::Manager.new
9
+ end
10
+
11
+ def test_should_use_indifferent_access
12
+ config = NewRelic::Agent::Configuration::DottedHash.new('string' => 'string', :symbol => 'symbol')
13
+ @manager.apply_config(config)
14
+ assert_equal 'string', @manager[:string]
15
+ assert_equal 'symbol', @manager['symbol']
16
+ @manager.remove_config(config)
17
+ end
18
+
19
+ def test_should_apply_config_sources_in_order
20
+ config0 = {
21
+ :foo => 'default foo',
22
+ :bar => 'default bar',
23
+ :baz => 'default baz'
24
+ }
25
+ @manager.apply_config(config0)
26
+ config1 = { :foo => 'real foo' }
27
+ @manager.apply_config(config1)
28
+ config2 = { :foo => 'wrong foo', :bar => 'real bar' }
29
+ @manager.apply_config(config2, 1)
30
+
31
+ assert_equal 'real foo', @manager['foo']
32
+ assert_equal 'real bar', @manager['bar']
33
+ assert_equal 'default baz', @manager['baz']
34
+
35
+ @manager.remove_config(config0)
36
+ @manager.remove_config(config1)
37
+ @manager.remove_config(config2)
38
+ end
39
+
40
+ def test_identifying_config_source
41
+ hash_source = {:foo => 'foo', :bar => 'default'}
42
+ @manager.apply_config(hash_source)
43
+ test_source = TestSource.new
44
+ test_source[:bar] = 'bar'
45
+ test_source[:baz] = 'baz'
46
+ @manager.apply_config(test_source)
47
+
48
+ assert_not_equal test_source, @manager.source(:foo)
49
+ assert_equal test_source, @manager.source(:bar)
50
+ assert_equal test_source, @manager.source(:baz)
51
+
52
+ @manager.remove_config(hash_source)
53
+ @manager.remove_config(test_source)
54
+ end
55
+
56
+ def test_callable_value_for_config_should_return_computed_value
57
+ source = {
58
+ :foo => 'bar',
59
+ :simple_value => Proc.new { '666' },
60
+ :reference => Proc.new { self['foo'] }
61
+ }
62
+ @manager.apply_config(source)
63
+
64
+ assert_equal 'bar', @manager[:foo]
65
+ assert_equal '666', @manager[:simple_value]
66
+ assert_equal 'bar', @manager[:reference]
67
+
68
+ @manager.remove_config(source)
69
+ end
70
+
71
+ def test_should_not_apply_removed_sources
72
+ test_source = TestSource.new
73
+ @manager.apply_config(test_source)
74
+ @manager.remove_config(test_source)
75
+
76
+ assert_equal nil, @manager['test_config_accessor']
77
+ end
78
+
79
+ def test_should_read_license_key_from_env
80
+ ENV['NEWRELIC_LICENSE_KEY'] = 'right'
81
+ manager = NewRelic::Agent::Configuration::Manager.new
82
+ manager.apply_config({:license_key => 'wrong'}, 1)
83
+
84
+ assert_equal 'right', manager['license_key']
85
+ end
86
+
87
+ def test_config_values_should_be_memoized
88
+ @manager.apply_config(:setting => 'correct value')
89
+ assert_equal 'correct value', @manager[:setting]
90
+
91
+ @manager.config_stack.unshift(:setting => 'wrong value')
92
+ assert_equal 'correct value', @manager[:setting]
93
+ end
94
+
95
+ def test_dotted_hash_to_hash_is_plain_hash
96
+ dotted = NewRelic::Agent::Configuration::DottedHash.new({})
97
+ assert_equal(::Hash, dotted.to_hash.class)
98
+ end
99
+
100
+ def test_to_collector_hash
101
+ @manager.instance_variable_set(:@config_stack, [])
102
+ @manager.apply_config(:eins => Proc.new { self[:one] })
103
+ @manager.apply_config(:one => 1)
104
+ @manager.apply_config(:two => 2)
105
+ @manager.apply_config(:nested => {:madness => 'test'})
106
+ @manager.apply_config(:'nested.madness' => 'test')
107
+
108
+ assert_equal({ :eins => 1, :one => 1, :two => 2, :'nested.madness' => 'test' },
109
+ @manager.to_collector_hash)
110
+ end
111
+
112
+ # Necessary to keep the pruby marshaller happy
113
+ def test_to_collector_hash_returns_bare_hash
114
+ @manager.instance_variable_set(:@config_stack, [])
115
+ @manager.apply_config(:eins => Proc.new { self[:one] })
116
+
117
+ assert_equal(::Hash, @manager.to_collector_hash.class)
118
+ end
119
+
120
+ def test_config_masks
121
+ NewRelic::Agent::Configuration::MASK_DEFAULTS[:boo] = Proc.new { true }
122
+
123
+ @manager.apply_config(:boo => 1)
124
+
125
+ assert_equal false, @manager.to_collector_hash.has_key?(:boo)
126
+ end
127
+
128
+ def test_config_masks_conditionally
129
+ NewRelic::Agent::Configuration::MASK_DEFAULTS[:boo] = Proc.new { false }
130
+
131
+ @manager.apply_config(:boo => 1)
132
+
133
+ assert @manager.to_collector_hash.has_key?(:boo)
134
+ end
135
+
136
+ def test_config_masks_thread_profiler
137
+ supported = NewRelic::Agent::ThreadProfiler.is_supported?
138
+ reported_config = @manager.to_collector_hash
139
+
140
+ if supported
141
+ assert_not_nil reported_config[:'thread_profiler.enabled']
142
+ else
143
+ assert_equal nil, reported_config[:'thread_profiler.enabled']
144
+ end
145
+ end
146
+
147
+ def test_replacing_a_layer_by_class
148
+ old_config = NewRelic::Agent::Configuration::ManualSource.new(:test => 'wrong')
149
+ @manager.apply_config(old_config, 1)
150
+ new_config = NewRelic::Agent::Configuration::ManualSource.new(:test => 'right')
151
+ @manager.replace_or_add_config(new_config)
152
+
153
+ assert_equal 'right', @manager[:test]
154
+ assert_equal 3, @manager.config_stack.size
155
+ assert_equal 1, @manager.config_stack.map{|s| s.class} \
156
+ .index(NewRelic::Agent::Configuration::ManualSource)
157
+ end
158
+
159
+ def test_registering_a_callback
160
+ observed_value = 'old'
161
+ @manager.apply_config(:test => 'original')
162
+
163
+ @manager.register_callback(:test) do |value|
164
+ observed_value = value
165
+ end
166
+ assert_equal 'original', observed_value
167
+
168
+ @manager.apply_config(:test => 'new')
169
+ assert_equal 'new', observed_value
170
+ end
171
+
172
+ def test_callback_not_called_if_no_change
173
+ @manager.apply_config(:test => true, :other => false)
174
+ @manager.register_callback(:test) do |value|
175
+ state = 'wrong'
176
+ end
177
+ state = 'right'
178
+ config = {:test => true}
179
+ @manager.apply_config(config)
180
+ @manager.remove_config(config)
181
+
182
+ assert_equal 'right', state
183
+ end
184
+
185
+ def test_should_log_when_applying
186
+ expects_logging(:debug, anything, includes("asdf"))
187
+ @manager.apply_config(:test => "asdf")
188
+ end
189
+
190
+ def test_should_log_when_removing
191
+ config = { :test => "asdf" }
192
+ @manager.apply_config(config)
193
+
194
+ expects_logging(:debug, anything, Not(includes("asdf")))
195
+ @manager.remove_config(config)
196
+ end
197
+
198
+ class TestSource < ::Hash
199
+ def test_config_accessor
200
+ 'some value'
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+ require 'new_relic/agent/configuration/server_source'
3
+
4
+ module NewRelic::Agent::Configuration
5
+ class ServerSourceTest < Test::Unit::TestCase
6
+ def setup
7
+ config = {
8
+ 'agent_config' => {
9
+ 'slow_sql.enabled' => true,
10
+ 'transaction_tracer.transaction_threshold' => 'apdex_f',
11
+ 'transaction_tracer.record_sql' => 'raw',
12
+ 'error_collector.enabled' => true
13
+ },
14
+ 'apdex_t' => 1.0,
15
+ 'collect_errors' => false,
16
+ 'collect_traces' => true
17
+ }
18
+ @source = ServerSource.new(config)
19
+ end
20
+
21
+ def test_should_set_apdex_t
22
+ assert_equal 1.0, @source[:apdex_t]
23
+ end
24
+
25
+ def test_should_set_agent_config_values
26
+ assert_equal 'raw', @source[:'transaction_tracer.record_sql']
27
+ end
28
+
29
+ def test_should_not_dot_the_agent_config_sub_hash
30
+ assert_nil @source[:'agent_config.slow_sql.enabled']
31
+ end
32
+
33
+ def test_should_enable_tracer_as_configured
34
+ assert @source[:'slow_sql.enabled']
35
+ end
36
+
37
+ def test_should_disable_tracer_as_configured
38
+ assert !@source[:'error_collector.enabled']
39
+ end
40
+
41
+ def test_should_ignore_apdex_f_setting_for_transaction_threshold
42
+ assert_equal nil, @source[:'transaction_tracer.transaction_threshold']
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+ require 'new_relic/agent/configuration/yaml_source'
3
+
4
+ module NewRelic::Agent::Configuration
5
+ class YamlSourceTest < Test::Unit::TestCase
6
+ def setup
7
+ test_yml_path = File.expand_path(File.join(File.dirname(__FILE__),
8
+ '..','..','..',
9
+ 'config','newrelic.yml'))
10
+ @source = YamlSource.new(test_yml_path, 'test')
11
+ end
12
+
13
+ def test_should_load_given_yaml_file
14
+ assert_equal '127.0.0.1', @source[:api_host]
15
+ end
16
+
17
+ def test_should_apply_erb_transformations
18
+ assert_equal 'heyheyhey', @source[:erb_value]
19
+ assert_equal '', @source[:message]
20
+ assert_equal '', @source[:license_key]
21
+ end
22
+
23
+ def test_config_booleans
24
+ assert_equal true, @source[:tval]
25
+ assert_equal false, @source[:fval]
26
+ assert_nil @source[:not_in_yaml_val]
27
+ assert_equal true, @source[:yval]
28
+ assert_equal 'sure', @source[:sval]
29
+ end
30
+
31
+ def test_appnames
32
+ assert_equal %w[a b c], @source[:app_name]
33
+ end
34
+
35
+ def test_should_load_the_config_for_the_correct_env
36
+ assert_not_equal 'the.wrong.host', @source[:host]
37
+ end
38
+
39
+ def test_should_convert_to_dot_notation
40
+ assert_equal 'raw', @source[:'transaction_tracer.record_sql']
41
+ end
42
+
43
+ def test_should_ignore_apdex_f_setting_for_transaction_threshold
44
+ assert_equal nil, @source[:'transaction_tracer.transaction_threshold']
45
+ end
46
+
47
+ def test_should_correctly_handle_floats
48
+ assert_equal 1.1, @source[:apdex_t]
49
+ end
50
+
51
+ def test_should_log_if_no_file_is_found
52
+ expects_logging(:error, any_parameters)
53
+ source = YamlSource.new('no_such_file.yml', 'test')
54
+ end
55
+
56
+ def test_should_not_fail_to_log_missing_file_during_startup
57
+ without_logger do
58
+ ::NewRelic::Agent::StartupLogger.any_instance.expects(:error)
59
+ source = YamlSource.new('no_such_file.yml', 'test')
60
+ end
61
+ end
62
+
63
+ def test_should_not_fail_to_log_invalid_file_during_startup
64
+ without_logger do
65
+ ::NewRelic::Agent::StartupLogger.any_instance.expects(:error)
66
+
67
+ File.stubs(:exists?).returns(true)
68
+ File.stubs(:read).raises(StandardError.new("boo"))
69
+
70
+ source = YamlSource.new('fake.yml', 'test')
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,77 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+
3
+ module NewRelic::Agent
4
+ class CrossProcessMonitoringTest < Test::Unit::TestCase
5
+ AGENT_CROSS_PROCESS_ID = "qwerty"
6
+ REQUEST_CROSS_PROCESS_ID = "asdf"
7
+
8
+ def setup
9
+ NewRelic::Agent.instance.stubs(:cross_process_id).returns(AGENT_CROSS_PROCESS_ID)
10
+ NewRelic::Agent.instance.stubs(:cross_process_encoding_bytes).returns([0])
11
+
12
+ @request_with_id = stub(:env => {'X-NewRelic-ID' => REQUEST_CROSS_PROCESS_ID})
13
+ @empty_request = stub(:env => {})
14
+
15
+ @response = {}
16
+ end
17
+
18
+ def test_adds_response_header
19
+ timings = stub(
20
+ :transaction_name => "transaction",
21
+ :queue_time_in_millis => 1000,
22
+ :app_time_in_millis => 2000)
23
+
24
+ NewRelic::Agent::BrowserMonitoring.stubs(:timings).returns(timings)
25
+
26
+ CrossProcessMonitoring.insert_response_header(@request_with_id, @response)
27
+
28
+ assert unpacked_response.include?("transaction")
29
+ assert unpacked_response.include?("1000")
30
+ assert unpacked_response.include?("2000")
31
+ assert unpacked_response.include?(AGENT_CROSS_PROCESS_ID)
32
+ end
33
+
34
+ def test_doesnt_add_header_if_no_id_in_request
35
+ CrossProcessMonitoring.insert_response_header(@empty_request, @response)
36
+ assert_nil response_app_data
37
+ end
38
+
39
+ def test_doesnt_add_header_if_no_id_on_agent
40
+ NewRelic::Agent.instance.stubs(:cross_process_id).returns(nil)
41
+
42
+ CrossProcessMonitoring.insert_response_header(@request_with_id, @response)
43
+ assert_nil response_app_data
44
+ end
45
+
46
+ def test_doesnt_add_header_if_config_disabled
47
+ with_config(:'cross_process.enabled' => false) do
48
+ CrossProcessMonitoring.insert_response_header(@request_with_id, @response)
49
+ assert_nil response_app_data
50
+ end
51
+ end
52
+
53
+ def test_finds_id_from_headers
54
+ %w{X-NewRelic-ID HTTP_X_NEWRELIC_ID X_NEWRELIC_ID}.each do |key|
55
+ request = stub(:env => { key => REQUEST_CROSS_PROCESS_ID })
56
+
57
+ assert_equal(
58
+ REQUEST_CROSS_PROCESS_ID, \
59
+ CrossProcessMonitoring.id_from_request(request),
60
+ "Failed to find header on key #{key}")
61
+ end
62
+ end
63
+
64
+ def test_doesnt_find_id_in_headers
65
+ request = stub(:env => {})
66
+ assert_nil CrossProcessMonitoring.id_from_request(request)
67
+ end
68
+
69
+ def response_app_data
70
+ @response['X-NewRelic-App-Data']
71
+ end
72
+
73
+ def unpacked_response
74
+ response_app_data.unpack("m0").first
75
+ end
76
+ end
77
+ end
@@ -73,17 +73,6 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
73
73
  assert_equal([], NewRelic::Agent::Database.explain_sql('SELECT', config))
74
74
  end
75
75
 
76
- def test_handle_exception_in_explain
77
- fake_error = StandardError.new('a message')
78
- NewRelic::Control.instance.log.expects(:error).with('Error getting query plan: a message')
79
- # backtrace can be basically any string, just should get logged
80
- NewRelic::Control.instance.log.expects(:debug).with(instance_of(String))
81
-
82
- NewRelic::Agent::Database.handle_exception_in_explain do
83
- raise(fake_error)
84
- end
85
- end
86
-
87
76
  def test_obfuscation_mysql_basic
88
77
  insert = %q[INSERT INTO `X` values("test",0, 1 , 2, 'test')]
89
78
  assert_equal("INSERT INTO `X` values(?,?, ? , ?, ?)",
@@ -146,4 +135,16 @@ class NewRelic::Agent::DatabaseTest < Test::Unit::TestCase
146
135
 
147
136
  NewRelic::Agent::Database::Obfuscator.instance.reset
148
137
  end
138
+
139
+ def test_close_connections_closes_all_held_db_connections
140
+ foo_connection = mock('foo connection')
141
+ bar_connection = mock('bar connection')
142
+ NewRelic::Agent::Database::ConnectionManager.instance.instance_eval do
143
+ @connections = { :foo => foo_connection, :bar => bar_connection }
144
+ end
145
+ foo_connection.expects(:disconnect!)
146
+ bar_connection.expects(:disconnect!)
147
+
148
+ NewRelic::Agent::Database.close_connections
149
+ end
149
150
  end
@@ -57,47 +57,51 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Test::Unit::TestCase
57
57
  end
58
58
 
59
59
  def test_request_params_from_opts_positive
60
- fake_control = mock('control')
61
- self.expects(:control).returns(fake_control)
62
- fake_control.expects(:capture_params).returns(true)
63
- val = {:request_params => 'foo'}
64
- assert_equal('foo', request_params_from_opts(val))
65
- assert_equal({}, val, "should delete request_params key from hash")
60
+ with_config(:capture_params => true) do
61
+ val = {:request_params => 'foo'}
62
+ assert_equal('foo', request_params_from_opts(val))
63
+ assert_equal({}, val, "should delete request_params key from hash")
64
+ end
66
65
  end
67
66
 
68
67
  def test_request_params_from_opts_negative
69
- fake_control = mock('control')
70
- self.expects(:control).returns(fake_control)
71
- fake_control.expects(:capture_params).returns(false)
72
- val = {:request_params => 'foo'}
73
- assert_equal(nil, request_params_from_opts(val))
74
- assert_equal({}, val, "should delete request_params key from hash")
68
+ with_config(:capture_params => false) do
69
+ val = {:request_params => 'foo'}
70
+ assert_equal(nil, request_params_from_opts(val))
71
+ assert_equal({}, val, "should delete request_params key from hash")
72
+ end
75
73
  end
76
74
 
77
75
  def test_normalized_request_and_custom_params_base
78
76
  self.expects(:normalize_params).with(nil).returns(nil)
79
77
  self.expects(:normalize_params).with({}).returns({})
80
- fake_control = mock('control')
81
- self.expects(:control).returns(fake_control)
82
- fake_control.expects(:capture_params).returns(true)
83
- assert_equal({:request_params => nil, :custom_params => {}}, normalized_request_and_custom_params({}))
78
+ with_config(:capture_params => true) do
79
+ assert_equal({:request_params => nil, :custom_params => {}},
80
+ normalized_request_and_custom_params({}))
81
+ end
84
82
  end
85
83
 
86
84
  def test_extract_source_base
87
- @capture_source = true
88
- self.expects(:sense_method).with(nil, 'source_extract')
89
- assert_equal(nil, extract_source(nil))
85
+ with_config(:'error_collector.capture_source' => true) do
86
+ error_collector = NewRelic::Agent::ErrorCollector.new
87
+ error_collector.expects(:sense_method).with(nil, 'source_extract')
88
+ assert_equal(nil, error_collector.extract_source(nil))
89
+ end
90
90
  end
91
91
 
92
92
  def test_extract_source_disabled
93
- @capture_source = false
94
- assert_equal(nil, extract_source(mock('exception')))
93
+ with_config(:'error_collector.capture_source' => false) do
94
+ error_collector = NewRelic::Agent::ErrorCollector.new
95
+ assert_equal(nil, error_collector.extract_source(mock('exception')))
96
+ end
95
97
  end
96
98
 
97
99
  def test_extract_source_with_source
98
- self.expects(:sense_method).with('happy', 'source_extract').returns('THE SOURCE')
99
- @capture_source = true
100
- assert_equal('THE SOURCE', extract_source('happy'))
100
+ with_config(:'error_collector.capture_source' => true) do
101
+ error_collector = NewRelic::Agent::ErrorCollector.new
102
+ error_collector.expects(:sense_method).with('happy', 'source_extract').returns('THE SOURCE')
103
+ assert_equal('THE SOURCE', error_collector.extract_source('happy'))
104
+ end
101
105
  end
102
106
 
103
107
  def test_extract_stack_trace
@@ -122,9 +126,7 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Test::Unit::TestCase
122
126
 
123
127
  def test_over_queue_limit_positive
124
128
  @errors = %w(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21)
125
- fake_log = mock('log')
126
- self.expects(:log).returns(fake_log)
127
- fake_log.expects(:warn).with('The error reporting queue has reached 20. The error detail for this and subsequent errors will not be transmitted to New Relic until the queued errors have been sent: hooray')
129
+ expects_logging(:warn, includes('The error reporting queue has reached 20'))
128
130
  assert over_queue_limit?('hooray')
129
131
  end
130
132
 
@@ -160,53 +162,56 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Test::Unit::TestCase
160
162
 
161
163
  def test_should_exit_notice_error_disabled
162
164
  error = mocked_error
163
- @enabled = false
164
- assert should_exit_notice_error?(error)
165
+ with_error_collector_config(:'error_collector.enabled' => false) do |error_collector|
166
+ assert error_collector.should_exit_notice_error?(error)
167
+ end
165
168
  end
166
169
 
167
170
  def test_should_exit_notice_error_nil
168
171
  error = nil
169
- @enabled = true
170
- self.expects(:error_is_ignored?).with(error).returns(false)
171
- # we increment it for the case that someone calls
172
- # NewRelic::Agent.notice_error(foo) # foo is nil
173
- # (which is probably not a good idea but is the existing api)
174
- self.expects(:increment_error_count!)
175
- assert should_exit_notice_error?(error)
172
+ with_error_collector_config(:'error_collector.enabled' => true) do |error_collector|
173
+ error_collector.expects(:error_is_ignored?).with(error).returns(false)
174
+ # we increment it for the case that someone calls
175
+ # NewRelic::Agent.notice_error(foo) # foo is nil
176
+ # (which is probably not a good idea but is the existing api)
177
+ error_collector.expects(:increment_error_count!)
178
+ assert error_collector.should_exit_notice_error?(error)
179
+ end
176
180
  end
177
181
 
178
182
  def test_should_exit_notice_error_positive
179
183
  error = mocked_error
180
- @enabled = true
181
- self.expects(:error_is_ignored?).with(error).returns(true)
182
- assert should_exit_notice_error?(error)
184
+ with_error_collector_config(:'error_collector.enabled' => true) do |error_collector|
185
+ error_collector.expects(:error_is_ignored?).with(error).returns(true)
186
+ assert error_collector.should_exit_notice_error?(error)
187
+ end
183
188
  end
184
189
 
185
190
  def test_should_exit_notice_error_negative
186
191
  error = mocked_error
187
- @enabled = true
188
- self.expects(:error_is_ignored?).with(error).returns(false)
189
- self.expects(:increment_error_count!)
190
- assert !should_exit_notice_error?(error)
192
+ with_error_collector_config(:'error_collector.enabled' => true) do |error_collector|
193
+ error_collector.expects(:error_is_ignored?).with(error).returns(false)
194
+ error_collector.expects(:increment_error_count!)
195
+ assert !error_collector.should_exit_notice_error?(error)
196
+ end
191
197
  end
192
198
 
193
199
  def test_filtered_error_positive
194
- @ignore = {'an_error' => true}
195
- error = mocked_error
196
- error_class = mock('error class')
197
- error.expects(:class).returns(error_class)
198
- error_class.expects(:name).returns('an_error')
199
- assert filtered_error?(error)
200
+ with_error_collector_config(:'error_collector.ignore_errors' => 'an_error') do |error_collector|
201
+ error = mocked_error
202
+ error_class = mock('error class')
203
+ error.expects(:class).returns(error_class)
204
+ error_class.expects(:name).returns('an_error')
205
+ assert error_collector.filtered_error?(error)
206
+ end
200
207
  end
201
208
 
202
209
  def test_filtered_error_negative
203
- @ignore = {}
204
210
  error = mocked_error
205
211
  error_class = mock('error class')
206
212
  error.expects(:class).returns(error_class)
207
213
  error_class.expects(:name).returns('an_error')
208
- self.expects(:filtered_by_error_filter?).with(error).returns(false)
209
- assert !filtered_error?(error)
214
+ assert !NewRelic::Agent::ErrorCollector.new.filtered_error?(error)
210
215
  end
211
216
 
212
217
  def test_filtered_by_error_filter_empty
@@ -251,7 +256,13 @@ class NewRelic::Agent::ErrorCollector::NoticeErrorTest < Test::Unit::TestCase
251
256
 
252
257
  def mocked_control
253
258
  fake_control = mock('control')
254
- self.stubs(:control).returns(fake_control)
259
+ NewRelic::Control.stubs(:instance).returns(fake_control)
255
260
  fake_control
256
261
  end
262
+
263
+ def with_error_collector_config(config)
264
+ with_config(config) do
265
+ yield NewRelic::Agent::ErrorCollector.new
266
+ end
267
+ end
257
268
  end