newrelic_rpm 3.18.1.330 → 4.0.0.332

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -74
  3. data/CHANGELOG.md +77 -0
  4. data/CONTRIBUTING.md +14 -6
  5. data/LICENSE +1 -88
  6. data/lib/new_relic/agent.rb +2 -103
  7. data/lib/new_relic/agent/agent.rb +3 -32
  8. data/lib/new_relic/agent/commands/thread_profiler_session.rb +2 -6
  9. data/lib/new_relic/agent/configuration/default_source.rb +1 -8
  10. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -12
  11. data/lib/new_relic/agent/cross_app_monitor.rb +2 -1
  12. data/lib/new_relic/agent/cross_app_tracing.rb +4 -2
  13. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  14. data/lib/new_relic/agent/datastores/redis.rb +1 -1
  15. data/lib/new_relic/agent/encoding_normalizer.rb +1 -20
  16. data/lib/new_relic/agent/error_collector.rb +8 -21
  17. data/lib/new_relic/agent/inbound_request_monitor.rb +4 -1
  18. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +14 -30
  19. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -1
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -5
  21. data/lib/new_relic/agent/instrumentation/curb.rb +2 -2
  22. data/lib/new_relic/agent/instrumentation/excon.rb +3 -3
  23. data/lib/new_relic/agent/instrumentation/grape.rb +3 -3
  24. data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
  25. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +2 -2
  26. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -2
  27. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +3 -7
  28. data/lib/new_relic/agent/instrumentation/queue_time.rb +13 -15
  29. data/lib/new_relic/agent/instrumentation/rack.rb +4 -50
  30. data/lib/new_relic/agent/instrumentation/rake.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/resque.rb +1 -2
  32. data/lib/new_relic/agent/instrumentation/sinatra.rb +0 -1
  33. data/lib/new_relic/agent/instrumentation/typhoeus.rb +2 -2
  34. data/lib/new_relic/agent/javascript_instrumentor.rb +3 -2
  35. data/lib/new_relic/agent/method_tracer.rb +1 -60
  36. data/lib/new_relic/agent/new_relic_service.rb +3 -2
  37. data/lib/new_relic/agent/new_relic_service/encoders.rb +5 -6
  38. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +7 -16
  39. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -3
  40. data/lib/new_relic/agent/pipe_service.rb +1 -3
  41. data/lib/new_relic/agent/rules_engine.rb +2 -17
  42. data/lib/new_relic/agent/stats_engine.rb +0 -2
  43. data/lib/new_relic/agent/stats_engine/metric_stats.rb +0 -48
  44. data/lib/new_relic/agent/supported_versions.rb +12 -19
  45. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -1
  46. data/lib/new_relic/agent/transaction.rb +0 -3
  47. data/lib/new_relic/agent/transaction/attributes.rb +1 -10
  48. data/lib/new_relic/agent/vm.rb +1 -4
  49. data/lib/new_relic/agent/vm/jruby_vm.rb +1 -3
  50. data/lib/new_relic/agent/vm/mri_vm.rb +2 -10
  51. data/lib/new_relic/control.rb +1 -2
  52. data/lib/new_relic/control/frameworks/rails.rb +1 -1
  53. data/lib/new_relic/control/frameworks/rails3.rb +1 -2
  54. data/lib/new_relic/control/frameworks/rails4.rb +1 -1
  55. data/lib/new_relic/control/frameworks/rails5.rb +1 -1
  56. data/lib/new_relic/control/instance_methods.rb +1 -1
  57. data/{vendor/gems/dependency_detection-0.0.1.build/lib → lib/new_relic}/dependency_detection.rb +0 -1
  58. data/lib/new_relic/helper.rb +6 -13
  59. data/lib/new_relic/language_support.rb +44 -139
  60. data/lib/new_relic/metric_spec.rb +0 -17
  61. data/lib/new_relic/noticed_error.rb +18 -27
  62. data/lib/new_relic/version.rb +3 -48
  63. data/lib/tasks/versions.rake +7 -5
  64. data/newrelic_rpm.gemspec +1 -16
  65. data/test/agent_helper.rb +4 -2
  66. data/test/environments/lib/environments/runner.rb +5 -14
  67. data/test/environments/norails/Gemfile +0 -8
  68. data/test/environments/rails21/Gemfile +0 -8
  69. data/test/environments/rails21/config/database.yml +1 -1
  70. data/test/environments/rails22/Gemfile +0 -8
  71. data/test/environments/rails22/config/database.yml +1 -1
  72. data/test/environments/rails23/Gemfile +1 -7
  73. data/test/environments/rails23/config/database.yml +1 -1
  74. data/test/environments/rails30/Gemfile +0 -1
  75. data/test/environments/rails30/config/database.yml +1 -1
  76. data/test/environments/rails31/Gemfile +0 -3
  77. data/test/environments/rails31/config/database.yml +1 -1
  78. data/test/environments/rails32/Gemfile +0 -3
  79. data/test/environments/rails32/config/database.yml +1 -1
  80. data/test/environments/rails40/Gemfile +0 -26
  81. data/test/environments/rails40/config/database.yml +1 -1
  82. data/test/environments/rails41/Gemfile +0 -18
  83. data/test/environments/rails41/config/database.yml +1 -1
  84. data/test/environments/rails42/Gemfile +0 -22
  85. data/test/environments/rails42/config/database.yml +1 -1
  86. data/test/environments/rails50/Gemfile +0 -13
  87. data/test/environments/rails50/config/database.yml +1 -1
  88. data/test/helpers/logging.rb +37 -0
  89. data/test/helpers/minitest.rb +50 -0
  90. data/test/helpers/misc.rb +87 -0
  91. data/test/helpers/transaction_sample.rb +44 -0
  92. data/test/multiverse/lib/multiverse/suite.rb +6 -91
  93. data/test/multiverse/script/runner +1 -1
  94. data/test/multiverse/suites/active_record/Envfile +1 -28
  95. data/test/multiverse/suites/active_record/active_record_test.rb +6 -6
  96. data/test/multiverse/suites/active_record/config/database.rb +2 -3
  97. data/test/multiverse/suites/active_record/config/database.yml +0 -2
  98. data/test/multiverse/suites/activemerchant/Envfile +4 -18
  99. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +7 -15
  100. data/test/multiverse/suites/agent_only/error_events_test.rb +1 -7
  101. data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +4 -20
  102. data/test/multiverse/suites/agent_only/labels_test.rb +1 -1
  103. data/test/multiverse/suites/agent_only/marshaling_test.rb +5 -10
  104. data/test/multiverse/suites/agent_only/script/public_api_when_disabled.rb +0 -11
  105. data/test/multiverse/suites/agent_only/start_up_test.rb +3 -3
  106. data/test/multiverse/suites/agent_only/synthetics_test.rb +1 -1
  107. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +0 -3
  108. data/test/multiverse/suites/agent_only/xray_sessions_test.rb +0 -3
  109. data/test/multiverse/suites/capistrano/Envfile +2 -4
  110. data/test/multiverse/suites/capistrano2/Envfile +0 -4
  111. data/test/multiverse/suites/curb/Envfile +3 -7
  112. data/test/multiverse/suites/datamapper/Envfile +2 -2
  113. data/test/multiverse/suites/datamapper/datamapper_test.rb +2 -2
  114. data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +0 -1
  115. data/test/multiverse/suites/delayed_job/Envfile +28 -41
  116. data/test/multiverse/suites/excon/Envfile +0 -3
  117. data/test/multiverse/suites/grape/Envfile +0 -4
  118. data/test/multiverse/suites/grape/grape_versioning_test.rb +2 -2
  119. data/test/multiverse/suites/grape/grape_versioning_test_api.rb +2 -2
  120. data/test/multiverse/suites/json/Envfile +1 -9
  121. data/test/multiverse/suites/marshalling/Envfile +0 -9
  122. data/test/multiverse/suites/memcached/Envfile +5 -23
  123. data/test/multiverse/suites/mongo/Envfile +9 -11
  124. data/test/multiverse/suites/padrino/Envfile +0 -6
  125. data/test/multiverse/suites/rack/http_response_code_test.rb +0 -1
  126. data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +5 -10
  127. data/test/multiverse/suites/rack/rack_cascade_test.rb +0 -1
  128. data/test/multiverse/suites/rack/rack_env_mutation_test.rb +0 -1
  129. data/test/multiverse/suites/rack/response_content_type_test.rb +0 -1
  130. data/test/multiverse/suites/rails/Envfile +1 -19
  131. data/test/multiverse/suites/rails/activejob_test.rb +1 -2
  132. data/test/multiverse/suites/rails/error_tracing_test.rb +0 -13
  133. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +12 -32
  134. data/test/multiverse/suites/rake/Envfile +15 -22
  135. data/test/multiverse/suites/redis/redis_instrumentation_test.rb +1 -1
  136. data/test/multiverse/suites/sequel/database.rb +1 -4
  137. data/test/multiverse/suites/sidekiq/Envfile +13 -23
  138. data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +3 -3
  139. data/test/multiverse/suites/typhoeus/Envfile +0 -19
  140. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +3 -3
  141. data/test/multiverse/suites/yajl/Envfile +5 -0
  142. data/test/multiverse/suites/yajl/yajl_test.rb +1 -3
  143. data/test/new_relic/agent/agent/start_test.rb +3 -3
  144. data/test/new_relic/agent/agent_logger_test.rb +2 -2
  145. data/test/new_relic/agent/agent_test.rb +2 -2
  146. data/test/new_relic/agent/attribute_processing_test.rb +3 -4
  147. data/test/new_relic/agent/audit_logger_test.rb +4 -6
  148. data/test/new_relic/agent/aws_info_test.rb +17 -1
  149. data/test/new_relic/agent/busy_calculator_test.rb +14 -16
  150. data/test/new_relic/agent/configuration/manager_test.rb +1 -7
  151. data/test/new_relic/agent/cross_app_monitor_test.rb +1 -1
  152. data/test/new_relic/agent/database_test.rb +2 -10
  153. data/test/new_relic/agent/datastores/mongo/event_formatter_test.rb +90 -93
  154. data/test/new_relic/agent/datastores/redis_test.rb +14 -16
  155. data/test/new_relic/agent/encoding_normalizer_test.rb +38 -40
  156. data/test/new_relic/agent/error_collector_test.rb +16 -49
  157. data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +0 -6
  158. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +1 -1
  159. data/test/new_relic/agent/instrumentation/mongodb_command_subscriber_test.rb +101 -103
  160. data/test/new_relic/agent/instrumentation/rack_test.rb +11 -14
  161. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -10
  162. data/test/new_relic/agent/javascript_instrumentor_test.rb +2 -2
  163. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -10
  164. data/test/new_relic/agent/method_tracer_test.rb +35 -76
  165. data/test/new_relic/agent/new_relic_service_test.rb +86 -102
  166. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -9
  167. data/test/new_relic/agent/pipe_service_test.rb +2 -3
  168. data/test/new_relic/agent/rpm_agent_test.rb +0 -4
  169. data/test/new_relic/agent/sampled_buffer_test.rb +2 -2
  170. data/test/new_relic/agent/samplers/cpu_sampler_test.rb +28 -0
  171. data/test/new_relic/agent/samplers/memory_sampler_test.rb +66 -0
  172. data/test/new_relic/agent/sized_buffer_test.rb +1 -1
  173. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +2 -14
  174. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +44 -66
  175. data/test/new_relic/agent/stats_test.rb +6 -8
  176. data/test/new_relic/agent/synthetics_event_buffer_test.rb +1 -1
  177. data/test/new_relic/agent/transaction/attributes_test.rb +4 -12
  178. data/test/new_relic/agent/transaction_test.rb +2 -10
  179. data/test/new_relic/agent/utilization_data_test.rb +17 -1
  180. data/test/new_relic/agent/vm/mri_vm_test.rb +5 -7
  181. data/test/new_relic/agent_test.rb +0 -43
  182. data/test/new_relic/coerce_test.rb +1 -3
  183. data/test/new_relic/fake_collector.rb +3 -3
  184. data/test/new_relic/fake_external_server.rb +1 -1
  185. data/test/new_relic/fake_server.rb +1 -1
  186. data/test/new_relic/http_client_test_cases.rb +3 -3
  187. data/test/new_relic/language_support_test.rb +6 -12
  188. data/test/new_relic/latest_changes_test.rb +0 -11
  189. data/test/new_relic/license_test.rb +3 -8
  190. data/test/new_relic/multiverse_helpers.rb +1 -1
  191. data/test/new_relic/noticed_error_test.rb +11 -7
  192. data/test/new_relic/rack/browser_monitoring_test.rb +1 -3
  193. data/test/nullverse/nullverse_helper.rb +1 -1
  194. data/test/performance/lib/performance.rb +1 -1
  195. data/test/performance/lib/performance/instrumentation/gc_stats.rb +4 -6
  196. data/test/performance/lib/performance/instrumentation/perf_tools.rb +1 -1
  197. data/test/performance/lib/performance/instrumentation/stackprof.rb +1 -1
  198. data/test/performance/lib/performance/platform.rb +1 -8
  199. data/test/performance/script/runner +1 -3
  200. data/test/performance/suites/active_record.rb +3 -24
  201. data/test/test_helper.rb +9 -216
  202. metadata +9 -45
  203. data/lib/conditional_vendored_dependency_detection.rb +0 -7
  204. data/lib/new_relic/agent/hash_extensions.rb +0 -41
  205. data/lib/new_relic/agent/instrumentation/metric_frame.rb +0 -39
  206. data/lib/new_relic/agent/instrumentation/rails/errors.rb +0 -51
  207. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +0 -47
  208. data/lib/new_relic/agent/instrumentation/rails4/errors.rb +0 -46
  209. data/lib/new_relic/agent/stats_engine/samplers.rb +0 -22
  210. data/lib/new_relic/agent/vm/rubinius_vm.rb +0 -140
  211. data/lib/new_relic/json_wrapper.rb +0 -78
  212. data/lib/new_relic/okjson.rb +0 -602
  213. data/lib/new_relic/rack/error_collector.rb +0 -27
  214. data/lib/new_relic/timer_lib.rb +0 -31
  215. data/test/helpers/runtime_detection.rb +0 -17
  216. data/test/multiverse/suites/no_json/Envfile +0 -12
  217. data/test/multiverse/suites/no_json/config/newrelic.yml +0 -27
  218. data/test/multiverse/suites/no_json/marshal_config_test.rb +0 -22
  219. data/test/new_relic/agent/hash_extensions_test.rb +0 -59
  220. data/test/new_relic/agent/instrumentation/metric_frame_test.rb +0 -22
  221. data/test/new_relic/agent/stats_engine/samplers_test.rb +0 -98
  222. data/test/new_relic/agent/vm/rubinius_vm_test.rb +0 -69
  223. data/test/new_relic/json_wrapper_test.rb +0 -32
  224. data/test/new_relic/rack/deferred_instrumentation_test.rb +0 -33
  225. data/test/new_relic/rack/error_collector_test.rb +0 -83
  226. data/test/new_relic/version_number_test.rb +0 -101
  227. data/test/script/before_install/revert_rubygems.sh +0 -15
  228. data/test/script/before_install/update_bundler.sh +0 -12
  229. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection/version.rb +0 -7
@@ -359,7 +359,7 @@ class NewRelicServiceTest < Minitest::Test
359
359
 
360
360
  def test_profile_data_does_not_normalize_encodings
361
361
  @http_handle.respond_to(:profile_data, nil)
362
- NewRelic::JSONWrapper.expects(:normalize).never
362
+ NewRelic::Agent::EncodingNormalizer.expects(:normalize_object).never
363
363
  @service.profile_data([])
364
364
  end
365
365
 
@@ -441,122 +441,114 @@ class NewRelicServiceTest < Minitest::Test
441
441
  end
442
442
  end
443
443
 
444
- if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
445
- def test_json_marshaller_handles_responses_from_collector
446
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
447
- assert_equal ['beep', 'boop'], marshaller.load('{"return_value": ["beep","boop"]}')
448
- end
444
+ def test_json_marshaller_handles_responses_from_collector
445
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
446
+ assert_equal ['beep', 'boop'], marshaller.load('{"return_value": ["beep","boop"]}')
447
+ end
449
448
 
450
- def test_json_marshaller_handles_errors_from_collector
451
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
452
- assert_raises(NewRelic::Agent::NewRelicService::CollectorError,
453
- 'JavaCrash: error message') do
454
- marshaller.load('{"exception": {"message": "error message", "error_type": "JavaCrash"}}')
455
- end
449
+ def test_json_marshaller_handles_errors_from_collector
450
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
451
+ assert_raises(NewRelic::Agent::NewRelicService::CollectorError,
452
+ 'JavaCrash: error message') do
453
+ marshaller.load('{"exception": {"message": "error message", "error_type": "JavaCrash"}}')
456
454
  end
455
+ end
457
456
 
458
- def test_json_marshaller_logs_on_empty_response_from_collector
459
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
460
- expects_logging(:error, any_parameters)
461
- assert_nil marshaller.load('')
462
- end
457
+ def test_json_marshaller_logs_on_empty_response_from_collector
458
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
459
+ expects_logging(:error, any_parameters)
460
+ assert_nil marshaller.load('')
461
+ end
462
+
463
+ def test_json_marshaller_logs_on_nil_response_from_collector
464
+ marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
465
+ expects_logging(:error, any_parameters)
466
+ assert_nil marshaller.load(nil)
467
+ end
463
468
 
464
- def test_json_marshaller_logs_on_nil_response_from_collector
465
- marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new
466
- expects_logging(:error, any_parameters)
467
- assert_nil marshaller.load(nil)
469
+ def test_raises_serialization_error_if_json_serialization_fails
470
+ ::JSON.stubs(:dump).raises(RuntimeError.new('blah'))
471
+ assert_raises(NewRelic::Agent::SerializationError) do
472
+ @service.send(:invoke_remote, 'wiggle', [{}])
468
473
  end
474
+ end
469
475
 
470
- def test_raises_serialization_error_if_json_serialization_fails
471
- ::NewRelic::JSONWrapper.stubs(:dump).raises(RuntimeError.new('blah'))
476
+ def test_raises_serialization_error_if_encoding_normalization_fails
477
+ with_config(:normalize_json_string_encodings => true) do
478
+ @http_handle.respond_to(:wiggle, 'hi')
479
+ NewRelic::Agent::EncodingNormalizer.stubs(:normalize_object).raises('blah')
472
480
  assert_raises(NewRelic::Agent::SerializationError) do
473
481
  @service.send(:invoke_remote, 'wiggle', [{}])
474
482
  end
475
483
  end
484
+ end
476
485
 
477
- def test_raises_serialization_error_if_encoding_normalization_fails
478
- with_config(:normalize_json_string_encodings => true) do
479
- @http_handle.respond_to(:wiggle, 'hi')
480
- NewRelic::JSONWrapper.stubs(:normalize).raises('blah')
481
- assert_raises(NewRelic::Agent::SerializationError) do
482
- @service.send(:invoke_remote, 'wiggle', [{}])
483
- end
484
- end
486
+ def test_skips_normalization_if_configured_to
487
+ @http_handle.respond_to(:wiggle, 'hello')
488
+ with_config(:normalize_json_string_encodings => false) do
489
+ NewRelic::Agent::EncodingNormalizer.expects(:normalize_object).never
490
+ @service.send(:invoke_remote, 'wiggle', [{ 'foo' => 'bar' }])
485
491
  end
492
+ end
486
493
 
487
- def test_skips_normalization_if_configured_to
488
- @http_handle.respond_to(:wiggle, 'hello')
489
- with_config(:normalize_json_string_encodings => false) do
490
- NewRelic::JSONWrapper.expects(:normalize).never
491
- @service.send(:invoke_remote, 'wiggle', [{ 'foo' => 'bar' }])
492
- end
493
- end
494
-
495
- def test_json_marshaller_handles_binary_strings
496
- input_string = (0..255).to_a.pack("C*")
497
- roundtripped_string = roundtrip_data(input_string)
498
-
499
- if NewRelic::LanguageSupport.supports_string_encodings?
500
- assert_equal(Encoding.find('ASCII-8BIT'), input_string.encoding)
501
- end
502
-
503
- expected = force_to_utf8(input_string.dup)
504
- assert_equal(expected, roundtripped_string)
505
- end
494
+ def test_json_marshaller_handles_binary_strings
495
+ input_string = (0..255).to_a.pack("C*")
496
+ roundtripped_string = roundtrip_data(input_string)
497
+ assert_equal(Encoding.find('ASCII-8BIT'), input_string.encoding)
498
+ expected = force_to_utf8(input_string.dup)
499
+ assert_equal(expected, roundtripped_string)
500
+ end
506
501
 
507
- if NewRelic::LanguageSupport.supports_string_encodings?
508
- def test_json_marshaller_handles_strings_with_incorrect_encoding
509
- input_string = (0..255).to_a.pack("C*").force_encoding("UTF-8")
510
- roundtripped_string = roundtrip_data(input_string)
502
+ def test_json_marshaller_handles_strings_with_incorrect_encoding
503
+ input_string = (0..255).to_a.pack("C*").force_encoding("UTF-8")
504
+ roundtripped_string = roundtrip_data(input_string)
511
505
 
512
- assert_equal(Encoding.find('UTF-8'), input_string.encoding)
513
- expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
514
- assert_equal(expected, roundtripped_string)
515
- end
516
- end
506
+ assert_equal(Encoding.find('UTF-8'), input_string.encoding)
507
+ expected = input_string.dup.force_encoding('ISO-8859-1').encode('UTF-8')
508
+ assert_equal(expected, roundtripped_string)
509
+ end
517
510
 
518
- def test_json_marshaller_failure_when_not_normalizing
519
- input_string = (0..255).to_a.pack("C*")
520
- assert_raises(NewRelic::Agent::SerializationError) do
521
- roundtrip_data(input_string, false)
522
- end
511
+ def test_json_marshaller_failure_when_not_normalizing
512
+ input_string = (0..255).to_a.pack("C*")
513
+ assert_raises(NewRelic::Agent::SerializationError) do
514
+ roundtrip_data(input_string, false)
523
515
  end
516
+ end
524
517
 
525
- def test_json_marshaller_should_handle_crazy_strings
526
- root = generate_object_graph_with_crazy_strings
527
- result = roundtrip_data(root)
518
+ def test_json_marshaller_should_handle_crazy_strings
519
+ root = generate_object_graph_with_crazy_strings
520
+ result = roundtrip_data(root)
528
521
 
529
- # Note that there's technically a possibility of collision here:
530
- # if two of the randomly-generated key strings happen to normalize to the
531
- # same value, we might see <100 results, but the chances of this seem
532
- # vanishingly small.
533
- assert_equal(100, result.length)
534
- end
522
+ # Note that there's technically a possibility of collision here:
523
+ # if two of the randomly-generated key strings happen to normalize to the
524
+ # same value, we might see <100 results, but the chances of this seem
525
+ # vanishingly small.
526
+ assert_equal(100, result.length)
527
+ end
535
528
 
536
- def test_normalization_should_account_for_to_collector_array
537
- binary_string = generate_random_byte_sequence
538
- data = DummyDataClass.new(binary_string, [])
539
- result = roundtrip_data(data)
529
+ def test_normalization_should_account_for_to_collector_array
530
+ binary_string = generate_random_byte_sequence
531
+ data = DummyDataClass.new(binary_string, [])
532
+ result = roundtrip_data(data)
540
533
 
541
- expected_string = force_to_utf8(binary_string)
542
- assert_equal(expected_string, result[0])
543
- end
534
+ expected_string = force_to_utf8(binary_string)
535
+ assert_equal(expected_string, result[0])
536
+ end
544
537
 
545
- def test_normalization_should_account_for_to_collector_array_with_nested_encodings
546
- binary_string = generate_random_byte_sequence
547
- data = DummyDataClass.new(binary_string, [binary_string])
548
- result = roundtrip_data(data)
538
+ def test_normalization_should_account_for_to_collector_array_with_nested_encodings
539
+ binary_string = generate_random_byte_sequence
540
+ data = DummyDataClass.new(binary_string, [binary_string])
541
+ result = roundtrip_data(data)
549
542
 
550
- expected_string = force_to_utf8(binary_string)
551
- assert_equal(expected_string, result[0])
543
+ expected_string = force_to_utf8(binary_string)
544
+ assert_equal(expected_string, result[0])
552
545
 
553
- base64_encoded_compressed_json_field = result[1]
554
- compressed_json_field = Base64.decode64(base64_encoded_compressed_json_field)
555
- json_field = Zlib::Inflate.inflate(compressed_json_field)
556
- field = JSON.parse(json_field)
546
+ base64_encoded_compressed_json_field = result[1]
547
+ compressed_json_field = Base64.decode64(base64_encoded_compressed_json_field)
548
+ json_field = Zlib::Inflate.inflate(compressed_json_field)
549
+ field = JSON.parse(json_field)
557
550
 
558
- assert_equal([expected_string], field)
559
- end
551
+ assert_equal([expected_string], field)
560
552
  end
561
553
 
562
554
  def test_compress_request_if_needed_compresses_large_payloads
@@ -782,11 +774,7 @@ class NewRelicServiceTest < Minitest::Test
782
774
  end
783
775
 
784
776
  def force_to_utf8(string)
785
- if NewRelic::LanguageSupport.supports_string_encodings?
786
- string.force_encoding('ISO-8859-1').encode('UTF-8')
787
- else
788
- Iconv.iconv('utf-8', 'iso-8859-1', string).join
789
- end
777
+ string.force_encoding('ISO-8859-1').encode('UTF-8')
790
778
  end
791
779
 
792
780
  def generate_random_byte_sequence(length=255, encoding=nil)
@@ -811,11 +799,7 @@ class NewRelicServiceTest < Minitest::Test
811
799
  end
812
800
 
813
801
  def random_encoding
814
- if NewRelic::LanguageSupport.supports_string_encodings?
815
- Encoding.list.sample
816
- else
817
- nil
818
- end
802
+ Encoding.list.sample
819
803
  end
820
804
 
821
805
  def roundtrip_data(data, normalize = true)
@@ -40,24 +40,23 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
40
40
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
41
41
  end
42
42
 
43
- if NewRelic::LanguageSupport.can_fork? && !NewRelic::LanguageSupport.using_version?('1.9.1')
43
+ if NewRelic::LanguageSupport.can_fork?
44
44
  def test_listener_merges_timeslice_metrics
45
45
  metric = 'Custom/test/method'
46
- engine = NewRelic::Agent.agent.stats_engine
47
- engine.get_stats_no_scope(metric).record_data_point(1.0)
46
+
47
+ NewRelic::Agent.record_metric(metric, 1.0)
48
48
 
49
49
  start_listener_with_pipe(666)
50
50
 
51
51
  run_child(666) do
52
52
  NewRelic::Agent.after_fork
53
53
  new_engine = NewRelic::Agent::StatsEngine.new
54
- new_engine.get_stats_no_scope(metric).record_data_point(2.0)
54
+ new_engine.tl_record_unscoped_metrics(metric, 2.0)
55
55
  service = NewRelic::Agent::PipeService.new(666)
56
56
  service.metric_data(new_engine.harvest!)
57
57
  end
58
58
 
59
59
  assert_metrics_recorded(metric => { :total_call_time => 3.0 })
60
- engine.reset!
61
60
  end
62
61
 
63
62
  def test_listener_merges_transaction_traces
@@ -259,10 +258,6 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
259
258
  end
260
259
 
261
260
  def test_listener_pipes_race_condition
262
- # 1.8.7 doesn't have easy singleton_class access, but also doesn't have
263
- # races thanks to green threads and the GIL, so pitch it!
264
- return if RUBY_VERSION < "1.9.2"
265
-
266
261
  begin
267
262
  listener = NewRelic::Agent::PipeChannelManager.listener
268
263
  listener.instance_variable_set(:@select_timeout, 0.00001)
@@ -36,8 +36,7 @@ class PipeServiceTest < Minitest::Test
36
36
  service.metric_data({})
37
37
  end
38
38
 
39
- if NewRelic::LanguageSupport.can_fork? &&
40
- !NewRelic::LanguageSupport.using_version?('1.9.1')
39
+ if NewRelic::LanguageSupport.can_fork?
41
40
 
42
41
  def test_metric_data
43
42
  received_data = data_from_forked_process do
@@ -128,7 +127,7 @@ class PipeServiceTest < Minitest::Test
128
127
 
129
128
  def generate_metric_data(metric_name, data=1.0)
130
129
  engine = NewRelic::Agent::StatsEngine.new
131
- engine.get_stats_no_scope(metric_name).record_data_point(data)
130
+ engine.tl_record_unscoped_metrics(metric_name, data)
132
131
  engine.harvest!
133
132
  end
134
133
 
@@ -88,8 +88,4 @@ class NewRelic::Agent::RpmAgentTest < Minitest::Test
88
88
  def test_agent_version_string
89
89
  assert_match(/\d\.\d+\.\d+/, NewRelic::VERSION::STRING)
90
90
  end
91
-
92
- def test_record_transaction
93
- NewRelic::Agent.record_transaction 0.5, 'uri' => "/users/create?foo=bar"
94
- end
95
91
  end
@@ -2,8 +2,8 @@
2
2
  # This file is distributed under New Relic's license terms.
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
- require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
- require 'test/new_relic/agent/event_buffer_test_cases'
5
+ require File.expand_path '../../../test_helper', __FILE__
6
+ require 'new_relic/agent/event_buffer_test_cases'
7
7
 
8
8
  module NewRelic::Agent
9
9
  class SampledBufferTest < Minitest::Test
@@ -48,4 +48,32 @@ class NewRelic::Agent::Samplers::CpuSamplerTest < Minitest::Test
48
48
  Object.const_set('JRUBY_VERSION', string)
49
49
  end
50
50
 
51
+ def test_cpu_sampler_records_user_and_system_time
52
+ timeinfo0 = mock
53
+ timeinfo0.stubs(:utime).returns(10.0)
54
+ timeinfo0.stubs(:stime).returns(5.0)
55
+
56
+ timeinfo1 = mock
57
+ timeinfo1.stubs(:utime).returns(14.0) # +5s
58
+ timeinfo1.stubs(:stime).returns(7.0) # +2s
59
+
60
+ elapsed = 10
61
+
62
+ freeze_time
63
+ Process.stubs(:times).returns(timeinfo0, timeinfo1)
64
+ NewRelic::Agent::SystemInfo.stubs(:num_logical_processors).returns(4)
65
+
66
+ s = NewRelic::Agent::Samplers::CpuSampler.new # this calls poll
67
+ advance_time(elapsed)
68
+ s.poll
69
+
70
+ assert_metrics_recorded({
71
+ 'CPU/User Time' => { :call_count => 1, :total_call_time => 4.0 },
72
+ 'CPU/System Time' => { :call_count => 1, :total_call_time => 2.0 },
73
+ # (4s user time) / ((10s elapsed time) * 4 cpus) = 0.1
74
+ 'CPU/User/Utilization' => { :call_count => 1, :total_call_time => 0.1 },
75
+ # (2s system time) / ((10s elapsed time) * 4 cpus) = 0.05
76
+ 'CPU/System/Utilization' => { :call_count => 1, :total_call_time => 0.05 }
77
+ })
78
+ end
51
79
  end
@@ -0,0 +1,66 @@
1
+ # -*- ruby -*-
2
+ # encoding: utf-8
3
+ # This file is distributed under New Relic's license terms.
4
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
7
+ require 'new_relic/agent/samplers/memory_sampler'
8
+
9
+ class NewRelic::Agent::Samplers::MemorySamplerTest < Minitest::Test
10
+ def setup
11
+ @stats_engine = NewRelic::Agent::StatsEngine.new
12
+ NewRelic::Agent.instance.stubs(:stats_engine).returns(@stats_engine)
13
+ end
14
+
15
+ def test_memory__default
16
+ stub_sampler_get_memory
17
+ s = NewRelic::Agent::Samplers::MemorySampler.new
18
+ s.poll
19
+ s.poll
20
+ s.poll
21
+ assert_metrics_recorded "Memory/Physical" => {:call_count => 3, :total_call_time => 999}
22
+ end
23
+
24
+ def test_memory__linux
25
+ return if RUBY_PLATFORM =~ /darwin/
26
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'linux'
27
+ stub_sampler_get_memory
28
+ s = NewRelic::Agent::Samplers::MemorySampler.new
29
+ s.poll
30
+ s.poll
31
+ s.poll
32
+
33
+ assert_metrics_recorded "Memory/Physical" => {:call_count => 3, :total_call_time => 999}
34
+ end
35
+
36
+ def test_memory__solaris
37
+ return if defined? JRuby
38
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'solaris'
39
+ NewRelic::Agent::Samplers::MemorySampler::ShellPS.any_instance.stubs(:get_memory).returns 999
40
+ s = NewRelic::Agent::Samplers::MemorySampler.new
41
+ s.poll
42
+ assert_metrics_recorded "Memory/Physical" => {:call_count => 1, :total_call_time => 999}
43
+ end
44
+
45
+ def test_memory__windows
46
+ return if defined? JRuby
47
+ NewRelic::Agent::Samplers::MemorySampler.any_instance.stubs(:platform).returns 'win32'
48
+ assert_raises NewRelic::Agent::Sampler::Unsupported do
49
+ NewRelic::Agent::Samplers::MemorySampler.new
50
+ end
51
+ end
52
+
53
+ def test_memory__is_supported
54
+ NewRelic::Agent::Samplers::MemorySampler.stubs(:platform).returns 'windows'
55
+ assert !NewRelic::Agent::Samplers::MemorySampler.supported_on_this_platform? || defined? JRuby
56
+ end
57
+
58
+ def stub_sampler_get_memory
59
+ if defined? JRuby
60
+ NewRelic::Agent::Samplers::MemorySampler::JavaHeapSampler.any_instance.stubs(:get_memory).returns 333
61
+ else
62
+ NewRelic::Agent::Samplers::MemorySampler::ShellPS.any_instance.stubs(:get_memory).returns 333
63
+ NewRelic::Agent::Samplers::MemorySampler::ProcStatus.any_instance.stubs(:get_memory).returns 333
64
+ end
65
+ end
66
+ end
@@ -3,7 +3,7 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
- require 'test/new_relic/agent/event_buffer_test_cases'
6
+ require 'new_relic/agent/event_buffer_test_cases'
7
7
  require 'new_relic/agent/sized_buffer'
8
8
 
9
9
  module NewRelic::Agent
@@ -30,7 +30,7 @@ class NewRelic::Agent::StatsEngine
30
30
 
31
31
  def test_init_profiler_for_ruby_19_and_greater
32
32
  return unless defined?(::GC::Profiler)
33
- return if NewRelic::LanguageSupport.using_engine?('jruby')
33
+ return if NewRelic::LanguageSupport.jruby?
34
34
 
35
35
  ::GC::Profiler.stubs(:enabled?).returns(true)
36
36
 
@@ -38,26 +38,14 @@ class NewRelic::Agent::StatsEngine
38
38
  GCProfiler.init.class)
39
39
  end
40
40
 
41
- def test_init_profiler_for_rbx_uses_stdlib
42
- return unless defined?(::Rubinius::GC)
43
-
44
- assert_equal(GCProfiler::CoreGCProfiler,
45
- GCProfiler.init.class)
46
- end
47
-
48
41
  def test_record_delta_returns_nil_when_snapshots_are_nil
49
42
  result = GCProfiler.record_delta(nil, nil)
50
43
  assert_nil(result)
51
44
  assert_metrics_not_recorded([GCProfiler::GC_ROLLUP, GCProfiler::GC_WEB, GCProfiler::GC_OTHER])
52
45
  end
53
46
 
54
- using_jruby = NewRelic::LanguageSupport.jruby?
55
- using_ree = NewRelic::LanguageSupport.ree?
56
- using_ruby18 = NewRelic::LanguageSupport.using_version?('1.8')
57
- using_ruby19_plus = !using_ruby18
58
-
59
47
  # Only run these tests in environments where GCProfiler is usable
60
- if !using_jruby && (using_ree || using_ruby19_plus)
48
+ if !NewRelic::LanguageSupport.jruby?
61
49
  def test_record_delta_returns_delta_in_seconds
62
50
  GCProfiler.init
63
51