wd_newrelic_rpm 3.3.4.1 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. data/.gitignore +20 -0
  2. data/.project +23 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG +317 -39
  5. data/GUIDELINES_FOR_CONTRIBUTING.md +76 -0
  6. data/Gemfile +16 -0
  7. data/LICENSE +1 -1
  8. data/{README.rdoc → README.md} +71 -55
  9. data/Rakefile +62 -0
  10. data/bin/mongrel_rpm +1 -1
  11. data/config.dot +290 -0
  12. data/config/database.yml +5 -0
  13. data/init.rb +31 -0
  14. data/lib/new_relic/agent.rb +31 -60
  15. data/lib/new_relic/agent/agent.rb +277 -502
  16. data/lib/new_relic/agent/agent_logger.rb +165 -0
  17. data/lib/new_relic/agent/audit_logger.rb +72 -0
  18. data/lib/new_relic/agent/beacon_configuration.rb +36 -50
  19. data/lib/new_relic/agent/browser_monitoring.rb +114 -61
  20. data/lib/new_relic/agent/busy_calculator.rb +14 -6
  21. data/lib/new_relic/agent/configuration.rb +74 -0
  22. data/lib/new_relic/agent/configuration/defaults.rb +126 -0
  23. data/lib/new_relic/agent/configuration/environment_source.rb +49 -0
  24. data/lib/new_relic/agent/configuration/manager.rb +136 -0
  25. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  26. data/lib/new_relic/agent/configuration/server_source.rb +27 -0
  27. data/lib/new_relic/agent/configuration/yaml_source.rb +63 -0
  28. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  29. data/lib/new_relic/agent/database.rb +39 -26
  30. data/lib/new_relic/agent/error_collector.rb +48 -49
  31. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -7
  33. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  36. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +35 -12
  37. data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -12
  38. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +2 -2
  39. data/lib/new_relic/agent/instrumentation/memcache.rb +6 -6
  40. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  42. data/lib/new_relic/agent/instrumentation/metric_frame.rb +4 -14
  43. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +6 -20
  46. data/lib/new_relic/agent/instrumentation/queue_time.rb +2 -2
  47. data/lib/new_relic/agent/instrumentation/rack.rb +1 -1
  48. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -7
  49. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  50. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  51. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  52. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +6 -2
  53. data/lib/new_relic/agent/instrumentation/resque.rb +81 -0
  54. data/lib/new_relic/agent/instrumentation/sinatra.rb +21 -10
  55. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  56. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +5 -4
  57. data/lib/new_relic/agent/method_tracer.rb +11 -9
  58. data/lib/new_relic/agent/new_relic_service.rb +379 -0
  59. data/lib/new_relic/agent/pipe_channel_manager.rb +175 -0
  60. data/lib/new_relic/agent/pipe_service.rb +58 -0
  61. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +86 -0
  62. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -8
  63. data/lib/new_relic/agent/sql_sampler.rb +31 -74
  64. data/lib/new_relic/agent/stats_engine.rb +0 -5
  65. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +40 -24
  66. data/lib/new_relic/agent/stats_engine/metric_stats.rb +89 -14
  67. data/lib/new_relic/agent/stats_engine/samplers.rb +9 -7
  68. data/lib/new_relic/agent/stats_engine/transactions.rb +20 -12
  69. data/lib/new_relic/agent/thread.rb +32 -0
  70. data/lib/new_relic/agent/thread_profiler.rb +306 -0
  71. data/lib/new_relic/agent/transaction_info.rb +24 -4
  72. data/lib/new_relic/agent/transaction_sample_builder.rb +12 -13
  73. data/lib/new_relic/agent/transaction_sampler.rb +49 -65
  74. data/lib/new_relic/agent/worker_loop.rb +31 -25
  75. data/lib/new_relic/collection_helper.rb +1 -1
  76. data/lib/new_relic/commands/deployments.rb +19 -10
  77. data/lib/new_relic/control.rb +1 -3
  78. data/lib/new_relic/control/class_methods.rb +10 -5
  79. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  80. data/lib/new_relic/control/frameworks/rails.rb +30 -45
  81. data/lib/new_relic/control/frameworks/rails3.rb +23 -18
  82. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  83. data/lib/new_relic/control/frameworks/ruby.rb +2 -23
  84. data/lib/new_relic/control/instance_methods.rb +35 -73
  85. data/lib/new_relic/control/instrumentation.rb +7 -12
  86. data/lib/new_relic/control/server_methods.rb +17 -19
  87. data/lib/new_relic/delayed_job_injection.rb +2 -2
  88. data/lib/new_relic/helper.rb +34 -0
  89. data/lib/new_relic/language_support.rb +56 -37
  90. data/lib/new_relic/local_environment.rb +32 -67
  91. data/lib/new_relic/metric_data.rb +10 -2
  92. data/lib/new_relic/metric_spec.rb +7 -3
  93. data/lib/new_relic/noticed_error.rb +32 -9
  94. data/lib/new_relic/rack.rb +4 -0
  95. data/lib/new_relic/rack/browser_monitoring.rb +34 -25
  96. data/lib/new_relic/rack/developer_mode.rb +3 -0
  97. data/lib/new_relic/rack/error_collector.rb +56 -0
  98. data/lib/new_relic/stats.rb +9 -7
  99. data/lib/new_relic/transaction_sample.rb +19 -18
  100. data/lib/new_relic/transaction_sample/segment.rb +13 -15
  101. data/lib/new_relic/version.rb +19 -3
  102. data/lib/newrelic_rpm.rb +1 -1
  103. data/lib/tasks/tests.rake +6 -8
  104. data/newrelic.yml +15 -32
  105. data/newrelic_rpm.gemspec +224 -43
  106. data/newrelic_rpm.gemspec.erb +54 -0
  107. data/test/config/newrelic.yml +4 -3
  108. data/test/config/test_control.rb +18 -18
  109. data/test/fixtures/gemspec_no_build.rb +442 -0
  110. data/test/fixtures/gemspec_with_build.rb +442 -0
  111. data/test/fixtures/gemspec_with_build_and_stage.rb +442 -0
  112. data/test/intentional_fail.rb +10 -0
  113. data/test/multiverse/.gitignore +10 -0
  114. data/test/multiverse/README.md +85 -0
  115. data/test/multiverse/lib/multiverse/color.rb +13 -0
  116. data/test/multiverse/lib/multiverse/envfile.rb +66 -0
  117. data/test/multiverse/lib/multiverse/environment.rb +16 -0
  118. data/test/multiverse/lib/multiverse/output_collector.rb +29 -0
  119. data/test/multiverse/lib/multiverse/runner.rb +44 -0
  120. data/test/multiverse/lib/multiverse/suite.rb +162 -0
  121. data/test/multiverse/script/run_one +3 -0
  122. data/test/multiverse/script/runner +9 -0
  123. data/test/multiverse/suites/active_record/Envfile +13 -0
  124. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +94 -0
  125. data/test/multiverse/suites/active_record/config/newrelic.yml +22 -0
  126. data/test/multiverse/suites/active_record/encoding_test.rb +26 -0
  127. data/test/multiverse/suites/agent_only/Envfile +4 -0
  128. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  129. data/test/multiverse/suites/agent_only/config/newrelic.yml +22 -0
  130. data/test/multiverse/suites/agent_only/http_response_code_test.rb +53 -0
  131. data/test/multiverse/suites/agent_only/marshaling_test.rb +109 -0
  132. data/test/multiverse/suites/agent_only/method_visibility_test.rb +98 -0
  133. data/test/multiverse/suites/agent_only/pipe_manager_test.rb +33 -0
  134. data/test/multiverse/suites/agent_only/service_timeout_test.rb +29 -0
  135. data/test/multiverse/suites/agent_only/test_trace_method_with_punctuation.rb +30 -0
  136. data/test/multiverse/suites/agent_only/test_trace_transaction_with_punctuation.rb +32 -0
  137. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +80 -0
  138. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  139. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  140. data/test/multiverse/suites/datamapper/Envfile +8 -0
  141. data/test/multiverse/suites/datamapper/config/newrelic.yml +22 -0
  142. data/test/multiverse/suites/datamapper/encoding_test.rb +36 -0
  143. data/test/multiverse/suites/logging/Envfile +4 -0
  144. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  145. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  146. data/test/multiverse/suites/monitor_mode_false/Envfile +2 -0
  147. data/test/multiverse/suites/monitor_mode_false/config/newrelic.yml +25 -0
  148. data/test/multiverse/suites/monitor_mode_false/no_dns_resolv.rb +29 -0
  149. data/test/multiverse/suites/no_load/Envfile +2 -0
  150. data/test/multiverse/suites/no_load/config/newrelic.yml +22 -0
  151. data/test/multiverse/suites/no_load/start_up_test.rb +14 -0
  152. data/test/multiverse/suites/rails_3_error_tracing/Envfile +15 -0
  153. data/test/multiverse/suites/rails_3_error_tracing/config/newrelic.yml +165 -0
  154. data/test/multiverse/suites/rails_3_error_tracing/error_tracing_test.rb +236 -0
  155. data/test/multiverse/suites/rails_3_gc/Envfile +8 -0
  156. data/test/multiverse/suites/rails_3_gc/config/newrelic.yml +167 -0
  157. data/test/multiverse/suites/rails_3_gc/instrumentation_test.rb +92 -0
  158. data/test/multiverse/suites/rails_3_queue_time/Envfile +15 -0
  159. data/test/multiverse/suites/rails_3_queue_time/config/newrelic.yml +165 -0
  160. data/test/multiverse/suites/rails_3_queue_time/queue_time_test.rb +75 -0
  161. data/test/multiverse/suites/rails_3_views/.gitignore +3 -0
  162. data/test/multiverse/suites/rails_3_views/Envfile +16 -0
  163. data/test/multiverse/suites/rails_3_views/app/views/foos/_foo.html.haml +1 -0
  164. data/test/multiverse/suites/rails_3_views/app/views/test/_a_partial.html.erb +1 -0
  165. data/test/multiverse/suites/rails_3_views/app/views/test/_mid_partial.html.erb +1 -0
  166. data/test/multiverse/suites/rails_3_views/app/views/test/_top_partial.html.erb +3 -0
  167. data/test/multiverse/suites/rails_3_views/app/views/test/deep_partial.html.erb +3 -0
  168. data/test/multiverse/suites/rails_3_views/app/views/test/haml_view.html.haml +6 -0
  169. data/test/multiverse/suites/rails_3_views/app/views/test/index.html.erb +4 -0
  170. data/test/multiverse/suites/rails_3_views/config/newrelic.yml +164 -0
  171. data/test/multiverse/suites/rails_3_views/view_instrumentation_test.rb +245 -0
  172. data/test/multiverse/suites/resque/Envfile +21 -0
  173. data/test/multiverse/suites/resque/config/newrelic.yml +22 -0
  174. data/test/multiverse/suites/resque/dump.rdb +0 -0
  175. data/test/multiverse/suites/resque/instrumentation_test.rb +73 -0
  176. data/test/multiverse/suites/rum_auto_instrumentation/Envfile +4 -0
  177. data/test/multiverse/suites/rum_auto_instrumentation/config/newrelic.yml +24 -0
  178. data/test/multiverse/suites/rum_auto_instrumentation/responses/worst_case_small.html +5000 -0
  179. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +102 -0
  180. data/test/multiverse/suites/sinatra/Envfile +13 -0
  181. data/test/multiverse/suites/sinatra/config/newrelic.yml +24 -0
  182. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +77 -0
  183. data/test/multiverse/suites/sinatra/sinatra_routes_test.rb +46 -0
  184. data/test/multiverse/suites/sinatra/sinatra_test.rb +55 -0
  185. data/test/multiverse/test/multiverse_test.rb +55 -0
  186. data/test/multiverse/test/suite_examples/one/a/Envfile +3 -0
  187. data/test/multiverse/test/suite_examples/one/a/a_test.rb +11 -0
  188. data/test/multiverse/test/suite_examples/one/a/config/newrelic.yml +24 -0
  189. data/test/multiverse/test/suite_examples/one/b/Envfile +3 -0
  190. data/test/multiverse/test/suite_examples/one/b/b_test.rb +11 -0
  191. data/test/multiverse/test/suite_examples/one/b/config/newrelic.yml +24 -0
  192. data/test/multiverse/test/suite_examples/three/a/Envfile +2 -0
  193. data/test/multiverse/test/suite_examples/three/a/fail_test.rb +6 -0
  194. data/test/multiverse/test/suite_examples/three/b/Envfile +2 -0
  195. data/test/multiverse/test/suite_examples/three/b/win_test.rb +6 -0
  196. data/test/multiverse/test/suite_examples/two/a/Envfile +1 -0
  197. data/test/multiverse/test/suite_examples/two/a/fail_test.rb +6 -0
  198. data/test/new_relic/agent/agent/connect_test.rb +151 -227
  199. data/test/new_relic/agent/agent/start_test.rb +68 -118
  200. data/test/new_relic/agent/agent/start_worker_thread_test.rb +12 -74
  201. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  202. data/test/new_relic/agent/agent_test.rb +116 -30
  203. data/test/new_relic/agent/agent_test_controller.rb +1 -1
  204. data/test/new_relic/agent/agent_test_controller_test.rb +42 -10
  205. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  206. data/test/new_relic/agent/beacon_configuration_test.rb +63 -67
  207. data/test/new_relic/agent/browser_monitoring_test.rb +151 -79
  208. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  209. data/test/new_relic/agent/configuration/environment_source_test.rb +79 -0
  210. data/test/new_relic/agent/configuration/manager_test.rb +204 -0
  211. data/test/new_relic/agent/configuration/server_source_test.rb +45 -0
  212. data/test/new_relic/agent/configuration/yaml_source_test.rb +75 -0
  213. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  214. data/test/new_relic/agent/database_test.rb +12 -11
  215. data/test/new_relic/agent/error_collector/notice_error_test.rb +64 -53
  216. data/test/new_relic/agent/error_collector_test.rb +33 -19
  217. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +60 -30
  218. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  219. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  220. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +6 -0
  221. data/test/new_relic/agent/instrumentation/queue_time_test.rb +14 -0
  222. data/test/new_relic/agent/instrumentation/sinatra_test.rb +25 -0
  223. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +2 -2
  224. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +4 -10
  225. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  226. data/test/new_relic/agent/method_tracer_test.rb +7 -6
  227. data/test/new_relic/agent/mock_scope_listener.rb +3 -0
  228. data/test/new_relic/agent/new_relic_service_test.rb +376 -0
  229. data/test/new_relic/agent/pipe_channel_manager_test.rb +131 -0
  230. data/test/new_relic/agent/pipe_service_test.rb +113 -0
  231. data/test/new_relic/agent/rpm_agent_test.rb +27 -50
  232. data/test/new_relic/agent/sql_sampler_test.rb +81 -56
  233. data/test/new_relic/agent/stats_engine/metric_stats/harvest_test.rb +3 -20
  234. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +12 -1
  235. data/test/new_relic/agent/stats_engine_test.rb +17 -8
  236. data/test/new_relic/agent/thread_profiler_test.rb +537 -0
  237. data/test/new_relic/agent/thread_test.rb +89 -0
  238. data/test/new_relic/agent/threaded_test.rb +65 -0
  239. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  240. data/test/new_relic/agent/transaction_sample_builder_test.rb +8 -7
  241. data/test/new_relic/agent/transaction_sampler_test.rb +193 -204
  242. data/test/new_relic/agent/worker_loop_test.rb +26 -11
  243. data/test/new_relic/agent_test.rb +113 -33
  244. data/test/new_relic/collection_helper_test.rb +7 -8
  245. data/test/new_relic/command/deployments_test.rb +18 -2
  246. data/test/new_relic/control/class_methods_test.rb +0 -18
  247. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  248. data/test/new_relic/control_test.rb +96 -137
  249. data/test/new_relic/delayed_job_injection_test.rb +6 -1
  250. data/test/new_relic/dispatcher_test.rb +54 -0
  251. data/test/new_relic/fake_collector.rb +283 -0
  252. data/test/new_relic/fake_service.rb +53 -0
  253. data/test/new_relic/fakes_sending_data.rb +30 -0
  254. data/test/new_relic/framework_test.rb +53 -0
  255. data/test/new_relic/load_test.rb +13 -0
  256. data/test/new_relic/local_environment_test.rb +11 -11
  257. data/test/new_relic/metric_data_test.rb +45 -16
  258. data/test/new_relic/noticed_error_test.rb +24 -0
  259. data/test/new_relic/rack/browser_monitoring_test.rb +20 -10
  260. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  261. data/test/new_relic/rack/error_collector_test.rb +74 -0
  262. data/test/new_relic/stats_test.rb +10 -0
  263. data/test/new_relic/transaction_sample/segment_test.rb +23 -4
  264. data/test/new_relic/transaction_sample_test.rb +47 -2
  265. data/test/new_relic/version_number_test.rb +32 -0
  266. data/test/script/build_test_gem.sh +9 -3
  267. data/test/script/ci.sh +108 -35
  268. data/test/script/ci_agent-tests_runner.sh +82 -0
  269. data/test/script/ci_multiverse_runner.sh +63 -0
  270. data/test/test_contexts.rb +1 -0
  271. data/test/test_helper.rb +68 -18
  272. data/ui/helpers/developer_mode_helper.rb +21 -11
  273. data/ui/views/layouts/newrelic_default.rhtml +1 -0
  274. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  275. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  276. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  277. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  278. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  279. data/ui/views/newrelic/show_sample.rhtml +1 -1
  280. data/ui/views/newrelic/threads.rhtml +2 -10
  281. data/vendor/gems/metric_parser-0.1.0.pre1/.specification +116 -0
  282. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/servlet_init.rb +7 -0
  283. metadata +191 -65
  284. data/lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb +0 -40
  285. data/lib/new_relic/control/configuration.rb +0 -206
  286. data/lib/new_relic/control/logging_methods.rb +0 -143
  287. data/lib/new_relic/data_serialization.rb +0 -151
  288. data/test/new_relic/control/configuration_test.rb +0 -84
  289. data/test/new_relic/control/logging_methods_test.rb +0 -185
  290. data/test/new_relic/data_serialization_test.rb +0 -208
@@ -0,0 +1,98 @@
1
+ require 'multiverse/color'
2
+
3
+ class MethodVisibilityTest < Test::Unit::TestCase
4
+ extend Multiverse::Color
5
+
6
+ class InstrumentedClass
7
+ include NewRelic::Agent::MethodTracer
8
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
9
+
10
+ def public_method!
11
+ end
12
+
13
+ def public_transaction!
14
+ end
15
+
16
+ private
17
+ def private_method!
18
+ end
19
+
20
+ def private_transaction!
21
+ end
22
+
23
+ protected
24
+ def protected_method!
25
+ end
26
+
27
+ def protected_transaction!
28
+ end
29
+
30
+ add_method_tracer :public_method!
31
+ add_method_tracer :private_method!
32
+ add_method_tracer :protected_method!
33
+
34
+ add_transaction_tracer :public_transaction!
35
+ add_transaction_tracer :private_transaction!
36
+ add_transaction_tracer :protected_transaction!
37
+ end
38
+
39
+
40
+ class ObjectWithInstrumentation
41
+ include NewRelic::Agent::MethodTracer
42
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
43
+ end
44
+
45
+ class ObjectWithTracers < ObjectWithInstrumentation
46
+ private
47
+ def a_private_method
48
+ end
49
+ def a_private_transaction
50
+ end
51
+ protected
52
+ def a_protected_method
53
+ end
54
+ def a_protected_transaction
55
+ end
56
+
57
+ add_method_tracer :a_private_method
58
+ add_method_tracer :a_protected_method
59
+ add_transaction_tracer :a_private_transaction
60
+ add_transaction_tracer :a_protected_transaction
61
+ end
62
+
63
+
64
+ def setup
65
+ @instance = InstrumentedClass.new
66
+ end
67
+
68
+ if NewRelic::VERSION::STRING >= '3.4.0.2'
69
+ %w| public private protected |.each do |visibility|
70
+ define_method "test_should_preserve_visibility_of_#{visibility}_traced_method" do
71
+ assert @instance.send("#{visibility}_methods").map{|s|s.to_sym}.include?(:"#{visibility}_method!"), "Method #{visibility}_method should be #{visibility}"
72
+ end
73
+
74
+ define_method "test_should_preserve_visibility_of_#{visibility}_traced_transaction" do
75
+ assert @instance.send("#{visibility}_methods").map{|s|s.to_sym}.include?(:"#{visibility}_transaction!"), "Transcation #{visibility}_transaction should be #{visibility}"
76
+ end
77
+ end
78
+
79
+ def test_tracing_non_public_methods_doesnt_add_public_methods
80
+ assert_equal [], ObjectWithTracers.public_instance_methods - ObjectWithInstrumentation.public_instance_methods
81
+ end
82
+
83
+ # FIXME: Currently including MethodTracer and ControllerInstrumentation
84
+ # adds a bunch of public methods to the class. It probably shouldn't do this.
85
+ #def test_instrumentation_doesnt_add_any_public_methods
86
+ # assert_equal [], ObjectWithInstrumentation.public_instance_methods - Object.public_instance_methods
87
+ #end
88
+ #
89
+
90
+
91
+
92
+ else
93
+ def test_truth
94
+ assert true # jruby freaks out if there are no tests defined in the test class
95
+ end
96
+ puts yellow('SKIPPED! 3.4.0.1 and earlier fail preserve_visibility tests')
97
+ end
98
+ end
@@ -0,0 +1,33 @@
1
+ # https://newrelic.atlassian.net/browse/RUBY-669
2
+
3
+ class PipeManagerTest < Test::Unit::TestCase
4
+ def setup
5
+ @listener = NewRelic::Agent::PipeChannelManager.listener
6
+ end
7
+
8
+ def teardown
9
+ @listener.stop
10
+ end
11
+
12
+ def test_old_pipes_are_cleaned_up_after_timeout
13
+ @listener.timeout = 1
14
+ NewRelic::Agent::PipeChannelManager.register_report_channel(:timeout_test)
15
+ sleep 2
16
+ @listener.start
17
+ sleep 0.5 # give the thread some time to start, and clean things up
18
+ assert_nil NewRelic::Agent::PipeChannelManager.channels[:timeout_test]
19
+ end
20
+
21
+ def test_pipes_are_regularly_checked_for_freshness
22
+ @listener.select_timeout = 1
23
+ @listener.timeout = 2
24
+ NewRelic::Agent::PipeChannelManager.register_report_channel(:select_test)
25
+
26
+ sleep 1.5
27
+ @listener.start
28
+ assert NewRelic::Agent::PipeChannelManager.channels[:select_test]
29
+
30
+ sleep 1.5
31
+ assert_nil NewRelic::Agent::PipeChannelManager.channels[:select_test]
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'socket'
2
+
3
+ class ServiceTimeoutTest < Test::Unit::TestCase
4
+ def setup
5
+ hk = TCPServer.new('127.0.0.1',8081)
6
+
7
+ Thread.new {
8
+ client = hk.accept
9
+ what = client.gets
10
+ sleep 4
11
+ client.close
12
+ Thread.exit
13
+ }
14
+ end
15
+
16
+ def test_service_timeout
17
+ server = NewRelic::Control::Server.new('localhost', 8081,'127.0.0.1')
18
+ NewRelic::Agent.config.apply_config(:timeout => 2)
19
+
20
+ service = NewRelic::Agent::NewRelicService.new('deadbeef', server)
21
+
22
+ assert_raise Timeout::Error do
23
+ service.send('send_request',
24
+ :uri => '/agent_listener/8/bd0e1d52adade840f7ca727d29a86249e89a6f1c/get_redirect_host',
25
+ :encoding => 'UTF-8', :collector => server, :data => 'blah')
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,30 @@
1
+
2
+ require 'test/unit'
3
+ require 'newrelic_rpm'
4
+ require 'new_relic/agent/method_tracer'
5
+
6
+
7
+ class MethodInterrobangTest < Test::Unit::TestCase
8
+ include NewRelic::Agent::MethodTracer
9
+
10
+ def interrogate?
11
+ "say what?"
12
+ end
13
+
14
+ def mutate!
15
+ "oh yeah!"
16
+ end
17
+
18
+ add_method_tracer :interrogate?
19
+ add_method_tracer :mutate!
20
+
21
+ def test_alias_method_ending_in_question_mark
22
+ assert_respond_to self,:interrogate?
23
+ assert_equal "say what?", interrogate?
24
+ end
25
+
26
+ def test_aliase_method_ending_in_exclamation_makr
27
+ assert_respond_to self,:mutate!
28
+ assert_equal "oh yeah!",mutate!
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+
2
+ require 'test/unit'
3
+ require 'newrelic_rpm'
4
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
5
+
6
+
7
+ class TransactionInterrobangTest < Test::Unit::TestCase
8
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
9
+
10
+ def interrogate?
11
+ "say what?"
12
+ end
13
+
14
+ def mutate!
15
+ "oh yeah!"
16
+ end
17
+
18
+ add_transaction_tracer :interrogate?
19
+ add_transaction_tracer :mutate!
20
+
21
+ def test_alias_method_ending_in_question_mark
22
+ assert_respond_to self,:interrogate?
23
+ assert_respond_to self, :interrogate_with_newrelic_transaction_trace?
24
+ assert_equal "say what?", interrogate?
25
+ end
26
+
27
+ def test_aliase_method_ending_in_exclamation_makr
28
+ assert_respond_to self,:mutate!
29
+ assert_respond_to self, :mutate_with_newrelic_transaction_trace!
30
+ assert_equal "oh yeah!",mutate!
31
+ end
32
+ end
@@ -0,0 +1,80 @@
1
+ # https://newrelic.atlassian.net/wiki/display/eng/Agent+Thread+Profiling
2
+ # https://newrelic.atlassian.net/browse/RUBY-917
3
+
4
+ if RUBY_VERSION >= '1.9'
5
+ class ThreadProfilingTest < Test::Unit::TestCase
6
+ def setup
7
+ NewRelic::Agent.manual_start(:'thread_profiler.enabled' => true)
8
+
9
+ @agent = NewRelic::Agent.instance
10
+ @thread_profiler = @agent.thread_profiler
11
+
12
+ $collector ||= NewRelic::FakeCollector.new
13
+ $collector.reset
14
+ $collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
15
+ $collector.mock['get_agent_commands'] = [200, {'return_value' => START_COMMAND}]
16
+ $collector.mock['agent_command_results'] = [200, {'return_value' => []}]
17
+ $collector.run
18
+ end
19
+
20
+ def teardown
21
+ $collector.reset
22
+ end
23
+
24
+ START_COMMAND = [[666,{
25
+ "name" => "start_profiler",
26
+ "arguments" => {
27
+ "profile_id" => -1,
28
+ "sample_period" => 0.01,
29
+ "duration" => 0.5,
30
+ "only_runnable_threads" => false,
31
+ "only_request_threads" => false,
32
+ "profile_agent_code" => false
33
+ }
34
+ }]]
35
+
36
+ STOP_COMMAND = [[666,{
37
+ "name" => "stop_profiler",
38
+ "arguments" => {
39
+ "profile_id" => -1,
40
+ "report_data" => true
41
+ }
42
+ }]]
43
+
44
+ # These are potentially fragile for being timing based
45
+ # START_COMMAND with 0.01 sampling and 0.5 duration expects to get
46
+ # roughly 50 polling cycles in. We check signficiantly less than that.
47
+
48
+ # STOP_COMMAND when immediately issued after a START_COMMAND is expected
49
+ # go only let a few cycles through, so we check less than 10
50
+
51
+ def test_thread_profiling
52
+ @agent.send(:check_for_agent_commands)
53
+ sleep(1)
54
+ NewRelic::Agent.shutdown
55
+
56
+ profile_data = $collector.calls_for('profile_data')[0]
57
+ assert_equal(666, profile_data[0])
58
+
59
+ poll_count = profile_data[1][0][3]
60
+ assert poll_count > 25, "Expected poll_count > 25, but was #{poll_count}"
61
+ end
62
+
63
+ def test_thread_profiling_can_stop
64
+ @agent.send(:check_for_agent_commands)
65
+
66
+ $collector.mock['get_agent_commands'] = [200, {'return_value' => STOP_COMMAND}]
67
+ @agent.send(:check_for_agent_commands)
68
+
69
+ sleep(0.1)
70
+ NewRelic::Agent.shutdown
71
+
72
+ profile_data = $collector.calls_for('profile_data')[0]
73
+ assert_equal(666, profile_data[0])
74
+
75
+ poll_count = profile_data[1][0][3]
76
+ assert poll_count < 10, "Expected poll_count < 10, but was #{poll_count}"
77
+ end
78
+ end
79
+ end
80
+
@@ -0,0 +1,7 @@
1
+ # don't start the agent
2
+ self.newrelic_gemfile_options=(':require => false')
3
+ gemfile <<-RB
4
+ # stub file system so we can test that newrelic.yml can be loaded from
5
+ # various places.
6
+ gem 'fakefs', :require => 'fakefs/safe'
7
+ RB
@@ -0,0 +1,106 @@
1
+ # Test the logic for loading the newrelic.yml config file.
2
+ #
3
+ # We will look at (in this priority):
4
+ # 1. ENV['NRCONFIG'] (if set)
5
+ # 2. ./config/newrelic.yml
6
+ # 3. ./newrelic.yml
7
+ # 4. ~/.newrelic/newrelic.yml
8
+ # 5. ~/newrelic.yml
9
+ #
10
+ # If this fails the agent will attempt to dial Lew Cirne's cell phone and ask
11
+ # that he verbally describe how it should be configured.
12
+ class ConfigFileLoadingTest < Test::Unit::TestCase
13
+
14
+ def setup
15
+ # While FakeFS stubs out all the File system related libraries (i.e. File,
16
+ # FileUtils, Dir, etc.) It doesn't handle the Logger library that is used
17
+ # to create the agent log file. Therefore we check for the presence of the
18
+ # log directory in the FakeFS, then error when we try to open the file in
19
+ # the Real FS. Set the log file to /dev/null to work around this issue.
20
+ # It's incidental to the functionality being tested.
21
+ #
22
+ # '/dev/null' can be changed to 'stdout' if more debugging output is needed
23
+ # in these tests.
24
+ ENV['NEW_RELIC_LOG'] = '/dev/null'
25
+
26
+ # Figure out where multiverse is in the real file system.
27
+ @cwd = Dir.pwd
28
+ # Use a fake file system so we don't damage the real one.
29
+ FakeFS.activate!
30
+ FakeFS::FileSystem.clear
31
+
32
+ # require the agent after we're in FakeFS
33
+ require 'newrelic_rpm'
34
+
35
+ FileUtils.mkdir_p(@cwd)
36
+ end
37
+
38
+ def teardown
39
+ ENV['NEW_RELIC_LOG'] = nil
40
+ FakeFS.deactivate!
41
+ end
42
+
43
+ def setup_config(path, manual_config_options = {})
44
+ NewRelic::Agent.shutdown
45
+ FileUtils.mkdir_p(File.dirname(path))
46
+ Dir.chdir @cwd
47
+ File.open(path, 'w') do |f|
48
+ f.print <<-YAML
49
+ development:
50
+ foo: "success!!"
51
+ test:
52
+ foo: "success!!"
53
+ bazbangbarn:
54
+ i_am: "bazbangbarn"
55
+ YAML
56
+ end
57
+ NewRelic::Agent.reset_config
58
+ NewRelic::Agent.manual_start(manual_config_options)
59
+ end
60
+
61
+ def assert_config_read_from(path)
62
+ setup_config(path)
63
+ assert NewRelic::Agent.config[:foo] == "success!!", "Failed to read yaml config from #{path.inspect}\n\n#{NewRelic::Agent.config.inspect}"
64
+ end
65
+
66
+ def assert_config_not_read_from(path)
67
+ setup_config(path)
68
+ assert NewRelic::Agent.config[:foo] != "success!!", "Read yaml config from #{path.inspect}\n\n#{NewRelic::Agent.config.inspect}"
69
+ end
70
+
71
+ def test_config_loads_from_config_newrelic_yml
72
+ assert_config_read_from(File.dirname(__FILE__) + "/config/newrelic.yml")
73
+ end
74
+
75
+ def test_config_loads_from_newrelic_yml
76
+ assert_config_read_from(File.dirname(__FILE__) + "/newrelic.yml")
77
+ end
78
+
79
+ def test_config_loads_from_home_newrelic_yml
80
+ assert_config_read_from(ENV['HOME'] + "/newrelic.yml")
81
+ end
82
+
83
+ def test_config_loads_from_home_dot_newrelic_newrelic_yml
84
+ assert_config_read_from(ENV['HOME'] + "/.newrelic/newrelic.yml")
85
+ end
86
+
87
+ def test_config_loads_from_env_NRCONFIG
88
+ ENV["NRCONFIG"] = "/tmp/foo/bar.yml"
89
+ assert_config_read_from("/tmp/foo/bar.yml")
90
+ ensure
91
+ ENV["NRCONFIG"] = nil
92
+ end
93
+
94
+ def test_config_isnt_loaded_from_somewhere_crazy
95
+ assert_config_not_read_from(File.dirname(__FILE__) + "/somewhere/crazy/newrelic.yml")
96
+ end
97
+
98
+ def test_config_will_load_settings_for_environment_passed_manual_start
99
+ path = File.dirname(__FILE__) + "/config/newrelic.yml"
100
+
101
+ # pass an env key to NewRelic::Agent.manual_start which should cause it to
102
+ # load that section of newrelic.yml
103
+ setup_config(path, {:env => 'bazbangbarn'} )
104
+ assert_equal 'bazbangbarn', NewRelic::Agent.config[:i_am], "Agent.config did not load bazbangbarn config as requested"
105
+ end
106
+ end
@@ -0,0 +1,8 @@
1
+ suite_condition("Datamapper not supported in 1.8.6") do
2
+ RUBY_VERSION != '1.8.6'
3
+ end
4
+
5
+ gemfile <<-RB
6
+ gem 'datamapper'
7
+ RB
8
+
@@ -0,0 +1,22 @@
1
+ ---
2
+ development:
3
+ error_collector:
4
+ capture_source: true
5
+ enabled: true
6
+ apdex_t: 0.5
7
+ ssl: false
8
+ monitor_mode: true
9
+ license_key: bootstrap_newrelic_admin_license_key_000
10
+ developer_mode: false
11
+ app_name: test
12
+ host: 127.0.0.1
13
+ api_host: 127.0.0.1
14
+ port: 30303
15
+ transaction_tracer:
16
+ record_sql: obfuscated
17
+ enabled: true
18
+ stack_trace_threshold: 0.5
19
+ transaction_threshold: 1.0
20
+ capture_params: false
21
+ log_level: debug
22
+ log_file_path: agent.log