wd_newrelic_rpm 3.3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/CHANGELOG +591 -0
  2. data/LICENSE +64 -0
  3. data/README.rdoc +179 -0
  4. data/bin/mongrel_rpm +33 -0
  5. data/bin/newrelic +13 -0
  6. data/bin/newrelic_cmd +5 -0
  7. data/cert/cacert.pem +118 -0
  8. data/cert/oldsite.pem +28 -0
  9. data/cert/site.pem +27 -0
  10. data/install.rb +9 -0
  11. data/lib/conditional_vendored_dependency_detection.rb +3 -0
  12. data/lib/conditional_vendored_metric_parser.rb +5 -0
  13. data/lib/new_relic/agent.rb +467 -0
  14. data/lib/new_relic/agent/agent.rb +1325 -0
  15. data/lib/new_relic/agent/beacon_configuration.rb +121 -0
  16. data/lib/new_relic/agent/browser_monitoring.rb +142 -0
  17. data/lib/new_relic/agent/busy_calculator.rb +99 -0
  18. data/lib/new_relic/agent/chained_call.rb +13 -0
  19. data/lib/new_relic/agent/database.rb +223 -0
  20. data/lib/new_relic/agent/error_collector.rb +251 -0
  21. data/lib/new_relic/agent/instrumentation.rb +9 -0
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +29 -0
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +137 -0
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +68 -0
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +19 -0
  26. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +443 -0
  27. data/lib/new_relic/agent/instrumentation/data_mapper.rb +238 -0
  28. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +52 -0
  29. data/lib/new_relic/agent/instrumentation/memcache.rb +80 -0
  30. data/lib/new_relic/agent/instrumentation/merb/controller.rb +41 -0
  31. data/lib/new_relic/agent/instrumentation/merb/errors.rb +29 -0
  32. data/lib/new_relic/agent/instrumentation/metric_frame.rb +353 -0
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +80 -0
  34. data/lib/new_relic/agent/instrumentation/net.rb +29 -0
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +37 -0
  36. data/lib/new_relic/agent/instrumentation/queue_time.rb +210 -0
  37. data/lib/new_relic/agent/instrumentation/rack.rb +98 -0
  38. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +114 -0
  39. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +42 -0
  40. data/lib/new_relic/agent/instrumentation/rails/errors.rb +42 -0
  41. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +180 -0
  42. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/sinatra.rb +78 -0
  44. data/lib/new_relic/agent/instrumentation/sunspot.rb +29 -0
  45. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +21 -0
  46. data/lib/new_relic/agent/method_tracer.rb +528 -0
  47. data/lib/new_relic/agent/sampler.rb +50 -0
  48. data/lib/new_relic/agent/samplers/cpu_sampler.rb +58 -0
  49. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +40 -0
  50. data/lib/new_relic/agent/samplers/memory_sampler.rb +143 -0
  51. data/lib/new_relic/agent/samplers/object_sampler.rb +26 -0
  52. data/lib/new_relic/agent/shim_agent.rb +29 -0
  53. data/lib/new_relic/agent/sql_sampler.rb +286 -0
  54. data/lib/new_relic/agent/stats_engine.rb +26 -0
  55. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +123 -0
  56. data/lib/new_relic/agent/stats_engine/metric_stats.rb +187 -0
  57. data/lib/new_relic/agent/stats_engine/samplers.rb +95 -0
  58. data/lib/new_relic/agent/stats_engine/transactions.rb +125 -0
  59. data/lib/new_relic/agent/transaction_info.rb +74 -0
  60. data/lib/new_relic/agent/transaction_sample_builder.rb +116 -0
  61. data/lib/new_relic/agent/transaction_sampler.rb +468 -0
  62. data/lib/new_relic/agent/worker_loop.rb +89 -0
  63. data/lib/new_relic/collection_helper.rb +77 -0
  64. data/lib/new_relic/command.rb +85 -0
  65. data/lib/new_relic/commands/deployments.rb +105 -0
  66. data/lib/new_relic/commands/install.rb +80 -0
  67. data/lib/new_relic/control.rb +46 -0
  68. data/lib/new_relic/control/class_methods.rb +53 -0
  69. data/lib/new_relic/control/configuration.rb +206 -0
  70. data/lib/new_relic/control/frameworks.rb +10 -0
  71. data/lib/new_relic/control/frameworks/external.rb +16 -0
  72. data/lib/new_relic/control/frameworks/merb.rb +31 -0
  73. data/lib/new_relic/control/frameworks/rails.rb +164 -0
  74. data/lib/new_relic/control/frameworks/rails3.rb +75 -0
  75. data/lib/new_relic/control/frameworks/ruby.rb +42 -0
  76. data/lib/new_relic/control/frameworks/sinatra.rb +20 -0
  77. data/lib/new_relic/control/instance_methods.rb +179 -0
  78. data/lib/new_relic/control/instrumentation.rb +100 -0
  79. data/lib/new_relic/control/logging_methods.rb +143 -0
  80. data/lib/new_relic/control/profiling.rb +25 -0
  81. data/lib/new_relic/control/server_methods.rb +114 -0
  82. data/lib/new_relic/data_serialization.rb +151 -0
  83. data/lib/new_relic/delayed_job_injection.rb +51 -0
  84. data/lib/new_relic/language_support.rb +73 -0
  85. data/lib/new_relic/local_environment.rb +428 -0
  86. data/lib/new_relic/merbtasks.rb +6 -0
  87. data/lib/new_relic/metric_data.rb +51 -0
  88. data/lib/new_relic/metric_spec.rb +76 -0
  89. data/lib/new_relic/metrics.rb +9 -0
  90. data/lib/new_relic/noticed_error.rb +29 -0
  91. data/lib/new_relic/rack/browser_monitoring.rb +76 -0
  92. data/lib/new_relic/rack/developer_mode.rb +268 -0
  93. data/lib/new_relic/recipes.rb +77 -0
  94. data/lib/new_relic/stats.rb +335 -0
  95. data/lib/new_relic/timer_lib.rb +27 -0
  96. data/lib/new_relic/transaction_analysis.rb +77 -0
  97. data/lib/new_relic/transaction_analysis/segment_summary.rb +49 -0
  98. data/lib/new_relic/transaction_sample.rb +261 -0
  99. data/lib/new_relic/transaction_sample/composite_segment.rb +27 -0
  100. data/lib/new_relic/transaction_sample/fake_segment.rb +9 -0
  101. data/lib/new_relic/transaction_sample/segment.rb +203 -0
  102. data/lib/new_relic/transaction_sample/summary_segment.rb +21 -0
  103. data/lib/new_relic/url_rule.rb +14 -0
  104. data/lib/new_relic/version.rb +55 -0
  105. data/lib/newrelic_rpm.rb +49 -0
  106. data/lib/tasks/all.rb +4 -0
  107. data/lib/tasks/install.rake +7 -0
  108. data/lib/tasks/tests.rake +19 -0
  109. data/newrelic.yml +265 -0
  110. data/newrelic_rpm.gemspec +312 -0
  111. data/recipes/newrelic.rb +6 -0
  112. data/test/active_record_fixtures.rb +77 -0
  113. data/test/config/newrelic.yml +48 -0
  114. data/test/config/test_control.rb +48 -0
  115. data/test/fixtures/proc_cpuinfo.txt +575 -0
  116. data/test/new_relic/agent/agent/connect_test.rb +403 -0
  117. data/test/new_relic/agent/agent/start_test.rb +255 -0
  118. data/test/new_relic/agent/agent/start_worker_thread_test.rb +153 -0
  119. data/test/new_relic/agent/agent_test.rb +140 -0
  120. data/test/new_relic/agent/agent_test_controller.rb +77 -0
  121. data/test/new_relic/agent/agent_test_controller_test.rb +382 -0
  122. data/test/new_relic/agent/apdex_from_server_test.rb +9 -0
  123. data/test/new_relic/agent/beacon_configuration_test.rb +111 -0
  124. data/test/new_relic/agent/browser_monitoring_test.rb +323 -0
  125. data/test/new_relic/agent/busy_calculator_test.rb +81 -0
  126. data/test/new_relic/agent/database_test.rb +149 -0
  127. data/test/new_relic/agent/error_collector/notice_error_test.rb +257 -0
  128. data/test/new_relic/agent/error_collector_test.rb +192 -0
  129. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +576 -0
  130. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +34 -0
  131. data/test/new_relic/agent/instrumentation/instrumentation_test.rb +11 -0
  132. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +171 -0
  133. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +50 -0
  134. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +84 -0
  135. data/test/new_relic/agent/instrumentation/queue_time_test.rb +382 -0
  136. data/test/new_relic/agent/instrumentation/rack_test.rb +35 -0
  137. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +184 -0
  138. data/test/new_relic/agent/memcache_instrumentation_test.rb +143 -0
  139. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +164 -0
  140. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +234 -0
  141. data/test/new_relic/agent/method_tracer_test.rb +386 -0
  142. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  143. data/test/new_relic/agent/rpm_agent_test.rb +149 -0
  144. data/test/new_relic/agent/sampler_test.rb +19 -0
  145. data/test/new_relic/agent/shim_agent_test.rb +20 -0
  146. data/test/new_relic/agent/sql_sampler_test.rb +192 -0
  147. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +150 -0
  148. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +82 -0
  149. data/test/new_relic/agent/stats_engine/samplers_test.rb +99 -0
  150. data/test/new_relic/agent/stats_engine_test.rb +220 -0
  151. data/test/new_relic/agent/transaction_info_test.rb +13 -0
  152. data/test/new_relic/agent/transaction_sample_builder_test.rb +219 -0
  153. data/test/new_relic/agent/transaction_sampler_test.rb +967 -0
  154. data/test/new_relic/agent/worker_loop_test.rb +66 -0
  155. data/test/new_relic/agent_test.rb +187 -0
  156. data/test/new_relic/collection_helper_test.rb +149 -0
  157. data/test/new_relic/command/deployments_test.rb +68 -0
  158. data/test/new_relic/control/class_methods_test.rb +62 -0
  159. data/test/new_relic/control/configuration_test.rb +84 -0
  160. data/test/new_relic/control/logging_methods_test.rb +185 -0
  161. data/test/new_relic/control_test.rb +256 -0
  162. data/test/new_relic/data_serialization_test.rb +208 -0
  163. data/test/new_relic/delayed_job_injection_test.rb +16 -0
  164. data/test/new_relic/local_environment_test.rb +85 -0
  165. data/test/new_relic/metric_data_test.rb +125 -0
  166. data/test/new_relic/metric_parser/metric_parser_test.rb +11 -0
  167. data/test/new_relic/metric_spec_test.rb +95 -0
  168. data/test/new_relic/rack/all_test.rb +11 -0
  169. data/test/new_relic/rack/browser_monitoring_test.rb +142 -0
  170. data/test/new_relic/rack/developer_mode_helper_test.rb +141 -0
  171. data/test/new_relic/rack/developer_mode_test.rb +74 -0
  172. data/test/new_relic/stats_test.rb +411 -0
  173. data/test/new_relic/transaction_analysis/segment_summary_test.rb +91 -0
  174. data/test/new_relic/transaction_analysis_test.rb +121 -0
  175. data/test/new_relic/transaction_sample/composite_segment_test.rb +35 -0
  176. data/test/new_relic/transaction_sample/fake_segment_test.rb +17 -0
  177. data/test/new_relic/transaction_sample/segment_test.rb +389 -0
  178. data/test/new_relic/transaction_sample/summary_segment_test.rb +31 -0
  179. data/test/new_relic/transaction_sample_subtest_test.rb +56 -0
  180. data/test/new_relic/transaction_sample_test.rb +177 -0
  181. data/test/new_relic/version_number_test.rb +89 -0
  182. data/test/script/build_test_gem.sh +51 -0
  183. data/test/script/ci.sh +94 -0
  184. data/test/script/ci_bench.sh +52 -0
  185. data/test/test_contexts.rb +29 -0
  186. data/test/test_helper.rb +155 -0
  187. data/ui/helpers/developer_mode_helper.rb +357 -0
  188. data/ui/helpers/google_pie_chart.rb +48 -0
  189. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  190. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  191. data/ui/views/newrelic/_sample.rhtml +20 -0
  192. data/ui/views/newrelic/_segment.rhtml +28 -0
  193. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  194. data/ui/views/newrelic/_segment_row.rhtml +12 -0
  195. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  196. data/ui/views/newrelic/_show_sample_sql.rhtml +24 -0
  197. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  198. data/ui/views/newrelic/_sql_row.rhtml +16 -0
  199. data/ui/views/newrelic/_stack_trace.rhtml +15 -0
  200. data/ui/views/newrelic/_table.rhtml +12 -0
  201. data/ui/views/newrelic/explain_sql.rhtml +43 -0
  202. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  203. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  204. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  205. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  206. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  207. data/ui/views/newrelic/file/images/new-relic-rpm-desktop.gif +0 -0
  208. data/ui/views/newrelic/file/images/new_relic_rpm_desktop.gif +0 -0
  209. data/ui/views/newrelic/file/images/textmate.png +0 -0
  210. data/ui/views/newrelic/file/javascript/jquery-1.4.2.js +6240 -0
  211. data/ui/views/newrelic/file/javascript/transaction_sample.js +120 -0
  212. data/ui/views/newrelic/file/stylesheets/style.css +490 -0
  213. data/ui/views/newrelic/index.rhtml +71 -0
  214. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  215. data/ui/views/newrelic/show_sample.rhtml +80 -0
  216. data/ui/views/newrelic/show_source.rhtml +3 -0
  217. data/ui/views/newrelic/threads.rhtml +53 -0
  218. data/vendor/gems/dependency_detection-0.0.1.build/LICENSE +5 -0
  219. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +67 -0
  220. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +3 -0
  221. data/vendor/gems/metric_parser-0.1.0.pre1/lib/metric_parser.rb +1 -0
  222. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser.rb +64 -0
  223. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/action_mailer.rb +14 -0
  224. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_merchant.rb +31 -0
  225. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/active_record.rb +33 -0
  226. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/apdex.rb +89 -0
  227. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/background_transaction.rb +7 -0
  228. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/client.rb +46 -0
  229. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller.rb +67 -0
  230. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_cpu.rb +43 -0
  231. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/controller_ext.rb +17 -0
  232. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database.rb +48 -0
  233. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/database_pool.rb +24 -0
  234. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net.rb +28 -0
  235. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/dot_net_parser.rb +17 -0
  236. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/errors.rb +11 -0
  237. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/external.rb +55 -0
  238. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/frontend.rb +40 -0
  239. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/gc.rb +20 -0
  240. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/hibernate_session.rb +7 -0
  241. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +31 -0
  242. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java_parser.rb +17 -0
  243. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp.rb +34 -0
  244. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/jsp_tag.rb +7 -0
  245. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/mem_cache.rb +55 -0
  246. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/metric_parser.rb +135 -0
  247. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/orm.rb +27 -0
  248. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/other_transaction.rb +40 -0
  249. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet.rb +7 -0
  250. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_context_listener.rb +7 -0
  251. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_filter.rb +7 -0
  252. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr.rb +27 -0
  253. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/solr_request_handler.rb +15 -0
  254. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring.rb +54 -0
  255. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_controller.rb +6 -0
  256. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/spring_view.rb +6 -0
  257. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_action.rb +20 -0
  258. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/struts_result.rb +20 -0
  259. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/version.rb +5 -0
  260. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +70 -0
  261. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_frontend.rb +18 -0
  262. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_service.rb +14 -0
  263. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/web_transaction.rb +133 -0
  264. metadata +376 -0
@@ -0,0 +1,62 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
2
+ require 'new_relic/control/class_methods'
3
+
4
+ class BaseClassMethods
5
+ # stub class to enable testing of the module
6
+ include NewRelic::Control::ClassMethods
7
+ end
8
+
9
+ class NewRelic::Control::ClassMethodsTest < Test::Unit::TestCase
10
+ def setup
11
+ @base = ::BaseClassMethods.new
12
+ super
13
+ end
14
+
15
+ def test_instance
16
+ assert_equal(nil, @base.instance_variable_get('@instance'), 'instance should start out nil')
17
+ @base.expects(:new_instance).returns('a new instance')
18
+ assert_equal('a new instance', @base.instance, "should return the result from the #new_instance call")
19
+ end
20
+
21
+ def test_new_instance_non_test
22
+ local_env = mock('local env')
23
+ @base.expects(:local_env).returns(local_env).at_least_once
24
+ local_env.expects(:framework).returns('nontest').twice
25
+ mock_klass = mock('klass')
26
+ mock_klass.expects(:new).with(local_env)
27
+ @base.expects(:load_framework_class).with('nontest').returns(mock_klass)
28
+ @base.new_instance
29
+ end
30
+
31
+ def test_new_instance_test_framework
32
+ local_env = mock('local env')
33
+ local_env.expects(:framework).returns(:test)
34
+ @base.expects(:local_env).returns(local_env)
35
+ @base.expects(:load_test_framework)
36
+ @base.new_instance
37
+ end
38
+
39
+ def test_load_test_framework
40
+ local_env = mock('local env')
41
+ # a loose requirement here because the tests will *all* break if
42
+ # this does not work.
43
+ NewRelic::Control::Frameworks::Test.expects(:new).with(local_env, instance_of(String))
44
+ @base.expects(:local_env).returns(local_env)
45
+ @base.load_test_framework
46
+ end
47
+
48
+ def test_load_framework_class_existing
49
+ %w[rails rails3 sinatra ruby merb external].each do |type|
50
+ @base.load_framework_class(type)
51
+ end
52
+ end
53
+
54
+ def test_load_framework_class_missing
55
+ # this is used to allow other people to insert frameworks without
56
+ # having the file in our agent, i.e. define your own
57
+ # NewRelic::Control::Framework::FooBar
58
+ assert_raise(NameError) do
59
+ @base.load_framework_class('missing')
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../../test_helper'))
2
+
3
+ class NewRelic::Control::ConfigurationTest < Test::Unit::TestCase
4
+ require 'new_relic/control/configuration'
5
+ include NewRelic::Control::Configuration
6
+
7
+ def setup
8
+ # The log stuff is memoized so let's clear it each time.
9
+ NewRelic::Control.instance.instance_variable_set '@log_path', nil
10
+ NewRelic::Control.instance.instance_variable_set '@log_file', nil
11
+ @root = ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT
12
+ end
13
+
14
+ def teardown
15
+ NewRelic::Control.instance.settings.delete('log_file_path')
16
+ end
17
+
18
+ def test_license_key_defaults_to_env_variable
19
+ ENV['NEWRELIC_LICENSE_KEY'] = nil
20
+ self.expects(:fetch).with('license_key', nil)
21
+ license_key
22
+
23
+ ENV['NEWRELIC_LICENSE_KEY'] = "a string"
24
+ self.expects(:fetch).with('license_key', 'a string')
25
+ license_key
26
+ end
27
+
28
+ def test_log_path_uses_default_if_not_set
29
+ NewRelic::Control.instance.setup_log
30
+ assert_equal(File.expand_path("log/newrelic_agent.log"),
31
+ NewRelic::Control.instance.log_file)
32
+ end
33
+
34
+ def test_log_file_path_uses_given_value
35
+ Dir.stubs(:mkdir).returns(true)
36
+ NewRelic::Control.instance['log_file_path'] = 'lerg'
37
+ NewRelic::Control.instance.setup_log
38
+ assert_match(/\/lerg\/newrelic_agent.log/,
39
+ NewRelic::Control.instance.log_file)
40
+ NewRelic::Control.instance.settings.delete('log_file_path') # = nil
41
+ end
42
+
43
+ def test_server_side_config_ignores_yaml
44
+ settings.merge! 'ssl' => false, 'transaction_tracer' => {'enabled' => true, 'stack_trace_threshold' => 1.0}, 'error_collector' => {'enabled' => true, 'ignore_errors' => 'ActiveRecord::RecordNotFound'}, 'capture_params' => false
45
+ merge_server_side_config 'transaction_tracer.enabled' => false, 'error_collector.enabled' => false
46
+ assert_equal({'ssl' => false, 'transaction_tracer' => {'enabled' => false}, 'error_collector' => {'enabled' => false}}, settings)
47
+ end
48
+
49
+ def test_install_browser_monitoring
50
+ require(File.expand_path(File.join(File.dirname(__FILE__),
51
+ '/../../../lib/new_relic/rack/browser_monitoring')))
52
+ middleware = stub('middleware config')
53
+ config = stub('rails config', :middleware => middleware)
54
+ middleware.expects(:use).with(NewRelic::Rack::BrowserMonitoring)
55
+ NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => true }
56
+ NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
57
+
58
+ NewRelic::Control.instance.install_browser_monitoring(config)
59
+ end
60
+
61
+ def test_install_browser_monitoring_should_not_install_when_not_configured
62
+ middleware = stub('middleware config')
63
+ config = stub('rails config', :middleware => middleware)
64
+ middleware.expects(:use).never
65
+ NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => false }
66
+ NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
67
+
68
+ NewRelic::Control.instance.install_browser_monitoring(config)
69
+
70
+ NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => true }
71
+ end
72
+
73
+ def test_data_serialization_default_off
74
+ DependencyDetection.send(:class_variable_set, '@@items', [])
75
+ assert NewRelic::Control.instance.disable_serialization?
76
+ end
77
+
78
+ def test_data_serialization_default_on_when_using_resque
79
+ DependencyDetection.defer { @name = :resque }
80
+ DependencyDetection.dependency_by_name(:resque).executed!
81
+ assert !NewRelic::Control.instance.disable_serialization?
82
+ DependencyDetection.send(:class_variable_set, '@@items', [])
83
+ end
84
+ end
@@ -0,0 +1,185 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
2
+ require 'new_relic/control/logging_methods'
3
+ require 'fileutils'
4
+
5
+ class BaseLoggingMethods
6
+ # stub class to enable testing of the module
7
+ include NewRelic::Control::LoggingMethods
8
+ include NewRelic::Control::Configuration
9
+ def root; "."; end
10
+ end
11
+
12
+ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
13
+ def setup
14
+ @base = BaseLoggingMethods.new
15
+ @base.settings['log_file_path'] = 'log/'
16
+ @base.settings['log_file_name'] = 'newrelic_agent.log'
17
+ super
18
+ end
19
+
20
+ def test_log_basic
21
+ mock_logger = mock('logger')
22
+ @base.instance_eval { @log = mock_logger }
23
+ assert_equal mock_logger, @base.log
24
+ end
25
+
26
+ def test_log_no_log
27
+ log = @base.log
28
+ assert_equal Logger, log.class
29
+ assert_equal Logger::INFO, log.level
30
+ # have to root around in the logger for the logdev
31
+ assert_equal STDOUT, log.instance_eval { @logdev }.dev
32
+ end
33
+
34
+ def test_logbang_basic
35
+ @base.expects(:should_log?).returns(true)
36
+ @base.expects(:to_stdout).with('whee')
37
+ @base.instance_eval { @log = nil }
38
+ @base.log!('whee')
39
+ end
40
+
41
+ def test_logbang_should_not_log
42
+ @base.expects(:should_log?).returns(false)
43
+ @base.stubs(:to_stdout)
44
+ assert_equal nil, @base.log!('whee')
45
+ end
46
+
47
+ def test_logbang_with_log
48
+ @base.expects(:should_log?).returns(true)
49
+ @base.expects(:to_stdout).with('whee')
50
+ fake_logger = mock('log')
51
+ fake_logger.expects(:send).with(:info, 'whee')
52
+ @base.instance_eval { @log = fake_logger }
53
+ @base.log!('whee')
54
+ end
55
+
56
+ def test_should_log_no_settings
57
+ @base.instance_eval { @settings = nil }
58
+ assert !@base.should_log?
59
+ end
60
+
61
+ def test_should_log_agent_disabled
62
+ @base.instance_eval { @settings = true }
63
+ @base.expects(:agent_enabled?).returns(false)
64
+ assert !@base.should_log?
65
+ end
66
+
67
+ def test_should_log_agent_enabled
68
+ @base.instance_eval { @settings = true }
69
+ @base.expects(:agent_enabled?).returns(true)
70
+ assert @base.should_log?
71
+ end
72
+
73
+ def test_set_log_level_base
74
+ fake_logger = mock('logger')
75
+ # bad configuration
76
+ @base.expects(:fetch).with('log_level', 'info').returns('whee')
77
+ fake_logger.expects(:level=).with(Logger::INFO)
78
+ assert_equal fake_logger, @base.set_log_level!(fake_logger)
79
+ end
80
+
81
+ def test_set_log_level_with_each_level
82
+ fake_logger = mock('logger')
83
+ %w[debug info warn error fatal].each do |level|
84
+ @base.expects(:fetch).with('log_level', 'info').returns(level)
85
+ fake_logger.expects(:level=).with(Logger.const_get(level.upcase))
86
+ assert_equal fake_logger, @base.set_log_level!(fake_logger)
87
+ end
88
+ end
89
+
90
+ def test_set_log_format
91
+ fake_logger = Object.new
92
+ assert !fake_logger.respond_to?(:format_message)
93
+ assert_equal fake_logger, @base.set_log_format!(fake_logger)
94
+ assert fake_logger.respond_to?(:format_message)
95
+ end
96
+
97
+ def test_setup_log_existing_file
98
+ fake_logger = mock('logger')
99
+ Logger.expects(:new).with('logpath/logfilename').returns(fake_logger)
100
+ @base.expects(:log_path).returns('logpath').at_least_once
101
+ @base.expects(:log_file_name).returns('logfilename')
102
+ @base.expects(:set_log_format!).with(fake_logger)
103
+ @base.expects(:set_log_level!).with(fake_logger)
104
+ assert_equal fake_logger, @base.setup_log
105
+ assert_equal fake_logger, @base.instance_eval { @log }
106
+ assert_equal 'logpath/logfilename', @base.instance_eval { @log_file }
107
+ end
108
+
109
+ def test_to_stdout
110
+ STDOUT.expects(:puts).with('** [NewRelic] whee')
111
+ @base.to_stdout('whee')
112
+ end
113
+
114
+ def test_log_path_exists
115
+ @base.instance_eval { @log_path = 'logpath' }
116
+ assert_equal 'logpath', @base.log_path
117
+ end
118
+
119
+ def test_log_path_path_exists
120
+ @base.settings['log_file_path'] = 'log'
121
+ assert File.directory?('log')
122
+ assert_equal File.expand_path('log'), @base.log_path
123
+ end
124
+
125
+ def test_log_path_path_created
126
+ path = File.expand_path('tmp/log_path_test')
127
+ @base.instance_eval { @log_path = nil }
128
+ @base.settings['log_file_path'] = 'tmp/log_path_test'
129
+ assert !File.directory?(path) || FileUtils.rmdir(path)
130
+ @base.expects(:log!).never
131
+ assert_equal path, @base.log_path
132
+ assert File.directory?(path)
133
+ end
134
+
135
+ def test_log_path_path_unable_to_create
136
+ path = File.expand_path('tmp/log_path_test')
137
+ @base.instance_eval { @log_path = nil }
138
+ @base.settings['log_file_path'] = 'tmp/log_path_test'
139
+ assert !File.directory?(path) || FileUtils.rmdir(path)
140
+ @base.expects(:log!).with("Error creating log directory tmp/log_path_test, using standard out for logging.", :warn)
141
+ Dir.expects(:mkdir).with(path).raises('cannot make directory bro!').twice # once for the relative directory, once for the directory relative to Rails.root
142
+ assert_nil @base.log_path
143
+ assert !File.directory?(path)
144
+ assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
145
+ end
146
+
147
+ def test_log_file_name
148
+ @base.expects(:fetch).with('log_file_name', 'newrelic_agent.log').returns('log_file_name')
149
+ assert_equal 'log_file_name', @base.log_file_name
150
+ end
151
+
152
+ def test_log_to_stdout_when_log_file_path_set_to_STDOUT
153
+ @base.stubs(:fetch).returns('whatever')
154
+ @base.expects(:fetch).with('log_file_path', 'log').returns('STDOUT')
155
+ Dir.expects(:mkdir).never
156
+ @base.setup_log
157
+ assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
158
+ end
159
+
160
+ def test_logs_to_stdout_include_newrelic_prefix
161
+ @base.stubs(:fetch).returns('whatever')
162
+ @base.expects(:fetch).with('log_file_path', 'log').returns('STDOUT')
163
+ STDOUT.expects(:write).with(regexp_matches(/\*\* \[NewRelic\].*whee/))
164
+ @base.setup_log
165
+ @base.log.info('whee')
166
+ end
167
+
168
+ def test_set_stdout_destination_from_NEW_RELIC_LOG_env_var
169
+ @base.stubs(:fetch).returns('whatever')
170
+ ENV['NEW_RELIC_LOG'] = 'stdout'
171
+ Dir.expects(:mkdir).never
172
+ @base.setup_log
173
+ assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
174
+ ENV['NEW_RELIC_LOG'] = nil
175
+ end
176
+
177
+ def test_set_file_destination_from_NEW_RELIC_LOG_env_var
178
+ @base.stubs(:fetch).returns('whatever')
179
+ ENV['NEW_RELIC_LOG'] = 'log/file.log'
180
+ @base.setup_log
181
+ assert_equal 'log', File.basename(@base.log_path)
182
+ assert_equal 'file.log', @base.log_file_name
183
+ ENV['NEW_RELIC_LOG'] = nil
184
+ end
185
+ end
@@ -0,0 +1,256 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../test_helper'))
2
+ class NewRelic::ControlTest < Test::Unit::TestCase
3
+
4
+ attr_reader :control
5
+
6
+ def setup
7
+ NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
8
+ @control = NewRelic::Control.instance
9
+ raise 'oh geez, wrong class' unless NewRelic::Control.instance.is_a?(::NewRelic::Control::Frameworks::Test)
10
+ end
11
+
12
+ def shutdown
13
+ NewRelic::Agent.shutdown
14
+ end
15
+
16
+ def test_cert_file_path
17
+ assert @control.cert_file_path
18
+ assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @control.cert_file_path
19
+ end
20
+
21
+ # This test does not actually use the ruby agent in any way - it's
22
+ # testing that the CA file we ship actually validates our server's
23
+ # certificate. It's used for customers who enable verify_certificate
24
+ def test_cert_file
25
+ return if ::RUBY_VERSION == '1.9.3'
26
+ require 'socket'
27
+ require 'openssl'
28
+
29
+ s = TCPSocket.new 'collector.newrelic.com', 443
30
+ ctx = OpenSSL::SSL::SSLContext.new
31
+ ctx.ca_file = @control.cert_file_path
32
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
33
+ s = OpenSSL::SSL::SSLSocket.new s, ctx
34
+ s.connect
35
+ # should not raise an error
36
+ end
37
+
38
+ # see above, but for staging, as well. This allows us to test new
39
+ # certificates in a non-customer-facing place before setting them
40
+ # live.
41
+ def test_staging_cert_file
42
+ return if ::RUBY_VERSION == '1.9.3'
43
+ require 'socket'
44
+ require 'openssl'
45
+
46
+ s = TCPSocket.new 'staging-collector.newrelic.com', 443
47
+ ctx = OpenSSL::SSL::SSLContext.new
48
+ ctx.ca_file = @control.cert_file_path
49
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
50
+ s = OpenSSL::SSL::SSLSocket.new s, ctx
51
+ s.connect
52
+ # should not raise an error
53
+ end
54
+
55
+ def test_monitor_mode
56
+ assert ! @control.monitor_mode?
57
+ @control.settings.delete 'enabled'
58
+ @control.settings.delete 'monitor_mode'
59
+ assert !@control.monitor_mode?
60
+ @control['enabled'] = false
61
+ assert ! @control.monitor_mode?
62
+ @control['enabled'] = true
63
+ assert @control.monitor_mode?
64
+ @control['monitor_mode'] = nil
65
+ assert !@control.monitor_mode?
66
+ @control['monitor_mode'] = false
67
+ assert !@control.monitor_mode?
68
+ @control['monitor_mode'] = true
69
+ assert @control.monitor_mode?
70
+ ensure
71
+ @control['enabled'] = false
72
+ @control['monitor_mode'] = false
73
+ end
74
+
75
+ def test_test_config
76
+ if defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
77
+ assert_equal :rails3, control.app
78
+ elsif defined?(Rails)
79
+ assert_equal :rails, control.app
80
+ else
81
+ assert_equal :test, control.app
82
+ end
83
+ assert_equal :test, control.framework
84
+ assert_match /test/i, control.dispatcher_instance_id
85
+ assert("" == control.dispatcher.to_s, "Expected dispatcher to be empty, but was #{control.dispatcher.to_s}")
86
+ assert !control['enabled']
87
+ assert_equal false, control['monitor_mode']
88
+ control.local_env
89
+ end
90
+
91
+ def test_root
92
+ assert File.directory?(NewRelic::Control.newrelic_root), NewRelic::Control.newrelic_root
93
+ if defined?(Rails)
94
+ assert File.directory?(File.join(NewRelic::Control.newrelic_root, "lib")), NewRelic::Control.newrelic_root + "/lib"
95
+ end
96
+ end
97
+
98
+ def test_info
99
+ props = NewRelic::Control.instance.local_env.snapshot
100
+ if defined?(Rails)
101
+ assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last, props.inspect
102
+ end
103
+ end
104
+
105
+ def test_resolve_ip
106
+ assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
107
+ assert_equal nil, control.send(:convert_to_ip_address, 'q1239988737.us')
108
+ # This will fail if you don't have a valid, accessible, DNS server
109
+ assert_equal '204.93.223.153', control.send(:convert_to_ip_address, 'collector.newrelic.com')
110
+ end
111
+
112
+ class FakeResolv
113
+ def self.getaddress(host)
114
+ raise 'deliberately broken'
115
+ end
116
+ end
117
+
118
+ def test_resolve_ip_with_broken_dns
119
+ # Here be dragons: disable the ruby DNS lookup methods we use so
120
+ # that it will actually fail to resolve.
121
+ old_resolv = Resolv
122
+ old_ipsocket = IPSocket
123
+ Object.instance_eval { remove_const :Resolv}
124
+ Object.instance_eval {remove_const:'IPSocket' }
125
+ assert_equal(nil, control.send(:convert_to_ip_address, 'collector.newrelic.com'), "DNS is down, should be no IP for server")
126
+
127
+ Object.instance_eval {const_set('Resolv', old_resolv); const_set('IPSocket', old_ipsocket)}
128
+ # these are here to make sure that the constant tomfoolery above
129
+ # has not broket the system unduly
130
+ assert_equal old_resolv, Resolv
131
+ assert_equal old_ipsocket, IPSocket
132
+ end
133
+
134
+ def test_config_yaml_erb
135
+ assert_equal 'heyheyhey', control['erb_value']
136
+ assert_equal '', control['message']
137
+ assert_equal '', control['license_key']
138
+ end
139
+
140
+ def test_appnames
141
+ assert_equal %w[a b c], NewRelic::Control.instance.app_names
142
+ end
143
+
144
+ def test_config_booleans
145
+ assert_equal control['tval'], true
146
+ assert_equal control['fval'], false
147
+ assert_nil control['not_in_yaml_val']
148
+ assert_equal control['yval'], true
149
+ assert_equal control['sval'], 'sure'
150
+ end
151
+
152
+ def test_config_apdex
153
+ assert_equal 1.1, control.apdex_t
154
+ end
155
+
156
+ # def test_transaction_threshold
157
+ # assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
158
+ # assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
159
+ # end
160
+
161
+ def test_log_file_name
162
+ NewRelic::Control.instance.setup_log
163
+ assert_match /newrelic_agent.log$/, control.instance_variable_get('@log_file')
164
+ end
165
+
166
+ # def test_transaction_threshold__apdex
167
+ # forced_start
168
+ # assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
169
+ # assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
170
+ # end
171
+
172
+ def test_transaction_threshold__default
173
+ forced_start :transaction_tracer => { :transaction_threshold => nil}
174
+ assert_nil control['transaction_tracer']['transaction_threshold']
175
+ assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
176
+ end
177
+
178
+ def test_transaction_threshold__override
179
+ forced_start :transaction_tracer => { :transaction_threshold => 1}
180
+ assert_equal 1, control['transaction_tracer']['transaction_threshold']
181
+ assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
182
+ end
183
+
184
+ def test_transaction_tracer_disabled
185
+ forced_start(:transaction_tracer => { :enabled => false },
186
+ :developer_mode => false, :monitor_mode => true)
187
+ NewRelic::Agent::Agent.instance.check_transaction_sampler_status
188
+
189
+ assert(!NewRelic::Agent::Agent.instance.transaction_sampler.enabled?,
190
+ 'transaction tracer enabled when config calls for disabled')
191
+
192
+ @control['developer_mode'] = true
193
+ @control['monitor_mode'] = false
194
+ end
195
+
196
+ def test_sql_tracer_disabled
197
+ forced_start(:slow_sql => { :enabled => false }, :monitor_mode => true)
198
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
199
+
200
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
201
+ 'sql tracer enabled when config calls for disabled')
202
+
203
+ @control['monitor_mode'] = false
204
+ end
205
+
206
+ def test_sql_tracer_disabled_with_record_sql_false
207
+ forced_start(:slow_sql => { :enabled => true, :record_sql => 'off' })
208
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
209
+
210
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
211
+ 'sql tracer enabled when config calls for disabled')
212
+ end
213
+
214
+ def test_sql_tracer_disabled_when_tt_disabled
215
+ forced_start(:transaction_tracer => { :enabled => false },
216
+ :slow_sql => { :enabled => true },
217
+ :developer_mode => false, :monitor_mode => true)
218
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
219
+
220
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
221
+ 'sql enabled when transaction tracer disabled')
222
+
223
+ @control['developer_mode'] = true
224
+ @control['monitor_mode'] = false
225
+ end
226
+
227
+ def test_sql_tracer_disabled_when_tt_disabled_by_server
228
+ forced_start(:slow_sql => { :enabled => true },
229
+ :transaction_tracer => { :enabled => true },
230
+ :monitor_mode => true)
231
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
232
+ NewRelic::Agent::Agent.instance.finish_setup('collect_traces' => false)
233
+
234
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
235
+ 'sql enabled when tracing disabled by server')
236
+
237
+ @control['monitor_mode'] = false
238
+ end
239
+
240
+ def test_merging_options
241
+ NewRelic::Control.send :public, :merge_options
242
+ @control.merge_options :api_port => 66, :transaction_tracer => { :explain_threshold => 2.0 }
243
+ assert_equal 66, NewRelic::Control.instance['api_port']
244
+ assert_equal 2.0, NewRelic::Control.instance['transaction_tracer']['explain_threshold']
245
+ assert_equal 'raw', NewRelic::Control.instance['transaction_tracer']['record_sql']
246
+ end
247
+
248
+ private
249
+
250
+ def forced_start overrides = {}
251
+ NewRelic::Agent.manual_start overrides
252
+ # This is to force the agent to start again.
253
+ NewRelic::Agent.instance.stubs(:started?).returns(nil)
254
+ NewRelic::Agent.instance.start
255
+ end
256
+ end