newrelic_rpm 3.6.4.122 → 3.6.5.130

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +14 -1
  3. data/lib/new_relic/agent.rb +8 -7
  4. data/lib/new_relic/agent/agent.rb +2 -0
  5. data/lib/new_relic/agent/configuration/defaults.rb +1 -1
  6. data/lib/new_relic/agent/configuration/server_source.rb +2 -1
  7. data/lib/new_relic/agent/cross_app_tracing.rb +52 -26
  8. data/lib/new_relic/agent/event_listener.rb +1 -1
  9. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +61 -0
  10. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +46 -0
  11. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +72 -0
  12. data/lib/new_relic/agent/{uri_util.rb → http_clients/uri_util.rb} +11 -17
  13. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -11
  14. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -1
  15. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -2
  16. data/lib/new_relic/agent/instrumentation/excon.rb +72 -0
  17. data/lib/new_relic/agent/instrumentation/excon/connection.rb +33 -0
  18. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +45 -0
  19. data/lib/new_relic/agent/instrumentation/net.rb +3 -1
  20. data/lib/new_relic/agent/instrumentation/typhoeus.rb +73 -0
  21. data/lib/new_relic/agent/method_tracer.rb +3 -6
  22. data/lib/new_relic/agent/new_relic_service.rb +1 -1
  23. data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
  24. data/lib/new_relic/agent/stats.rb +12 -10
  25. data/lib/new_relic/agent/stats_engine/metric_stats.rb +24 -6
  26. data/lib/new_relic/agent/stats_engine/stats_hash.rb +9 -11
  27. data/lib/new_relic/agent/transaction.rb +34 -33
  28. data/lib/new_relic/agent/transaction_sampler.rb +15 -6
  29. data/lib/new_relic/language_support.rb +8 -0
  30. data/lib/new_relic/local_environment.rb +10 -14
  31. data/lib/new_relic/version.rb +1 -1
  32. data/test/agent_helper.rb +43 -0
  33. data/test/config/test.cert.crt +14 -0
  34. data/test/config/test.cert.csr +11 -0
  35. data/test/config/test.cert.key +15 -0
  36. data/test/config/testing-privkey.pem +18 -0
  37. data/test/multiverse/lib/multiverse/color.rb +9 -3
  38. data/test/multiverse/lib/multiverse/suite.rb +11 -1
  39. data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -0
  40. data/test/multiverse/suites/agent_only/config/newrelic.yml +4 -0
  41. data/test/multiverse/suites/agent_only/http_response_code_test.rb +1 -1
  42. data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -1
  43. data/test/multiverse/suites/agent_only/start_up_test.rb +3 -2
  44. data/test/multiverse/suites/config_file_loading/Envfile +2 -0
  45. data/test/multiverse/suites/excon/Envfile +15 -0
  46. data/test/multiverse/suites/excon/config/newrelic.yml +21 -0
  47. data/test/multiverse/suites/excon/excon_test.rb +60 -0
  48. data/test/multiverse/suites/net_http/Envfile +6 -0
  49. data/test/multiverse/suites/net_http/config/newrelic.yml +21 -0
  50. data/test/multiverse/suites/net_http/net_http_test.rb +102 -0
  51. data/test/multiverse/suites/rails/Envfile +1 -1
  52. data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -0
  53. data/test/multiverse/suites/resque/Envfile +0 -9
  54. data/test/multiverse/suites/resque/instrumentation_test.rb +21 -6
  55. data/test/multiverse/suites/typhoeus/Envfile +46 -0
  56. data/test/multiverse/suites/typhoeus/config/newrelic.yml +21 -0
  57. data/test/multiverse/suites/typhoeus/typhoeus_test.rb +77 -0
  58. data/test/new_relic/agent/agent_test_controller_test.rb +11 -10
  59. data/test/new_relic/agent/configuration/server_source_test.rb +23 -9
  60. data/test/new_relic/agent/database_test.rb +6 -0
  61. data/test/new_relic/agent/http_clients/uri_util_test.rb +64 -0
  62. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +0 -406
  63. data/test/new_relic/agent/new_relic_service_test.rb +23 -19
  64. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +29 -12
  65. data/test/new_relic/agent/stats_hash_test.rb +24 -3
  66. data/test/new_relic/agent/stats_test.rb +4 -4
  67. data/test/new_relic/agent/transaction/pop_test.rb +1 -1
  68. data/test/new_relic/agent/transaction_sampler_test.rb +18 -0
  69. data/test/new_relic/agent/transaction_test.rb +64 -69
  70. data/test/new_relic/agent_test.rb +20 -0
  71. data/test/new_relic/dependency_detection_test.rb +99 -0
  72. data/test/new_relic/evil_server.rb +56 -0
  73. data/test/new_relic/fake_collector.rb +12 -96
  74. data/test/new_relic/fake_external_server.rb +55 -0
  75. data/test/new_relic/fake_server.rb +97 -0
  76. data/test/new_relic/http_client_test_cases.rb +444 -0
  77. data/test/new_relic/language_support_test.rb +45 -0
  78. data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +25 -4
  79. metadata +37 -35
  80. metadata.gz.sig +0 -0
  81. data/test/multiverse/suites/resque/resque_setup.rb +0 -19
  82. data/test/new_relic/agent/uri_util_test.rb +0 -75
@@ -4,6 +4,7 @@
4
4
 
5
5
  # RUBY-981 Audit Log
6
6
 
7
+ require 'test/unit'
7
8
  require 'newrelic_rpm'
8
9
  require 'fake_collector'
9
10
 
@@ -11,7 +11,11 @@ development:
11
11
  app_name: test
12
12
  host: 127.0.0.1
13
13
  api_host: 127.0.0.1
14
+ <% if $collector && $collector.port %>
15
+ port: <%= $collector.port %>
16
+ <% else %>
14
17
  port: <%= 30_000 + ($$ % 10_000) %>
18
+ <% end %>
15
19
  transaction_tracer:
16
20
  record_sql: obfuscated
17
21
  enabled: true
@@ -10,7 +10,7 @@ class HttpResponseCodeTest < Test::Unit::TestCase
10
10
  $collector ||= NewRelic::FakeCollector.new
11
11
  $collector.reset
12
12
  $collector.run
13
- NewRelic::Agent.manual_start(:send_data_on_exit => false)
13
+ NewRelic::Agent.manual_start(:send_data_on_exit => false, :port => $collector.port)
14
14
  @agent = NewRelic::Agent.instance
15
15
  end
16
16
 
@@ -32,7 +32,8 @@ class RenameRuleTest < Test::Unit::TestCase
32
32
  $collector.run
33
33
 
34
34
  NewRelic::Agent.manual_start(:sync_startup => true,
35
- :force_reconnect => true)
35
+ :force_reconnect => true,
36
+ :port => $collector.port)
36
37
  TestWidget.new.txn
37
38
  end
38
39
 
@@ -13,12 +13,13 @@ class StartUpTest < Test::Unit::TestCase
13
13
  sin, sout, serr = Open3.popen3(cmd)
14
14
  output = sout.read + serr.read
15
15
 
16
- jruby_noise = [
16
+ expected_noise = [
17
17
  "JRuby limited openssl loaded. http://jruby.org/openssl\n",
18
18
  "gem install jruby-openssl for full support.\n",
19
+ "fatal: Not a git repository (or any of the parent directories): .git\n",
19
20
  /Exception\: java\.lang.*\n/]
20
21
 
21
- jruby_noise.each {|noise| output.gsub!(noise, "")}
22
+ expected_noise.each {|noise| output.gsub!(noise, "")}
22
23
 
23
24
  assert_equal '', output.chomp
24
25
  end
@@ -4,4 +4,6 @@ gemfile <<-RB
4
4
  # stub file system so we can test that newrelic.yml can be loaded from
5
5
  # various places.
6
6
  gem 'fakefs', :require => 'fakefs/safe'
7
+
8
+ gem 'jruby-openssl', :platforms => [:jruby]
7
9
  RB
@@ -0,0 +1,15 @@
1
+ suite_condition("Excon not supported in 1.8.6") do
2
+ RUBY_VERSION != '1.8.6'
3
+ end
4
+
5
+ excon_versions = %w(0.24.0 0.19.0 0.18.0 0.10.0)
6
+
7
+ excon_versions.each do |excon_version|
8
+ gemfile <<-RB
9
+ gem 'excon', '~> #{excon_version}'
10
+ gem 'rack'
11
+ if RUBY_VERSION < '1.9.0'
12
+ gem 'json'
13
+ end
14
+ RB
15
+ end
@@ -0,0 +1,21 @@
1
+ ---
2
+ development:
3
+ error_collector:
4
+ capture_source: true
5
+ enabled: true
6
+ apdex_t: 0.5
7
+ ssl: false
8
+ monitor_mode: true
9
+ license_key: bootstrap_newrelic_admin_license_key_000
10
+ developer_mode: false
11
+ app_name: test
12
+ host: 127.0.0.1
13
+ api_host: 127.0.0.1
14
+ port: <%= 30_000 + ($$ % 10_000) %>
15
+ transaction_tracer:
16
+ record_sql: obfuscated
17
+ enabled: true
18
+ stack_trace_threshold: 0.5
19
+ transaction_threshold: 1.0
20
+ capture_params: false
21
+ log_level: debug
@@ -0,0 +1,60 @@
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 "excon"
6
+ require "newrelic_rpm"
7
+ require "test/unit"
8
+ require "http_client_test_cases"
9
+
10
+ require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
11
+
12
+ class ExconTest < Test::Unit::TestCase
13
+ include HttpClientTestCases
14
+
15
+ def client_name
16
+ "Excon"
17
+ end
18
+
19
+ def get_response(url=nil)
20
+ Excon.get(url || default_url)
21
+ end
22
+
23
+ def get_response_multi(url, n)
24
+ responses = []
25
+ conn = Excon.new(url)
26
+ n.times { responses << conn.get }
27
+ conn.reset
28
+ responses
29
+ end
30
+
31
+ def head_response
32
+ Excon.head(default_url)
33
+ end
34
+
35
+ def post_response
36
+ Excon.post(default_url, :body => "")
37
+ end
38
+
39
+ def request_instance
40
+ NewRelic::Agent::HTTPClients::ExconHTTPRequest.new({:headers => ""})
41
+ end
42
+
43
+ def response_instance
44
+ NewRelic::Agent::HTTPClients::ExconHTTPResponse.new(Excon::Response.new)
45
+ end
46
+
47
+ def test_still_records_tt_node_when_request_expects_different_response_code
48
+ in_transaction do
49
+ conn = Excon.new("#{default_url}?status=500")
50
+ begin
51
+ conn.request(:method => :get, :expects => [200])
52
+ rescue Excon::Errors::Error => e
53
+ # meh
54
+ end
55
+
56
+ last_segment = find_last_transaction_segment()
57
+ assert_equal("External/localhost/Excon/GET", last_segment.metric_name)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,6 @@
1
+ gemfile <<-RB
2
+ gem 'rack'
3
+ if RUBY_VERSION < '1.9.0'
4
+ gem 'json'
5
+ end
6
+ RB
@@ -0,0 +1,21 @@
1
+ ---
2
+ development:
3
+ error_collector:
4
+ capture_source: true
5
+ enabled: true
6
+ apdex_t: 0.5
7
+ ssl: false
8
+ monitor_mode: true
9
+ license_key: bootstrap_newrelic_admin_license_key_000
10
+ developer_mode: false
11
+ app_name: test
12
+ host: 127.0.0.1
13
+ api_host: 127.0.0.1
14
+ port: <%= 30_000 + ($$ % 10_000) %>
15
+ transaction_tracer:
16
+ record_sql: obfuscated
17
+ enabled: true
18
+ stack_trace_threshold: 0.5
19
+ transaction_threshold: 1.0
20
+ capture_params: false
21
+ log_level: debug
@@ -0,0 +1,102 @@
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 "net/http"
6
+ require "newrelic_rpm"
7
+ require "test/unit"
8
+ require "http_client_test_cases"
9
+
10
+ require File.join(File.dirname(__FILE__), "..", "..", "..", "agent_helper")
11
+
12
+ class NetHttpTest < Test::Unit::TestCase
13
+ include HttpClientTestCases
14
+
15
+ #
16
+ # Support for shared test cases
17
+ #
18
+
19
+ def client_name
20
+ "Net::HTTP"
21
+ end
22
+
23
+ def get_response(url=nil)
24
+ uri = default_uri
25
+ uri = URI.parse(url) unless url.nil?
26
+
27
+ start(uri) { |http| http.get(uri.path) }
28
+ end
29
+
30
+ def get_response_multi(url, n)
31
+ uri = URI(url)
32
+ responses = []
33
+
34
+ start(uri) do |conn|
35
+ n.times do
36
+ req = Net::HTTP::Get.new(url)
37
+ responses << conn.request(req)
38
+ end
39
+ end
40
+
41
+ responses
42
+ end
43
+
44
+ def head_response
45
+ start(default_uri) { |http| http.head(default_uri.path) }
46
+ end
47
+
48
+ def post_response
49
+ start(default_uri) { |http| http.post(default_uri.path, "") }
50
+ end
51
+
52
+ def create_http(uri)
53
+ http = Net::HTTP.new(uri.host, uri.port)
54
+ if use_ssl?
55
+ http.use_ssl = true
56
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
57
+ end
58
+ http
59
+ end
60
+
61
+ def start(uri, &block)
62
+ http = create_http(uri)
63
+ http.start(&block)
64
+ end
65
+
66
+ def request_instance
67
+ http = Net::HTTP.new(default_uri.host, default_uri.port)
68
+ request = Net::HTTP::Get.new(default_uri.request_uri)
69
+ NewRelic::Agent::HTTPClients::NetHTTPRequest.new(http, request)
70
+ end
71
+
72
+ def response_instance
73
+ Net::HTTPResponse.new(nil, nil, nil)
74
+ end
75
+
76
+ #
77
+ # Net::HTTP specific tests
78
+ #
79
+ def test_get__simple
80
+ # Don't check this specific condition against SSL, since API doesn't support it
81
+ return if use_ssl?
82
+
83
+ Net::HTTP.get default_uri
84
+
85
+ assert_metrics_recorded([
86
+ 'External/all',
87
+ 'External/localhost/Net::HTTP/GET',
88
+ 'External/allOther',
89
+ 'External/localhost/all'
90
+ ])
91
+ end
92
+
93
+ # https://newrelic.atlassian.net/browse/RUBY-835
94
+ def test_direct_get_request_doesnt_double_count
95
+ http = create_http(default_uri)
96
+ http.request(Net::HTTP::Get.new(default_uri.request_uri))
97
+
98
+ assert_metrics_recorded([
99
+ 'External/localhost/Net::HTTP/GET'
100
+ ])
101
+ end
102
+ end
@@ -4,7 +4,7 @@ end
4
4
 
5
5
  if RUBY_VERSION >= '1.9.3'
6
6
  gemfile <<-RB
7
- gem 'rails', '~>4.0.0.rc1'
7
+ gem 'rails', '~>4.0.0'
8
8
  gem 'haml', '4.0.2' # Getting load issues with haml 4.0.3
9
9
  RB
10
10
  end
@@ -90,6 +90,12 @@ class ViewControllerTest < ActionController::TestCase
90
90
  .subscribe(/^process_action.action_controller$/)
91
91
  end
92
92
  end
93
+
94
+ def teardown
95
+ super
96
+ request_sampler = NewRelic::Agent.instance.instance_variable_get(:@request_sampler)
97
+ request_sampler.reset unless request_sampler.nil?
98
+ end
93
99
  end
94
100
 
95
101
  # SANITY TESTS - Make sure nothing raises errors,
@@ -13,12 +13,3 @@ gemfile <<-RB
13
13
  gem 'json'
14
14
  gem 'rake'
15
15
  RB
16
-
17
- before_suite do
18
- ENV["NEWRELIC_MULTIVERSE_REDIS_PORT"] = (20_000 + ($$ % 10_000)).to_s
19
- system("echo 'port #{ENV["NEWRELIC_MULTIVERSE_REDIS_PORT"]}' | redis-server - > /dev/null &")
20
- end
21
-
22
- after_suite do
23
- system("redis-cli -p #{ENV["NEWRELIC_MULTIVERSE_REDIS_PORT"]} shutdown")
24
- end
@@ -9,9 +9,26 @@ require 'test/unit'
9
9
  require 'logger'
10
10
  require 'newrelic_rpm'
11
11
  require 'fake_collector'
12
- require File.join(File.dirname(__FILE__), 'resque_setup')
13
12
 
14
13
  class ResqueTest < Test::Unit::TestCase
14
+ class JobForTesting
15
+ @queue = :resque_test
16
+ @count = 0
17
+
18
+ def self.reset_counter
19
+ @count = 0
20
+ end
21
+
22
+ def self.count
23
+ @count
24
+ end
25
+
26
+ def self.perform(sleep_duration=0)
27
+ sleep sleep_duration
28
+ @count += 1
29
+ end
30
+ end
31
+
15
32
  JOB_COUNT = 5
16
33
 
17
34
  def setup
@@ -19,9 +36,7 @@ class ResqueTest < Test::Unit::TestCase
19
36
  $collector.reset
20
37
  $collector.run
21
38
 
22
- $redis.del('queue:resque_test')
23
- $redis.set('index_key', 0)
24
- Resque::Stat.clear('processed')
39
+ JobForTesting.reset_counter
25
40
 
26
41
  # From multiverse, we only run the Resque jobs inline to check that we
27
42
  # are properly instrumenting the methods. Testing of the forking/backgrounding
@@ -29,14 +44,14 @@ class ResqueTest < Test::Unit::TestCase
29
44
  Resque.inline = true
30
45
 
31
46
  JOB_COUNT.times do |i|
32
- Resque.enqueue(JobForTesting, 'index_key', i + 1)
47
+ Resque.enqueue(JobForTesting)
33
48
  end
34
49
 
35
50
  NewRelic::Agent.instance.send(:transmit_data)
36
51
  end
37
52
 
38
53
  def test_all_jobs_ran
39
- assert_equal(JOB_COUNT, $redis.get('index_key').to_i)
54
+ assert_equal(JOB_COUNT, JobForTesting.count)
40
55
  end
41
56
 
42
57
  def test_agent_posts_correct_metric_data
@@ -0,0 +1,46 @@
1
+ suite_condition("Typhoeus not supported in 1.8.6") do
2
+ RUBY_VERSION != '1.8.6'
3
+ end
4
+
5
+ gemfile <<-RB
6
+ gem 'typhoeus', '~> 0.6.3'
7
+ gem 'rack'
8
+ if RUBY_VERSION < '1.9.0'
9
+ gem 'json'
10
+ end
11
+ RB
12
+
13
+ gemfile <<-RB
14
+ # Compatibility issues with ethon 0.5.12 https://github.com/typhoeus/ethon/issues/51
15
+ gem 'ethon', '0.5.11'
16
+
17
+ gem 'typhoeus', '~> 0.5.4'
18
+ gem 'rack'
19
+ if RUBY_VERSION < '1.9.0'
20
+ gem 'json'
21
+ end
22
+ RB
23
+
24
+ # Earliest supported version
25
+ gemfile <<-RB
26
+ # Compatibility issues with ethon 0.5.12 https://github.com/typhoeus/ethon/issues/51
27
+ gem 'ethon', '0.5.11'
28
+
29
+ gem 'typhoeus', '0.5.3'
30
+ gem 'rack'
31
+ if RUBY_VERSION < '1.9.0'
32
+ gem 'json'
33
+ end
34
+ RB
35
+
36
+ # Prior to supported versions
37
+ gemfile <<-RB
38
+ # Compatibility issues with ethon 0.5.12 https://github.com/typhoeus/ethon/issues/51
39
+ gem 'ethon', '0.5.11'
40
+
41
+ gem 'typhoeus', '0.5.2'
42
+ gem 'rack'
43
+ if RUBY_VERSION < '1.9.0'
44
+ gem 'json'
45
+ end
46
+ RB