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
@@ -1,11 +1,8 @@
1
- suite_condition("Typhoeus not supported in 1.8.6 and excluded on 1.8.7 non-REE") do
2
-
1
+ suite_condition("Typhoeus excluded on 1.8.7 non-REE") do
3
2
  # Under Ruby 1.8.7 (but not REE), there are persistent segfaults with Typhoeus
4
3
  # and the Ruby agent. This predated our Typhoeus instrumentation, but given
5
4
  # usage levels and obscurity of the issue, it isn't worth deeper digging.
6
5
  # Just use REE, or better yet >= 1.9
7
-
8
- (RUBY_VERSION != '1.8.6') &&
9
6
  (RUBY_VERSION != '1.8.7' || RUBY_DESCRIPTION =~ /Enterprise/)
10
7
  end
11
8
 
@@ -11,8 +11,7 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Minitest::Test
11
11
  self.expects(:catch_errors).yields
12
12
  self.expects(:connect).with('connection_options')
13
13
  self.stubs(:connected?).returns(true)
14
- self.expects(:log_worker_loop_start)
15
- self.expects(:create_and_run_worker_loop)
14
+ self.expects(:create_and_run_event_loop)
16
15
  deferred_work!('connection_options')
17
16
  end
18
17
 
@@ -23,17 +22,6 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Minitest::Test
23
22
  deferred_work!('connection_options')
24
23
  end
25
24
 
26
- def test_create_and_run_worker_loop
27
- @should_send_samples = true
28
- wl = mock('worker loop')
29
- NewRelic::Agent::WorkerLoop.expects(:new).returns(wl)
30
- wl.expects(:run).with(30).yields
31
- self.expects(:transmit_data)
32
- with_config(:data_report_period => 30) do
33
- create_and_run_worker_loop
34
- end
35
- end
36
-
37
25
  def test_handle_force_restart
38
26
  # hooray for methods with no branches
39
27
  error = mock(:message => 'a message')
@@ -337,6 +337,17 @@ class AgentLoggerTest < Minitest::Test
337
337
  )
338
338
  end
339
339
 
340
+ def test_can_overwrite_log_formatter
341
+ log_message = 'How are you?'
342
+ log_formatter = Proc.new { |s, t, p, m| m.reverse }
343
+
344
+ logger = create_basic_logger
345
+ logger.log_formatter = log_formatter
346
+ logger.warn log_message
347
+
348
+ assert_logged log_message.reverse
349
+ end
350
+
340
351
  #
341
352
  # Helpers
342
353
  #
@@ -311,15 +311,21 @@ module NewRelic
311
311
  end
312
312
 
313
313
  def test_connect_settings
314
- settings = @agent.connect_settings
315
- assert settings.include?(:pid)
316
- assert settings.include?(:host)
317
- assert settings.include?(:app_name)
318
- assert settings.include?(:language)
319
- assert settings.include?(:agent_version)
320
- assert settings.include?(:environment)
321
- assert settings.include?(:settings)
322
- assert settings.include?(:high_security)
314
+ expected = [
315
+ :pid,
316
+ :host,
317
+ :app_name,
318
+ :language,
319
+ :labels,
320
+ :agent_version,
321
+ :environment,
322
+ :settings,
323
+ :high_security
324
+ ]
325
+
326
+ expected.each do |expect_key|
327
+ assert_includes @agent.connect_settings.keys, expect_key
328
+ end
323
329
  end
324
330
 
325
331
  def test_connect_settings_checks_environment_report_can_marshal
@@ -327,6 +333,23 @@ module NewRelic
327
333
  assert_equal [], @agent.connect_settings[:environment]
328
334
  end
329
335
 
336
+ def test_connect_settings_includes_labels_from_config
337
+ with_config({:labels => {'Server' => 'East'}}) do
338
+ expected = [ {"label_type"=>"Server", "label_value"=>"East"} ]
339
+ assert_equal expected, @agent.connect_settings[:labels]
340
+ end
341
+ end
342
+
343
+ def test_connect_settings_includes_labels_from_semicolon_separated_config
344
+ with_config(:labels => "Server:East;Server:West;") do
345
+ expected = [
346
+ {"label_type"=>"Server", "label_value"=>"East"},
347
+ {"label_type"=>"Server", "label_value"=>"West"}
348
+ ]
349
+ assert_equal expected, @agent.connect_settings[:labels]
350
+ end
351
+ end
352
+
330
353
  def test_defer_start_if_resque_dispatcher_and_channel_manager_isnt_started_and_forkable
331
354
  NewRelic::LanguageSupport.stubs(:can_fork?).returns(true)
332
355
  NewRelic::Agent::PipeChannelManager.listener.stubs(:started?).returns(false)
@@ -514,37 +537,37 @@ module NewRelic
514
537
  end
515
538
  end
516
539
 
517
- def test_stop_worker_loop_runs_loop_before_exit_with_force_send_config
540
+ def test_stop_event_loop_runs_loop_before_exit_with_force_send_config
518
541
  fake_loop = mock
519
- fake_loop.expects(:run_task)
542
+ fake_loop.expects(:run_once)
520
543
  fake_loop.stubs(:stop)
521
544
 
522
- @agent.instance_variable_set(:@worker_loop, fake_loop)
545
+ @agent.instance_variable_set(:@event_loop, fake_loop)
523
546
 
524
547
  with_config(:force_send => true) do
525
- @agent.stop_worker_loop
548
+ @agent.stop_event_loop
526
549
  end
527
550
  end
528
551
 
529
- def test_stop_worker_loop_doesnt_run_loop_if_force_send_is_false
552
+ def test_stop_event_loop_doesnt_run_loop_if_force_send_is_false
530
553
  fake_loop = mock
531
- fake_loop.expects(:run_task).never
554
+ fake_loop.expects(:run_once).never
532
555
  fake_loop.stubs(:stop)
533
556
 
534
- @agent.instance_variable_set(:@worker_loop, fake_loop)
557
+ @agent.instance_variable_set(:@event_loop, fake_loop)
535
558
 
536
559
  with_config(:force_send => false) do
537
- @agent.stop_worker_loop
560
+ @agent.stop_event_loop
538
561
  end
539
562
  end
540
563
 
541
- def test_stop_worker_loop_stops_the_loop
564
+ def test_stop_event_loop_stops_the_loop
542
565
  fake_loop = mock
543
566
  fake_loop.expects(:stop)
544
567
 
545
- @agent.instance_variable_set(:@worker_loop, fake_loop)
568
+ @agent.instance_variable_set(:@event_loop, fake_loop)
546
569
 
547
- @agent.stop_worker_loop
570
+ @agent.stop_event_loop
548
571
  end
549
572
 
550
573
  def test_untraced_graceful_disconnect_logs_errors
@@ -32,9 +32,13 @@ class AuditLoggerTest < Minitest::Test
32
32
  end
33
33
 
34
34
  def assert_log_contains_string(str)
35
+ log_body = read_log_body
36
+ assert(log_body.include?(str), "Expected log to contain string '#{str}'\nLog body was: #{log_body}")
37
+ end
38
+
39
+ def read_log_body
35
40
  @fakelog.rewind
36
- log_body = @fakelog.read
37
- assert(log_body.include?(str), "Expected log to contain string '#{str}'")
41
+ @fakelog.read
38
42
  end
39
43
 
40
44
  def test_never_setup_if_disabled
@@ -117,7 +121,7 @@ class AuditLoggerTest < Minitest::Test
117
121
  setup_fake_logger
118
122
  json_marshaller = marshaller_cls.new
119
123
  @logger.log_request(@uri, @dummy_data, json_marshaller)
120
- assert_log_contains_string(JSON.dump(@dummy_data))
124
+ assert_audit_log_contains_object(read_log_body, @dummy_data, :json)
121
125
  end
122
126
  end
123
127
 
@@ -63,7 +63,6 @@ if !NewRelic::Agent::Threading::BacktraceService.is_supported?
63
63
  end
64
64
 
65
65
  def test_wont_start_and_reports_error
66
- errors = nil
67
66
  assert_raises NewRelic::Agent::Commands::AgentCommandRouter::AgentCommandError do
68
67
  @profiler.handle_start_command(start_command)
69
68
  end
@@ -325,7 +325,7 @@ module NewRelic::Agent::Commands
325
325
  end
326
326
 
327
327
  def command_for(*session_ids)
328
- command = create_agent_command({ "xray_ids" => session_ids})
328
+ create_agent_command({ "xray_ids" => session_ids})
329
329
  end
330
330
 
331
331
  end
@@ -0,0 +1,53 @@
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
+
7
+ module NewRelic::Agent::Configuration
8
+ class DottedHashTest < Minitest::Test
9
+ def test_without_nesting
10
+ hash = DottedHash.new({ :turtle => 1 })
11
+ assert_equal({ :turtle => 1 }, hash)
12
+ end
13
+
14
+ def test_with_nesting
15
+ hash = DottedHash.new({ :turtle => { :turtle => 1 } })
16
+ assert_equal({ :'turtle.turtle' => 1 }, hash)
17
+ end
18
+
19
+ def test_with_multiple_layers_of_nesting
20
+ hash = DottedHash.new({ :turtle => { :turtle => { :turtle => 1 } } })
21
+ assert_equal({ :'turtle.turtle.turtle' => 1 }, hash)
22
+ end
23
+
24
+ def test_turns_keys_to_symbols
25
+ hash = DottedHash.new({ "turtle" => { "turtle" => { "turtle" => 1 } } })
26
+ assert_equal({ :'turtle.turtle.turtle' => 1 }, hash)
27
+ end
28
+
29
+ def test_to_hash
30
+ dotted = DottedHash.new({ "turtle" => { "turtle" => { "turtle" => 1 } } })
31
+ hash = dotted.to_hash
32
+
33
+ assert_instance_of(Hash, hash)
34
+ assert_equal({ :'turtle.turtle.turtle' => 1 }, hash)
35
+ end
36
+
37
+ def test_option_to_keep_nesting
38
+ hash = DottedHash.new({ :turtle => { :turtle => 1 } }, true)
39
+ expected = {
40
+ :turtle => { :turtle => 1},
41
+ :'turtle.turtle' => 1,
42
+ }
43
+
44
+ assert_equal(expected, hash)
45
+ end
46
+
47
+ def test_borks_with_non_symbolizing_key
48
+ assert_raises(NoMethodError) do
49
+ DottedHash.new({ Object.new => 2 }, true)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -32,11 +32,11 @@ module NewRelic::Agent::Configuration
32
32
  :bar => 'default bar',
33
33
  :baz => 'default baz'
34
34
  }
35
- @manager.add_config_for_testing(config0)
36
- config1 = { :foo => 'real foo' }
35
+ @manager.add_config_for_testing(config0, false)
36
+ config1 = { :foo => 'wrong foo', :bar => 'real bar' }
37
37
  @manager.add_config_for_testing(config1)
38
- config2 = { :foo => 'wrong foo', :bar => 'real bar' }
39
- @manager.add_config_for_testing(config2, 1)
38
+ config2 = { :foo => 'real foo' }
39
+ @manager.add_config_for_testing(config2)
40
40
 
41
41
  assert_equal 'real foo' , @manager['foo']
42
42
  assert_equal 'real bar' , @manager['bar']
@@ -63,7 +63,7 @@ module NewRelic::Agent::Configuration
63
63
 
64
64
  def test_identifying_config_source
65
65
  hash_source = {:foo => 'foo', :bar => 'default'}
66
- @manager.add_config_for_testing(hash_source, 3)
66
+ @manager.add_config_for_testing(hash_source, false)
67
67
  test_source = ManualSource.new(:bar => 'bar', :baz => 'baz')
68
68
  @manager.replace_or_add_config(test_source)
69
69
 
@@ -109,7 +109,7 @@ module NewRelic::Agent::Configuration
109
109
  def test_should_read_license_key_from_env
110
110
  ENV['NEWRELIC_LICENSE_KEY'] = 'right'
111
111
  manager = NewRelic::Agent::Configuration::Manager.new
112
- manager.add_config_for_testing({:license_key => 'wrong'}, 1)
112
+ manager.add_config_for_testing({:license_key => 'wrong'}, false)
113
113
 
114
114
  assert_equal 'right', manager['license_key']
115
115
  ensure
@@ -282,5 +282,98 @@ module NewRelic::Agent::Configuration
282
282
  refute @manager.config_classes_for_testing.include?(YamlSource)
283
283
  refute @manager.config_classes_for_testing.include?(HighSecuritySource)
284
284
  end
285
+
286
+ load_cross_agent_test("labels").each do |testcase|
287
+ define_method("test_#{testcase['name']}") do
288
+ @manager.add_config_for_testing(:labels => testcase["labelString"])
289
+
290
+ assert_warning if testcase["warning"]
291
+ assert_equal(testcase["expected"], @manager.parse_labels_from_string)
292
+ end
293
+ end
294
+
295
+ def test_parse_labels_from_dictionary_with_hard_failure
296
+ bad_label_object = Object.new
297
+ @manager.add_config_for_testing(:labels => bad_label_object)
298
+
299
+ assert_parsing_error
300
+ assert_parsed_labels([])
301
+ end
302
+
303
+ def test_parse_labels_from_string_with_hard_failure
304
+ bad_string = "baaaad"
305
+ bad_string.stubs(:gsub).raises("Booom")
306
+ @manager.add_config_for_testing(:labels => bad_string)
307
+
308
+ assert_parsing_error
309
+ assert_parsed_labels([])
310
+ end
311
+
312
+ def test_parse_labels_from_dictionary
313
+ @manager.add_config_for_testing(:labels => { 'Server' => 'East', 'Data Center' => 'North' })
314
+
315
+ assert_parsed_labels([
316
+ { 'label_type' => 'Server', 'label_value' => 'East' },
317
+ { 'label_type' => 'Data Center', 'label_value' => 'North' }
318
+ ])
319
+ end
320
+
321
+ def test_parse_labels_from_dictionary_applies_length_limits
322
+ @manager.add_config_for_testing(:labels => { 'K' * 256 => 'V' * 256 })
323
+ expected = [ { 'label_type' => 'K' * 255, 'label_value' => 'V' * 255 } ]
324
+
325
+ expects_logging(:warn, includes("truncated"))
326
+ assert_parsed_labels(expected)
327
+ end
328
+
329
+ def test_parse_labels_from_dictionary_disallows_further_nested_hashes
330
+ @manager.add_config_for_testing(:labels => {
331
+ "More Nesting" => { "Hahaha" => "Ha" }
332
+ })
333
+
334
+ assert_warning
335
+ assert_parsed_labels([])
336
+ end
337
+
338
+ def test_parse_labels_from_dictionary_allows_numerics
339
+ @manager.add_config_for_testing(:labels => {
340
+ "the answer" => 42
341
+ })
342
+
343
+ expected = [{ 'label_type' => 'the answer', 'label_value' => '42' }]
344
+ assert_parsed_labels(expected)
345
+ end
346
+
347
+ def test_parse_labels_from_dictionary_allows_booleans
348
+ @manager.add_config_for_testing(:labels => {
349
+ "truthy" => true,
350
+ "falsy" => false
351
+ })
352
+
353
+ expected = [
354
+ { 'label_type' => 'truthy', 'label_value' => 'true' },
355
+ { 'label_type' => 'falsy', 'label_value' => 'false' }
356
+ ]
357
+ assert_parsed_labels(expected)
358
+ end
359
+
360
+ def assert_parsed_labels(expected)
361
+ result = @manager.parsed_labels
362
+
363
+ # 1.8.7 hash ordering means we can't directly compare. Lean on the
364
+ # structure and flattened array sorting to do the comparison we need.
365
+ result = result.map(&:to_a).sort
366
+ expected = expected.map(&:to_a).sort
367
+
368
+ assert_equal expected, result
369
+ end
370
+
371
+ def assert_warning
372
+ expects_logging(:warn, any_parameters, any_parameters)
373
+ end
374
+
375
+ def assert_parsing_error
376
+ expects_logging(:error, includes(Manager::PARSING_LABELS_FAILURE), any_parameters)
377
+ end
285
378
  end
286
379
  end
@@ -0,0 +1,18 @@
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
+
7
+ module NewRelic::Agent::Configuration
8
+ class ManualSourceTest < Minitest::Test
9
+ def test_prepopulates_nested_keys
10
+ source = ManualSource.new({ :outer => { :inner => "stuff" } })
11
+ expected = {
12
+ :outer => { :inner => "stuff" },
13
+ :'outer.inner' => "stuff"
14
+ }
15
+ assert_equal(expected, source)
16
+ end
17
+ end
18
+ end
@@ -33,7 +33,7 @@ class OrphanedConfigTest < Minitest::Test
33
33
  end
34
34
  end
35
35
 
36
- AGENT_CONFIG_PATTERN = /Agent\.config\[:['"]?([a-z\._]+)['"]?\]/
36
+ AGENT_CONFIG_PATTERN = /Agent\.config\[:['"]?([a-z\._]+)['"]?\s*\]/
37
37
  REGISTER_CALLBACK_PATTERN = /register_callback\(:['"]?([a-z\._]+)['"]?\)/
38
38
  NAMED_DEPENDENCY_PATTERN = /^\s*named[ (]+\:?([a-z\._]+).*$/
39
39
 
@@ -44,6 +44,10 @@ module NewRelic::Agent::Configuration
44
44
  assert_equal 'raw', @source[:'transaction_tracer.record_sql']
45
45
  end
46
46
 
47
+ def test_should_still_have_nested_hashes_around
48
+ refute_nil @source[:transaction_tracer]
49
+ end
50
+
47
51
  def test_should_ignore_apdex_f_setting_for_transaction_threshold
48
52
  assert_equal nil, @source[:'transaction_tracer.transaction_threshold']
49
53
  end
@@ -59,18 +63,18 @@ module NewRelic::Agent::Configuration
59
63
 
60
64
  def test_should_log_if_no_file_is_found
61
65
  expects_logging(:warn, any_parameters)
62
- source = YamlSource.new('no_such_file.yml', 'test')
66
+ YamlSource.new('no_such_file.yml', 'test')
63
67
  end
64
68
 
65
69
  def test_should_log_if_environment_is_not_present
66
70
  expects_logging(:error, any_parameters)
67
- source = YamlSource.new(@test_yml_path, 'nonsense')
71
+ YamlSource.new(@test_yml_path, 'nonsense')
68
72
  end
69
73
 
70
74
  def test_should_not_fail_to_log_missing_file_during_startup
71
75
  without_logger do
72
76
  ::NewRelic::Agent::StartupLogger.any_instance.expects(:warn)
73
- source = YamlSource.new('no_such_file.yml', 'test')
77
+ YamlSource.new('no_such_file.yml', 'test')
74
78
  end
75
79
  end
76
80
 
@@ -81,7 +85,7 @@ module NewRelic::Agent::Configuration
81
85
  File.stubs(:exists?).returns(true)
82
86
  File.stubs(:read).raises(StandardError.new("boo"))
83
87
 
84
- source = YamlSource.new('fake.yml', 'test')
88
+ YamlSource.new('fake.yml', 'test')
85
89
  end
86
90
  end
87
91