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,131 @@
1
+ require 'timeout'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
3
+ require 'new_relic/agent/pipe_channel_manager'
4
+
5
+ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
6
+ def setup
7
+ @test_config = { :developer_mode => true }
8
+ NewRelic::Agent.config.apply_config(@test_config)
9
+ NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
10
+ NewRelic::Agent.manual_start
11
+ end
12
+
13
+ def teardown
14
+ NewRelic::Agent::PipeChannelManager.listener.stop
15
+ NewRelic::Agent.shutdown
16
+ NewRelic::Agent.config.remove_config(@test_config)
17
+ end
18
+
19
+ def test_registering_a_pipe
20
+ NewRelic::Agent::PipeChannelManager.listener.wake.in.expects(:<<).with('.')
21
+ NewRelic::Agent::PipeChannelManager.register_report_channel(1)
22
+ pipe = NewRelic::Agent::PipeChannelManager.channels[1]
23
+
24
+ assert pipe.out.kind_of?(IO)
25
+ assert pipe.in.kind_of?(IO)
26
+
27
+ NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
28
+ end
29
+
30
+ if NewRelic::LanguageSupport.can_fork? && !NewRelic::LanguageSupport.using_version?('1.9.1')
31
+ def test_listener_merges_timeslice_metrics
32
+ metric = 'Custom/test/method'
33
+ engine = NewRelic::Agent.agent.stats_engine
34
+ engine.get_stats_no_scope(metric).record_data_point(1.0)
35
+
36
+ listener = start_listener_with_pipe(666)
37
+
38
+ pid = Process.fork do
39
+ NewRelic::Agent.after_fork
40
+ new_engine = NewRelic::Agent::StatsEngine.new
41
+ new_engine.get_stats_no_scope(metric).record_data_point(2.0)
42
+ listener.pipes[666].write(:stats => new_engine.harvest_timeslice_data({}, {}))
43
+ end
44
+ Process.wait(pid)
45
+ listener.stop
46
+
47
+ assert_equal(3.0, engine.lookup_stats(metric).total_call_time)
48
+ engine.reset_stats
49
+ end
50
+
51
+ def test_listener_merges_transaction_traces
52
+ sampler = NewRelic::Agent.agent.transaction_sampler
53
+ TransactionSampleTestHelper.run_sample_trace_on(sampler)
54
+ NewRelic::Agent.agent.merge_data_from([nil, [sampler.samples], nil])
55
+
56
+ assert_equal(1, NewRelic::Agent.agent.unsent_traces_size)
57
+
58
+ listener = start_listener_with_pipe(667)
59
+
60
+ pid = Process.fork do
61
+ NewRelic::Agent.after_fork
62
+ new_sampler = NewRelic::Agent::TransactionSampler.new
63
+ sample = TransactionSampleTestHelper.run_sample_trace_on(new_sampler)
64
+ new_sampler.store_force_persist(sample)
65
+ with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
66
+ listener.pipes[667].write(:transaction_traces => new_sampler.harvest([]))
67
+ end
68
+ end
69
+ Process.wait(pid)
70
+ listener.stop
71
+
72
+ assert_equal(2, NewRelic::Agent.agent.unsent_traces_size)
73
+ end
74
+
75
+ def test_listener_merges_error_traces
76
+ sampler = NewRelic::Agent.agent.error_collector
77
+ sampler.notice_error(Exception.new("message"), :uri => '/myurl/',
78
+ :metric => 'path', :referer => 'test_referer',
79
+ :request_params => {:x => 'y'})
80
+ NewRelic::Agent.agent.merge_data_from([nil, nil, [sampler.errors]])
81
+
82
+ assert_equal(1, NewRelic::Agent.agent.unsent_errors_size)
83
+
84
+ listener = start_listener_with_pipe(668)
85
+
86
+ pid = Process.fork do
87
+ NewRelic::Agent.after_fork
88
+ new_sampler = NewRelic::Agent::ErrorCollector.new
89
+ new_sampler.notice_error(Exception.new("new message"), :uri => '/myurl/',
90
+ :metric => 'path', :referer => 'test_referer',
91
+ :request_params => {:x => 'y'})
92
+ listener.pipes[668].write(:error_traces => new_sampler.harvest_errors([]))
93
+ end
94
+ Process.wait(pid)
95
+ listener.stop
96
+
97
+ assert_equal(2, NewRelic::Agent.agent.unsent_errors_size)
98
+ end
99
+
100
+ def test_close_pipe_on_EOF_string
101
+ listener = start_listener_with_pipe(669)
102
+
103
+ pid = Process.fork do
104
+ listener.pipes[669].write('EOF')
105
+ end
106
+ Process.wait(pid)
107
+ listener.stop
108
+
109
+ assert(!NewRelic::Agent::PipeChannelManager.channels[669] ||
110
+ NewRelic::Agent::PipeChannelManager.channels[669].closed?)
111
+ end
112
+
113
+ def test_manager_does_not_crash_when_given_bad_data
114
+ listener = start_listener_with_pipe(670)
115
+ assert_nothing_raised do
116
+ pid = Process.fork do
117
+ listener.pipes[670].in << 'some unloadable garbage'
118
+ end
119
+ Process.wait(pid)
120
+ listener.stop
121
+ end
122
+ end
123
+ end
124
+
125
+ def start_listener_with_pipe(pipe_id)
126
+ listener = NewRelic::Agent::PipeChannelManager.listener
127
+ listener.start
128
+ listener.register_pipe(pipe_id)
129
+ listener
130
+ end
131
+ end
@@ -0,0 +1,113 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
2
+
3
+ class PipeServiceTest < Test::Unit::TestCase
4
+ def setup
5
+ NewRelic::Agent::PipeChannelManager.listener.stop
6
+ NewRelic::Agent::PipeChannelManager.register_report_channel(:pipe_service_test)
7
+ @service = NewRelic::Agent::PipeService.new(:pipe_service_test)
8
+ end
9
+
10
+ def test_constructor
11
+ assert_equal :pipe_service_test, @service.channel_id
12
+ end
13
+
14
+ def test_connect_returns_nil
15
+ assert_nil @service.connect({})
16
+ end
17
+
18
+ if NewRelic::LanguageSupport.can_fork? &&
19
+ !NewRelic::LanguageSupport.using_version?('1.9.1')
20
+
21
+ def test_metric_data
22
+ received_data = data_from_forked_process do
23
+ metric_data0 = generate_metric_data('Custom/something')
24
+ @service.metric_data(0.0, 0.1, metric_data0)
25
+ end
26
+
27
+ assert_equal 'Custom/something', received_data[:stats].keys.sort[0].name
28
+ end
29
+
30
+ def test_transaction_sample_data
31
+ received_data = data_from_forked_process do
32
+ @service.transaction_sample_data(['txn'])
33
+ end
34
+
35
+ assert_equal ['txn'], received_data[:transaction_traces]
36
+ end
37
+
38
+ def test_error_data
39
+ received_data = data_from_forked_process do
40
+ @service.error_data(['err'])
41
+ end
42
+ assert_equal ['err'], received_data[:error_traces]
43
+ end
44
+
45
+ def test_sql_trace_data
46
+ received_data = data_from_forked_process do
47
+ @service.sql_trace_data(['sql'])
48
+ end
49
+ assert_equal ['sql'], received_data[:sql_traces]
50
+ end
51
+
52
+ def test_multiple_writes_to_pipe
53
+ pid = Process.fork do
54
+ metric_data0 = generate_metric_data('Custom/something')
55
+ @service.metric_data(0.0, 0.1, metric_data0)
56
+ @service.transaction_sample_data(['txn0'])
57
+ @service.error_data(['err0'])
58
+ @service.sql_trace_data(['sql0'])
59
+ @service.shutdown(Time.now)
60
+ end
61
+ Process.wait(pid)
62
+
63
+ received_data = read_from_pipe
64
+
65
+ assert_equal 'Custom/something', received_data[:stats].keys.sort[0].name
66
+ assert_equal ['txn0'], received_data[:transaction_traces]
67
+ assert_equal ['err0'], received_data[:error_traces].sort
68
+ end
69
+
70
+ def test_shutdown_sends_EOF
71
+ received_data = data_from_forked_process do
72
+ @service.shutdown(Time.now)
73
+ end
74
+ assert_equal 'EOF', received_data[:EOF]
75
+ end
76
+
77
+ def test_shutdown_closes_pipe
78
+ data_from_forked_process do
79
+ @service.shutdown(Time.now)
80
+ assert NewRelic::Agent::PipeChannelManager \
81
+ .channels[:pipe_service_test].closed?
82
+ end
83
+ end
84
+ end
85
+
86
+ def generate_metric_data(metric_name, data=1.0)
87
+ engine = NewRelic::Agent::StatsEngine.new
88
+ engine.get_stats_no_scope(metric_name).record_data_point(data)
89
+ engine.harvest_timeslice_data({}, {}).values
90
+ end
91
+
92
+ def read_from_pipe
93
+ pipe = NewRelic::Agent::PipeChannelManager.channels[:pipe_service_test]
94
+ pipe.in.close
95
+ data = {}
96
+ while payload = pipe.out.gets("\n\n")
97
+ got = Marshal.load(payload)
98
+ if got == 'EOF'
99
+ got = {:EOF => 'EOF'}
100
+ end
101
+ data.merge!(got)
102
+ end
103
+ data
104
+ end
105
+
106
+ def data_from_forked_process
107
+ pid = Process.fork do
108
+ yield
109
+ end
110
+ Process.wait(pid)
111
+ read_from_pipe
112
+ end
113
+ end
@@ -34,21 +34,23 @@ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::Test
34
34
  end
35
35
 
36
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
37
+ with_config(:agent_enabled => true) do
38
+ @agent = NewRelic::Agent::ShimAgent.instance
39
+ @agent.shutdown
40
+ assert (not @agent.started?)
41
+ @agent.start
42
+ assert !@agent.started?
43
+ # this installs the real agent:
44
+ NewRelic::Agent.manual_start
45
+ @agent = NewRelic::Agent.instance
46
+ assert @agent != NewRelic::Agent::ShimAgent.instance
47
+ assert @agent.started?
48
+ @agent.shutdown
49
+ assert !@agent.started?
50
+ @agent.start
51
+ assert @agent.started?
52
+ NewRelic::Agent.shutdown
53
+ end
52
54
  end
53
55
 
54
56
  should "manual_start" do
@@ -67,26 +69,30 @@ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::Test
67
69
  end
68
70
  should "manual_overrides" do
69
71
  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
+ assert_equal "testjobs", NewRelic::Agent.config.app_names[0]
73
+ assert_equal "mailer", NewRelic::Control.instance.local_env.dispatcher_instance_id
72
74
  NewRelic::Agent.shutdown
73
75
  end
74
76
 
75
77
  should "restart" do
76
78
  NewRelic::Agent.manual_start :app_name => "noapp", :dispatcher_instance_id => ""
77
79
  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
+ assert_equal "testjobs", NewRelic::Agent.config.app_names[0]
81
+ assert_equal "mailer", NewRelic::Control.instance.local_env.dispatcher_instance_id
80
82
  NewRelic::Agent.shutdown
81
83
  end
82
84
 
83
85
  should "send_timeslice_data" do
84
86
  # this test fails due to a rubinius bug
85
87
  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)
88
+ @agent.service = NewRelic::FakeService.new
89
+ @agent.service.expects(:metric_data).returns([ [{'name' => '/A/b/c'}, 1],
90
+ [{'name' => '/A/b/c', 'scope' => '/X'}, 2],
91
+ [{'name' => '/A/b/d'}, 3] ])
87
92
  @agent.send :harvest_and_send_timeslice_data
88
93
  assert_equal 3, @agent.metric_ids.size
89
- assert_equal 3, @agent.metric_ids[NewRelic::MetricSpec.new("/A/b/d") ], @agent.metric_ids.inspect
94
+ assert_equal(3, @agent.metric_ids[NewRelic::MetricSpec.new('/A/b/d')],
95
+ @agent.metric_ids.inspect)
90
96
  end
91
97
  should "set_record_sql" do
92
98
  @agent.set_record_sql(false)
@@ -106,34 +112,6 @@ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::Test
106
112
  assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
107
113
  end
108
114
 
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
115
  context "with transaction api" do
138
116
  should "reject empty arguments" do
139
117
  assert_raises RuntimeError do
@@ -143,7 +121,6 @@ class NewRelic::Agent::RpmAgentTest < Test::Unit::TestCase # ActiveSupport::Test
143
121
  should "record a transaction" do
144
122
  NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
145
123
  end
146
-
147
124
  end
148
125
  end
149
126
  end
@@ -1,7 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
2
 
3
3
  class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
4
-
5
4
  def setup
6
5
  agent = NewRelic::Agent.instance
7
6
  stats_engine = NewRelic::Agent::StatsEngine.new
@@ -10,17 +9,17 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
10
9
  @connection = stub('ActiveRecord connection', :execute => 'result')
11
10
  NewRelic::Agent::Database.stubs(:get_connection).returns(@connection)
12
11
  end
13
-
12
+
14
13
  def test_notice_first_scope_push
15
- assert_nil @sampler.transaction_data
14
+ assert_nil @sampler.transaction_data
16
15
  @sampler.notice_first_scope_push nil
17
16
  assert_not_nil @sampler.transaction_data
18
17
  @sampler.notice_scope_empty
19
18
  assert_nil @sampler.transaction_data
20
19
  end
21
-
20
+
22
21
  def test_notice_sql_no_transaction
23
- assert_nil @sampler.transaction_data
22
+ assert_nil @sampler.transaction_data
24
23
  @sampler.notice_sql "select * from test", "Database/test/select", nil, 10
25
24
  end
26
25
 
@@ -33,45 +32,45 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
33
32
  assert_not_nil @sampler.transaction_data
34
33
  assert_equal 2, @sampler.transaction_data.sql_data.size
35
34
  end
36
-
35
+
37
36
  def test_harvest_slow_sql
38
37
  data = NewRelic::Agent::TransactionSqlData.new
39
38
  data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
40
39
  'guid')
41
40
  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),
41
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
42
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
44
43
  NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)
45
44
  ]
46
45
  @sampler.harvest_slow_sql data
47
-
46
+
48
47
  assert_equal 2, @sampler.sql_traces.size
49
48
  end
50
-
49
+
51
50
  def test_sql_aggregation
52
- sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
51
+ sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
53
52
  NewRelic::Agent::SlowSql.new("select * from test",
54
53
  "Database/test/select", {}, 1.2),
55
54
  "tx_name", "uri")
56
-
55
+
57
56
  sql_trace.aggregate NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5), "slowest_tx_name", "slow_uri"
58
57
  sql_trace.aggregate NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.1), "other_tx_name", "uri2"
59
-
58
+
60
59
  assert_equal 3, sql_trace.call_count
61
60
  assert_equal "slowest_tx_name", sql_trace.path
62
61
  assert_equal "slow_uri", sql_trace.url
63
62
  assert_equal 1.5, sql_trace.max_call_time
64
63
  end
65
-
64
+
66
65
  def test_harvest
67
66
  data = NewRelic::Agent::TransactionSqlData.new
68
67
  data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
69
68
  '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),
69
+ data.sql_data.concat [NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
70
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
72
71
  NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)]
73
72
  @sampler.harvest_slow_sql data
74
-
73
+
75
74
  sql_traces = @sampler.harvest
76
75
  assert_equal 2, sql_traces.size
77
76
  end
@@ -83,10 +82,10 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
83
82
  data.sql_data << NewRelic::Agent::SlowSql.new("select * from test#{(i+97).chr}",
84
83
  "Database/test#{(i+97).chr}/select", {}, i)
85
84
  end
86
-
85
+
87
86
  @sampler.harvest_slow_sql data
88
87
  result = @sampler.harvest
89
-
88
+
90
89
  assert_equal(10, result.size)
91
90
  assert_equal(14, result.sort{|a,b| b.max_call_time <=> a.max_call_time}.first.total_call_time)
92
91
  end
@@ -96,13 +95,13 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
96
95
  data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
97
96
  'guid')
98
97
  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),
98
+ NewRelic::Agent::SlowSql.new("select * from test where foo in (1, 2) ", "Database/test/select", {}, 1.5),
99
+ NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2, 3 ,4, 5,6, 'snausage')", "Database/test/select", {}, 1.2),
101
100
  NewRelic::Agent::SlowSql.new("select * from test2 where foo in (1,2)", "Database/test2/select", {}, 1.1)
102
101
  ]
103
102
  data.sql_data.concat(queries)
104
103
  @sampler.harvest_slow_sql data
105
-
104
+
106
105
  sql_traces = @sampler.harvest
107
106
  assert_equal 2, sql_traces.size
108
107
  end
@@ -117,19 +116,19 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
117
116
  data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
118
117
  'guid')
119
118
  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),
119
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
120
+ NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
122
121
  NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)
123
122
  ]
124
123
  data.sql_data.concat(queries)
125
- @sampler.harvest_slow_sql data
124
+ @sampler.harvest_slow_sql data
126
125
  sql_traces = @sampler.harvest
127
126
  assert_equal(["header0", "header1", "header2"],
128
127
  sql_traces[0].params[:explain_plan][0].sort)
129
128
  assert_equal(["header0", "header1", "header2"],
130
129
  sql_traces[1].params[:explain_plan][0].sort)
131
130
  assert_equal(["foo0", "foo1", "foo2"],
132
- sql_traces[0].params[:explain_plan][1][0].sort)
131
+ sql_traces[0].params[:explain_plan][1][0].sort)
133
132
  assert_equal(["bar0", "bar1", "bar2"],
134
133
  sql_traces[1].params[:explain_plan][1][0].sort)
135
134
  end
@@ -145,48 +144,74 @@ class NewRelic::Agent::SqlSamplerTest < Test::Unit::TestCase
145
144
  assert_equal(NewRelic::Agent.instance.transaction_sampler.builder.sample.guid,
146
145
  NewRelic::Agent.instance.sql_sampler.transaction_data.guid)
147
146
  end
148
-
147
+
149
148
  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 }
149
+ with_config(:'transaction_tracer.explain_enabled' => false) do
150
+ data = NewRelic::Agent::TransactionSqlData.new
151
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
152
+ 'guid')
153
+
154
+ queries = [
155
+ NewRelic::Agent::SlowSql.new("select * from test",
156
+ "Database/test/select", {}, 1.5)
157
+ ]
158
+ data.sql_data.concat(queries)
159
+ @sampler.harvest_slow_sql data
160
+ sql_traces = @sampler.harvest
161
+ assert_equal(nil, sql_traces[0].params[:explain_plan])
162
+ end
164
163
  end
165
164
 
166
165
  def test_sql_id_fits_in_a_mysql_int_11
167
- sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
166
+ sql_trace = NewRelic::Agent::SqlTrace.new("select * from test",
168
167
  NewRelic::Agent::SlowSql.new("select * from test",
169
168
  "Database/test/select", {}, 1.2),
170
169
  "tx_name", "uri")
171
-
170
+
172
171
  assert -2147483648 <= sql_trace.sql_id, "sql_id too small"
173
172
  assert 2147483647 >= sql_trace.sql_id, "sql_id too large"
174
173
  end
175
174
 
176
175
  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
176
+ with_config(:'transaction_tracer.record_sql' => 'obfuscated') do
177
+ data = NewRelic::Agent::TransactionSqlData.new
178
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
179
+ 'guid')
180
+ data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test where foo = 'bar'",
181
+ "Database/test/select", {}, 1.5),
182
+ NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
183
+ "Database/test/select", {}, 1.2)])
184
+ @sampler.harvest_slow_sql(data)
185
+ sql_traces = @sampler.harvest
186
+
187
+ assert_equal('select * from test where foo = ?', sql_traces[0].sql)
188
+ assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
189
+ end
190
+ end
188
191
 
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)
192
+ def test_to_collector_array
193
+ with_config(:'transaction_tracer.explain_enabled' => false) do
194
+ data = NewRelic::Agent::TransactionSqlData.new
195
+ data.set_transaction_info("WebTransaction/Controller/c/a", "/c/a", {},
196
+ 'guid')
197
+ data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
198
+ "Database/test/select",
199
+ {}, 1.5)])
200
+ @sampler.harvest_slow_sql(data)
201
+ sql_traces = @sampler.harvest
202
+
203
+ params = RUBY_VERSION >= '1.9.2' ? "eJyrrgUAAXUA+Q==\n" : {}
204
+ expected = [ 'WebTransaction/Controller/c/a', '/c/a', 526336943,
205
+ 'select * from test', 'Database/test/select',
206
+ 1, 1500, 1500, 1500, params ]
207
+
208
+ if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
209
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
210
+ else
211
+ marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
212
+ end
213
+
214
+ assert_equal expected, sql_traces[0].to_collector_array(marshaller.default_encoder)
215
+ end
191
216
  end
192
217
  end