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
@@ -60,7 +60,7 @@ module Multiverse
60
60
  # start their processes, make sure we don't blatantly interleave output.
61
61
  def self.output(*args)
62
62
  @output_lock.synchronize do
63
- puts *args
63
+ puts(*args)
64
64
  end
65
65
  end
66
66
  end
@@ -72,7 +72,7 @@ module Multiverse
72
72
  puts red("Error when trying to run suite in #{full_path.inspect}")
73
73
  puts
74
74
  puts "#{e.class}: #{e}"
75
- puts *e.backtrace
75
+ puts(*e.backtrace)
76
76
  notice_exit_status 1
77
77
  end
78
78
  end
@@ -176,8 +176,19 @@ module Multiverse
176
176
  ENV['SERIALIZE'] || debug
177
177
  end
178
178
 
179
+ def check_environment_condition
180
+ if environments.condition && !environments.condition.call
181
+ puts yellow("SKIPPED #{directory.inspect}: #{environments.skip_message}")
182
+ false
183
+ else
184
+ true
185
+ end
186
+ end
187
+
179
188
  def prime
180
189
  ENV["VERBOSE"]= "1"
190
+ return unless check_environment_condition
191
+
181
192
  puts yellow("\nPriming #{directory.inspect}")
182
193
  @environments = nil
183
194
 
@@ -196,10 +207,7 @@ module Multiverse
196
207
  # implement #fork so we resort to a hack. We exec this lib file, which
197
208
  # loads a new JVM for the tests to run in.
198
209
  def execute
199
- if environments.condition && !environments.condition.call
200
- puts yellow("SKIPPED #{directory.inspect}: #{environments.skip_message}")
201
- return
202
- end
210
+ return unless check_environment_condition
203
211
 
204
212
  label = should_serialize? ? 'serial' : 'parallel'
205
213
  env_count = filter_env ? 1 : environments.size
@@ -212,6 +220,13 @@ module Multiverse
212
220
  execute_parallel
213
221
  end
214
222
  environments.after.call if environments.after
223
+ rescue => e
224
+ puts red("Failure during execution of suite #{directory.inspect}.")
225
+ puts red("This typically is a result of a Ruby failure in your Envfile.")
226
+ puts
227
+ puts red(e.class)
228
+ puts red(e.message)
229
+ exit(1)
215
230
  end
216
231
 
217
232
  def execute_serial
@@ -23,43 +23,6 @@ class AuditLogTest < Minitest::Test
23
23
  @contents
24
24
  end
25
25
 
26
- def assert_audit_log_contains(needle)
27
- # Original request bodies dumped to the log have symbol keys, but once
28
- # they go through a dump/load, they're strings again, so we strip
29
- # double-quotes and colons from the log, and the strings we searching for.
30
- regex = /[:"]/
31
- needle = needle.gsub(regex, '')
32
- haystack = audit_log_contents.gsub(regex, '')
33
- assert(haystack.include?(needle), "Expected log to contain '#{needle}'")
34
- end
35
-
36
- # Because we don't generate a strictly machine-readable representation of
37
- # request bodies for the audit log, the transformation into strings is
38
- # effectively one-way. This, combined with the fact that Hash traversal order
39
- # is arbitrary in Ruby 1.8.x means that it's difficult to directly assert that
40
- # some object graph made it into the audit log (due to different possible
41
- # orderings of the key/value pairs in Hashes that were embedded in the request
42
- # body). So, this method traverses an object graph and only makes assertions
43
- # about the terminal (non-Array-or-Hash) nodes therein.
44
- def assert_audit_log_contains_object(o, format)
45
- if format == :json
46
- assert_audit_log_contains(JSON.dump(o))
47
- else
48
- case o
49
- when Hash
50
- o.each do |k,v|
51
- assert_audit_log_contains_object(v, format)
52
- end
53
- when Array
54
- o.each do |el|
55
- assert_audit_log_contains_object(el, format)
56
- end
57
- else
58
- assert_audit_log_contains(o.inspect)
59
- end
60
- end
61
- end
62
-
63
26
  def test_logs_nothing_by_default
64
27
  run_agent do
65
28
  perform_actions
@@ -79,7 +42,7 @@ class AuditLogTest < Minitest::Test
79
42
  perform_actions
80
43
  format = NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported? ? :json : :pruby
81
44
  $collector.agent_data.each do |req|
82
- assert_audit_log_contains_object(req.body, format)
45
+ assert_audit_log_contains_object(audit_log_contents, req.body, format)
83
46
  end
84
47
  end
85
48
  end
@@ -8,19 +8,30 @@ require 'open3'
8
8
  class CollectorExceptionHandlingTest < Minitest::Test
9
9
  include MultiverseHelpers
10
10
 
11
- setup_and_teardown_agent
11
+ setup_and_teardown_agent do
12
+ NewRelic::Agent.agent.stubs(:sleep)
13
+ end
12
14
 
13
- def test_should_reconnect_on_force_restart_exception
15
+ def after_setup
16
+ # there's a call to sleep in handle_force_restart that we want to skip
14
17
  $collector.reset
18
+ end
19
+
20
+
21
+ RESTART_PAYLOAD = { 'error_type' => 'NewRelic::Agent::ForceRestartException' }
22
+ DISCONNECT_PAYLOAD = { 'error_type' => 'NewRelic::Agent::ForceDisconnectException' }
23
+ RUNTIME_ERROR_PAYLOAD = { 'error_type' => 'RuntimeError' }
24
+
25
+
26
+ def test_should_reconnect_on_force_restart_exception
27
+ # We stub these exceptions because we want the EventLoop to exit with a
28
+ # ForceRestartException the first time through, then (after reconnecting)
29
+ # we force the disconnect so that this test will end cleanly.
15
30
 
16
- payload = { 'error_type' => 'NewRelic::Agent::ForceRestartException' }
17
- $collector.stub_exception('metric_data', payload).once
31
+ $collector.stub_exception('metric_data' , RESTART_PAYLOAD ).once
32
+ $collector.stub_exception('get_agent_commands', DISCONNECT_PAYLOAD).once
18
33
 
19
34
  with_config(:data_report_period => 0) do
20
- worker_loop = NewRelic::Agent::WorkerLoop.new(:limit => 1)
21
- NewRelic::Agent.agent.stubs(:create_worker_loop).returns(worker_loop)
22
- # there's a call to sleep in handle_force_restart that we want to skip
23
- NewRelic::Agent.agent.stubs(:sleep)
24
35
  NewRelic::Agent.agent.deferred_work!({})
25
36
  end
26
37
 
@@ -34,10 +45,7 @@ class CollectorExceptionHandlingTest < Minitest::Test
34
45
  end
35
46
 
36
47
  def test_should_stop_reporting_after_force_disconnect
37
- $collector.reset
38
-
39
- payload = { 'error_type' => 'NewRelic::Agent::ForceDisconnectException' }
40
- $collector.stub_exception('metric_data', payload).once
48
+ $collector.stub_exception('metric_data', DISCONNECT_PAYLOAD).once
41
49
 
42
50
  with_config(:data_report_period => 0) do
43
51
  NewRelic::Agent.agent.deferred_work!({})
@@ -48,15 +56,9 @@ class CollectorExceptionHandlingTest < Minitest::Test
48
56
  end
49
57
 
50
58
  def test_should_stop_reporting_after_force_disconnect_on_connect
51
- $collector.reset
52
-
53
- payload = { 'error_type' => 'NewRelic::Agent::ForceDisconnectException' }
54
- $collector.stub_exception('connect', payload).once
59
+ $collector.stub_exception('connect', DISCONNECT_PAYLOAD).once
55
60
 
56
61
  with_config(:data_report_period => 0) do
57
- worker_loop = NewRelic::Agent::WorkerLoop.new(:limit => 1)
58
- NewRelic::Agent.agent.stubs(:create_worker_loop).returns(worker_loop)
59
- NewRelic::Agent.agent.stubs(:sleep)
60
62
  NewRelic::Agent.agent.deferred_work!({})
61
63
  end
62
64
 
@@ -64,16 +66,10 @@ class CollectorExceptionHandlingTest < Minitest::Test
64
66
  end
65
67
 
66
68
  def test_should_reconnect_on_connect_exception
67
- $collector.reset
68
-
69
- payload = { 'error_type' => 'RuntimeError' }
70
- $collector.stub_exception('connect', payload).once
69
+ $collector.stub_exception('connect', RUNTIME_ERROR_PAYLOAD).once
70
+ $collector.stub_exception('metric_data', DISCONNECT_PAYLOAD).once
71
71
 
72
72
  with_config(:data_report_period => 0) do
73
- worker_loop = NewRelic::Agent::WorkerLoop.new(:limit => 1)
74
- NewRelic::Agent.agent.stubs(:create_worker_loop).returns(worker_loop)
75
- # there's a call to sleep in connect that we want to skip
76
- NewRelic::Agent.agent.stubs(:sleep)
77
73
  NewRelic::Agent.agent.deferred_work!({})
78
74
  end
79
75
 
@@ -81,16 +77,10 @@ class CollectorExceptionHandlingTest < Minitest::Test
81
77
  end
82
78
 
83
79
  def test_should_reconnect_on_get_redirect_host_exception
84
- $collector.reset
85
-
86
- payload = { 'error_type' => 'RuntimeError' }
87
- $collector.stub_exception('get_redirect_host', payload).once
80
+ $collector.stub_exception('get_redirect_host', RUNTIME_ERROR_PAYLOAD).once
81
+ $collector.stub_exception('metric_data', DISCONNECT_PAYLOAD).once
88
82
 
89
83
  with_config(:data_report_period => 0) do
90
- worker_loop = NewRelic::Agent::WorkerLoop.new(:limit => 1)
91
- NewRelic::Agent.agent.stubs(:create_worker_loop).returns(worker_loop)
92
- # there's a call to sleep in connect that we want to skip
93
- NewRelic::Agent.agent.stubs(:sleep)
94
84
  NewRelic::Agent.agent.deferred_work!({})
95
85
  end
96
86
 
@@ -18,3 +18,5 @@ development:
18
18
  capture_params: false
19
19
  browser_monitoring:
20
20
  auto_instrument: true
21
+ labels:
22
+ Server: Yaml
@@ -88,6 +88,7 @@ class EncodingHandlingTest < Minitest::Test
88
88
 
89
89
  def assert_endpoint_received_string(endpoint, string)
90
90
  agent.send(:transmit_data)
91
+ agent.send(:transmit_transaction_event_data)
91
92
  requests = $collector.calls_for(endpoint)
92
93
  assert_equal(1, requests.size)
93
94
  request = requests.first
@@ -11,7 +11,7 @@ class HarvestTimestampsTest < Minitest::Test
11
11
  setup_and_teardown_agent
12
12
 
13
13
  def test_resets_metric_data_timestamps_after_forking
14
- t0 = freeze_time
14
+ freeze_time
15
15
 
16
16
  t1 = advance_time 10
17
17
  NewRelic::Agent.after_fork
@@ -0,0 +1,29 @@
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 'newrelic_rpm'
6
+ require 'multiverse_helpers'
7
+
8
+ class KeepaliveTest < Minitest::Test
9
+ include MultiverseHelpers
10
+
11
+ def test_can_reestablish_connection
12
+ setup_agent(:aggressive_keepalive => true)
13
+
14
+ NewRelic::Agent.agent.send(:transmit_data)
15
+
16
+ # This is the closest I can easily get to closing the underlying TCP
17
+ # connection from the server side in between harvests.
18
+ conn0 = NewRelic::Agent.agent.service.http_connection
19
+ conn0.instance_variable_get(:@socket).close
20
+
21
+ NewRelic::Agent.agent.send(:transmit_data)
22
+
23
+ conn1 = NewRelic::Agent.agent.service.http_connection
24
+
25
+ metric_data_calls = $collector.calls_for('metric_data')
26
+ assert_equal(2, metric_data_calls.size)
27
+ assert_same(conn0, conn1)
28
+ end
29
+ end
@@ -0,0 +1,89 @@
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.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
6
+ require 'fake_collector'
7
+ require 'multiverse_helpers'
8
+
9
+ class LabelsTest < Minitest::Test
10
+ include MultiverseHelpers
11
+
12
+ setup_and_teardown_agent
13
+
14
+ EXPECTED = [{'label_type' => 'Server', 'label_value' => 'East'}]
15
+ YML_EXPECTED = [{'label_type' => 'Server', 'label_value' => 'Yaml'}]
16
+
17
+ def after_setup
18
+ $collector.reset
19
+ make_sure_agent_reconnects({})
20
+ end
21
+
22
+ def test_yaml_makes_it_to_the_collector
23
+ # Relies on the agent_only/config/newrelic.yml!
24
+ NewRelic::Agent.manual_start
25
+ assert_connect_had_labels(YML_EXPECTED)
26
+ end
27
+
28
+ def test_labels_from_config_hash_make_it_to_the_collector
29
+ with_config("labels" => { "Server" => "East" }) do
30
+ NewRelic::Agent.manual_start
31
+ assert_connect_had_labels(EXPECTED)
32
+ end
33
+ end
34
+
35
+ def test_labels_from_manual_start_hash_make_it_to_the_collector
36
+ NewRelic::Agent.manual_start(:labels => { "Server" => "East" })
37
+ assert_connect_had_labels(EXPECTED)
38
+ end
39
+
40
+ def test_numeric_values_for_labels
41
+ NewRelic::Agent.manual_start(:labels => { "Server" => 42 })
42
+ expected = [
43
+ { 'label_type' => 'Server', 'label_value' => '42' }
44
+ ]
45
+ assert_connect_had_labels(expected)
46
+ end
47
+
48
+ def test_boolean_values_for_labels
49
+ NewRelic::Agent.manual_start(:labels => { "Server" => true })
50
+ expected = [
51
+ { 'label_type' => 'Server', 'label_value' => 'true' }
52
+ ]
53
+ assert_connect_had_labels(expected)
54
+ end
55
+
56
+ # All testing of string parsed label pairs should go through the cross agent
57
+ # test file for labels. Our dictionary passing is custom to Ruby, though.
58
+ load_cross_agent_test("labels").each do |testcase|
59
+ define_method("test_#{testcase['name']}_from_config_string") do
60
+ with_config("labels" => testcase["labelString"]) do
61
+ NewRelic::Agent.manual_start
62
+ assert_connect_had_labels(testcase["expected"])
63
+ end
64
+ end
65
+
66
+ define_method("test_#{testcase['name']}_from_manual_start") do
67
+ NewRelic::Agent.manual_start(:labels => testcase["labelString"])
68
+ assert_connect_had_labels(testcase["expected"])
69
+ end
70
+
71
+ define_method("test_#{testcase['name']}_from_env") do
72
+ begin
73
+ # Value must be here before reset for EnvironmentSource to see it
74
+ ENV['NEW_RELIC_LABELS'] = testcase["labelString"]
75
+ NewRelic::Agent.config.reset_to_defaults
76
+
77
+ NewRelic::Agent.manual_start
78
+ assert_connect_had_labels(testcase["expected"])
79
+ ensure
80
+ ENV['NEW_RELIC_LABELS'] = nil
81
+ end
82
+ end
83
+ end
84
+
85
+ def assert_connect_had_labels(expected)
86
+ result = $collector.calls_for('connect').first['labels']
87
+ assert_equal expected, result
88
+ end
89
+ end
@@ -16,7 +16,7 @@ class MarshalingTest < Minitest::Test
16
16
  end
17
17
 
18
18
  def test_transaction_trace_marshaling
19
- time = freeze_time
19
+ freeze_time
20
20
 
21
21
  in_transaction do
22
22
  trace_execution_scoped('a') do
@@ -31,8 +31,6 @@ class MarshalingTest < Minitest::Test
31
31
  agent.service.connect
32
32
  agent.send(:harvest_and_send_transaction_traces)
33
33
 
34
- marshaller = agent.service.marshaller
35
-
36
34
  actual = $collector.calls_for('transaction_sample_data')[0][1][0]
37
35
  encoder = NewRelic::Agent::NewRelicService::Encoders::Identity
38
36
 
@@ -12,7 +12,7 @@ class ServiceTimeoutTest < Minitest::Test
12
12
 
13
13
  Thread.new {
14
14
  client = hk.accept
15
- what = client.gets
15
+ client.gets
16
16
  sleep 4
17
17
  client.close
18
18
  Thread.exit
@@ -10,7 +10,7 @@ class StartUpTest < Minitest::Test
10
10
  ruby = 'require "newrelic_rpm"; NewRelic::Agent.manual_start; NewRelic::Agent.shutdown'
11
11
  cmd = "bundle exec ruby -e '#{ruby}'"
12
12
 
13
- sin, sout, serr = Open3.popen3(cmd)
13
+ _sin, sout, serr = Open3.popen3(cmd)
14
14
  output = sout.read + serr.read
15
15
 
16
16
  expected_noise = [
@@ -30,4 +30,12 @@ class StartUpTest < Minitest::Test
30
30
  problems = output.scan(/ERROR : .*/)
31
31
  assert_empty problems
32
32
  end
33
+
34
+ def test_after_fork_does_not_blow_away_manual_start_settings
35
+ NewRelic::Agent.manual_start(:app_name => 'my great app')
36
+
37
+ NewRelic::Agent.after_fork
38
+
39
+ assert_equal('my great app', NewRelic::Agent.config[:app_name])
40
+ end
33
41
  end
@@ -6,5 +6,9 @@ set :application, 'test'
6
6
 
7
7
  # Since Capistrano 3 doesn't allow settings direct from command-line, add any
8
8
  # settings we want to conditionally toggle from tests in the following manner.
9
- set :newrelic_user, ENV["NEWRELIC_USER"] if ENV["NEWRELIC_USER"]
10
- set :newrelic_appname, ENV["NEWRELIC_APPNAME"] if ENV["NEWRELIC_APPNAME"]
9
+ ENV.keys.each do |key|
10
+ if key.match(/NEWRELIC_CAPISTRANO_/)
11
+ name = key.gsub('NEWRELIC_CAPISTRANO_', '').downcase
12
+ set "newrelic_#{name}".to_sym, ENV[key]
13
+ end
14
+ end
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'fake_rpm_site'
6
6
  require 'multiverse_helpers'
7
+ require 'new_relic/cli/command'
7
8
 
8
9
  class DeploymentTest < Minitest::Test
9
10
  def setup
@@ -21,14 +22,21 @@ class DeploymentTest < Minitest::Test
21
22
  # Capistrano 3 doesn't provide built-in commandline params -> settings
22
23
  # We wire our own up via ENV to test setting out setting custom values
23
24
  env = {
24
- 'NEWRELIC_USER' => "someone",
25
- 'NEWRELIC_APPNAME' => "somewhere"
25
+ 'NEWRELIC_CAPISTRANO_USER' => "Optimus Prime",
26
+ 'NEWRELIC_CAPISTRANO_APPNAME' => "Tesseract",
27
+ 'NEWRELIC_CAPISTRANO_REVISION' => "C-001",
28
+ 'NEWRELIC_CAPISTRANO_CHANGELOG' => "The greatest weakness of most humans is their hesitancy to tell others they love them while they're alive.",
26
29
  }
27
30
 
28
31
  cap_it(env)
29
32
 
30
- assert_deployment_value("user", "someone")
31
- assert_deployment_value("application_id", "somewhere")
33
+ assert_deployment_value("user", "Optimus Prime")
34
+ assert_deployment_value("application_id", "Tesseract")
35
+ assert_deployment_value("revision", "C-001")
36
+ assert_deployment_value("changelog", "The greatest weakness of most humans is their hesitancy to tell others they love them while they're alive.")
37
+ end
38
+
39
+ def test_newrelic_revision_override
32
40
  end
33
41
 
34
42
  def assert_deployment_value(key, value)