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,23 @@
1
+
2
+ class NewRelic::Agent::MockScopeListener
3
+
4
+ attr_reader :scope
5
+
6
+ def initialize
7
+ @scope = {}
8
+ end
9
+
10
+ def notice_first_scope_push(time)
11
+ end
12
+
13
+ def notice_push_scope(scope, time)
14
+ @scope[scope] = true
15
+ end
16
+
17
+ def notice_pop_scope(scope, time)
18
+ end
19
+
20
+ def notice_scope_empty(time)
21
+
22
+ end
23
+ end
@@ -0,0 +1,149 @@
1
+ ENV['SKIP_RAILS'] = 'true'
2
+ require File.expand_path('../../../test_helper', __FILE__)
3
+
4
+ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::TestCase
5
+ extend TestContexts
6
+
7
+ attr_reader :agent
8
+
9
+ with_running_agent do
10
+ # Fake out the agent to think mongrel is running
11
+
12
+ should "agent_setup" do
13
+ assert NewRelic::Agent.instance.class == NewRelic::Agent::Agent
14
+ assert_raise RuntimeError do
15
+ NewRelic::Control.instance.init_plugin :agent_enabled => false
16
+ end
17
+ end
18
+
19
+ should "public_apis" do
20
+ assert_raise RuntimeError do
21
+ NewRelic::Agent.set_sql_obfuscator(:unknown) do |sql|
22
+ puts sql
23
+ end
24
+ end
25
+
26
+ ignore_called = false
27
+ NewRelic::Agent.ignore_error_filter do |e|
28
+ ignore_called = true
29
+ nil
30
+ end
31
+ NewRelic::Agent.notice_error(StandardError.new("message"), :request_params => {:x => "y"})
32
+ assert ignore_called
33
+ NewRelic::Agent.instance.error_collector.instance_variable_set '@ignore_filter', nil
34
+ end
35
+
36
+ should "startup_shutdown" do
37
+ @agent = NewRelic::Agent::ShimAgent.instance
38
+ @agent.shutdown
39
+ assert (not @agent.started?)
40
+ @agent.start
41
+ assert !@agent.started?
42
+ # this installs the real agent:
43
+ NewRelic::Agent.manual_start
44
+ @agent = NewRelic::Agent.instance
45
+ assert @agent != NewRelic::Agent::ShimAgent.instance
46
+ assert @agent.started?
47
+ @agent.shutdown
48
+ assert !@agent.started?
49
+ @agent.start
50
+ assert @agent.started?
51
+ NewRelic::Agent.shutdown
52
+ end
53
+
54
+ should "manual_start" do
55
+ NewRelic::Agent.instance.expects(:connect).once
56
+ NewRelic::Agent.instance.expects(:start_worker_thread).once
57
+ NewRelic::Agent.instance.instance_variable_set '@started', nil
58
+ NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
59
+ NewRelic::Agent.shutdown
60
+ end
61
+
62
+ should "post_fork_handler" do
63
+ NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
64
+ NewRelic::Agent.after_fork
65
+ NewRelic::Agent.after_fork
66
+ NewRelic::Agent.shutdown
67
+ end
68
+ should "manual_overrides" do
69
+ NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
70
+ assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
71
+ assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
72
+ NewRelic::Agent.shutdown
73
+ end
74
+
75
+ should "restart" do
76
+ NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
77
+ NewRelic::Agent.manual_start :app_name => "testjobs", :dispatcher_instance_id => "mailer"
78
+ assert_equal "testjobs", NewRelic::Control.instance.app_names[0]
79
+ assert_equal "mailer", NewRelic::Control.instance.dispatcher_instance_id
80
+ NewRelic::Agent.shutdown
81
+ end
82
+
83
+ should "send_timeslice_data" do
84
+ # this test fails due to a rubinius bug
85
+ return if NewRelic::LanguageSupport.using_engine?('rbx')
86
+ @agent.expects(:invoke_remote).returns({NewRelic::MetricSpec.new("/A/b/c") => 1, NewRelic::MetricSpec.new("/A/b/c", "/X") => 2, NewRelic::MetricSpec.new("/A/b/d") => 3 }.to_a)
87
+ @agent.send :harvest_and_send_timeslice_data
88
+ assert_equal 3, @agent.metric_ids.size
89
+ assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
90
+ end
91
+ should "set_record_sql" do
92
+ @agent.set_record_sql(false)
93
+ assert !NewRelic::Agent.is_sql_recorded?
94
+ NewRelic::Agent.disable_sql_recording do
95
+ assert_equal false, NewRelic::Agent.is_sql_recorded?
96
+ NewRelic::Agent.disable_sql_recording do
97
+ assert_equal false, NewRelic::Agent.is_sql_recorded?
98
+ end
99
+ assert_equal false, NewRelic::Agent.is_sql_recorded?
100
+ end
101
+ assert !NewRelic::Agent.is_sql_recorded?
102
+ @agent.set_record_sql(nil)
103
+ end
104
+
105
+ should "version" do
106
+ assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
107
+ end
108
+
109
+ should "invoke_remote__ignore_non_200_results" do
110
+ NewRelic::Agent::Agent.class_eval do
111
+ public :invoke_remote
112
+ end
113
+ response_mock = mock()
114
+ Net::HTTP.any_instance.stubs(:request).returns(response_mock)
115
+ response_mock.stubs(:message).returns("bogus error")
116
+
117
+ for code in %w[500 504 400 302 503] do
118
+ assert_raise NewRelic::Agent::ServerConnectionException, "Ignore #{code}" do
119
+ response_mock.stubs(:code).returns(code)
120
+ NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0
121
+ end
122
+ end
123
+ end
124
+ should "invoke_remote__throw_other_errors" do
125
+ NewRelic::Agent::Agent.class_eval do
126
+ public :invoke_remote
127
+ end
128
+ response_mock = Net::HTTPSuccess.new nil, nil, nil
129
+ response_mock.stubs(:body).returns("")
130
+ Marshal.stubs(:load).raises(RuntimeError, "marshal issue")
131
+ Net::HTTP.any_instance.stubs(:request).returns(response_mock)
132
+ assert_raise RuntimeError do
133
+ NewRelic::Agent.agent.invoke_remote :get_data_report_period, 0xFEFE
134
+ end
135
+ end
136
+
137
+ context "with transaction api" do
138
+ should "reject empty arguments" do
139
+ assert_raises RuntimeError do
140
+ NewRelic::Agent.record_transaction 0.5
141
+ end
142
+ end
143
+ should "record a transaction" do
144
+ NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
145
+ end
146
+
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
2
+ class NewRelic::Agent::SamplerTest < Test::Unit::TestCase
3
+ require 'new_relic/agent/sampler'
4
+
5
+ def test_inherited_should_append_subclasses_to_sampler_classes
6
+ test_class = Class.new(NewRelic::Agent::Sampler)
7
+ sampler_classes = NewRelic::Agent::Sampler.instance_eval { @sampler_classes }
8
+ assert(sampler_classes.include?(test_class), "Sampler classes (#{@sampler_classes.inspect}) does not include #{test_class.inspect}")
9
+ # cleanup the sampler created above
10
+ NewRelic::Agent::Sampler.instance_eval { @sampler_classes.delete(test_class) }
11
+ end
12
+
13
+ def test_sampler_classes_should_be_an_array
14
+ sampler_classes = NewRelic::Agent::Sampler.instance_variable_get('@sampler_classes')
15
+ assert(sampler_classes.is_a?(Array), 'Sampler classes should be saved as an array')
16
+ assert(sampler_classes.include?(NewRelic::Agent::Samplers::CpuSampler), 'Sampler classes should include the CPU sampler')
17
+ end
18
+
19
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ module NewRelic
3
+ module Agent
4
+ class ShimAgentTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ super
8
+ @agent = NewRelic::Agent::ShimAgent.new
9
+ end
10
+
11
+ def test_serialize
12
+ assert_equal(nil, @agent.serialize, "should return nil when shut down")
13
+ end
14
+
15
+ def test_merge_data_from
16
+ assert_equal(nil, @agent.merge_data_from(mock('metric data')))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,192 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+
3
+ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ agent = NewRelic::Agent.instance
7
+ stats_engine = NewRelic::Agent::StatsEngine.new
8
+ agent.stubs(:stats_engine).returns(stats_engine)
9
+ @sampler = NewRelic::Agent::SqlSampler.new
10
+ @connection = stub('ActiveRecord connection', :execute => 'result')
11
+ NewRelic::Agent::Database.stubs(:get_connection).returns(@connection)
12
+ end
13
+
14
+ def test_notice_first_scope_push
15
+ assert_nil @sampler.transaction_data
16
+ @sampler.notice_first_scope_push nil
17
+ assert_not_nil @sampler.transaction_data
18
+ @sampler.notice_scope_empty
19
+ assert_nil @sampler.transaction_data
20
+ end
21
+
22
+ def test_notice_sql_no_transaction
23
+ assert_nil @sampler.transaction_data
24
+ @sampler.notice_sql "select * from test", "Database/test/select", nil, 10
25
+ end
26
+
27
+ def test_notice_sql
28
+ @sampler.notice_first_scope_push nil
29
+ @sampler.notice_sql "select * from test", "Database/test/select", nil, 1.5
30
+ @sampler.notice_sql "select * from test2", "Database/test2/select", nil, 1.3
31
+ # this sql will not be captured
32
+ @sampler.notice_sql "select * from test", "Database/test/select", nil, 0
33
+ assert_not_nil @sampler.transaction_data
34
+ assert_equal 2, @sampler.transaction_data.sql_data.size
35
+ end
36
+
37
+ def test_harvest_slow_sql
38
+ data = NewRelic::Agent::TransactionSqlData.new
39
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
40
+ 'guid')
41
+ data.sql_data.concat [
42
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
43
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
44
+ NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)
45
+ ]
46
+ @sampler.harvest_slow_sql data
47
+
48
+ assert_equal 2, @sampler.sql_traces.size
49
+ end
50
+
51
+ def test_sql_aggregation
52
+ sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
53
+ NewRelic::Agent::SlowSql.new("select * from test",
54
+ "Database/test/select", {}, 1.2),
55
+ "tx_name", "uri")
56
+
57
+ sql_trace.aggregate NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5), "slowest_tx_name", "slow_uri"
58
+ sql_trace.aggregate NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.1), "other_tx_name", "uri2"
59
+
60
+ assert_equal 3, sql_trace.call_count
61
+ assert_equal "slowest_tx_name", sql_trace.path
62
+ assert_equal "slow_uri", sql_trace.url
63
+ assert_equal 1.5, sql_trace.max_call_time
64
+ end
65
+
66
+ def test_harvest
67
+ data = NewRelic::Agent::TransactionSqlData.new
68
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
69
+ 'guid')
70
+ data.sql_data.concat [NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
71
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
72
+ NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)]
73
+ @sampler.harvest_slow_sql data
74
+
75
+ sql_traces = @sampler.harvest
76
+ assert_equal 2, sql_traces.size
77
+ end
78
+
79
+ def test_harvest_should_not_take_more_than_10
80
+ data = NewRelic::Agent::TransactionSqlData.new
81
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {}, 'guid')
82
+ 15.times do |i|
83
+ data.sql_data << NewRelic::Agent::SlowSql.new("select * from test#{(i+97).chr}",
84
+ "Database/test#{(i+97).chr}/select", {}, i)
85
+ end
86
+
87
+ @sampler.harvest_slow_sql data
88
+ result = @sampler.harvest
89
+
90
+ assert_equal(10, result.size)
91
+ assert_equal(14, result.sort{|a,b| b.max_call_time <=> a.max_call_time}.first.total_call_time)
92
+ end
93
+
94
+ def test_harvest_should_aggregate_similar_queries
95
+ data = NewRelic::Agent::TransactionSqlData.new
96
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
97
+ 'guid')
98
+ queries = [
99
+ NewRelic::Agent::SlowSql.new("select * from test where foo in (1, 2) ", "Database/test/select", {}, 1.5),
100
+ NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2, 3 ,4, 5,6, 'snausage')", "Database/test/select", {}, 1.2),
101
+ NewRelic::Agent::SlowSql.new("select * from test2 where foo in (1,2)", "Database/test2/select", {}, 1.1)
102
+ ]
103
+ data.sql_data.concat(queries)
104
+ @sampler.harvest_slow_sql data
105
+
106
+ sql_traces = @sampler.harvest
107
+ assert_equal 2, sql_traces.size
108
+ end
109
+
110
+ def test_harvest_should_collect_explain_plans
111
+ @connection.expects(:execute).with("EXPLAIN select * from test") \
112
+ .returns([{"header0" => 'foo0', "header1" => 'foo1', "header2" => 'foo2'}])
113
+ @connection.expects(:execute).with("EXPLAIN select * from test2") \
114
+ .returns([{"header0" => 'bar0', "header1" => 'bar1', "header2" => 'bar2'}])
115
+
116
+ data = NewRelic::Agent::TransactionSqlData.new
117
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
118
+ 'guid')
119
+ queries = [
120
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
121
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
122
+ NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)
123
+ ]
124
+ data.sql_data.concat(queries)
125
+ @sampler.harvest_slow_sql data
126
+ sql_traces = @sampler.harvest
127
+ assert_equal(["header0", "header1", "header2"],
128
+ sql_traces[0].params[:explain_plan][0].sort)
129
+ assert_equal(["header0", "header1", "header2"],
130
+ sql_traces[1].params[:explain_plan][0].sort)
131
+ assert_equal(["foo0", "foo1", "foo2"],
132
+ sql_traces[0].params[:explain_plan][1][0].sort)
133
+ assert_equal(["bar0", "bar1", "bar2"],
134
+ sql_traces[1].params[:explain_plan][1][0].sort)
135
+ end
136
+
137
+ def test_sql_trace_should_include_transaction_guid
138
+ txn_sampler = NewRelic::Agent::TransactionSampler.new
139
+ NewRelic::Agent.instance.stats_engine.transaction_sampler = txn_sampler
140
+ txn_sampler.start_builder(Time.now)
141
+ txn_sampler.notice_transaction('a path', 'a uri', {:some => :params})
142
+ @sampler.create_transaction_data
143
+ @sampler.notice_transaction('a path', 'a uri', {:some => :params})
144
+
145
+ assert_equal(NewRelic::Agent.instance.transaction_sampler.builder.sample.guid,
146
+ NewRelic::Agent.instance.sql_sampler.transaction_data.guid)
147
+ end
148
+
149
+ def test_should_not_collect_explain_plans_when_disabled
150
+ NewRelic::Control.instance['transaction_tracer'] = { 'explain_enabled' => false }
151
+ data = NewRelic::Agent::TransactionSqlData.new
152
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
153
+ 'guid')
154
+
155
+ queries = [
156
+ NewRelic::Agent::SlowSql.new("select * from test",
157
+ "Database/test/select", {}, 1.5)
158
+ ]
159
+ data.sql_data.concat(queries)
160
+ @sampler.harvest_slow_sql data
161
+ sql_traces = @sampler.harvest
162
+ assert_equal(nil, sql_traces[0].params[:explain_plan])
163
+ NewRelic::Control.instance['transaction_tracer'] = { 'explain_enabled' => true }
164
+ end
165
+
166
+ def test_sql_id_fits_in_a_mysql_int_11
167
+ sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
168
+ NewRelic::Agent::SlowSql.new("select * from test",
169
+ "Database/test/select", {}, 1.2),
170
+ "tx_name", "uri")
171
+
172
+ assert -2147483648 <= sql_trace.sql_id, "sql_id too small"
173
+ assert 2147483647 >= sql_trace.sql_id, "sql_id too large"
174
+ end
175
+
176
+ def test_sends_obfuscated_queries_when_configured
177
+ NewRelic::Control.instance['transaction_tracer'] = { 'record_sql' => 'obfuscated' }
178
+
179
+ data = NewRelic::Agent::TransactionSqlData.new
180
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
181
+ 'guid')
182
+ data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
183
+ "Database/test/select", {}, 1.5),
184
+ NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
185
+ "Database/test/select", {}, 1.2)])
186
+ @sampler.harvest_slow_sql(data)
187
+ sql_traces = @sampler.harvest
188
+
189
+ assert_equal('select * from test where foo = ?', sql_traces[0].sql)
190
+ assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
191
+ end
192
+ end
@@ -0,0 +1,150 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','..','test_helper'))
2
+ require 'new_relic/agent/stats_engine/metric_stats'
3
+ class NewRelic::Agent::StatsEngine::MetricStats::HarvestTest < Test::Unit::TestCase
4
+ include NewRelic::Agent::StatsEngine::MetricStats::Harvest
5
+
6
+ attr_accessor :stats_hash
7
+ def test_merge_stats_trivial
8
+ self.stats_hash = {}
9
+ merge_stats({}, {})
10
+ end
11
+
12
+ def test_merge_stats_with_nil_stats
13
+ metric_ids = mock('metric ids')
14
+ mock_stats_hash = mock('stats_hash')
15
+ mock_spec = mock('spec')
16
+ mock_stats = mock('stats')
17
+ mock_stats_hash.expects(:each).yields(mock_spec, mock_stats)
18
+ self.stats_hash = mock_stats_hash
19
+
20
+ self.expects(:coerce_to_metric_spec).with(mock_spec).returns(mock_spec)
21
+ self.expects(:clone_and_reset_stats).with(mock_spec, mock_stats).returns(mock_stats)
22
+ self.expects(:merge_old_data!).with(mock_spec, mock_stats, {})
23
+ metric_ids.expects(:[]).with(mock_spec).returns('an id')
24
+ self.expects(:add_data_to_send_unless_empty).with({}, mock_stats, mock_spec, 'an id')
25
+
26
+
27
+ merge_stats({}, metric_ids)
28
+ end
29
+
30
+
31
+ def test_get_stats_hash_from_hash
32
+ assert_equal({}, get_stats_hash_from({}))
33
+ end
34
+
35
+ def test_get_stats_hash_from_engine
36
+ assert_equal({}, get_stats_hash_from(NewRelic::Agent::StatsEngine.new))
37
+ end
38
+
39
+ def test_coerce_to_metric_spec_metric_spec
40
+ assert_equal NewRelic::MetricSpec.new, coerce_to_metric_spec(NewRelic::MetricSpec.new)
41
+ end
42
+
43
+ def test_coerce_to_metric_spec_string
44
+ assert_equal NewRelic::MetricSpec.new('foo'), coerce_to_metric_spec('foo')
45
+ end
46
+
47
+ def test_clone_and_reset_stats_nil
48
+ spec = NewRelic::MetricSpec.new('foo', 'bar')
49
+ stats = nil
50
+ begin
51
+ clone_and_reset_stats(spec, stats)
52
+ rescue RuntimeError => e
53
+ assert_equal("Nil stats for foo (bar)", e.message)
54
+ end
55
+ end
56
+
57
+ def test_clone_and_reset_stats_present
58
+ # spec is only used for debug output
59
+ spec = nil
60
+ stats = mock('stats')
61
+ stats_clone = mock('stats_clone')
62
+ stats.expects(:clone).returns(stats_clone)
63
+ stats.expects(:reset)
64
+ # should return a clone
65
+ assert_equal stats_clone, clone_and_reset_stats(spec, stats)
66
+ end
67
+
68
+ def test_merge_old_data_present
69
+ metric_spec = mock('metric_spec')
70
+ stats = mock('stats obj')
71
+ stats.expects(:merge!).with('some stats')
72
+ old_data = mock('old data')
73
+ old_data.expects(:stats).returns('some stats')
74
+ old_data_hash = {metric_spec => old_data}
75
+ merge_old_data!(metric_spec, stats, old_data_hash)
76
+ end
77
+
78
+ def test_merge_old_data_nil
79
+ metric_spec = mock('metric_spec')
80
+ stats = mock('stats') # doesn't matter
81
+ old_data_hash = {metric_spec => nil}
82
+ merge_old_data!(metric_spec, stats, old_data_hash)
83
+ end
84
+
85
+ def test_add_data_to_send_unless_empty_when_is_empty
86
+ stats = mock('stats')
87
+ stats.expects(:is_reset?).returns(true)
88
+ assert_equal nil, add_data_to_send_unless_empty(nil, stats, nil, nil)
89
+ end
90
+
91
+ def test_add_data_to_send_unless_empty_main
92
+ data = mock('data hash')
93
+ stats = mock('stats')
94
+ stats.expects(:is_reset?).returns(false)
95
+ metric_spec = mock('spec')
96
+
97
+ NewRelic::MetricData.expects(:new).with(metric_spec, stats, nil).returns('metric data')
98
+ data.expects(:[]=).with(metric_spec, 'metric data')
99
+ add_data_to_send_unless_empty(data, stats, metric_spec, nil)
100
+ end
101
+
102
+ def test_add_data_to_send_unless_empty_with_id
103
+ data = mock('data hash')
104
+ stats = mock('stats')
105
+ stats.expects(:is_reset?).returns(false)
106
+ metric_spec = mock('spec')
107
+ id = mock('id')
108
+
109
+ NewRelic::MetricData.expects(:new).with(nil, stats, id).returns('metric data')
110
+ data.expects(:[]=).with(metric_spec, 'metric data')
111
+ assert_equal 'metric data', add_data_to_send_unless_empty(data, stats, metric_spec, id)
112
+ end
113
+
114
+ def test_merge_data_basic
115
+ mock_stats_hash = mock('stats hash')
116
+ self.stats_hash = mock_stats_hash
117
+ merge_data({})
118
+ end
119
+
120
+ def test_merge_data_new_and_old_data
121
+ stats = NewRelic::MethodTraceStats.new
122
+ stats.record_data_point(1.0)
123
+ new_stats = NewRelic::MethodTraceStats.new
124
+ new_stats.record_data_point(2.0)
125
+ self.expects(:lookup_stats).with('Custom/test/method', '').returns(new_stats)
126
+ assert_equal(2.0, new_stats.total_call_time)
127
+
128
+ metric_spec = NewRelic::MetricSpec.new('Custom/test/method')
129
+ mock_stats_hash = mock('stats_hash')
130
+ self.stats_hash = mock_stats_hash
131
+ merge_data({metric_spec => NewRelic::MetricData.new(metric_spec, stats, nil)})
132
+ assert_equal(3.0, new_stats.total_call_time)
133
+ end
134
+
135
+ def test_merge_data_old_data
136
+ stats = NewRelic::MethodTraceStats.new
137
+ stats.record_data_point(1.0)
138
+ self.expects(:lookup_stats).returns(nil)
139
+
140
+ metric_spec = NewRelic::MetricSpec.new('Custom/test/method')
141
+ mock_stats_hash = mock('stats_hash')
142
+ mock_stats_hash.expects(:[]=).with(metric_spec, stats)
143
+ self.stats_hash = mock_stats_hash
144
+ merge_data({metric_spec => NewRelic::MetricData.new(metric_spec, stats, nil)})
145
+ end
146
+
147
+ end
148
+
149
+
150
+