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,102 @@
1
+ require 'test/unit'
2
+ require "rack/test"
3
+ require 'new_relic/rack/browser_monitoring'
4
+ require 'benchmark'
5
+
6
+ class MyApp
7
+ # allow tests to set up the response they want.
8
+ class << self
9
+ def reset_headers
10
+ @headers = {'Content-Type' => 'text/html'}
11
+ end
12
+ attr_accessor :response
13
+ attr_accessor :headers
14
+ def add_header(key, value)
15
+ @headers[key] = value
16
+ @headers
17
+ end
18
+ end
19
+
20
+
21
+
22
+ def call(env)
23
+ [200, self.class.headers, [self.class.response]]
24
+ end
25
+ end
26
+
27
+ NewRelic::Agent.manual_start(:browser_key => 'browserKey', :application_id => 'appId',
28
+ :beacon => 'beacon', :episodes_file => 'this_is_my_file')
29
+ NewRelic::Agent.instance.instance_eval do
30
+ @beacon_configuration = NewRelic::Agent::BeaconConfiguration.new
31
+ end
32
+
33
+ class RumAutoTest < Test::Unit::TestCase
34
+ def setup
35
+ MyApp.reset_headers
36
+ end
37
+
38
+ include Rack::Test::Methods
39
+
40
+ def app
41
+ NewRelic::Rack::BrowserMonitoring.new(MyApp.new)
42
+ end
43
+
44
+
45
+ def test_autoinstrumenation_is_active
46
+ MyApp.response = "<html><head><title>W00t!</title></head><body><p>Hello World</p></body></html>"
47
+ get '/'
48
+ assert(last_response.body =~ %r|<script|, "response body should include RUM auto instrumentation js:\n #{last_response.body}")
49
+ assert(last_response.body =~ %r|NREUMQ|, "response body should include RUM auto instrumentation js:\n #{last_response.body}")
50
+ end
51
+
52
+ def test_autoinstrumenation_with_basic_page_puts_header_at_beggining_of_head
53
+ MyApp.response = "<html><head><title>foo</title></head><body><p>Hello World</p></body></html>"
54
+ get '/'
55
+ assert(last_response.body.include?('<html><head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script><title>foo</title></head><body>'))
56
+ end
57
+
58
+ def test_autoinstrumenation_with_body_only_puts_header_before_body
59
+ MyApp.response = "<html><body><p>Hello World</p></body></html>"
60
+ get '/'
61
+ assert(last_response.body.include?('<html><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script><body>'))
62
+ end
63
+
64
+ def test_autoinstrumenation_with_X_UA_Compatible_puts_header_at_end_of_head
65
+ MyApp.response = '<html><head><meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" /></head><body><p>Hello World</p></body></html>'
66
+ get '/'
67
+ assert(last_response.body.include?(
68
+ '<html><head><meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" /><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script></head><body>'
69
+ ))
70
+ end
71
+
72
+ # regression
73
+ def test_autoinstrumenation_fails_gracefully_with_X_UA_Compatible_and_no_close_head_tag_puts_header_before_body_tag
74
+ MyApp.response = '<html><head><meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" /><body><p>Hello World</p></body></html>'
75
+ get '/'
76
+ assert(!last_response.body.include?(%'NREUMQ'))
77
+ end
78
+
79
+ def test_autoinstrumenation_doesnt_run_for_crazy_shit_like_this
80
+ MyApp.response = '<html><head <body </body>'
81
+ get '/'
82
+ assert_equal('<html><head <body </body>', last_response.body)
83
+ end
84
+
85
+ def test_content_length_is_correctly_set_if_present
86
+ MyApp.response = "<html><head><title>W00t!</title></head><body><p>Hello World</p></body></html>"
87
+ content_length = MyApp.response.length
88
+ MyApp.add_header("Content-Length", content_length)
89
+ get '/'
90
+ assert(last_response.headers['Content-Length'].to_i > content_length)
91
+ assert_equal(last_response.body.length.to_s, last_response.headers['Content-Length'])
92
+ end
93
+
94
+ def test_xml_responses_arent_instrumented
95
+ body = "<html><head><title>W00t!</title></head><body><p>Hello World</p></body></html>"
96
+ MyApp.response = body
97
+ MyApp.add_header("Content-Type", "text/xml")
98
+ get '/'
99
+ assert_equal(last_response.body, body)
100
+ end
101
+ end
102
+
@@ -0,0 +1,13 @@
1
+ suite_condition("Sinatra not compatible with 1.8.6") do
2
+ RUBY_VERSION != '1.8.6'
3
+ end
4
+
5
+ gemfile <<-RB
6
+ gem 'sinatra', '1.3.3'
7
+ gem 'rack-test', :require => 'rack/test'
8
+ RB
9
+
10
+ gemfile <<-RB
11
+ gem 'sinatra', '1.2.8'
12
+ gem 'rack-test', :require => 'rack/test'
13
+ RB
@@ -0,0 +1,24 @@
1
+ ---
2
+ development:
3
+ error_collector:
4
+ capture_source: true
5
+ enabled: true
6
+ apdex_t: 0.5
7
+ ssl: false
8
+ agent_enabled: true
9
+ monitor_mode: true
10
+ license_key: bootstrap_newrelic_admin_license_key_000
11
+ developer_mode: false
12
+ app_name: test
13
+ host: 127.0.0.1
14
+ api_host: 127.0.0.1
15
+ port: 30303
16
+ transaction_tracer:
17
+ record_sql: obfuscated
18
+ enabled: true
19
+ stack_trace_threshold: 0.5
20
+ transaction_threshold: 1.0
21
+ capture_params: false
22
+ log_level: debug
23
+ #log_file_path: STDOUT
24
+ disable_serialization: false
@@ -0,0 +1,77 @@
1
+
2
+ class SinatraTestApp < Sinatra::Base
3
+ get '/hello/:name' do |name|
4
+ name ||= 'world'
5
+ "hello #{name}"
6
+ end
7
+
8
+ get '/another_controller' do
9
+ "I'm another controller"
10
+ end
11
+
12
+ get '/slow_transaction' do
13
+ sleep 2
14
+ 'that was slow'
15
+ end
16
+
17
+ get '/agent_shutdown' do
18
+ NewRelic::Agent.shutdown
19
+ 'ok'
20
+ end
21
+ end
22
+
23
+ class SinatraMetricExplosionTest < Test::Unit::TestCase
24
+ include Rack::Test::Methods
25
+ include ::NewRelic::Agent::Instrumentation::Sinatra
26
+
27
+ def app
28
+ SinatraTestApp
29
+ end
30
+
31
+ def setup
32
+
33
+ # puts ::NewRelic::Agent.manual_start
34
+ # puts ::NewRelic::Agent.agent.started?.inspect
35
+ ::NewRelic::Agent.agent.stats_engine.clear_stats
36
+ end
37
+
38
+ def test_sinatra_returns_properly
39
+ get '/hello/world'
40
+ assert_equal 'hello world', last_response.body
41
+ end
42
+
43
+ def test_transaction_name_from_route
44
+ get '/hello/world'
45
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.map{|k| k.name}
46
+ assert metric_names.include?('Controller/Sinatra/SinatraTestApp/GET hello/([^/?#]+)')
47
+ assert metric_names.include?('Apdex/Sinatra/SinatraTestApp/GET hello/([^/?#]+)')
48
+ end
49
+
50
+ def test_transaction_name_from_path
51
+ get '/wrong'
52
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.map{|k| k.name}
53
+ assert metric_names.include?('Controller/Sinatra/SinatraTestApp/GET (unknown)')
54
+ assert metric_names.include?('Apdex/Sinatra/SinatraTestApp/GET (unknown)')
55
+ end
56
+
57
+ def test_transaction_name_does_not_explode
58
+ get '/hello/my%20darling'
59
+ get '/hello/my_honey'
60
+ get '/hello/my.ragtime.gal'
61
+ get '/hello/isitmeyourelookingfor?'
62
+ get '/another_controller'
63
+
64
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.
65
+ map{|k| k.name} - ['CPU/User Time', "Middleware/all", "WebFrontend/QueueTime", "WebFrontend/WebServer/all"]
66
+ assert_equal 6, metric_names.size, "Explosion detected in: #{metric_names.inspect}"
67
+ end
68
+
69
+ def test_does_not_break_when_no_verb_matches
70
+ assert_nothing_raised do
71
+ post '/some/garbage'
72
+ end
73
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.map{|k| k.name}
74
+ assert metric_names.include?('Controller/Sinatra/SinatraTestApp/POST (unknown)')
75
+ assert metric_names.include?('Apdex/Sinatra/SinatraTestApp/POST (unknown)')
76
+ end
77
+ end
@@ -0,0 +1,46 @@
1
+
2
+ class SinatraRouteTestApp < Sinatra::Base
3
+ configure do
4
+ # create a condition (sintra's version of a before_filter) that returns the
5
+ # value that was passed into it.
6
+ set :my_condition do |boolean|
7
+ condition do
8
+ halt 404 unless boolean
9
+ end
10
+ end
11
+ end
12
+
13
+ get '/user/login' do
14
+ "please log in"
15
+ end
16
+
17
+ # this action will always return 404 because of the condition.
18
+ get '/user/:id', :my_condition => false do |id|
19
+ "Welcome #{id}"
20
+ end
21
+ end
22
+
23
+ class SinatraRoutesTest < Test::Unit::TestCase
24
+ include Rack::Test::Methods
25
+ include ::NewRelic::Agent::Instrumentation::Sinatra
26
+
27
+ def app
28
+ SinatraRouteTestApp
29
+ end
30
+
31
+ def setup
32
+ ::NewRelic::Agent.manual_start
33
+ end
34
+
35
+ # https://support.newrelic.com/tickets/24779
36
+ def test_lower_priority_route_conditions_arent_applied_to_higher_priority_routes
37
+ get '/user/login'
38
+ assert_equal 200, last_response.status
39
+ assert_equal 'please log in', last_response.body
40
+ end
41
+
42
+ def test_conditions_are_applied_to_an_action_that_uses_them
43
+ get '/user/1'
44
+ assert_equal 404, last_response.status
45
+ end
46
+ end
@@ -0,0 +1,55 @@
1
+
2
+ class SinatraRouteTestApp < Sinatra::Base
3
+ configure do
4
+ # create a condition (sintra's version of a before_filter) that returns the
5
+ # value that was passed into it.
6
+ set :my_condition do |boolean|
7
+ condition do
8
+ halt 404 unless boolean
9
+ end
10
+ end
11
+ end
12
+
13
+ get '/user/login' do
14
+ "please log in"
15
+ end
16
+
17
+ # this action will always return 404 because of the condition.
18
+ get '/user/:id', :my_condition => false do |id|
19
+ "Welcome #{id}"
20
+ end
21
+ end
22
+
23
+ class SinatraTest < Test::Unit::TestCase
24
+ include Rack::Test::Methods
25
+ include ::NewRelic::Agent::Instrumentation::Sinatra
26
+
27
+ def app
28
+ SinatraRouteTestApp
29
+ end
30
+
31
+ def setup
32
+ ::NewRelic::Agent.manual_start
33
+ end
34
+
35
+ # https://support.newrelic.com/tickets/24779
36
+ def test_lower_priority_route_conditions_arent_applied_to_higher_priority_routes
37
+ get '/user/login'
38
+ assert_equal 200, last_response.status
39
+ assert_equal 'please log in', last_response.body
40
+ end
41
+
42
+ def test_conditions_are_applied_to_an_action_that_uses_them
43
+ get '/user/1'
44
+ assert_equal 404, last_response.status
45
+ end
46
+
47
+ def test_queue_time_headers_are_passed_to_agent
48
+ get '/user/login', {}, {"X-Request-Start" => 't=1234567890'}
49
+ metric_names = ::NewRelic::Agent.agent.stats_engine.stats_hash.keys.map{|k| k.name}
50
+ assert metric_names.include?("Middleware/all")
51
+ assert metric_names.include?("WebFrontend/QueueTime")
52
+ assert metric_names.include?("WebFrontend/WebServer/all")
53
+ assert ::NewRelic::Agent.agent.stats_engine.get_stats("WebFrontend/WebServer/all")
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require 'test/unit'
2
+ ENV['NEWRELIC_GEM_PATH'] = '../../../../../ruby_agent'
3
+
4
+ class MultiverseTest < Test::Unit::TestCase
5
+ RUNNER = File.expand_path(File.join(
6
+ File.dirname(__FILE__), '..', 'script', 'runner'))
7
+ TEST_SUITE_EXAMPLES_ROOT = File.expand_path(File.join(
8
+ File.dirname(__FILE__), 'suite_examples'))
9
+
10
+ # encapsulates state from a example test suite run
11
+ class SuiteRun
12
+ def initialize
13
+ @output = ''
14
+ end
15
+ attr_accessor :output, :exit_status
16
+ end
17
+
18
+ def suite_directory_for(name)
19
+ File.join(TEST_SUITE_EXAMPLES_ROOT, name.to_s)
20
+ end
21
+
22
+ def run_suite(suite)
23
+ ENV['SUITES_DIRECTORY'] = suite_directory_for(suite)
24
+ ENV['NEWRELIC_GEM_PATH'] = '../../../../../../..'
25
+ cmd = RUNNER
26
+ suite_run = SuiteRun.new
27
+ IO.popen(cmd) do |io|
28
+ while line = io.gets
29
+ suite_run.output << line
30
+ # print line # uncomment for debugging rake test:self
31
+ end
32
+ end
33
+ suite_run.exit_status = $?
34
+ suite_run
35
+ end
36
+
37
+ def test_suite_environments_are_isolated_from_each_other
38
+ run = run_suite('one')
39
+ assert_equal 0, run.exit_status, "Test suite should demonstrate that " <<
40
+ "gems loaded in for one suite don't " <<
41
+ "persist in the next suite\n"# + run.output
42
+ end
43
+
44
+ def test_failed_tests_mean_unsuccessful_exit_code_in_parent_with_fork_execute_mode
45
+ run = run_suite('two')
46
+ assert_not_equal 0, run.exit_status, "Failed test should mean unsucessful " <<
47
+ "exit status in parent \n" # + run.output
48
+ end
49
+
50
+ def test_failed_tests_mean_unsucessful_exit_code_in_parent_with_spawn_execute_mode
51
+ run = run_suite('three')
52
+ assert_not_equal 0, run.exit_status, "Failed test in spawn mode should mean unsucessful " <<
53
+ "exit status in parent \n" # + run.output
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ gemfile <<-RUBY
2
+ gem "timetrap"
3
+ RUBY
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ class ATest < Test::Unit::TestCase
3
+ def test_timetrap_is_loaded
4
+ assert Timetrap
5
+ end
6
+
7
+ def test_haml_is_not_loaded
8
+ assert !defined?(Haml)
9
+ end
10
+ end
11
+
@@ -0,0 +1,24 @@
1
+ ---
2
+ development:
3
+ browser_monitoring:
4
+ auto_instrument: true
5
+ error_collector:
6
+ capture_source: true
7
+ enabled: true
8
+ apdex_t: 0.5
9
+ ssl: false
10
+ monitor_mode: true
11
+ license_key: bootstrap_newrelic_admin_license_key_000
12
+ developer_mode: false
13
+ app_name: test
14
+ host: 127.0.0.1
15
+ api_host: 127.0.0.1
16
+ port: 30303
17
+ transaction_tracer:
18
+ record_sql: obfuscated
19
+ enabled: true
20
+ stack_trace_threshold: 0.5
21
+ transaction_threshold: 1.0
22
+ capture_params: false
23
+ log_level: debug
24
+ disable_serialization: false
@@ -0,0 +1,3 @@
1
+ gemfile <<-RUBY
2
+ gem "haml"
3
+ RUBY
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ class BTest < Test::Unit::TestCase
3
+ def test_timetrap_is_not_loaded
4
+ assert !defined?(Timetrap)
5
+ end
6
+
7
+ def test_haml_is_loaded
8
+ assert Haml
9
+ end
10
+ end
11
+
@@ -0,0 +1,24 @@
1
+ ---
2
+ development:
3
+ browser_monitoring:
4
+ auto_instrument: true
5
+ error_collector:
6
+ capture_source: true
7
+ enabled: true
8
+ apdex_t: 0.5
9
+ ssl: false
10
+ monitor_mode: true
11
+ license_key: bootstrap_newrelic_admin_license_key_000
12
+ developer_mode: false
13
+ app_name: test
14
+ host: 127.0.0.1
15
+ api_host: 127.0.0.1
16
+ port: 30303
17
+ transaction_tracer:
18
+ record_sql: obfuscated
19
+ enabled: true
20
+ stack_trace_threshold: 0.5
21
+ transaction_threshold: 1.0
22
+ capture_params: false
23
+ log_level: debug
24
+ disable_serialization: false