newrelic_rpm 3.7.3.204 → 3.8.0.218

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +73 -0
  3. data/README.md +1 -1
  4. data/Rakefile +1 -5
  5. data/lib/new_relic/agent.rb +1 -0
  6. data/lib/new_relic/agent/agent.rb +47 -18
  7. data/lib/new_relic/agent/agent_logger.rb +11 -1
  8. data/lib/new_relic/agent/configuration/default_source.rb +85 -1
  9. data/lib/new_relic/agent/configuration/manager.rb +5 -1
  10. data/lib/new_relic/agent/datastores/mongo.rb +8 -3
  11. data/lib/new_relic/agent/harvester.rb +5 -1
  12. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -0
  13. data/lib/new_relic/agent/instrumentation/active_merchant.rb +7 -3
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +13 -3
  15. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +7 -1
  16. data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -1
  17. data/lib/new_relic/agent/instrumentation/sinatra.rb +3 -1
  18. data/lib/new_relic/agent/new_relic_service.rb +8 -0
  19. data/lib/new_relic/agent/request_sampler.rb +1 -1
  20. data/lib/new_relic/agent/sampler.rb +22 -2
  21. data/lib/new_relic/agent/sampler_collection.rb +13 -1
  22. data/lib/new_relic/agent/samplers/cpu_sampler.rb +3 -1
  23. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -1
  24. data/lib/new_relic/agent/samplers/memory_sampler.rb +2 -1
  25. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -3
  26. data/lib/new_relic/agent/samplers/vm_sampler.rb +126 -0
  27. data/lib/new_relic/agent/stats.rb +0 -15
  28. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +66 -75
  29. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  30. data/lib/new_relic/agent/supported_versions.rb +2 -2
  31. data/lib/new_relic/agent/transaction.rb +6 -3
  32. data/lib/new_relic/agent/vm/monotonic_gc_profiler.rb +17 -5
  33. data/lib/new_relic/agent/vm/mri_vm.rb +2 -1
  34. data/lib/new_relic/agent/vm/snapshot.rb +5 -1
  35. data/lib/new_relic/control/instance_methods.rb +8 -5
  36. data/lib/new_relic/control/instrumentation.rb +0 -9
  37. data/lib/new_relic/environment_report.rb +1 -1
  38. data/lib/new_relic/language_support.rb +4 -0
  39. data/lib/new_relic/local_environment.rb +39 -14
  40. data/lib/new_relic/noticed_error.rb +7 -4
  41. data/lib/new_relic/rack/browser_monitoring.rb +16 -3
  42. data/lib/new_relic/version.rb +2 -2
  43. data/newrelic_rpm.gemspec +1 -1
  44. data/test/agent_helper.rb +5 -3
  45. data/test/environments/lib/environments/runner.rb +8 -7
  46. data/test/environments/norails/Gemfile +1 -1
  47. data/test/environments/rails21/Gemfile +1 -0
  48. data/test/environments/rails22/Gemfile +1 -0
  49. data/test/environments/rails23/Gemfile +1 -0
  50. data/test/environments/rails30/Gemfile +4 -1
  51. data/test/environments/rails31/Gemfile +4 -1
  52. data/test/environments/rails32/Gemfile +3 -4
  53. data/test/environments/rails40/Gemfile +1 -1
  54. data/test/environments/rails41/Gemfile +1 -1
  55. data/test/flaky_proxy/lib/flaky_proxy/proxy.rb +1 -0
  56. data/test/multiverse/lib/multiverse/output_collector.rb +3 -1
  57. data/test/multiverse/lib/multiverse/runner.rb +2 -10
  58. data/test/multiverse/lib/multiverse/suite.rb +100 -30
  59. data/test/multiverse/suites/activemerchant/Envfile +16 -0
  60. data/test/multiverse/suites/activemerchant/activemerchant_test.rb +65 -0
  61. data/test/multiverse/suites/agent_only/custom_queue_time_test.rb +57 -0
  62. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +1 -1
  63. data/test/multiverse/suites/mongo/Envfile +9 -1
  64. data/test/multiverse/suites/rails/Envfile +2 -2
  65. data/test/multiverse/suites/rails/app.rb +3 -0
  66. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +0 -2
  67. data/test/multiverse/suites/rails/error_tracing_test.rb +1 -2
  68. data/test/multiverse/suites/rails/gc_instrumentation_test.rb +17 -8
  69. data/test/multiverse/suites/rails/ignore_test.rb +0 -2
  70. data/test/multiverse/suites/rails/mongrel_queue_depth_test.rb +0 -2
  71. data/test/multiverse/suites/rails/queue_time_test.rb +40 -11
  72. data/test/multiverse/suites/rails/request_statistics_test.rb +0 -3
  73. data/test/multiverse/suites/rails/view_instrumentation_test.rb +0 -2
  74. data/test/multiverse/suites/sidekiq/Envfile +7 -2
  75. data/test/multiverse/suites/sinatra/Envfile +1 -1
  76. data/test/multiverse/suites/sinatra/nested_middleware_test.rb +41 -0
  77. data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +1 -1
  78. data/test/new_relic/agent/agent/connect_test.rb +32 -4
  79. data/test/new_relic/agent/agent/start_test.rb +9 -1
  80. data/test/new_relic/agent/agent_logger_test.rb +23 -2
  81. data/test/new_relic/agent/agent_test.rb +49 -7
  82. data/test/new_relic/agent/configuration/manager_test.rb +8 -0
  83. data/test/new_relic/agent/configuration/orphan_configuration_test.rb +7 -0
  84. data/test/new_relic/agent/cross_app_monitor_test.rb +5 -6
  85. data/test/new_relic/agent/harvester_test.rb +13 -8
  86. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +28 -7
  87. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +32 -21
  88. data/test/new_relic/agent/new_relic_service_test.rb +14 -0
  89. data/test/new_relic/agent/request_sampler_test.rb +5 -3
  90. data/test/new_relic/agent/rpm_agent_test.rb +2 -3
  91. data/test/new_relic/agent/sampler_collection_test.rb +15 -5
  92. data/test/new_relic/agent/sampler_test.rb +43 -0
  93. data/test/new_relic/agent/{cpu_sampler_test.rb → samplers/cpu_sampler_test.rb} +1 -1
  94. data/test/new_relic/agent/samplers/vm_sampler_test.rb +349 -0
  95. data/test/new_relic/agent/stats_engine/gc_profiler_test.rb +165 -44
  96. data/test/new_relic/agent/stats_hash_test.rb +1 -1
  97. data/test/new_relic/agent/transaction_test.rb +14 -0
  98. data/test/new_relic/agent/vm/monotonic_gc_profiler_test.rb +5 -5
  99. data/test/new_relic/agent/vm/mri_vm_test.rb +7 -0
  100. data/test/new_relic/agent/vm/snapshot_test.rb +5 -0
  101. data/test/new_relic/agent_test.rb +2 -2
  102. data/test/new_relic/control/instance_methods_test.rb +30 -0
  103. data/test/new_relic/control_test.rb +43 -21
  104. data/test/new_relic/dispatcher_test.rb +5 -0
  105. data/test/new_relic/local_environment_test.rb +3 -26
  106. data/test/new_relic/multiverse_helpers.rb +5 -0
  107. data/test/new_relic/noticed_error_test.rb +7 -0
  108. data/test/new_relic/rack/browser_monitoring_test.rb +13 -14
  109. data/test/test_helper.rb +2 -1
  110. metadata +56 -68
  111. metadata.gz.sig +1 -1
  112. data/lib/new_relic/agent/instrumentation/puma.rb +0 -25
  113. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +0 -26
  114. data/test/multiverse/script/run_one +0 -5
  115. data/test/rum/basic.result.html +0 -10
  116. data/test/rum/basic.source.html +0 -10
  117. data/test/rum/comments1.result.html +0 -24
  118. data/test/rum/comments1.source.html +0 -24
  119. data/test/rum/comments2.result.html +0 -24
  120. data/test/rum/comments2.source.html +0 -24
  121. data/test/rum/gt_in_quotes1.result.html +0 -27
  122. data/test/rum/gt_in_quotes1.source.html +0 -27
  123. data/test/rum/gt_in_quotes2.result.html +0 -24
  124. data/test/rum/gt_in_quotes2.source.html +0 -24
  125. data/test/rum/gt_in_quotes_mismatch.result.html +0 -24
  126. data/test/rum/gt_in_quotes_mismatch.source.html +0 -24
  127. data/test/rum/gt_in_single_quotes1.result.html +0 -25
  128. data/test/rum/gt_in_single_quotes1.source.html +0 -25
  129. data/test/rum/gt_in_single_quotes_mismatch.result.html +0 -25
  130. data/test/rum/gt_in_single_quotes_mismatch.source.html +0 -25
  131. data/test/rum/incomplete_non_meta_tags.result.html +0 -10
  132. data/test/rum/incomplete_non_meta_tags.source.html +0 -10
  133. data/test/rum/no_body.result.html +0 -21
  134. data/test/rum/no_body.source.html +0 -21
  135. data/test/rum/no_header.result.html +0 -7
  136. data/test/rum/no_header.source.html +0 -7
  137. data/test/rum/no_html_and_no_header.result.html +0 -3
  138. data/test/rum/no_html_and_no_header.source.html +0 -3
  139. data/test/rum/no_start_header.result.html +0 -9
  140. data/test/rum/no_start_header.source.html +0 -9
  141. data/test/rum/script1.result.html +0 -19
  142. data/test/rum/script1.source.html +0 -19
  143. data/test/rum/script2.result.html +0 -17
  144. data/test/rum/script2.source.html +0 -17
  145. data/test/rum/x_ua_meta_tag.result.html +0 -10
  146. data/test/rum/x_ua_meta_tag.source.html +0 -10
  147. data/test/rum/x_ua_meta_tag_multiline.result.html +0 -11
  148. data/test/rum/x_ua_meta_tag_multiline.source.html +0 -11
  149. data/test/rum/x_ua_meta_tag_spaces_around_equals.result.html +0 -10
  150. data/test/rum/x_ua_meta_tag_spaces_around_equals.source.html +0 -10
  151. data/test/rum/x_ua_meta_tag_with_others.result.html +0 -11
  152. data/test/rum/x_ua_meta_tag_with_others.source.html +0 -11
  153. data/test/rum/x_ua_meta_tag_with_spaces.result.html +0 -10
  154. data/test/rum/x_ua_meta_tag_with_spaces.source.html +0 -10
@@ -0,0 +1,57 @@
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 CustomQueueTimeTest < Minitest::Test
9
+ include MultiverseHelpers
10
+
11
+ setup_and_teardown_agent
12
+
13
+ DummyRequest = Struct.new(:headers, :cookies)
14
+
15
+ class DummyApp
16
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
17
+
18
+ def run_transaction(request, simulated_queue_time)
19
+ opts = { :name => 'run_transaction', :class_name => 'DummyApp', :request => request }
20
+
21
+ advance_time(simulated_queue_time)
22
+
23
+ perform_action_with_newrelic_trace(opts) do
24
+ # nothing
25
+ end
26
+ end
27
+ end
28
+
29
+ def setup
30
+ freeze_time
31
+ @headers = { 'HTTP_X_REQUEST_START' => "t=#{Time.now.to_f}" }
32
+ end
33
+
34
+ def test_pulls_request_headers_from_passed_in_rack_request
35
+ request = Rack::Request.new(@headers)
36
+ DummyApp.new.run_transaction(request, 10)
37
+
38
+ assert_metrics_recorded(
39
+ 'WebFrontend/QueueTime' => {
40
+ :call_count => 1,
41
+ :total_call_time => 10
42
+ }
43
+ )
44
+ end
45
+
46
+ def test_pulls_request_headers_from_passed_in_request_responding_to_headers
47
+ request = DummyRequest.new(@headers, {})
48
+ DummyApp.new.run_transaction(request, 10)
49
+
50
+ assert_metrics_recorded(
51
+ 'WebFrontend/QueueTime' => {
52
+ :call_count => 1,
53
+ :total_call_time => 10
54
+ }
55
+ )
56
+ end
57
+ end
@@ -69,7 +69,7 @@ bazbangbarn:
69
69
 
70
70
  def assert_config_read_from(path)
71
71
  setup_config(path)
72
- assert NewRelic::Agent.config[:foo] == "success!!", "Failed to read yaml config from #{path.inspect}\n\n#{NewRelic::Agent.config.inspect}"
72
+ assert NewRelic::Agent.config[:foo] == "success!!", "Failed to read yaml config from #{path.inspect[0..100]}\n\n#{NewRelic::Agent.config.inspect[0..100]}"
73
73
  end
74
74
 
75
75
  def assert_config_not_read_from(path)
@@ -1,3 +1,11 @@
1
+ # Versions >= 1.10.0 are not supported at this time.
2
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE != 'jruby'
3
+ gemfile <<-RB
4
+ gem 'mongo', '1.10.0'
5
+ gem 'bson_ext', :platforms => :ruby
6
+ RB
7
+ end
8
+
1
9
  gemfile <<-RB
2
10
  gem 'mongo', '1.9.2'
3
11
  gem 'bson_ext', :platforms => :ruby
@@ -8,7 +16,7 @@ gemfile <<-RB
8
16
  gem 'bson_ext', :platforms => :ruby
9
17
  RB
10
18
 
11
- # Newest unsupported version of the driver!
19
+ # Versions <= 1.7.1 are not supported and never will be.
12
20
  gemfile <<-RB
13
21
  gem 'mongo', '~>1.7.1'
14
22
  gem 'bson_ext', :platforms => :ruby
@@ -1,6 +1,6 @@
1
1
  if RUBY_VERSION >= '1.9.3'
2
2
  gemfile <<-RB
3
- gem 'rails', '~>4.1.0.rc1'
3
+ gem 'rails', '~>4.1.0'
4
4
  # Multiverse has an incompatibility with Minitest 5.3.0, so lock here for
5
5
  # now
6
6
  gem 'minitest', '5.2.3'
@@ -10,7 +10,7 @@ if RUBY_VERSION >= '1.9.3'
10
10
  RB
11
11
 
12
12
  gemfile <<-RB
13
- gem 'rails', '~>4.0.2'
13
+ gem 'rails', '~>4.0.4'
14
14
  gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
15
15
  RB
16
16
  end
@@ -5,6 +5,9 @@
5
5
  require 'action_controller/railtie'
6
6
  require 'active_model'
7
7
 
8
+ require 'multiverse_helpers'
9
+ require 'rails/test_help'
10
+
8
11
  # We define our single Rails application here, one time, upon the first inclusion
9
12
  # Tests should feel free to define their own Controllers locally, but if they
10
13
  # need anything special at the Application level, put it here
@@ -3,8 +3,6 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require './app'
6
- require 'rails/test_help'
7
- require 'multiverse_helpers'
8
6
 
9
7
  class BadInstrumentationController < ApplicationController
10
8
  include Rails.application.routes.url_helpers
@@ -3,9 +3,8 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  # https://newrelic.atlassian.net/browse/RUBY-747
6
- require 'rails/test_help'
6
+ require './app'
7
7
  require 'fake_collector'
8
- require 'multiverse_helpers'
9
8
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'helpers', 'exceptions'))
10
9
 
11
10
  class ErrorController < ApplicationController
@@ -3,21 +3,20 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require './app'
6
- require 'multiverse_helpers'
7
6
 
8
7
  # GC instrumentation only works with REE or MRI >= 1.9.2
9
- if (defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise/) ||
10
- (RUBY_VERSION >= '1.9.2' && !NewRelic::LanguageSupport.using_engine?('jruby'))
8
+ if NewRelic::LanguageSupport.ree? ||
9
+ (RUBY_VERSION >= '1.9.2' && !NewRelic::LanguageSupport.jruby?)
11
10
 
12
11
  class GcController < ApplicationController
13
12
  include Rails.application.routes.url_helpers
14
13
  def gc_action
15
14
  begin
16
15
  profiler = NewRelic::Agent::StatsEngine::GCProfiler.init
17
- gc_count = profiler.call_count
16
+ initial_gc_count = current_gc_count
18
17
 
19
18
  Timeout.timeout(5) do
20
- until profiler.call_count > gc_count
19
+ until current_gc_count > initial_gc_count
21
20
  long_string = "01234567" * 100_000
22
21
  long_string = nil
23
22
  another_long_string = "01234567" * 100_000
@@ -29,6 +28,14 @@ class GcController < ApplicationController
29
28
 
30
29
  render :text => 'ha'
31
30
  end
31
+
32
+ def current_gc_count
33
+ if NewRelic::LanguageSupport.ree?
34
+ ::GC.collections
35
+ elsif RUBY_VERSION >= '1.9.2'
36
+ ::GC.count
37
+ end
38
+ end
32
39
  end
33
40
 
34
41
  class GCRailsInstrumentationTest < ActionController::TestCase
@@ -37,6 +44,8 @@ class GCRailsInstrumentationTest < ActionController::TestCase
37
44
  include MultiverseHelpers
38
45
 
39
46
  setup_and_teardown_agent do
47
+ NewRelic::Agent.drop_buffered_data
48
+ NewRelic::Agent::StatsEngine::GCProfiler.reset
40
49
  enable_gc_stats
41
50
  @controller = GcController.new
42
51
  end
@@ -46,8 +55,8 @@ class GCRailsInstrumentationTest < ActionController::TestCase
46
55
  get :gc_action
47
56
  elapsed = Time.now.to_f - start.to_f
48
57
 
49
- assert_in_range(elapsed, get_call_time('GC/cumulative'))
50
- assert_in_range(elapsed, get_call_time('GC/cumulative', 'Controller/gc/gc_action'))
58
+ assert_in_range(elapsed, get_call_time('GC/Transaction/allWeb'))
59
+ assert_in_range(elapsed, get_call_time('GC/Transaction/allWeb', 'Controller/gc/gc_action'))
51
60
  end
52
61
 
53
62
  def test_records_transaction_param_for_gc_activity
@@ -71,7 +80,7 @@ class GCRailsInstrumentationTest < ActionController::TestCase
71
80
  end
72
81
 
73
82
  def enable_gc_stats
74
- if RUBY_DESCRIPTION =~ /Enterprise/
83
+ if NewRelic::LanguageSupport.ree?
75
84
  GC.enable_stats
76
85
  elsif RUBY_VERSION >= '1.9.2'
77
86
  GC::Profiler.enable
@@ -4,9 +4,7 @@
4
4
 
5
5
  # https://newrelic.atlassian.net/browse/RUBY-927
6
6
 
7
- require 'rails/test_help'
8
7
  require './app'
9
- require 'multiverse_helpers'
10
8
 
11
9
  class IgnoredController < ApplicationController
12
10
  include Rails.application.routes.url_helpers
@@ -7,9 +7,7 @@
7
7
  # Mongrel is only supported on older versions, so don't check for queue depth
8
8
  if Rails::VERSION::MAJOR.to_i < 4
9
9
 
10
- require 'rails/test_help'
11
10
  require './app'
12
- require 'multiverse_helpers'
13
11
  require 'ostruct'
14
12
 
15
13
  class MongrelController < ApplicationController
@@ -4,9 +4,7 @@
4
4
 
5
5
  # https://newrelic.atlassian.net/browse/RUBY-927
6
6
 
7
- require 'rails/test_help'
8
7
  require './app'
9
- require 'multiverse_helpers'
10
8
 
11
9
  class QueueController < ApplicationController
12
10
  include Rails.application.routes.url_helpers
@@ -16,30 +14,61 @@ class QueueController < ApplicationController
16
14
  format.html { render :text => "<html><head></head><body>Queued</body></html>" }
17
15
  end
18
16
  end
17
+
18
+ def nested
19
+ nested_transaction
20
+ render :text => 'whatever'
21
+ end
22
+
23
+ def nested_transaction; end
24
+
25
+ add_transaction_tracer :nested_transaction
19
26
  end
20
27
 
21
28
  class QueueTimeTest < ActionDispatch::IntegrationTest
22
29
 
30
+ REQUEST_START_HEADER = 'HTTP_X_REQUEST_START'
31
+
23
32
  include MultiverseHelpers
24
33
 
25
34
  setup_and_teardown_agent(:beacon => "beacon", :browser_key => "key", :js_agent_loader => "loader")
26
35
 
27
36
  def test_should_track_queue_time_metric
28
- get_queued
37
+ t0 = freeze_time
38
+ t1 = advance_time(2)
39
+ get_path('/queue/queued', t0)
29
40
 
30
- stat = agent.stats_engine.lookup_stats('WebFrontend/QueueTime')
31
- assert_equal 1, stat.call_count
32
- assert stat.total_call_time > 0, "Should track some queue time"
41
+ assert_metrics_recorded(
42
+ 'WebFrontend/QueueTime' => {
43
+ :call_count => 1,
44
+ :total_call_time => (t1 - t0)
45
+ }
46
+ )
33
47
  end
34
48
 
35
49
  def test_should_see_queue_time_in_rum
36
- get_queued
37
- assert extract_queue_time_from_response > 0, "Queue time was missing or zero"
50
+ t0 = freeze_time
51
+ t1 = advance_time(2)
52
+ get_path('/queue/queued', t0)
53
+ queue_time = extract_queue_time_from_response
54
+ assert_equal((t1 - t0) * 1000, queue_time)
55
+ end
56
+
57
+ def test_should_not_track_queue_time_for_nested_transactions
58
+ t0 = freeze_time
59
+ t1 = advance_time(2)
60
+ get_path('/queue/nested', t0)
61
+ assert_metrics_recorded(
62
+ 'WebFrontend/QueueTime' => {
63
+ :call_count => 1,
64
+ :total_call_time => (t1 - t0)
65
+ }
66
+ )
38
67
  end
39
68
 
40
- def get_queued(header="HTTP_X_REQUEST_START")
41
- value = "t=#{(Time.now.to_i * 1_000_000) - 1_000}"
42
- get('/queue/queued', nil, header => value)
69
+ def get_path(path, queue_start_time)
70
+ value = "t=#{(queue_start_time.to_f * 1_000_000).to_i}"
71
+ get(path, nil, REQUEST_START_HEADER => value)
43
72
  end
44
73
 
45
74
  def extract_queue_time_from_response
@@ -4,10 +4,7 @@
4
4
 
5
5
  # https://newrelic.atlassian.net/browse/RUBY-1096
6
6
 
7
- require 'rails/test_help'
8
7
  require './app'
9
- require 'multiverse_helpers'
10
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper')
11
8
 
12
9
  class RequestStatsController < ApplicationController
13
10
  include Rails.application.routes.url_helpers
@@ -3,9 +3,7 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require './app'
6
- require 'rails/test_help'
7
6
  require 'haml'
8
- require 'multiverse_helpers'
9
7
 
10
8
  ActionController::Base.view_paths = ['app/views']
11
9
 
@@ -3,9 +3,14 @@ suite_condition("SideKiq requires MRI 1.9.3 or JRuby 1.6 in 1.9 mode") do
3
3
  end
4
4
 
5
5
  gemfile <<-RB
6
- # Latest version
7
6
  gem 'json'
8
- gem 'sidekiq', '~> 2.17.0'
7
+ gem 'sidekiq', '~> 3.0.0'
8
+ gem 'rack'
9
+ RB
10
+
11
+ gemfile <<-RB
12
+ gem 'json'
13
+ gem 'sidekiq', '~> 2.17.7'
9
14
  gem 'rack'
10
15
  RB
11
16
 
@@ -1,5 +1,5 @@
1
1
  gemfile <<-RB
2
- gem 'sinatra', '~> 1.4.4'
2
+ gem 'sinatra', '~> 1.4.5'
3
3
  gem 'rack-test', :require => 'rack/test'
4
4
  RB
5
5
 
@@ -0,0 +1,41 @@
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__), '..', '..', '..', 'agent_helper'))
6
+
7
+ class MiddlewareApp < Sinatra::Base
8
+ get '/middle' do
9
+ "From the middlewarez"
10
+ end
11
+ end
12
+
13
+ class MainApp < Sinatra::Base
14
+ use MiddlewareApp
15
+
16
+ get '/main' do
17
+ "mainly done"
18
+ end
19
+ end
20
+
21
+ class NestedMiddlewareTest < Minitest::Test
22
+ include Rack::Test::Methods
23
+ include MultiverseHelpers
24
+
25
+ def app
26
+ MainApp
27
+ end
28
+
29
+ setup_and_teardown_agent
30
+
31
+ def test_inner_transaction
32
+ get '/main'
33
+ assert_metrics_recorded(["Controller/Sinatra/MainApp/GET main"])
34
+ assert_metrics_not_recorded(["Controller/Sinatra/MiddlewareApp/GET (unknown)"])
35
+ end
36
+
37
+ def test_outer_transaction
38
+ get '/middle'
39
+ assert_metrics_recorded(["Controller/Sinatra/MiddlewareApp/GET middle"])
40
+ end
41
+ end
@@ -73,7 +73,7 @@ class SinatraMetricExplosionTest < Minitest::Test
73
73
 
74
74
  name_beginnings_to_ignore = [
75
75
  "Supportability",
76
- "GC/cumulative"
76
+ "GC/Transaction"
77
77
  ]
78
78
  metric_names.delete_if do|metric|
79
79
  name_beginnings_to_ignore.any? {|name| metric.start_with?(name)}
@@ -21,11 +21,16 @@ class NewRelic::Agent::Agent::ConnectTest < Minitest::Test
21
21
  @stats_engine = NewRelic::Agent::StatsEngine.new
22
22
  server = NewRelic::Control::Server.new('localhost', 30303)
23
23
  @service = NewRelic::Agent::NewRelicService.new('abcdef', server)
24
+ NewRelic::Agent.instance.service = @service
25
+ @local_host = nil
26
+
24
27
  @test_config = { :developer_mode => true }
28
+ NewRelic::Agent.reset_config
25
29
  NewRelic::Agent.config.apply_config(@test_config)
26
30
  end
27
31
 
28
32
  def teardown
33
+ NewRelic::Agent.reset_config
29
34
  NewRelic::Agent.config.remove_config(@test_config)
30
35
  end
31
36
 
@@ -39,6 +44,10 @@ class NewRelic::Agent::Agent::ConnectTest < Minitest::Test
39
44
  fake_control
40
45
  end
41
46
 
47
+ def local_host
48
+ @local_host
49
+ end
50
+
42
51
  def test_should_connect_if_pending
43
52
  @connect_state = :pending
44
53
  assert(should_connect?, "should attempt to connect if pending")
@@ -99,11 +108,16 @@ class NewRelic::Agent::Agent::ConnectTest < Minitest::Test
99
108
  end
100
109
 
101
110
  def test_connect_settings
102
- NewRelic::Agent.config.expects(:app_names)
103
- keys = %w(pid host app_name language agent_version environment settings)
104
- value = connect_settings
111
+ NewRelic::Agent.config.expects(:app_names).returns(["apps"])
112
+ @local_host = "lo-calhost"
113
+ @environment_report = {}
114
+
115
+ keys = %w(pid host app_name language agent_version environment settings).map(&:to_sym)
116
+
117
+ settings = connect_settings
105
118
  keys.each do |k|
106
- assert(value.has_key?(k.to_sym), "should include the key #{k}")
119
+ assert_includes(settings.keys, k)
120
+ refute_nil(settings[k], "expected a value for #{k}")
107
121
  end
108
122
  end
109
123
 
@@ -250,6 +264,20 @@ class NewRelic::Agent::Agent::ConnectTest < Minitest::Test
250
264
  end
251
265
  end
252
266
 
267
+ def test_finish_setup_replaces_server_config
268
+ finish_setup(:boo => "boo")
269
+ finish_setup(:hoo => true)
270
+
271
+ assert_equal 1, server_layers.length
272
+
273
+ assert NewRelic::Agent.config[:hoo]
274
+ assert_nil NewRelic::Agent.config[:boo]
275
+ end
276
+
277
+ def server_layers
278
+ stack = NewRelic::Agent.config.config_stack
279
+ stack.select{|layer| layer.class == NewRelic::Agent::Configuration::ServerSource}
280
+ end
253
281
 
254
282
  def test_logging_collector_messages
255
283
  NewRelic::Agent.manual_start