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,34 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
2
+ class NewRelic::Agent::Instrumentation::ControllerInstrumentationTest < Test::Unit::TestCase
3
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
4
+ class TestObject
5
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
6
+ end
7
+
8
+ def test_detect_upstream_wait_basic
9
+ start_time = Time.now
10
+ object = TestObject.new
11
+ # should return the start time above by default
12
+ object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
13
+ object.expects(:parse_frontend_headers).with({:request => 'headers'}).returns(start_time)
14
+ assert_equal(start_time, object.send(:_detect_upstream_wait, start_time))
15
+ end
16
+
17
+ def test_detect_upstream_wait_with_upstream
18
+ start_time = Time.now
19
+ runs_at = start_time + 1
20
+ object = TestObject.new
21
+ object.expects(:newrelic_request_headers).returns(true).twice
22
+ object.expects(:parse_frontend_headers).returns(start_time)
23
+ assert_equal(start_time, object.send(:_detect_upstream_wait, runs_at))
24
+ end
25
+
26
+ def test_detect_upstream_wait_swallows_errors
27
+ start_time = Time.now
28
+ object = TestObject.new
29
+ # should return the start time above when an error is raised
30
+ object.expects(:newrelic_request_headers).returns({:request => 'headers'}).twice
31
+ object.expects(:parse_frontend_headers).with({:request => 'headers'}).raises("an error")
32
+ assert_equal(start_time, object.send(:_detect_upstream_wait, start_time))
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
2
+ class NewRelic::Agent::Instrumentation::InstrumentationTest < Test::Unit::TestCase
3
+ def test_load_all_instrumentation_files
4
+ # just checking for syntax errors and unguarded code
5
+ Dir.glob('new_relic/agent/instrumentation/**/*.rb') do |f|
6
+ require f
7
+ end
8
+ require 'new_relic/delayed_job_injection'
9
+ end
10
+ end
11
+
@@ -0,0 +1,171 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'test_helper'))
2
+ require 'new_relic/agent/instrumentation/metric_frame/pop'
3
+ class NewRelic::Agent::Instrumentation::MetricFrame::PopTest < Test::Unit::TestCase
4
+ include NewRelic::Agent::Instrumentation::MetricFrame::Pop
5
+
6
+ attr_reader :agent
7
+ attr_reader :transaction_sampler
8
+ attr_reader :sql_sampler
9
+
10
+ def setup
11
+ @agent = mock('agent')
12
+ @transaction_sampler = mock('transaction sampler')
13
+ @sql_sampler = mock('sql sampler')
14
+ end
15
+
16
+ def teardown
17
+ Thread.current[:newrelic_metric_frame] = nil
18
+ end
19
+
20
+ def test_clear_thread_metric_frame
21
+ Thread.current[:newrelic_metric_frame] = 'whee'
22
+ clear_thread_metric_frame!
23
+ assert_equal nil, Thread.current[:newrelic_metric_frame], 'should nil out the thread var'
24
+ end
25
+
26
+ def test_set_new_scope
27
+ fakeagent = mock('agent')
28
+ self.expects(:agent).returns(fakeagent)
29
+ fakeengine = mock('stats_engine')
30
+ fakeagent.expects(:stats_engine).returns(fakeengine)
31
+ fakeengine.expects(:scope_name=).with('A METRIC')
32
+
33
+ set_new_scope!('A METRIC')
34
+ end
35
+
36
+ def test_log_underflow
37
+ NewRelic::Agent.logger.expects(:error).with(regexp_matches(/Underflow in metric frames: /))
38
+ log_underflow
39
+ end
40
+
41
+ def test_notice_scope_empty
42
+ transaction_sampler.expects(:notice_scope_empty)
43
+ sql_sampler.expects(:notice_scope_empty)
44
+ notice_scope_empty
45
+ end
46
+
47
+ def test_record_transaction_cpu_positive
48
+ self.expects(:cpu_burn).once.returns(1.0)
49
+ transaction_sampler.expects(:notice_transaction_cpu_time).with(1.0)
50
+ record_transaction_cpu
51
+ end
52
+
53
+ def test_record_transaction_cpu_negative
54
+ self.expects(:cpu_burn).once.returns(nil)
55
+ # should not be called for the nil case
56
+ transaction_sampler.expects(:notice_transaction_cpu_time).never
57
+ record_transaction_cpu
58
+ end
59
+
60
+ def test_normal_cpu_burn_positive
61
+ @process_cpu_start = 3
62
+ self.expects(:process_cpu).returns(4)
63
+ assert_equal 1, normal_cpu_burn
64
+ end
65
+
66
+ def test_normal_cpu_burn_negative
67
+ @process_cpu_start = nil
68
+ self.expects(:process_cpu).never
69
+ assert_equal nil, normal_cpu_burn
70
+ end
71
+
72
+ def test_jruby_cpu_burn_positive
73
+ @jruby_cpu_start = 3
74
+ self.expects(:jruby_cpu_time).returns(4)
75
+ self.expects(:record_jruby_cpu_burn).with(1)
76
+ assert_equal 1, jruby_cpu_burn
77
+ end
78
+
79
+ def test_jruby_cpu_burn_negative
80
+ @jruby_cpu_start = nil
81
+ self.expects(:jruby_cpu_time).never
82
+ self.expects(:record_jruby_cpu_burn).never
83
+ assert_equal nil, jruby_cpu_burn
84
+ end
85
+
86
+ def test_record_jruby_cpu_burn
87
+ NewRelic::Agent.get_stats_no_scope(NewRelic::Metrics::USER_TIME).expects(:record_data_point).with(1.0)
88
+ record_jruby_cpu_burn(1.0)
89
+ end
90
+
91
+ def test_cpu_burn_normal
92
+ self.expects(:normal_cpu_burn).returns(1)
93
+ self.expects(:jruby_cpu_burn).never
94
+ assert_equal 1, cpu_burn
95
+ end
96
+
97
+ def test_cpu_burn_jruby
98
+ self.expects(:normal_cpu_burn).returns(nil)
99
+ self.expects(:jruby_cpu_burn).returns(2)
100
+ assert_equal 2, cpu_burn
101
+ end
102
+
103
+ def test_end_transaction
104
+ fake_stats_engine = mock('stats engine')
105
+ agent.expects(:stats_engine).returns(fake_stats_engine)
106
+ fake_stats_engine.expects(:end_transaction)
107
+ end_transaction!
108
+ end
109
+
110
+ def test_notify_transaction_sampler_true
111
+ self.expects(:record_transaction_cpu)
112
+ self.expects(:notice_scope_empty)
113
+ notify_transaction_sampler(true)
114
+ end
115
+
116
+ def test_notify_transaction_sampler_false
117
+ self.expects(:record_transaction_cpu)
118
+ self.expects(:notice_scope_empty)
119
+ notify_transaction_sampler(false)
120
+ end
121
+
122
+ def test_traced
123
+ NewRelic::Agent.expects(:is_execution_traced?)
124
+ traced?
125
+ end
126
+
127
+ def test_handle_empty_path_stack_default
128
+ @path_stack = [] # it is empty
129
+ self.expects(:traced?).returns(true)
130
+ fakemetric = mock('metric')
131
+ fakemetric.expects(:is_web_transaction?).returns(true)
132
+ self.expects(:notify_transaction_sampler).with(true)
133
+ self.expects(:end_transaction!)
134
+ self.expects(:clear_thread_metric_frame!)
135
+ handle_empty_path_stack(fakemetric)
136
+ end
137
+
138
+ def test_handle_empty_path_stack_non_web
139
+ @path_stack = [] # it is empty
140
+ self.expects(:traced?).returns(true)
141
+ fakemetric = mock('metric')
142
+ fakemetric.expects(:is_web_transaction?).returns(false)
143
+ self.expects(:notify_transaction_sampler).with(false)
144
+ self.expects(:end_transaction!)
145
+ self.expects(:clear_thread_metric_frame!)
146
+ handle_empty_path_stack(fakemetric)
147
+ end
148
+
149
+ def test_handle_empty_path_stack_error
150
+ @path_stack = ['not empty']
151
+ assert_raise(RuntimeError) do
152
+ handle_empty_path_stack(mock('metric'))
153
+ end
154
+ end
155
+
156
+ def test_handle_empty_path_stack_untraced
157
+ @path_stack = [] # it is empty
158
+ self.expects(:traced?).returns(false)
159
+ fakemetric = mock('metric')
160
+ fakemetric.expects(:is_web_transaction?).never
161
+ self.expects(:end_transaction!)
162
+ self.expects(:clear_thread_metric_frame!)
163
+ handle_empty_path_stack(fakemetric)
164
+ end
165
+
166
+ def test_current_stack_metric
167
+ self.expects(:metric_name)
168
+ current_stack_metric
169
+ end
170
+ end
171
+
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
2
+
3
+ class NewRelic::Agent::Instrumentation::MetricFrameTest < Test::Unit::TestCase
4
+
5
+ attr_reader :f
6
+ def setup
7
+ @f = NewRelic::Agent::Instrumentation::MetricFrame.new
8
+ end
9
+
10
+ def test_request_parsing__none
11
+ assert_nil f.uri
12
+ assert_nil f.referer
13
+ end
14
+ def test_request_parsing__path
15
+ request = stub(:path => '/path?hello=bob#none')
16
+ f.request = request
17
+ assert_equal "/path", f.uri
18
+ end
19
+ def test_request_parsing__fullpath
20
+ request = stub(:fullpath => '/path?hello=bob#none')
21
+ f.request = request
22
+ assert_equal "/path", f.uri
23
+ end
24
+ def test_request_parsing__referer
25
+ request = stub(:referer => 'https://www.yahoo.com:8080/path/hello?bob=none&foo=bar')
26
+ f.request = request
27
+ assert_nil f.uri
28
+ assert_equal "https://www.yahoo.com:8080/path/hello", f.referer
29
+ end
30
+
31
+ def test_request_parsing__uri
32
+ request = stub(:uri => 'http://creature.com/path?hello=bob#none', :referer => '/path/hello?bob=none&foo=bar')
33
+ f.request = request
34
+ assert_equal "/path", f.uri
35
+ assert_equal "/path/hello", f.referer
36
+ end
37
+
38
+ def test_request_parsing__hostname_only
39
+ request = stub(:uri => 'http://creature.com')
40
+ f.request = request
41
+ assert_equal "/", f.uri
42
+ assert_nil f.referer
43
+ end
44
+ def test_request_parsing__slash
45
+ request = stub(:uri => 'http://creature.com/')
46
+ f.request = request
47
+ assert_equal "/", f.uri
48
+ assert_nil f.referer
49
+ end
50
+ end
@@ -0,0 +1,84 @@
1
+ unless ENV['FAST_TESTS']
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
3
+
4
+ class NewRelic::Agent::Instrumentation::NetInstrumentationTest < Test::Unit::TestCase
5
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
6
+ def setup
7
+ NewRelic::Agent.manual_start
8
+ @engine = NewRelic::Agent.instance.stats_engine
9
+ @engine.clear_stats
10
+ end
11
+
12
+ def metrics_without_gc
13
+ @engine.metrics - ['GC/cumulative']
14
+ end
15
+
16
+ private :metrics_without_gc
17
+
18
+ def test_get
19
+ url = URI.parse('http://www.google.com/index.html')
20
+ res = Net::HTTP.start(url.host, url.port) {|http|
21
+ http.get('/index.html')
22
+ }
23
+ assert_match /<head>/i, res.body
24
+ assert_equal %w[External/all External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort,
25
+ metrics_without_gc.sort
26
+ end
27
+
28
+ def test_background
29
+ perform_action_with_newrelic_trace("task", :category => :task) do
30
+ url = URI.parse('http://www.google.com/index.html')
31
+ res = Net::HTTP.start(url.host, url.port) {|http|
32
+ http.get('/index.html')
33
+ }
34
+ assert_match /<head>/i, res.body
35
+ end
36
+ assert_equal %w[External/all External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all
37
+ External/www.google.com/Net::HTTP/GET:OtherTransaction/Background/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
38
+ end
39
+
40
+ def test_transactional
41
+ perform_action_with_newrelic_trace("task") do
42
+ url = URI.parse('http://www.google.com/index.html')
43
+ res = Net::HTTP.start(url.host, url.port) {|http|
44
+ http.get('/index.html')
45
+ }
46
+ assert_match /<head>/i, res.body
47
+ end
48
+ assert_equal %w[External/all External/www.google.com/Net::HTTP/GET External/allWeb External/www.google.com/all
49
+ External/www.google.com/Net::HTTP/GET:Controller/NewRelic::Agent::Instrumentation::NetInstrumentationTest/task].sort, metrics_without_gc.select{|m| m =~ /^External/}.sort
50
+ end
51
+ def test_get__simple
52
+ Net::HTTP.get URI.parse('http://www.google.com/index.html')
53
+ assert_equal metrics_without_gc.sort,
54
+ %w[External/all External/www.google.com/Net::HTTP/GET External/allOther External/www.google.com/all].sort
55
+ end
56
+ def test_ignore
57
+ NewRelic::Agent.disable_all_tracing do
58
+ url = URI.parse('http://www.google.com/index.html')
59
+ res = Net::HTTP.start(url.host, url.port) {|http|
60
+ http.post('/index.html','data')
61
+ }
62
+ end
63
+ assert_equal 0, metrics_without_gc.size
64
+ end
65
+ def test_head
66
+ url = URI.parse('http://www.google.com/index.html')
67
+ res = Net::HTTP.start(url.host, url.port) {|http|
68
+ http.head('/index.html')
69
+ }
70
+ assert_equal %w[External/all External/www.google.com/Net::HTTP/HEAD External/allOther External/www.google.com/all].sort,
71
+ metrics_without_gc.sort
72
+ end
73
+
74
+ def test_post
75
+ url = URI.parse('http://www.google.com/index.html')
76
+ res = Net::HTTP.start(url.host, url.port) {|http|
77
+ http.post('/index.html','data')
78
+ }
79
+ assert_equal %w[External/all External/www.google.com/Net::HTTP/POST External/allOther External/www.google.com/all].sort,
80
+ metrics_without_gc.sort
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,382 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper'))
2
+ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
3
+ require 'new_relic/agent/instrumentation/queue_time'
4
+ include NewRelic::Agent::Instrumentation::QueueTime
5
+
6
+ def setup
7
+ NewRelic::Agent.instance.stats_engine.clear_stats
8
+ end
9
+
10
+ def create_test_start_time(env)
11
+ env[APP_HEADER] = "t=#{convert_to_microseconds(Time.at(1002))}"
12
+ end
13
+
14
+ def test_parse_frontend_headers
15
+ middleware_start = Time.at(1002)
16
+ queue_start = Time.at(1001)
17
+ server_start = Time.at(1000)
18
+ Time.stubs(:now).returns(Time.at(1003)) # whee!
19
+ self.expects(:add_end_time_header).with(Time.at(1003), {:env => 'hash'})
20
+ # ordering is important here, unfortunately, the mocks don't
21
+ # support that kind of checking.
22
+ self.expects(:parse_middleware_time_from).with({:env => 'hash'}).returns(middleware_start)
23
+ self.expects(:parse_queue_time_from).with({:env => 'hash'}).returns(queue_start)
24
+ self.expects(:parse_server_time_from).with({:env => 'hash'}).returns(server_start)
25
+ assert_equal(server_start, parse_frontend_headers({:env => 'hash'}), "should return the oldest start time")
26
+ end
27
+
28
+ def test_parse_frontend_headers_should_return_earliest_start
29
+ middleware_start = Time.at(1002)
30
+ queue_start = Time.at(1000)
31
+ server_start = Time.at(1001)
32
+ Time.stubs(:now).returns(Time.at(1003)) # whee!
33
+ self.expects(:add_end_time_header).with(Time.at(1003), {:env => 'hash'})
34
+ # ordering is important here, unfortunately, the mocks don't
35
+ # support that kind of checking.
36
+ self.expects(:parse_middleware_time_from).with({:env => 'hash'}).returns(middleware_start)
37
+ self.expects(:parse_queue_time_from).with({:env => 'hash'}).returns(queue_start)
38
+ self.expects(:parse_server_time_from).with({:env => 'hash'}).returns(server_start)
39
+ assert_equal(queue_start, parse_frontend_headers({:env => 'hash'}), "should return the oldest start time")
40
+ end
41
+
42
+ def test_all_combined_frontend_headers
43
+ env = {}
44
+ env[MAIN_HEADER] = "t=#{convert_to_microseconds(Time.at(1000))}"
45
+ env[QUEUE_HEADER] = "t=#{convert_to_microseconds(Time.at(1001))}"
46
+ env[MIDDLEWARE_HEADER] = "t=#{convert_to_microseconds(Time.at(1002))}"
47
+
48
+ env[APP_HEADER] = "t=#{convert_to_microseconds(Time.at(1003))}"
49
+
50
+ assert_calls_metrics('WebFrontend/WebServer/all', 'WebFrontend/QueueTime', 'Middleware/all') do
51
+ assert_equal(Time.at(1002), parse_middleware_time_from(env))
52
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
53
+ assert_equal(Time.at(1000), parse_server_time_from(env))
54
+ end
55
+
56
+ check_metric_time('WebFrontend/WebServer/all', 1.0, 0.001)
57
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
58
+ check_metric_time('Middleware/all', 1.0, 0.001)
59
+ end
60
+
61
+ def test_combined_middleware_and_queue
62
+ env = {}
63
+ env[QUEUE_HEADER] = "t=#{convert_to_microseconds(Time.at(1000))}"
64
+ env[MIDDLEWARE_HEADER] = "t=#{convert_to_microseconds(Time.at(1001))}"
65
+ create_test_start_time(env)
66
+
67
+ assert_calls_metrics('Middleware/all', 'WebFrontend/QueueTime') do
68
+ parse_middleware_time_from(env)
69
+ assert_equal(Time.at(1000), parse_queue_time_from(env))
70
+ end
71
+
72
+ check_metric_time('Middleware/all', 1.0, 0.001)
73
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
74
+ end
75
+
76
+ def test_combined_queue_and_server
77
+ env = {}
78
+ env[MAIN_HEADER] = "t=#{convert_to_microseconds(Time.at(1000))}"
79
+ env[QUEUE_HEADER] = "t=#{convert_to_microseconds(Time.at(1001))}"
80
+ create_test_start_time(env)
81
+
82
+ assert_calls_metrics('WebFrontend/WebServer/all', 'WebFrontend/QueueTime') do
83
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
84
+ parse_server_time_from(env)
85
+ end
86
+
87
+ check_metric_time('WebFrontend/WebServer/all', 1.0, 0.001)
88
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
89
+ end
90
+
91
+ def test_combined_middleware_and_server
92
+ env = {}
93
+ env[MAIN_HEADER] = "t=#{convert_to_microseconds(Time.at(1000))}"
94
+ env[MIDDLEWARE_HEADER] = "t=#{convert_to_microseconds(Time.at(1001))}"
95
+ create_test_start_time(env)
96
+
97
+ assert_calls_metrics('WebFrontend/WebServer/all', 'Middleware/all') do
98
+ parse_middleware_time_from(env)
99
+ parse_server_time_from(env)
100
+ end
101
+
102
+ check_metric_time('WebFrontend/WebServer/all', 1.0, 0.001)
103
+ check_metric_time('Middleware/all', 1.0, 0.001)
104
+ end
105
+
106
+ # initial base case, a router and a static content server
107
+ def test_parse_server_time_from_initial
108
+ env = {}
109
+ create_test_start_time(env)
110
+ time1 = convert_to_microseconds(Time.at(1000))
111
+ time2 = convert_to_microseconds(Time.at(1001))
112
+ env['HTTP_X_REQUEST_START'] = "servera t=#{time1}, serverb t=#{time2}"
113
+ assert_calls_metrics('WebFrontend/WebServer/all', 'WebFrontend/WebServer/servera', 'WebFrontend/WebServer/serverb') do
114
+ parse_server_time_from(env)
115
+ end
116
+ check_metric_time('WebFrontend/WebServer/all', 2.0, 0.1)
117
+ check_metric_time('WebFrontend/WebServer/servera', 1.0, 0.1)
118
+ check_metric_time('WebFrontend/WebServer/serverb', 1.0, 0.1)
119
+ end
120
+
121
+ # test for backwards compatibility with old header
122
+ def test_parse_server_time_from_with_no_server_name
123
+ env = {'HTTP_X_REQUEST_START' => "t=#{convert_to_microseconds(Time.at(1001))}"}
124
+ create_test_start_time(env)
125
+ assert_calls_metrics('WebFrontend/WebServer/all') do
126
+ parse_server_time_from(env)
127
+ end
128
+ check_metric_time('WebFrontend/WebServer/all', 1.0, 0.1)
129
+ end
130
+
131
+ def test_parse_server_time_from_with_bad_header
132
+ env = {'HTTP_X_REQUEST_START' => 't=t=t=t='}
133
+ create_test_start_time(env)
134
+ assert_calls_metrics('WebFrontend/WebServer/all') do
135
+ parse_server_time_from(env)
136
+ end
137
+ end
138
+
139
+ def test_parse_server_time_from_with_no_header
140
+ assert_calls_metrics('WebFrontend/WebServer/all') do
141
+ parse_server_time_from({})
142
+ end
143
+ end
144
+
145
+ def test_parse_middleware_time
146
+ env = {}
147
+ create_test_start_time(env)
148
+ time1 = convert_to_microseconds(Time.at(1000))
149
+ time2 = convert_to_microseconds(Time.at(1001))
150
+
151
+ env['HTTP_X_MIDDLEWARE_START'] = "base t=#{time1}, second t=#{time2}"
152
+ assert_calls_metrics('Middleware/all', 'Middleware/base', 'Middleware/second') do
153
+ parse_middleware_time_from(env)
154
+ end
155
+ check_metric_time('Middleware/all', 2.0, 0.1)
156
+ check_metric_time('Middleware/base', 1.0, 0.1)
157
+ check_metric_time('Middleware/second', 1.0, 0.1)
158
+ end
159
+
160
+ def test_parse_queue_time
161
+ env = {}
162
+ create_test_start_time(env)
163
+ time1 = convert_to_microseconds(Time.at(1000))
164
+
165
+ env['HTTP_X_QUEUE_START'] = "t=#{time1}"
166
+ assert_calls_metrics('WebFrontend/QueueTime') do
167
+ assert_equal(Time.at(1000), parse_queue_time_from(env))
168
+ end
169
+
170
+ check_metric_time('WebFrontend/QueueTime', 2.0, 0.1)
171
+ end
172
+
173
+ def test_check_for_alternate_queue_length
174
+ env = {}
175
+ create_test_start_time(env)
176
+ env['HTTP_X_QUEUE_TIME'] = '1000000'
177
+ assert_calls_metrics('WebFrontend/QueueTime') do
178
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
179
+ end
180
+
181
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
182
+ end
183
+
184
+ def test_check_for_alternate_queue_length_override
185
+ env = {}
186
+ create_test_start_time(env)
187
+ env['HTTP_X_QUEUE_START'] = 't=1' # obviously incorrect
188
+ env['HTTP_X_QUEUE_TIME'] = '1000000'
189
+ assert_calls_metrics('WebFrontend/QueueTime') do
190
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
191
+ end
192
+
193
+ # alternate queue should override normal header
194
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
195
+ end
196
+
197
+ def test_check_for_heroku_queue_length
198
+ env = {}
199
+ create_test_start_time(env)
200
+ env['HTTP_X_HEROKU_QUEUE_WAIT_TIME'] = '1000'
201
+ assert_calls_metrics('WebFrontend/QueueTime') do
202
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
203
+ end
204
+
205
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
206
+ end
207
+
208
+ def test_check_for_heroku_queue_length_override
209
+ env = {}
210
+ create_test_start_time(env)
211
+ env['HTTP_X_QUEUE_TIME'] = '10000000' # ten MEEELION useconds
212
+ env['HTTP_X_HEROKU_QUEUE_WAIT_TIME'] = '1000'
213
+ assert_calls_metrics('WebFrontend/QueueTime') do
214
+ assert_equal(Time.at(1001), parse_queue_time_from(env))
215
+ end
216
+
217
+ # heroku queue should override alternate queue
218
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.001)
219
+ end
220
+
221
+ # each server should be one second, and the total would be 2 seconds
222
+ def test_record_individual_server_stats
223
+ matches = [['foo', Time.at(1000)], ['bar', Time.at(1001)]]
224
+ assert_calls_metrics('WebFrontend/WebServer/foo', 'WebFrontend/WebServer/bar') do
225
+ record_individual_server_stats(Time.at(1002), matches)
226
+ end
227
+ check_metric_time('WebFrontend/WebServer/foo', 1.0, 0.1)
228
+ check_metric_time('WebFrontend/WebServer/bar', 1.0, 0.1)
229
+ end
230
+
231
+ def test_record_rollup_server_stat
232
+ assert_calls_metrics('WebFrontend/WebServer/all') do
233
+ record_rollup_server_stat(Time.at(1001), [['a', Time.at(1000)]])
234
+ end
235
+ check_metric_time('WebFrontend/WebServer/all', 1.0, 0.1)
236
+ end
237
+
238
+ def test_record_rollup_server_stat_no_data
239
+ assert_calls_metrics('WebFrontend/WebServer/all') do
240
+ record_rollup_server_stat(Time.at(1001), [])
241
+ end
242
+ check_metric_time('WebFrontend/WebServer/all', 0.0, 0.001)
243
+ end
244
+
245
+ def test_record_rollup_middleware_stat
246
+ assert_calls_metrics('Middleware/all') do
247
+ record_rollup_middleware_stat(Time.at(1001), [['a', Time.at(1000)]])
248
+ end
249
+ check_metric_time('Middleware/all', 1.0, 0.1)
250
+ end
251
+
252
+ def test_record_rollup_middleware_stat_no_data
253
+ assert_calls_metrics('Middleware/all') do
254
+ record_rollup_middleware_stat(Time.at(1001), [])
255
+ end
256
+ check_metric_time('Middleware/all', 0.0, 0.001)
257
+ end
258
+
259
+ def test_record_rollup_queue_stat
260
+ assert_calls_metrics('WebFrontend/QueueTime') do
261
+ record_rollup_queue_stat(Time.at(1001), [[nil, Time.at(1000)]])
262
+ end
263
+ check_metric_time('WebFrontend/QueueTime', 1.0, 0.1)
264
+ end
265
+
266
+ def test_record_rollup_queue_stat_no_data
267
+ assert_calls_metrics('WebFrontend/QueueTime') do
268
+ record_rollup_queue_stat(Time.at(1001), [])
269
+ end
270
+ check_metric_time('WebFrontend/QueueTime', 0.0, 0.001)
271
+ end
272
+
273
+ def test_find_oldest_time
274
+ test_array = [
275
+ ['c', Time.at(1002)],
276
+ ['a', Time.at(1000)],
277
+ ['b', Time.at(1001)],
278
+ ['d', Time.at(1000)],
279
+ ]
280
+ assert_equal(find_oldest_time(test_array), Time.at(1000),
281
+ "Should be the oldest time in the array")
282
+ end
283
+
284
+ # trivial test but the method doesn't do much
285
+ def test_record_server_time_for
286
+ name = 'foo'
287
+ time = Time.at(1000)
288
+ start_time = Time.at(1001)
289
+ self.expects(:record_time_stat).with('WebFrontend/WebServer/foo', time, start_time)
290
+ record_server_time_for(name, time, start_time)
291
+ end
292
+
293
+ def test_record_time_stat
294
+ assert_calls_metrics('WebFrontend/WebServer/foo') do
295
+ record_time_stat('WebFrontend/WebServer/foo', Time.at(1000), Time.at(1001))
296
+ end
297
+ check_metric_time('WebFrontend/WebServer/foo', 1.0, 0.1)
298
+ assert_raises(RuntimeError) do
299
+ record_time_stat('foo', Time.at(1001), Time.at(1000))
300
+ end
301
+ end
302
+
303
+ def test_record_time_stat_with_end_after_start
304
+ record_time_stat('WebFrontend/WebServer/foo', Time.at(1.0001), Time.at(1))
305
+ rescue RuntimeError => e
306
+ assert_match(/should not provide an end time less than start time/, e.message)
307
+ end
308
+
309
+ def test_convert_to_microseconds
310
+ assert_equal((1_000_000_000), convert_to_microseconds(Time.at(1000)), 'time at 1000 seconds past epoch should be 1,000,000,000 usec')
311
+ assert_equal 1_000_000_000, convert_to_microseconds(1_000_000_000), 'should not mess with a number if passed in'
312
+ assert_raises(TypeError) do
313
+ convert_to_microseconds('whoo yeah buddy')
314
+ end
315
+ end
316
+
317
+ def test_convert_from_microseconds
318
+ assert_equal Time.at(1000), convert_from_microseconds(1_000_000_000), 'time at 1,000,000,000 usec should be 1000 seconds after epoch'
319
+ assert_equal Time.at(1000), convert_from_microseconds(Time.at(1000)), 'should not mess with a time passed in'
320
+ assert_raises(TypeError) do
321
+ convert_from_microseconds('10000000000')
322
+ end
323
+ end
324
+
325
+ def test_add_end_time_header
326
+ env = {}
327
+ start_time = Time.at(1)
328
+ add_end_time_header(start_time, env)
329
+ assert_equal({'HTTP_X_APPLICATION_START' => "t=#{convert_to_microseconds(Time.at(1))}"}, env, "should add the header to the env hash")
330
+ end
331
+
332
+ def test_parse_end_time_base
333
+ env = {}
334
+ env['HTTP_X_APPLICATION_START'] = "t=#{convert_to_microseconds(Time.at(1))}"
335
+ start_time = parse_end_time(env)
336
+ assert_equal(Time.at(1), start_time, "should pull the correct start time from the app header")
337
+ end
338
+
339
+ def test_get_matches_from_header
340
+ env = {'A HEADER' => 't=1000000'}
341
+ self.expects(:convert_from_microseconds).with(1000000).returns(Time.at(1))
342
+ matches = get_matches_from_header('A HEADER', env)
343
+ assert_equal [[nil, Time.at(1)]], matches, "should pull the correct time from the string"
344
+ end
345
+
346
+ def test_convert_to_name_time_pair
347
+ name = :foo
348
+ time = "1000000"
349
+
350
+ pair = convert_to_name_time_pair(name, time)
351
+ assert_equal [:foo, Time.at(1)], pair
352
+ end
353
+
354
+ def test_get_matches
355
+ str = "servera t=1000000, serverb t=1000000"
356
+ matches = get_matches(str) # start a fire
357
+ assert_equal [['servera', '1000000'], ['serverb', '1000000']], matches
358
+ end
359
+
360
+ def test_matches_with_bad_data
361
+ str = "stephan is a dumb lol"
362
+ matches = get_matches(str)
363
+ assert_equal [], matches
364
+
365
+ str = "t=100"
366
+ matches = get_matches(str)
367
+ assert_equal [[nil, '100']], matches
368
+
369
+ str = nil
370
+ matches = get_matches(str)
371
+ assert_equal [], matches
372
+ end
373
+ # each server should be one second, and the total would be 2 seconds
374
+ def test_record_individual_middleware_stats
375
+ matches = [['foo', Time.at(1000)], ['bar', Time.at(1001)]]
376
+ assert_calls_metrics('Middleware/foo', 'Middleware/bar') do
377
+ record_individual_middleware_stats(Time.at(1002), matches)
378
+ end
379
+ check_metric_time('Middleware/foo', 1.0, 0.1)
380
+ check_metric_time('Middleware/bar', 1.0, 0.1)
381
+ end
382
+ end