newrelic_rpm 3.9.1.236 → 3.9.2.239

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data.tar.gz.sig +2 -4
  2. data/CHANGELOG +96 -2
  3. data/lib/new_relic/agent.rb +47 -4
  4. data/lib/new_relic/agent/agent.rb +51 -26
  5. data/lib/new_relic/agent/agent_logger.rb +4 -0
  6. data/lib/new_relic/agent/configuration.rb +2 -32
  7. data/lib/new_relic/agent/configuration/default_source.rb +153 -118
  8. data/lib/new_relic/agent/configuration/dotted_hash.rb +52 -0
  9. data/lib/new_relic/agent/configuration/environment_source.rb +1 -1
  10. data/lib/new_relic/agent/configuration/manager.rb +101 -2
  11. data/lib/new_relic/agent/configuration/manual_source.rb +17 -0
  12. data/lib/new_relic/agent/configuration/server_source.rb +12 -4
  13. data/lib/new_relic/agent/configuration/yaml_source.rb +46 -22
  14. data/lib/new_relic/agent/cross_app_monitor.rb +1 -1
  15. data/lib/new_relic/agent/cross_app_tracing.rb +1 -1
  16. data/lib/new_relic/agent/database/obfuscation_helpers.rb +55 -14
  17. data/lib/new_relic/agent/database/obfuscator.rb +22 -7
  18. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +6 -8
  19. data/lib/new_relic/agent/error_collector.rb +24 -16
  20. data/lib/new_relic/agent/event_loop.rb +189 -0
  21. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +8 -17
  22. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -1
  24. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +17 -16
  25. data/lib/new_relic/agent/instrumentation/ignore_actions.rb +41 -0
  26. data/lib/new_relic/agent/instrumentation/merb/controller.rb +0 -11
  27. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +1 -1
  28. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +0 -8
  29. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -9
  30. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -18
  31. data/lib/new_relic/agent/instrumentation/rubyprof.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/sidekiq.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/sinatra.rb +12 -1
  34. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -1
  35. data/lib/new_relic/agent/method_tracer.rb +33 -39
  36. data/lib/new_relic/agent/new_relic_service.rb +35 -156
  37. data/lib/new_relic/agent/new_relic_service/encoders.rb +34 -0
  38. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +50 -0
  39. data/lib/new_relic/agent/new_relic_service/marshaller.rb +52 -0
  40. data/lib/new_relic/agent/new_relic_service/pruby_marshaller.rb +52 -0
  41. data/lib/new_relic/agent/threading/backtrace_node.rb +1 -1
  42. data/lib/new_relic/agent/traced_method_stack.rb +16 -2
  43. data/lib/new_relic/agent/transaction.rb +0 -4
  44. data/lib/new_relic/collection_helper.rb +2 -2
  45. data/lib/new_relic/control/frameworks/rails.rb +3 -0
  46. data/lib/new_relic/control/instrumentation.rb +6 -2
  47. data/lib/new_relic/json_wrapper.rb +47 -25
  48. data/lib/new_relic/language_support.rb +0 -4
  49. data/lib/new_relic/latest_changes.rb +2 -2
  50. data/lib/new_relic/rack/developer_mode.rb +4 -3
  51. data/lib/new_relic/recipes/capistrano3.rb +2 -2
  52. data/lib/new_relic/recipes/capistrano_legacy.rb +1 -1
  53. data/lib/new_relic/timer_lib.rb +1 -1
  54. data/lib/new_relic/version.rb +2 -2
  55. data/lib/tasks/config.html.erb +28 -0
  56. data/lib/tasks/config.rake +134 -0
  57. data/lib/tasks/config.text.erb +7 -0
  58. data/lib/tasks/install.rake +0 -63
  59. data/newrelic.yml +7 -0
  60. data/test/active_record_fixtures.rb +4 -4
  61. data/test/agent_helper.rb +58 -18
  62. data/test/environments/lib/environments/runner.rb +1 -1
  63. data/test/environments/rails21/Gemfile +1 -1
  64. data/test/environments/rails21/config/boot.rb +1 -1
  65. data/test/environments/rails22/Gemfile +1 -1
  66. data/test/environments/rails22/config/boot.rb +1 -1
  67. data/test/environments/rails23/config/boot.rb +2 -2
  68. data/test/environments/rails30/Gemfile +1 -1
  69. data/test/environments/rails31/Gemfile +1 -1
  70. data/test/environments/rails32/Gemfile +1 -1
  71. data/test/environments/rails40/Gemfile +1 -1
  72. data/test/environments/rails41/Gemfile +1 -1
  73. data/test/fixtures/cross_agent_tests/labels.json +104 -0
  74. data/test/fixtures/cross_agent_tests/sql_obfuscation/README.md +23 -0
  75. data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.obfuscated +1 -0
  76. data/test/fixtures/cross_agent_tests/sql_obfuscation/back_quoted_identifiers.mysql.sql +1 -0
  77. data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.obfuscated +1 -0
  78. data/test/fixtures/cross_agent_tests/sql_obfuscation/comment_delimiters_in_strings.sql +1 -0
  79. data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.obfuscated +1 -0
  80. data/test/fixtures/cross_agent_tests/sql_obfuscation/double_quoted_identifiers.postgres.sql +1 -0
  81. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.obfuscated +2 -0
  82. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comment_in_string.sql +2 -0
  83. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comments_with_quotes.obfuscated +1 -0
  84. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_line_comments_with_quotes.sql +2 -0
  85. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.obfuscated +1 -0
  86. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_cstyle.sql +1 -0
  87. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.obfuscated +2 -0
  88. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_doubledash.sql +2 -0
  89. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.obfuscated +1 -0
  90. data/test/fixtures/cross_agent_tests/sql_obfuscation/end_of_query_comment_hash.sql +1 -0
  91. data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.obfuscated +1 -0
  92. data/test/fixtures/cross_agent_tests/sql_obfuscation/escape_string_constants.postgres.sql +4 -0
  93. data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_double_quoted_string.mysql.sql +1 -0
  94. data/test/fixtures/cross_agent_tests/sql_obfuscation/malformed/unterminated_single_quoted_string.sql +1 -0
  95. data/test/fixtures/cross_agent_tests/sql_obfuscation/mixed_comments_and_quotes.obfuscated +1 -0
  96. data/test/fixtures/cross_agent_tests/sql_obfuscation/mixed_comments_and_quotes.sql +2 -0
  97. data/test/fixtures/cross_agent_tests/sql_obfuscation/mixed_quotes_comments_and_newlines.obfuscated +1 -0
  98. data/test/fixtures/cross_agent_tests/sql_obfuscation/mixed_quotes_comments_and_newlines.sql +4 -0
  99. data/test/fixtures/cross_agent_tests/sql_obfuscation/mixed_quotes_end_of_line_comments.obfuscated +1 -0
  100. data/test/fixtures/cross_agent_tests/sql_obfuscation/mixed_quotes_end_of_line_comments.sql +3 -0
  101. data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.obfuscated +1 -0
  102. data/test/fixtures/cross_agent_tests/sql_obfuscation/multiple_literal_types.mysql.sql +1 -0
  103. data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.obfuscated +1 -0
  104. data/test/fixtures/cross_agent_tests/sql_obfuscation/numbers_in_identifiers.sql +1 -0
  105. data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.obfuscated +1 -0
  106. data/test/fixtures/cross_agent_tests/sql_obfuscation/numeric_literals.sql +1 -0
  107. data/test/fixtures/cross_agent_tests/sql_obfuscation/quote_delimiters_in_comments.obfuscated +1 -0
  108. data/test/fixtures/cross_agent_tests/sql_obfuscation/quote_delimiters_in_comments.sql +1 -0
  109. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.obfuscated +1 -0
  110. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_double_quoted.mysql.sql +1 -0
  111. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.obfuscated +1 -0
  112. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_single_quoted.sql +1 -0
  113. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.obfuscated +1 -0
  114. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_backslash_and_twin_single_quotes.sql +4 -0
  115. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.obfuscated +1 -0
  116. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_double_quote.sql +1 -0
  117. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.obfuscated +1 -0
  118. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_newline.sql +2 -0
  119. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.obfuscated +1 -0
  120. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_embedded_single_quote.mysql.sql +1 -0
  121. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.obfuscated +1 -0
  122. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_escaped_quotes.mysql.sql +1 -0
  123. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.obfuscated +1 -0
  124. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_backslash.sql +4 -0
  125. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.obfuscated +1 -0
  126. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash.mysql.sql +1 -0
  127. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.obfuscated +1 -0
  128. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_backslash_single_quoted.sql +1 -0
  129. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.obfuscated +1 -0
  130. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_trailing_escaped_quote.sql +1 -0
  131. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.obfuscated +1 -0
  132. data/test/fixtures/cross_agent_tests/sql_obfuscation/string_with_twin_single_quotes.sql +1 -0
  133. data/test/multiverse/lib/multiverse/output_collector.rb +1 -1
  134. data/test/multiverse/lib/multiverse/runner.rb +1 -1
  135. data/test/multiverse/lib/multiverse/suite.rb +19 -4
  136. data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -38
  137. data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +25 -35
  138. data/test/multiverse/suites/agent_only/config/newrelic.yml +2 -0
  139. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +1 -0
  140. data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +1 -1
  141. data/test/multiverse/suites/agent_only/keepalive_test.rb +29 -0
  142. data/test/multiverse/suites/agent_only/labels_test.rb +89 -0
  143. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -3
  144. data/test/multiverse/suites/agent_only/service_timeout_test.rb +1 -1
  145. data/test/multiverse/suites/agent_only/start_up_test.rb +9 -1
  146. data/test/multiverse/suites/capistrano/config/deploy.rb +6 -2
  147. data/test/multiverse/suites/capistrano/deployment_test.rb +12 -4
  148. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +29 -1
  149. data/test/multiverse/suites/curb/Envfile +6 -2
  150. data/test/multiverse/suites/datamapper/Envfile +0 -4
  151. data/test/multiverse/suites/deferred_instrumentation/Envfile +0 -4
  152. data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +1 -1
  153. data/test/multiverse/suites/excon/Envfile +5 -4
  154. data/test/multiverse/suites/excon/excon_test.rb +1 -1
  155. data/test/multiverse/suites/httpclient/Envfile +0 -4
  156. data/test/multiverse/suites/marshalling/Envfile +12 -0
  157. data/test/multiverse/suites/marshalling/config/newrelic.yml +20 -0
  158. data/test/multiverse/suites/marshalling/marshalling_test.rb +60 -0
  159. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +1 -1
  160. data/test/multiverse/suites/mongo/helpers/mongo_replica_set.rb +1 -1
  161. data/test/multiverse/suites/mongo/helpers/mongo_server.rb +4 -4
  162. data/test/multiverse/suites/padrino/Envfile +0 -5
  163. data/test/multiverse/suites/padrino/padrino_test.rb +1 -1
  164. data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +1 -1
  165. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +2 -1
  166. data/test/multiverse/suites/rails/ignore_test.rb +22 -0
  167. data/test/multiverse/suites/rails/rails2_app/config/boot.rb +2 -2
  168. data/test/multiverse/suites/rails/rails2_app/config/routes.rb +1 -0
  169. data/test/multiverse/suites/resque/Envfile +0 -4
  170. data/test/multiverse/suites/sequel/Envfile +0 -5
  171. data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +1 -1
  172. data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +1 -1
  173. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +22 -0
  174. data/test/multiverse/suites/typhoeus/Envfile +1 -4
  175. data/test/new_relic/agent/agent/start_worker_thread_test.rb +1 -13
  176. data/test/new_relic/agent/agent_logger_test.rb +11 -0
  177. data/test/new_relic/agent/agent_test.rb +43 -20
  178. data/test/new_relic/agent/audit_logger_test.rb +7 -3
  179. data/test/new_relic/agent/commands/thread_profiler_session_test.rb +0 -1
  180. data/test/new_relic/agent/commands/xray_session_collection_test.rb +1 -1
  181. data/test/new_relic/agent/configuration/dotted_hash_test.rb +53 -0
  182. data/test/new_relic/agent/configuration/manager_test.rb +99 -6
  183. data/test/new_relic/agent/configuration/manual_source_test.rb +18 -0
  184. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +1 -1
  185. data/test/new_relic/agent/configuration/yaml_source_test.rb +8 -4
  186. data/test/new_relic/agent/database/sql_obfuscation_test.rb +76 -0
  187. data/test/new_relic/agent/database_test.rb +2 -38
  188. data/test/new_relic/agent/error_collector/notice_error_test.rb +21 -3
  189. data/test/new_relic/agent/error_collector_test.rb +15 -2
  190. data/test/new_relic/agent/event_loop_test.rb +202 -0
  191. data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +4 -0
  192. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +283 -182
  193. data/test/new_relic/agent/method_tracer_test.rb +1 -2
  194. data/test/new_relic/agent/new_relic_service_test.rb +83 -27
  195. data/test/new_relic/agent/pipe_channel_manager_test.rb +6 -6
  196. data/test/new_relic/agent/rpm_agent_test.rb +1 -8
  197. data/test/new_relic/agent/sql_sampler_test.rb +10 -8
  198. data/test/new_relic/agent/threading/backtrace_service_test.rb +1 -1
  199. data/test/new_relic/agent/traced_method_stack_test.rb +45 -13
  200. data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -2
  201. data/test/new_relic/agent/transaction_test.rb +3 -3
  202. data/test/new_relic/agent_test.rb +47 -8
  203. data/test/new_relic/collection_helper_test.rb +5 -5
  204. data/test/new_relic/control/instrumentation_test.rb +56 -0
  205. data/test/new_relic/control_test.rb +4 -3
  206. data/test/new_relic/fake_collector.rb +7 -2
  207. data/test/new_relic/http_client_test_cases.rb +4 -4
  208. data/test/new_relic/latest_changes_test.rb +3 -3
  209. data/test/new_relic/transaction_sample/segment_test.rb +0 -1
  210. data/test/new_relic/transaction_sample_test.rb +19 -2
  211. data/test/performance/lib/performance/runner.rb +4 -4
  212. data/test/performance/suites/marshalling.rb +46 -30
  213. data/test/performance/suites/sql_obfuscation.rb +30 -0
  214. data/test/test_helper.rb +1 -1
  215. data/ui/helpers/developer_mode_helper.rb +2 -2
  216. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/java.rb +1 -1
  217. data/vendor/gems/metric_parser-0.1.0.pre1/lib/new_relic/metric_parser/view.rb +1 -1
  218. metadata +84 -3
  219. metadata.gz.sig +0 -0
  220. data/test/environments/rails23/config/environments/development.rb +0 -11
@@ -13,6 +13,7 @@ module NewRelic
13
13
  include NewRelic::Agent::MethodTracer
14
14
 
15
15
  def setup
16
+ NewRelic::Agent.manual_start
16
17
  NewRelic::Agent.reset_config
17
18
  NewRelic::Agent.instance.stubs(:start_worker_thread)
18
19
  end
@@ -45,9 +46,10 @@ module NewRelic
45
46
  end
46
47
 
47
48
  def test_finish_setup_applied_server_side_config
48
- with_config({ :'transction_tracer.enabled' => true,
49
- 'error_collector.enabled' => true,
50
- :log_level => 'info' }, :level => 2) do
49
+ with_config_low_priority({
50
+ :'transction_tracer.enabled' => true,
51
+ :'error_collector.enabled' => true,
52
+ :log_level => 'info' }) do
51
53
  NewRelic::Agent.instance.finish_setup('log_level' => 'debug',
52
54
  'agent_config' => { 'transaction_tracer.enabled' => false },
53
55
  'collect_errors' => false)
@@ -104,13 +106,17 @@ module NewRelic
104
106
  NewRelic::Agent.get_stats_no_scope('Custom/test/metric')
105
107
  end
106
108
 
107
- def test_agent_not_started
108
- old_agent = NewRelic::Agent.agent
109
- NewRelic::Agent.instance_eval { @agent = nil }
110
- assert_raises(RuntimeError) do
109
+ def test_agent_logs_warning_when_not_started
110
+ with_unstarted_agent do
111
+ expects_logging(:warn, includes("hasn't been started"))
111
112
  NewRelic::Agent.agent
112
113
  end
113
- NewRelic::Agent.instance_eval { @agent = old_agent }
114
+ end
115
+
116
+ def test_agent_can_shut_down_when_not_started
117
+ with_unstarted_agent do
118
+ NewRelic::Agent.shutdown
119
+ end
114
120
  end
115
121
 
116
122
  def test_agent_when_started
@@ -176,6 +182,7 @@ module NewRelic
176
182
  end
177
183
 
178
184
  def test_instance
185
+ NewRelic::Agent.manual_start
179
186
  assert_equal(NewRelic::Agent.agent, NewRelic::Agent.instance, "should return the same agent for both identical methods")
180
187
  end
181
188
 
@@ -371,8 +378,40 @@ module NewRelic
371
378
  assert called
372
379
  end
373
380
 
381
+ # The assumption is that txn.ignore! works as expected, and is tested elsewhere.
382
+ def test_ignore_transaction_works
383
+ in_transaction do |txn|
384
+ NewRelic::Agent.ignore_transaction
385
+ assert txn.ignore?
386
+ end
387
+ end
388
+
389
+ # The assumption is that txn.ignore_apdex! works as expected, and is tested elsewhere.
390
+ def test_ignore_apdex_works
391
+ in_transaction do |txn|
392
+ NewRelic::Agent.ignore_apdex
393
+ assert txn.ignore_apdex?
394
+ end
395
+ end
396
+
397
+ # The assumption is that txn.ignore_enduser! works as expected, and is tested elsewhere.
398
+ def test_ignore_enduser_works
399
+ in_transaction do |txn|
400
+ NewRelic::Agent.ignore_enduser
401
+ assert txn.ignore_enduser?
402
+ end
403
+ end
404
+
374
405
  private
375
406
 
407
+ def with_unstarted_agent
408
+ old_agent = NewRelic::Agent.agent
409
+ NewRelic::Agent.instance_eval { @agent = nil }
410
+ yield
411
+ ensure
412
+ NewRelic::Agent.instance_eval { @agent = old_agent }
413
+ end
414
+
376
415
  def mocked_agent
377
416
  agent = mock('agent')
378
417
  NewRelic::Agent.stubs(:agent).returns(agent)
@@ -50,7 +50,7 @@ class NewRelic::CollectionHelperTest < Minitest::Test
50
50
  assert_equal String, truncate(s, 2).class
51
51
  end
52
52
  def test_number
53
- np = normalize_params({ 'one' => 1.0, 'two' => '2'})
53
+ normalize_params({ 'one' => 1.0, 'two' => '2'})
54
54
  end
55
55
  def test_nil
56
56
  np = normalize_params({ nil => 1.0, 'two' => nil})
@@ -83,7 +83,7 @@ class NewRelic::CollectionHelperTest < Minitest::Test
83
83
  custom_params = { :one => {:hash => { :a => :b}, :myenum => e }}
84
84
  nh = normalize_params(custom_params)
85
85
  myenum = nh[:one][:myenum]
86
- assert_match /MyEnumerable/, myenum
86
+ assert_match(/MyEnumerable/, myenum)
87
87
  end
88
88
 
89
89
  def test_stringio
@@ -91,13 +91,13 @@ class NewRelic::CollectionHelperTest < Minitest::Test
91
91
  s = StringIO.new "start" + ("foo bar bat " * 1000)
92
92
  val = nil
93
93
  s.each { | entry | val = entry; break }
94
- assert_match /^startfoo bar/, val
94
+ assert_match(/^startfoo bar/, val)
95
95
 
96
96
  # make sure stringios aren't affected by calling normalize_params:
97
97
  s = StringIO.new "start" + ("foo bar bat " * 1000)
98
- v = normalize_params({ :foo => s.string })
98
+ normalize_params({ :foo => s.string })
99
99
  s.each { | entry | val = entry; break }
100
- assert_match /^startfoo bar/, val
100
+ assert_match(/^startfoo bar/, val)
101
101
  end
102
102
  class MyEnumerable
103
103
  include Enumerable
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
6
+ require 'new_relic/control/instrumentation'
7
+
8
+ class InstrumentationTestClass
9
+ include NewRelic::Control::Instrumentation
10
+
11
+ def initialize
12
+ @instrumentation_files = []
13
+ end
14
+ end
15
+
16
+ class NewRelic::Control::InstrumentationTest < Minitest::Test
17
+ def setup
18
+ @test_class = InstrumentationTestClass.new
19
+ end
20
+
21
+ def test_load_instrumentation_files_logs_errors_during_require
22
+ @test_class.stubs(:require).raises('Instrumentation Test Error')
23
+ expects_logging(:warn, includes("Error loading"), any_parameters)
24
+ @test_class.load_instrumentation_files '*'
25
+ end
26
+
27
+ def test_add_instrumentation_loads_the_instrumentation_files_if_instrumented
28
+ pattern = 'Instrumentation test pattern'
29
+ @test_class.instance_eval { @instrumented = true }
30
+ @test_class.expects(:load_instrumentation_files).with(pattern).once
31
+ @test_class.add_instrumentation(pattern)
32
+ end
33
+
34
+ def test_add_instrumentation_adds_pattern_to_instrumentation_files_if_uninstrumented
35
+ expected_pattern = 'Instrumentation test pattern'
36
+ @test_class.instance_eval { @instrumented = false }
37
+ @test_class.add_instrumentation(expected_pattern)
38
+ result = @test_class.instance_variable_get(:@instrumentation_files)
39
+ assert_equal [expected_pattern], result
40
+ end
41
+
42
+ def test_install_shim_logs_if_instrumentation_has_already_been_installed
43
+ @test_class.instance_eval { @instrumented = true }
44
+ expects_logging(:error, includes('Cannot install'))
45
+ @test_class.install_shim
46
+ end
47
+
48
+ def test_install_shim_does_not_set_agent_if_already_instrumented
49
+ fake_shim = "Instrumentation Test Shim Agent"
50
+ @test_class.instance_eval { @instrumented = true }
51
+ NewRelic::Agent::ShimAgent.class_eval { @instance = fake_shim }
52
+
53
+ @test_class.install_shim
54
+ refute_equal NewRelic::Agent.agent, fake_shim
55
+ end
56
+ end
@@ -31,7 +31,7 @@ class NewRelic::ControlTest < Minitest::Test
31
31
  def test_info
32
32
  NewRelic::Agent.manual_start
33
33
  if defined?(Rails::VERSION)
34
- assert_match /jdbc|postgres|mysql|sqlite/, NewRelic::EnvironmentReport.new["Database adapter"]
34
+ assert_match(/jdbc|postgres|mysql|sqlite/, NewRelic::EnvironmentReport.new["Database adapter"])
35
35
  end
36
36
  end
37
37
 
@@ -151,9 +151,10 @@ class NewRelic::ControlTest < Minitest::Test
151
151
  end
152
152
 
153
153
  def test_sql_tracer_disabled_when_tt_disabled_by_server
154
- with_config({:'slow_sql.enabled' => true,
154
+ with_config_low_priority({
155
+ :'slow_sql.enabled' => true,
155
156
  :'transaction_tracer.enabled' => true,
156
- :monitor_mode => true}, :level => 2) do
157
+ :monitor_mode => true}) do
157
158
  NewRelic::Agent.instance.finish_setup('collect_traces' => false)
158
159
 
159
160
  refute NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
@@ -104,7 +104,7 @@ module NewRelic
104
104
 
105
105
  if uri.path =~ /agent_listener\/\d+\/.+\/(\w+)/
106
106
  method = $1
107
- format = json_format?(uri) && RUBY_VERSION >= '1.9' ? :json : :pruby
107
+ format = json_format?(uri) ? :json : :pruby
108
108
  if @mock.keys.include? method
109
109
  status, body = @mock[method].evaluate
110
110
  res.status = status
@@ -133,8 +133,13 @@ module NewRelic
133
133
  # rely on strings to compare against in fake collector results.
134
134
  body = NewRelic::JSONWrapper.normalize(body)
135
135
  end
136
- rescue => err
136
+ rescue
137
137
  body = "UNABLE TO DECODE BODY: #{raw_body}"
138
+
139
+ # Since this is for testing, output failure at this point. If we
140
+ # don't your only evidence of a problem is in obscure test failures
141
+ # from not receiving the data you expect.
142
+ puts body
138
143
  end
139
144
 
140
145
  @agent_data << AgentPost.create(:action => method,
@@ -183,7 +183,7 @@ module HttpClientTestCases
183
183
 
184
184
  def test_transactional_traces_nodes
185
185
  perform_action_with_newrelic_trace(:name => "task") do
186
- res = get_response
186
+ get_response
187
187
 
188
188
  last_segment = find_last_transaction_segment()
189
189
  assert_equal "External/localhost/#{client_name}/GET", last_segment.metric_name
@@ -193,7 +193,7 @@ module HttpClientTestCases
193
193
  def test_ignore
194
194
  in_transaction do
195
195
  NewRelic::Agent.disable_all_tracing do
196
- res = post_response
196
+ post_response
197
197
  end
198
198
  end
199
199
 
@@ -201,7 +201,7 @@ module HttpClientTestCases
201
201
  end
202
202
 
203
203
  def test_head
204
- res = head_response
204
+ head_response
205
205
  assert_externals_recorded_for("localhost", "HEAD")
206
206
  end
207
207
 
@@ -466,7 +466,7 @@ module HttpClientTestCases
466
466
  in_transaction do
467
467
  begin
468
468
  get_response("http://localhost:#{evil_server.port}")
469
- rescue => e
469
+ rescue
470
470
  # it's expected that this will raise for some HTTP libraries (e.g.
471
471
  # Net::HTTP). we unfortunately don't know the exact exception class
472
472
  # across all libraries
@@ -20,13 +20,13 @@ module NewRelic
20
20
 
21
21
  def test_read_default_changelog
22
22
  result = NewRelic::LatestChanges.read
23
- assert_match /# New Relic Ruby Agent Release Notes #/, result
24
- assert_match /## v\d\.\d\.\d ##/, result
23
+ assert_match(/# New Relic Ruby Agent Release Notes #/, result)
24
+ assert_match(/## v\d\.\d\.\d ##/, result)
25
25
  end
26
26
 
27
27
  def test_latest_changes_from_fakechangelog
28
28
  result = NewRelic::LatestChanges.read(File.join(File.dirname(__FILE__), 'FAKECHANGELOG'))
29
- assert_match /3.7.2/, result
29
+ assert_match(/3.7.2/, result)
30
30
  end
31
31
 
32
32
  def test_patch_latest_changes_from_fakechangelog
@@ -319,7 +319,6 @@ class NewRelic::TransactionSample::SegmentTest < Minitest::Test
319
319
  statement.config = config
320
320
  statement.explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
321
321
  s.params = {:sql => statement}
322
- connection = mock('connection')
323
322
  NewRelic::Agent::Database.expects(:get_connection).with(config).raises(RuntimeError.new("whee"))
324
323
  s.explain_sql
325
324
  end
@@ -270,7 +270,15 @@ class NewRelic::TransactionSampleTest < Minitest::Test
270
270
  trace_tree,
271
271
  @t.guid, nil, !!@t.force_persist, @t.xray_session_id]
272
272
 
273
- assert_equal expected_array, @t.to_collector_array(@marshaller.default_encoder)
273
+ assert_collector_arrays_match expected_array, @t.to_collector_array(@marshaller.default_encoder)
274
+
275
+ end
276
+
277
+ def assert_collector_arrays_match(expected_array, actual_array)
278
+ expected_array[4] = expand_trace_tree(expected_array[4])
279
+ actual_array[4] = expand_trace_tree(actual_array[4])
280
+
281
+ assert_equal expected_array, actual_array
274
282
  end
275
283
 
276
284
  FORCE_PERSIST_POSITION = 7
@@ -294,7 +302,8 @@ class NewRelic::TransactionSampleTest < Minitest::Test
294
302
  transaction.guid,
295
303
  nil, false, nil]
296
304
 
297
- assert_equal expected, transaction.to_collector_array(@marshaller.default_encoder)
305
+ actual = transaction.to_collector_array(@marshaller.default_encoder)
306
+ assert_collector_arrays_match expected, actual
298
307
  end
299
308
 
300
309
  INVALID_UTF8_STRING = (''.respond_to?(:force_encoding) ? "\x80".force_encoding('UTF-8') : "\x80")
@@ -324,6 +333,14 @@ class NewRelic::TransactionSampleTest < Minitest::Test
324
333
  Base64.encode64(Zlib::Deflate.deflate(string, Zlib::DEFAULT_COMPRESSION))
325
334
  end
326
335
 
336
+ def expand_trace_tree(encoded_tree)
337
+ if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
338
+ JSON.load(Zlib::Inflate.inflate(Base64.decode64(encoded_tree)))
339
+ else
340
+ encoded_tree
341
+ end
342
+ end
343
+
327
344
  def extract_captured_sql(trace)
328
345
  sqls = []
329
346
  trace.each_segment do |s|
@@ -52,10 +52,10 @@ module Performance
52
52
  end
53
53
 
54
54
  def add_progress_callbacks(test_case)
55
- test_case.on(:before_each) do |test_case, name|
55
+ test_case.on(:before_each) do |_test_case, name|
56
56
  print "#{name}: "
57
57
  end
58
- test_case.on(:after_each) do |test_case, name, result|
58
+ test_case.on(:after_each) do |_test_case, name, result|
59
59
  print "#{result.elapsed} s\n"
60
60
  end
61
61
  end
@@ -104,7 +104,7 @@ module Performance
104
104
  filter = Regexp.new(@options[:name])
105
105
  methods = methods.select { |m| m.match(filter) }
106
106
  elsif @options[:identifier]
107
- suite, method = @options[:identifier].split('#')
107
+ _suite, method = @options[:identifier].split('#')
108
108
  methods = methods.select { |m| m == method }
109
109
  end
110
110
  methods
@@ -174,7 +174,7 @@ module Performance
174
174
 
175
175
  def suites_to_run
176
176
  if @options[:identifier]
177
- suite, method = @options[:identifier].split('#')
177
+ suite, _method = @options[:identifier].split('#')
178
178
  TestCase.subclasses.select { |cls| cls.name == suite }
179
179
  elsif @options[:suite]
180
180
  TestCase.subclasses.select { |cls| cls.name == @options[:suite] }
@@ -2,56 +2,64 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
+ require File.join(File.dirname(__FILE__), '..', '..', 'agent_helper')
6
+
5
7
  class Marshalling < Performance::TestCase
6
8
  def setup
7
9
  @payload = build_analytics_events_payload
8
10
  @tt_payload = build_transaction_trace_payload
9
11
  end
10
12
 
11
- skip_test :test_basic_marshalling_json, :platforms => :mri_18
12
-
13
13
  def test_basic_marshalling_json(timer)
14
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
15
- timer.measure do
16
- (iterations / 100).times do
17
- marshaller.dump(@payload)
18
- marshaller.dump(@tt_payload)
14
+ with_config(:normalize_json_string_encodings => true) do
15
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
16
+ timer.measure do
17
+ (iterations / 100).times do
18
+ marshaller.dump(@payload)
19
+ marshaller.dump(@tt_payload)
20
+ end
19
21
  end
20
22
  end
21
23
  end
22
24
 
23
25
  def test_json_marshalling_binary_strings(timer)
24
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
25
- convert_strings_to_binary(@payload)
26
- convert_strings_to_binary(@tt_payload)
27
- timer.measure do
28
- (iterations / 100).times do
29
- marshaller.dump(@payload)
30
- marshaller.dump(@tt_payload)
26
+ with_config(:normalize_json_string_encodings => true) do
27
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
28
+ convert_strings_to_binary(@payload)
29
+ convert_strings_to_binary(@tt_payload)
30
+ timer.measure do
31
+ (iterations / 100).times do
32
+ marshaller.dump(@payload)
33
+ marshaller.dump(@tt_payload)
34
+ end
31
35
  end
32
36
  end
33
37
  end
34
38
 
35
39
  def test_json_marshalling_utf16_strings(timer)
36
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
37
- convert_strings_to_utf16(@payload)
38
- convert_strings_to_utf16(@tt_payload)
39
- timer.measure do
40
- (iterations / 100).times do
41
- marshaller.dump(@payload)
42
- marshaller.dump(@tt_payload)
40
+ with_config(:normalize_json_string_encodings => true) do
41
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
42
+ convert_strings_to_utf16(@payload)
43
+ convert_strings_to_utf16(@tt_payload)
44
+ timer.measure do
45
+ (iterations / 100).times do
46
+ marshaller.dump(@payload)
47
+ marshaller.dump(@tt_payload)
48
+ end
43
49
  end
44
50
  end
45
51
  end
46
52
 
47
53
  def test_json_marshalling_latin1_strings(timer)
48
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
49
- convert_strings_to_latin1(@payload)
50
- convert_strings_to_latin1(@tt_payload)
51
- timer.measure do
52
- (iterations / 100).times do
53
- marshaller.dump(@payload)
54
- marshaller.dump(@tt_payload)
54
+ with_config(:normalize_json_string_encodings => true) do
55
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
56
+ convert_strings_to_latin1(@payload)
57
+ convert_strings_to_latin1(@tt_payload)
58
+ timer.measure do
59
+ (iterations / 100).times do
60
+ marshaller.dump(@payload)
61
+ marshaller.dump(@tt_payload)
62
+ end
55
63
  end
56
64
  end
57
65
  end
@@ -84,7 +92,8 @@ class Marshalling < Performance::TestCase
84
92
 
85
93
  def generate_random_string(length)
86
94
  bytes = []
87
- length.times { bytes << BYTE_ALPHABET.sample }
95
+ meth = BYTE_ALPHABET.respond_to?(:sample) ? :sample : :choice
96
+ length.times { bytes << BYTE_ALPHABET.send(meth) }
88
97
  bytes.pack("C*")
89
98
  end
90
99
 
@@ -96,11 +105,18 @@ class Marshalling < Performance::TestCase
96
105
 
97
106
  def convert_strings_to_utf16(object)
98
107
  each_string(object) do |s|
99
- s.encode!('UTF-16')
108
+ if s.respond_to?(:encode!)
109
+ s.encode!('UTF-16')
110
+ else
111
+ require 'iconv'
112
+ s.replace(Iconv.conv('UTF-16', 'UTF-8', s))
113
+ end
100
114
  end
101
115
  end
102
116
 
103
117
  def convert_strings_to_latin1(object)
118
+ return object unless "".respond_to?(:force_encoding)
119
+
104
120
  each_string(object) do |s|
105
121
  s.replace(generate_random_string(s.bytesize)).force_encoding('ISO-8859-1')
106
122
  end