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
@@ -23,8 +23,7 @@ class Insider
23
23
  def thrower(level)
24
24
  if level == 0
25
25
  # don't use a real sampler because we can't instantiate one
26
- # sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
27
- sampler = "<none>"
26
+ # NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
28
27
  begin
29
28
  fail "This should not have worked."
30
29
  rescue
@@ -16,7 +16,7 @@ class NewRelicServiceKeepAliveTest < Minitest::Test
16
16
  end
17
17
 
18
18
  def stub_net_http_handle(overrides = {})
19
- defaults = { :start => true, :finish => true, :address => '10.10.10.10', :port => 30303, :started? => true }
19
+ defaults = { :address => '10.10.10.10', :port => 30303, :started? => true }
20
20
  stub('http_handle', defaults.merge(overrides))
21
21
  end
22
22
 
@@ -42,6 +42,10 @@ class NewRelicServiceKeepAliveTest < Minitest::Test
42
42
  handle2 = stub_net_http_handle
43
43
  @service.stubs(:create_http_connection).returns(handle1, handle2)
44
44
 
45
+ handle1.expects(:start).once
46
+ handle1.expects(:finish).once
47
+ handle2.expects(:start).never
48
+
45
49
  block_ran = false
46
50
  @service.session do
47
51
  block_ran = true
@@ -78,6 +82,25 @@ class NewRelicServiceKeepAliveTest < Minitest::Test
78
82
  assert(block_ran)
79
83
  end
80
84
 
85
+ def test_session_does_not_close_connection_if_aggressive_keepalive_on
86
+ defaults = { :address => '10.10.10.10', :port => 30303, :started? => true }
87
+ handle = stub('http_handle', defaults)
88
+
89
+ handle.expects(:start).once
90
+ handle.expects(:finish).never
91
+
92
+ @service.stubs(:create_http_connection).returns(handle)
93
+
94
+ calls_to_block = 0
95
+
96
+ with_config(:aggressive_keepalive => true) do
97
+ 2.times do
98
+ @service.session { calls_to_block += 1 }
99
+ end
100
+ end
101
+
102
+ assert_equal(2, calls_to_block)
103
+ end
81
104
  end
82
105
 
83
106
  class NewRelicServiceTest < Minitest::Test
@@ -210,7 +233,7 @@ class NewRelicServiceTest < Minitest::Test
210
233
  @service.metric_data(stats_hash)
211
234
  payload = @http_handle.last_request_payload
212
235
  _, last_harvest_timestamp, harvest_timestamp, _ = payload
213
- assert_equal(t0.to_f, harvest_timestamp)
236
+ assert_in_delta(t0.to_f, harvest_timestamp, 0.0001)
214
237
 
215
238
  t1 = advance_time(10)
216
239
  stats_hash.harvested_at = t1
@@ -218,8 +241,8 @@ class NewRelicServiceTest < Minitest::Test
218
241
  @service.metric_data(stats_hash)
219
242
  payload = @http_handle.last_request_payload
220
243
  _, last_harvest_timestamp, harvest_timestamp, _ = payload
221
- assert_equal(t1.to_f, harvest_timestamp)
222
- assert_equal(t0.to_f, last_harvest_timestamp)
244
+ assert_in_delta(t1.to_f, harvest_timestamp, 0.0001)
245
+ assert_in_delta(t0.to_f, last_harvest_timestamp, 0.0001)
223
246
  end
224
247
 
225
248
  def test_fill_metric_id_cache_from_collect_response
@@ -265,7 +288,7 @@ class NewRelicServiceTest < Minitest::Test
265
288
  @service.metric_data(stats_hash)
266
289
 
267
290
  timeslice_start = @http_handle.last_request_payload[1]
268
- assert timeslice_start >= t0.to_f + 10
291
+ assert_in_delta(timeslice_start, t0.to_f + 10, 0.0001)
269
292
  end
270
293
 
271
294
  def test_error_data
@@ -401,10 +424,12 @@ class NewRelicServiceTest < Minitest::Test
401
424
  end
402
425
 
403
426
  def test_raises_serialization_error_if_encoding_normalization_fails
404
- @http_handle.respond_to(:wiggle, 'hi')
405
- NewRelic::JSONWrapper.stubs(:normalize).raises('blah')
406
- assert_raises(NewRelic::Agent::SerializationError) do
407
- @service.send(:invoke_remote, 'wiggle', {})
427
+ with_config(:normalize_json_string_encodings => true) do
428
+ @http_handle.respond_to(:wiggle, 'hi')
429
+ NewRelic::JSONWrapper.stubs(:normalize).raises('blah')
430
+ assert_raises(NewRelic::Agent::SerializationError) do
431
+ @service.send(:invoke_remote, 'wiggle', {})
432
+ end
408
433
  end
409
434
  end
410
435
 
@@ -420,18 +445,30 @@ class NewRelicServiceTest < Minitest::Test
420
445
  input_string = (0..255).to_a.pack("C*")
421
446
  roundtripped_string = roundtrip_data(input_string)
422
447
 
423
- assert_equal(Encoding.find('ASCII-8BIT'), input_string.encoding)
424
- expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
448
+ if NewRelic::LanguageSupport.supports_string_encodings?
449
+ assert_equal(Encoding.find('ASCII-8BIT'), input_string.encoding)
450
+ end
451
+
452
+ expected = force_to_utf8(input_string.dup)
425
453
  assert_equal(expected, roundtripped_string)
426
454
  end
427
455
 
428
- def test_json_marshaller_handles_strings_with_incorrect_encoding
429
- input_string = (0..255).to_a.pack("C*").force_encoding("UTF-8")
430
- roundtripped_string = roundtrip_data(input_string)
456
+ if NewRelic::LanguageSupport.supports_string_encodings?
457
+ def test_json_marshaller_handles_strings_with_incorrect_encoding
458
+ input_string = (0..255).to_a.pack("C*").force_encoding("UTF-8")
459
+ roundtripped_string = roundtrip_data(input_string)
431
460
 
432
- assert_equal(Encoding.find('UTF-8'), input_string.encoding)
433
- expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
434
- assert_equal(expected, roundtripped_string)
461
+ assert_equal(Encoding.find('UTF-8'), input_string.encoding)
462
+ expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
463
+ assert_equal(expected, roundtripped_string)
464
+ end
465
+ end
466
+
467
+ def test_json_marshaller_failure_when_not_normalizing
468
+ input_string = (0..255).to_a.pack("C*")
469
+ assert_raises(NewRelic::Agent::SerializationError) do
470
+ roundtrip_data(input_string, false)
471
+ end
435
472
  end
436
473
 
437
474
  def test_json_marshaller_should_handle_crazy_strings
@@ -450,7 +487,7 @@ class NewRelicServiceTest < Minitest::Test
450
487
  data = DummyDataClass.new(binary_string, [])
451
488
  result = roundtrip_data(data)
452
489
 
453
- expected_string = binary_string.force_encoding('ISO-8859-1').encode('UTF-8')
490
+ expected_string = force_to_utf8(binary_string)
454
491
  assert_equal(expected_string, result[0])
455
492
  end
456
493
 
@@ -459,7 +496,7 @@ class NewRelicServiceTest < Minitest::Test
459
496
  data = DummyDataClass.new(binary_string, [binary_string])
460
497
  result = roundtrip_data(data)
461
498
 
462
- expected_string = binary_string.force_encoding('ISO-8859-1').encode('UTF-8')
499
+ expected_string = force_to_utf8(binary_string)
463
500
  assert_equal(expected_string, result[0])
464
501
 
465
502
  base64_encoded_compressed_json_field = result[1]
@@ -612,10 +649,20 @@ class NewRelicServiceTest < Minitest::Test
612
649
  hash
613
650
  end
614
651
 
652
+ def force_to_utf8(string)
653
+ if NewRelic::LanguageSupport.supports_string_encodings?
654
+ string.force_encoding('ISO-8859-1').encode('UTF-8')
655
+ else
656
+ Iconv.iconv('utf-8', 'iso-8859-1', string).join
657
+ end
658
+ end
659
+
615
660
  def generate_random_byte_sequence(length=255, encoding=nil)
616
661
  bytes = []
617
662
  alphabet = (0..255).to_a
618
- length.times { bytes << alphabet.sample }
663
+ meth = alphabet.respond_to?(:sample) ? :sample : :choice
664
+ length.times { bytes << alphabet.send(meth) }
665
+
619
666
  string = bytes.pack("C*")
620
667
  string.force_encoding(encoding) if encoding
621
668
  string
@@ -623,19 +670,28 @@ class NewRelicServiceTest < Minitest::Test
623
670
 
624
671
  def generate_object_graph_with_crazy_strings
625
672
  strings = {}
626
- encodings = Encoding.list
627
673
  100.times do
628
- key_string = generate_random_byte_sequence(255, encodings.sample)
629
- value_string = generate_random_byte_sequence(255, encodings.sample)
674
+ key_string = generate_random_byte_sequence(255, random_encoding)
675
+ value_string = generate_random_byte_sequence(255, random_encoding)
630
676
  strings[key_string] = value_string
631
677
  end
632
678
  strings
633
679
  end
634
680
 
635
- def roundtrip_data(data)
636
- @http_handle.respond_to(:roundtrip, 'roundtrip')
637
- @service.send(:invoke_remote, 'roundtrip', data)
638
- @http_handle.last_request_payload[0]
681
+ def random_encoding
682
+ if NewRelic::LanguageSupport.supports_string_encodings?
683
+ Encoding.list.sample
684
+ else
685
+ nil
686
+ end
687
+ end
688
+
689
+ def roundtrip_data(data, normalize = true)
690
+ with_config(:normalize_json_string_encodings => normalize) do
691
+ @http_handle.respond_to(:roundtrip, 'roundtrip')
692
+ @service.send(:invoke_remote, 'roundtrip', data)
693
+ @http_handle.last_request_payload[0]
694
+ end
639
695
  end
640
696
 
641
697
  class DummyDataClass
@@ -41,7 +41,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
41
41
  engine = NewRelic::Agent.agent.stats_engine
42
42
  engine.get_stats_no_scope(metric).record_data_point(1.0)
43
43
 
44
- listener = start_listener_with_pipe(666)
44
+ start_listener_with_pipe(666)
45
45
 
46
46
  run_child(666) do
47
47
  NewRelic::Agent.after_fork
@@ -60,7 +60,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
60
60
  sample = run_sample_trace
61
61
  assert_equal(1, sampler.count)
62
62
 
63
- listener = start_listener_with_pipe(667)
63
+ start_listener_with_pipe(667)
64
64
  run_child(667) do
65
65
  NewRelic::Agent.after_fork
66
66
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
@@ -82,7 +82,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
82
82
 
83
83
  assert_equal(1, NewRelic::Agent.agent.error_collector.errors.size)
84
84
 
85
- listener = start_listener_with_pipe(668)
85
+ start_listener_with_pipe(668)
86
86
 
87
87
  run_child(668) do
88
88
  NewRelic::Agent.after_fork
@@ -100,7 +100,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
100
100
  def test_listener_merges_analytics_events
101
101
  request_sampler = NewRelic::Agent.agent.instance_variable_get(:@request_sampler)
102
102
 
103
- listener = start_listener_with_pipe(699)
103
+ start_listener_with_pipe(699)
104
104
  NewRelic::Agent.agent.stubs(:connected?).returns(true)
105
105
  run_child(699) do
106
106
  NewRelic::Agent.after_fork(:report_to_channel => 699)
@@ -110,7 +110,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
110
110
  :duration => 10,
111
111
  :type => :controller
112
112
  })
113
- NewRelic::Agent.agent.send(:transmit_data)
113
+ NewRelic::Agent.agent.send(:transmit_transaction_event_data)
114
114
  end
115
115
 
116
116
  assert_equal(1, request_sampler.samples.size)
@@ -120,7 +120,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
120
120
  sampler = NewRelic::Agent.agent.sql_sampler
121
121
  create_sql_sample(sampler)
122
122
 
123
- listener = start_listener_with_pipe(667)
123
+ start_listener_with_pipe(667)
124
124
  run_child(667) do
125
125
  NewRelic::Agent.after_fork
126
126
  create_sql_sample(sampler)
@@ -15,13 +15,6 @@ class NewRelic::Agent::RpmAgentTest < Minitest::Test
15
15
  NewRelic::Agent.instance.shutdown
16
16
  end
17
17
 
18
- def test_agent_setup
19
- assert(NewRelic::Agent.instance.class == NewRelic::Agent::Agent)
20
- assert_raises(RuntimeError) do
21
- NewRelic::Control.instance.init_plugin(:agent_enabled => false)
22
- end
23
- end
24
-
25
18
  def test_public_apis
26
19
  assert_raises(RuntimeError) do
27
20
  NewRelic::Agent.set_sql_obfuscator(:unknown) { |sql| puts sql }
@@ -102,7 +95,7 @@ class NewRelic::Agent::RpmAgentTest < Minitest::Test
102
95
  end
103
96
 
104
97
  def test_agent_version_string
105
- assert_match /\d\.\d+\.\d+/, NewRelic::VERSION::STRING
98
+ assert_match(/\d\.\d+\.\d+/, NewRelic::VERSION::STRING)
106
99
  end
107
100
 
108
101
  def test_record_transaction
@@ -231,8 +231,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
231
231
  "Database/test/select", {}, 1.2),
232
232
  "tx_name", "uri")
233
233
 
234
- assert -2147483648 <= sql_trace.sql_id, "sql_id too small"
235
- assert 2147483647 >= sql_trace.sql_id, "sql_id too large"
234
+ assert(-2147483648 <= sql_trace.sql_id, "sql_id too small")
235
+ assert( 2147483647 >= sql_trace.sql_id, "sql_id too large")
236
236
  end
237
237
 
238
238
  def test_sends_obfuscated_queries_when_configured
@@ -298,17 +298,18 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
298
298
  @sampler.harvest_slow_sql(data)
299
299
  sql_traces = @sampler.harvest!
300
300
 
301
- params = RUBY_VERSION >= '1.9.2' ? "eJyrrgUAAXUA+Q==\n" : {}
302
- expected = [ 'WebTransaction/Controller/c/a', '/c/a', 526336943,
303
- 'select * from test', 'Database/test/select',
304
- 1, 1500, 1500, 1500, params ]
305
-
306
301
  if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
307
302
  marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
303
+ params = "eJyrrgUAAXUA+Q==\n"
308
304
  else
309
305
  marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
306
+ params = {}
310
307
  end
311
308
 
309
+ expected = [ 'WebTransaction/Controller/c/a', '/c/a', 526336943,
310
+ 'select * from test', 'Database/test/select',
311
+ 1, 1500, 1500, 1500, params ]
312
+
312
313
  assert_equal expected, sql_traces[0].to_collector_array(marshaller.default_encoder)
313
314
  end
314
315
  end
@@ -321,11 +322,12 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
321
322
 
322
323
  if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
323
324
  marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
325
+ params = "eJyrrgUAAXUA+Q==\n"
324
326
  else
325
327
  marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
328
+ params = {}
326
329
  end
327
330
 
328
- params = RUBY_VERSION >= '1.9.2' ? "eJyrrgUAAXUA+Q==\n" : {}
329
331
  expected = [ "path", "uri", 1234, "query", "transaction",
330
332
  10, 12000, 12000, 12000, params]
331
333
 
@@ -61,7 +61,7 @@ if NewRelic::Agent::Threading::BacktraceService.is_supported?
61
61
  def test_stop_clears_buffered_backtraces
62
62
  fake_worker_loop(@service)
63
63
 
64
- thread = fake_thread(:request)
64
+ fake_thread(:request)
65
65
 
66
66
  @service.subscribe('foo')
67
67
  @service.poll
@@ -10,7 +10,7 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
10
10
  @frame_stack = NewRelic::Agent::TracedMethodStack.new
11
11
  end
12
12
 
13
- def test_scope__overlap
13
+ def test_scope_overlap
14
14
  freeze_time
15
15
 
16
16
  in_transaction('orlando') do
@@ -36,21 +36,10 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
36
36
  })
37
37
  end
38
38
 
39
-
40
- def test_scope_failure
41
- state = NewRelic::Agent::TransactionState.tl_get
42
-
43
- scope1 = @frame_stack.push_frame(state, :scope1)
44
- scope2 = @frame_stack.push_frame(state, :scope2)
45
- assert_raises(RuntimeError) do
46
- @frame_stack.pop_frame(state, scope1, "name 1", Time.now.to_f)
47
- end
48
- end
49
-
50
39
  def test_children_time
51
40
  state = NewRelic::Agent::TransactionState.tl_get
52
41
 
53
- t1 = freeze_time
42
+ freeze_time
54
43
  expected1 = @frame_stack.push_frame(state, :a)
55
44
  advance_time(0.001)
56
45
  t2 = Time.now
@@ -145,6 +134,49 @@ class NewRelic::Agent::TracedMethodStackTest < Minitest::Test
145
134
  assert_sampler_enabled_with(false, :'transaction_tracer.enabled' => false, :developer_mode => false)
146
135
  end
147
136
 
137
+ def test_fetch_matching_frame_fetches_the_next_matching_frame
138
+ state = NewRelic::Agent::TransactionState.tl_get
139
+ frame = @frame_stack.push_frame(state, :a, 0)
140
+
141
+ result = @frame_stack.fetch_matching_frame(frame)
142
+
143
+ assert_equal :a, result.tag
144
+ assert_equal frame, result
145
+ end
146
+
147
+ def test_fetch_matching_frame_discards_mismatched_frames
148
+ state = NewRelic::Agent::TransactionState.tl_get
149
+ frame = @frame_stack.push_frame(state, :a, 0)
150
+ @frame_stack.push_frame(state, :b, 0)
151
+
152
+ result = @frame_stack.fetch_matching_frame(frame)
153
+
154
+ assert_equal :a, result.tag
155
+ assert_equal frame, result
156
+ end
157
+
158
+ def test_fetch_matching_frame_raises_an_error_if_no_match
159
+ state = NewRelic::Agent::TransactionState.tl_get
160
+ frame = @frame_stack.push_frame(state, :a, 0)
161
+ @frame_stack.fetch_matching_frame(frame)
162
+
163
+ error = assert_raises(RuntimeError) do
164
+ @frame_stack.fetch_matching_frame(frame)
165
+ end
166
+
167
+ assert_match(/not found/, error.message)
168
+ end
169
+
170
+ def test_fetch_matching_frame_logs_any_unexpected_frame_tags
171
+ state = NewRelic::Agent::TransactionState.tl_get
172
+ frame = @frame_stack.push_frame(state, :a, 0)
173
+ @frame_stack.push_frame(state, :unexpected, 0)
174
+
175
+ expects_logging(:info, includes("unexpected"))
176
+
177
+ @frame_stack.fetch_matching_frame(frame)
178
+ end
179
+
148
180
  def assert_sampler_enabled_with(expected, opts={})
149
181
  with_config(opts) do
150
182
  assert_equal expected, @frame_stack.sampler_enabled?
@@ -178,7 +178,7 @@ class NewRelic::Agent::TransationSampleBuilderTest < Minitest::Test
178
178
  config = { :'transaction_tracer.transaction_threshold' => 4.0 }
179
179
 
180
180
  in_transaction do
181
- with_config(config, :do_not_cast => true) do
181
+ with_config(config) do
182
182
  NewRelic::Agent::TransactionState.tl_get.current_transaction.stubs(:apdex_t).returns(1.5)
183
183
  assert_equal 4.0, @builder.transaction_trace_threshold
184
184
  end
@@ -210,7 +210,6 @@ class NewRelic::Agent::TransationSampleBuilderTest < Minitest::Test
210
210
  end
211
211
  assert(child.entry_timestamp >= parent.entry_timestamp,
212
212
  "#{child.entry_timestamp} !>= #{parent.entry_timestamp}")
213
- last_metric = child
214
213
 
215
214
  validate_segment(child, check_names)
216
215
  end
@@ -116,7 +116,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
116
116
  :apdex_t => 2.0
117
117
  }
118
118
 
119
- with_config(config, :do_not_cast => true) do
119
+ with_config(config) do
120
120
  in_transaction('Controller/foo/bar') do |txn|
121
121
  assert_equal 1.5, txn.apdex_t
122
122
  end
@@ -137,7 +137,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
137
137
  def test_update_apdex_records_correct_apdex_for_key_transaction
138
138
  t0 = freeze_time
139
139
 
140
- with_config(KEY_TRANSACTION_CONFIG, :do_not_cast => true) do
140
+ with_config(KEY_TRANSACTION_CONFIG) do
141
141
  in_web_transaction('Controller/slow/txn') do
142
142
  state = NewRelic::Agent::TransactionState.tl_get
143
143
  txn = state.current_transaction
@@ -157,7 +157,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
157
157
  def test_update_apdex_records_correct_apdex_for_non_key_transaction
158
158
  t0 = freeze_time
159
159
 
160
- with_config(KEY_TRANSACTION_CONFIG, :do_not_cast => true) do
160
+ with_config(KEY_TRANSACTION_CONFIG) do
161
161
  in_web_transaction('Controller/other/txn') do
162
162
  state = NewRelic::Agent::TransactionState.tl_get
163
163
  txn = state.current_transaction