newrelic_rpm 3.5.6.48.beta → 3.5.6.55
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +1 -0
- data/CHANGELOG +52 -0
- data/gem-public_cert.pem +20 -0
- data/lib/new_relic/agent.rb +3 -0
- data/lib/new_relic/agent/agent.rb +21 -14
- data/lib/new_relic/agent/agent_logger.rb +9 -1
- data/lib/new_relic/agent/configuration/defaults.rb +3 -3
- data/lib/new_relic/agent/configuration/mask_defaults.rb +1 -0
- data/lib/new_relic/agent/error_collector.rb +11 -2
- data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +2 -2
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra.rb +10 -2
- data/lib/new_relic/agent/new_relic_service.rb +90 -10
- data/lib/new_relic/agent/pipe_service.rb +9 -0
- data/lib/new_relic/agent/sql_sampler.rb +10 -3
- data/lib/new_relic/agent/thread_profiler.rb +20 -7
- data/lib/new_relic/coerce.rb +37 -0
- data/lib/new_relic/commands/deployments.rb +1 -1
- data/lib/new_relic/control/frameworks/rails.rb +12 -2
- data/lib/new_relic/control/frameworks/rails3.rb +2 -11
- data/lib/new_relic/control/instance_methods.rb +10 -6
- data/lib/new_relic/control/server_methods.rb +5 -37
- data/lib/new_relic/local_environment.rb +1 -1
- data/lib/new_relic/metric_data.rb +13 -2
- data/lib/new_relic/noticed_error.rb +8 -1
- data/lib/new_relic/transaction_sample.rb +12 -3
- data/lib/new_relic/transaction_sample/segment.rb +6 -3
- data/newrelic.yml +6 -19
- data/newrelic_rpm.gemspec +7 -0
- data/test/multiverse/lib/multiverse/environment.rb +1 -1
- data/test/multiverse/suites/agent_only/logging_test.rb +19 -0
- data/test/multiverse/suites/agent_only/ssl_test.rb +22 -0
- data/test/multiverse/suites/rails/config/newrelic.yml +3 -136
- data/test/multiverse/suites/rails/error_tracing_test.rb +39 -21
- data/test/multiverse/suites/rails/gc_instrumentation_test.rb +26 -24
- data/test/multiverse/suites/resque/Rakefile +6 -0
- data/test/multiverse/suites/resque/instrumentation_test.rb +18 -5
- data/test/multiverse/suites/sinatra/sinatra_error_tracing_test.rb +38 -0
- data/test/multiverse/suites/sinatra/sinatra_test.rb +17 -0
- data/test/new_relic/agent/agent/connect_test.rb +7 -26
- data/test/new_relic/agent/agent_test.rb +27 -31
- data/test/new_relic/agent/browser_monitoring_test.rb +1 -1
- data/test/new_relic/agent/error_collector_test.rb +16 -0
- data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +1 -1
- data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +1 -0
- data/test/new_relic/agent/new_relic_service_test.rb +95 -2
- data/test/new_relic/agent/pipe_channel_manager_test.rb +3 -3
- data/test/new_relic/agent/pipe_service_test.rb +21 -1
- data/test/new_relic/agent/rpm_agent_test.rb +1 -1
- data/test/new_relic/agent/sql_sampler_test.rb +20 -0
- data/test/new_relic/agent/thread_profiler_test.rb +53 -8
- data/test/new_relic/agent/worker_loop_test.rb +4 -8
- data/test/new_relic/agent_test.rb +1 -2
- data/test/new_relic/coerce_test.rb +65 -0
- data/test/new_relic/command/deployments_test.rb +1 -1
- data/test/new_relic/control_test.rb +19 -44
- data/test/new_relic/fake_collector.rb +3 -2
- data/test/new_relic/local_environment_test.rb +1 -1
- data/test/new_relic/metric_data_test.rb +29 -0
- data/test/new_relic/noticed_error_test.rb +8 -0
- data/test/new_relic/transaction_sample/segment_test.rb +7 -0
- data/test/new_relic/transaction_sample_test.rb +36 -8
- data/test/test_contexts.rb +1 -1
- data/test/test_helper.rb +21 -2
- data/ui/helpers/google_pie_chart.rb +1 -0
- metadata +68 -10
- metadata.gz.sig +0 -0
- data/test/new_relic/fake_service.rb +0 -53
data.tar.gz.sig
ADDED
Binary file
|
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -3,12 +3,64 @@
|
|
3
3
|
|
4
4
|
## v3.5.6 ##
|
5
5
|
|
6
|
+
* Use HTTPS by default
|
7
|
+
|
8
|
+
The agent now defaults to using SSL when it communicates with New Relic's
|
9
|
+
servers. By defaults already configured, New Relic does not transmit any
|
10
|
+
sensitive information (e.g. SQL parameters are masked), but SSL adds
|
11
|
+
another layer of security. Upgrading customers may need to remove the
|
12
|
+
"ssl: false" directive from their newrelic.yml to enable ssl. Customers on
|
13
|
+
Jruby may need to install the jruby-openssl gem to take advantage of this
|
14
|
+
feature.
|
15
|
+
|
6
16
|
* Fix two Resque-related issues
|
7
17
|
|
8
18
|
Fixes a possible hang on exit of an instrumented Resque master process
|
9
19
|
(https://github.com/defunkt/resque/issues/578), as well as a file descriptor
|
10
20
|
leak that could occur during startup of the Resque master process.
|
11
21
|
|
22
|
+
* Fix for error graph over 100%
|
23
|
+
|
24
|
+
Some errors were double counted toward the overall error total. This
|
25
|
+
resulted in graphs with error percentages over 100%. This duplication did
|
26
|
+
not impact the specific error traces captured, only the total metric.
|
27
|
+
|
28
|
+
* Notice gracefully handled errors in Sinatra
|
29
|
+
|
30
|
+
When show_exceptions was set to false in Sinatra, errors weren't caught
|
31
|
+
by New Relic's error collector. Now handled errors also have the chance
|
32
|
+
to get reported back.
|
33
|
+
|
34
|
+
* Ruby 2.0 compatibility fixes
|
35
|
+
|
36
|
+
Ruby 2.0 no longer finds protected methods by default, but will with a flag.
|
37
|
+
http://tenderlovemaking.com/2012/09/07/protected-methods-and-ruby-2-0.html
|
38
|
+
|
39
|
+
Thanks Ravil Bayramgalin and Charlie Somerville for the fixes.
|
40
|
+
|
41
|
+
* Auto-detect Trinidad as dispatcher
|
42
|
+
|
43
|
+
Code already existing for detecting Trinidad as a dispatcher, but was only
|
44
|
+
accessible via an ENV variable. This now auto-detects on startup. Thanks
|
45
|
+
Robert Rasmussen for catching that.
|
46
|
+
|
47
|
+
* Coercion of types in collector communication
|
48
|
+
|
49
|
+
Certain metrics can be recorded with a Ruby Rational type, which JSON
|
50
|
+
serializes as a string rather than a floating point value. We now treat
|
51
|
+
coerce each outgoing value, and log issues before sending the data.
|
52
|
+
|
53
|
+
* Developer mode fix for chart error
|
54
|
+
|
55
|
+
Added require to fix a NameError in developer mode for summary page. Thanks
|
56
|
+
to Ryan B. Harvey.
|
57
|
+
|
58
|
+
* Don't touch deprecated RAILS_ROOT if on Rails 3
|
59
|
+
|
60
|
+
Under some odd startup conditions, we would look for the RAILS_ROOT constant
|
61
|
+
after failing to find the ::Rails.root in a Rails 3 app, causing deprecation
|
62
|
+
warnings. Thanks for Adrian Irving-Beer for the fix.
|
63
|
+
|
12
64
|
## v3.5.5 ##
|
13
65
|
|
14
66
|
* Add thread profiling support
|
data/gem-public_cert.pem
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDODCCAiCgAwIBAgIBADANBgkqhkiG9w0BAQUFADBCMREwDwYDVQQDDAhzZWN1
|
3
|
+
cml0eTEYMBYGCgmSJomT8ixkARkWCG5ld3JlbGljMRMwEQYKCZImiZPyLGQBGRYD
|
4
|
+
Y29tMB4XDTEzMDIxMjE5MDcwN1oXDTE0MDIxMjE5MDcwN1owQjERMA8GA1UEAwwI
|
5
|
+
c2VjdXJpdHkxGDAWBgoJkiaJk/IsZAEZFghuZXdyZWxpYzETMBEGCgmSJomT8ixk
|
6
|
+
ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJyYRvlk1XUo
|
7
|
+
8JhWQcE/v6RmpK//JbeKvTKnmWVUKz5oTDSOg/LKEhzChpJJVSOMJHCxd4OoxkIN
|
8
|
+
pjQF5U2af1m5ONeN1j4p4MujbwNeqxsJmixGLK/BZ9xTnbpYAa6xCRN1UfEcu3O9
|
9
|
+
jjLHX3c63ghldwRBn/c2ZD6anMtDeq3C5MLiycFs9h7JXOa3cTTHLZknkYIoHMKN
|
10
|
+
EFri5zlks50lbeaVvFRm4IMrYWRsEwzLZWaMOy68BVZe0UlBBKSMnzJfWkbdRRcm
|
11
|
+
xqu7viu4hrrCGjUmdHKnl6tf7BY7wqQyKjj+O5DhayKmKRuQcEX8QVnsM+ayqiVU
|
12
|
+
EtMiwNScUnsCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUOauaMsU0Elp6
|
13
|
+
hiUisj4l63ZunSUwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQAuwrHh
|
14
|
+
jOjIfAQoEbGakiwHTeImqmC1EjBEWb1+U+rC2OcsSQ3+2Q0mGq2u3lAphAeLa6i5
|
15
|
+
WXb5OdQqZY2aI7NgMxRG98/+TcIlAT8tDR0e6/+QBlBuDXP3YI5Nuhp5U4LEvghr
|
16
|
+
jEPaEo0AFPc1JpSO/zKmktU+e9VRAE+q55gLthP8fe0uZvtGUn0KgDbXJyOuGlHF
|
17
|
+
J93N937OcyA2rD8gR1qkr3/0/we1dwLZnL6kN4p8nGzPgXZgOHsmTdYZ2ryYowtb
|
18
|
+
Kc9+v+QxnbZYpu2IaPXOvm3T8G4O6qZvhnLh/Uien++Dj8eFBecTPoM8pVjK3ph5
|
19
|
+
n/EwuZCcE6ghtCCM
|
20
|
+
-----END CERTIFICATE-----
|
data/lib/new_relic/agent.rb
CHANGED
@@ -123,6 +123,9 @@ module NewRelic
|
|
123
123
|
# drop it and not try to resend
|
124
124
|
class UnrecoverableServerException < ServerConnectionException; end
|
125
125
|
|
126
|
+
# An unrecoverable client-side error that prevents the agent from continuing
|
127
|
+
class UnrecoverableAgentException < ServerConnectionException; end
|
128
|
+
|
126
129
|
# Reserved for future use. Meant to represent a problem on the server side.
|
127
130
|
class ServerError < StandardError; end
|
128
131
|
|
@@ -224,8 +224,7 @@ module NewRelic
|
|
224
224
|
# loop if it exists and is running.
|
225
225
|
#
|
226
226
|
# Options:
|
227
|
-
# :force_send
|
228
|
-
# before shutting down
|
227
|
+
# :force_send => (true/false) # force the agent to send data
|
229
228
|
def shutdown(options={})
|
230
229
|
run_loop_before_exit = Agent.config[:force_send]
|
231
230
|
return if not started?
|
@@ -238,7 +237,6 @@ module NewRelic
|
|
238
237
|
|
239
238
|
# if litespeed, then ignore all future SIGUSR1 - it's
|
240
239
|
# litespeed trying to shut us down
|
241
|
-
|
242
240
|
if Agent.config[:dispatcher] == :litespeed
|
243
241
|
Signal.trap("SIGUSR1", "IGNORE")
|
244
242
|
Signal.trap("SIGTERM", "IGNORE")
|
@@ -686,6 +684,12 @@ module NewRelic
|
|
686
684
|
disconnect
|
687
685
|
end
|
688
686
|
|
687
|
+
def handle_unrecoverable_agent_error(error)
|
688
|
+
::NewRelic::Agent.logger.error(error.message)
|
689
|
+
disconnect
|
690
|
+
shutdown
|
691
|
+
end
|
692
|
+
|
689
693
|
# Checks whether we should send environment info, and if so,
|
690
694
|
# returns the snapshot from the local environment
|
691
695
|
def environment_for_connect
|
@@ -800,11 +804,9 @@ module NewRelic
|
|
800
804
|
@traces = transaction_traces
|
801
805
|
end
|
802
806
|
end
|
803
|
-
if errors && errors.respond_to?(:
|
804
|
-
|
805
|
-
@
|
806
|
-
else
|
807
|
-
@unsent_errors = errors
|
807
|
+
if errors && errors.respond_to?(:each)
|
808
|
+
errors.each do |err|
|
809
|
+
@error_collector.add_to_error_queue(err)
|
808
810
|
end
|
809
811
|
end
|
810
812
|
end
|
@@ -842,6 +844,8 @@ module NewRelic
|
|
842
844
|
@connect_state = :connected
|
843
845
|
rescue NewRelic::Agent::LicenseException => e
|
844
846
|
handle_license_error(e)
|
847
|
+
rescue NewRelic::Agent::UnrecoverableAgentException => e
|
848
|
+
handle_unrecoverable_agent_error(e)
|
845
849
|
rescue Timeout::Error, StandardError => e
|
846
850
|
log_error(e)
|
847
851
|
if opts[:keep_retrying]
|
@@ -1024,13 +1028,16 @@ module NewRelic
|
|
1024
1028
|
def transmit_data(disconnecting=false)
|
1025
1029
|
now = Time.now
|
1026
1030
|
::NewRelic::Agent.logger.debug "Sending data to New Relic Service"
|
1027
|
-
harvest_and_send_errors
|
1028
|
-
harvest_and_send_slowest_sample
|
1029
|
-
harvest_and_send_slowest_sql
|
1030
|
-
harvest_and_send_timeslice_data
|
1031
|
-
harvest_and_send_thread_profile(disconnecting)
|
1032
1031
|
|
1033
|
-
|
1032
|
+
@service.session do # use http keep-alive
|
1033
|
+
harvest_and_send_errors
|
1034
|
+
harvest_and_send_slowest_sample
|
1035
|
+
harvest_and_send_slowest_sql
|
1036
|
+
harvest_and_send_timeslice_data
|
1037
|
+
harvest_and_send_thread_profile(disconnecting)
|
1038
|
+
|
1039
|
+
check_for_agent_commands
|
1040
|
+
end
|
1034
1041
|
rescue => e
|
1035
1042
|
retry_count ||= 0
|
1036
1043
|
retry_count += 1
|
@@ -32,6 +32,10 @@ module NewRelic
|
|
32
32
|
@log.debug(format_messages(msgs))
|
33
33
|
end
|
34
34
|
|
35
|
+
def is_startup_logger?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
35
39
|
# Allows for passing exceptions in explicitly, which format with backtrace
|
36
40
|
def format_messages(msgs)
|
37
41
|
msgs.map do |msg|
|
@@ -120,12 +124,16 @@ module NewRelic
|
|
120
124
|
end
|
121
125
|
end
|
122
126
|
|
123
|
-
#
|
127
|
+
# Base class for startup logging and testing in multiverse
|
124
128
|
class MemoryLogger
|
125
129
|
def initialize
|
126
130
|
@messages = []
|
127
131
|
end
|
128
132
|
|
133
|
+
def is_startup_logger?
|
134
|
+
true
|
135
|
+
end
|
136
|
+
|
129
137
|
attr_accessor :messages, :level
|
130
138
|
|
131
139
|
def fatal(*msgs)
|
@@ -30,7 +30,7 @@ module NewRelic
|
|
30
30
|
when 4
|
31
31
|
:rails4
|
32
32
|
else
|
33
|
-
Agent.logger.error "Detected unsupported Rails version #{Rails::VERSION::STRING}"
|
33
|
+
::NewRelic::Agent::Agent.logger.error "Detected unsupported Rails version #{Rails::VERSION::STRING}"
|
34
34
|
end
|
35
35
|
when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra
|
36
36
|
when defined?(::NewRelic::IA) then :external
|
@@ -55,8 +55,8 @@ module NewRelic
|
|
55
55
|
:api_host => 'rpm.newrelic.com',
|
56
56
|
:port => Proc.new { self[:ssl] ? 443 : 80 },
|
57
57
|
:api_port => Proc.new { self[:port] },
|
58
|
-
:ssl =>
|
59
|
-
:verify_certificate =>
|
58
|
+
:ssl => true,
|
59
|
+
:verify_certificate => true,
|
60
60
|
:sync_startup => false,
|
61
61
|
:send_data_on_exit => true,
|
62
62
|
:post_size_limit => 2 * 1024 * 1024, # 2 megs
|
@@ -4,6 +4,7 @@ module NewRelic
|
|
4
4
|
MASK_DEFAULTS = {
|
5
5
|
:'thread_profiler' => Proc.new { !NewRelic::Agent::ThreadProfiler.is_supported? },
|
6
6
|
:'thread_profiler.enabled' => Proc.new { !NewRelic::Agent::ThreadProfiler.is_supported? },
|
7
|
+
:verify_certificate => Proc.new{ true }
|
7
8
|
}
|
8
9
|
end
|
9
10
|
end
|
@@ -21,6 +21,8 @@ module NewRelic
|
|
21
21
|
# Returns a new error collector
|
22
22
|
def initialize
|
23
23
|
@errors = []
|
24
|
+
@seen_error_ids = []
|
25
|
+
|
24
26
|
# lookup of exception class names to ignore. Hash for fast access
|
25
27
|
@ignore = {}
|
26
28
|
@capture_source = Agent.config[:'error_collector.capture_source']
|
@@ -92,7 +94,11 @@ module NewRelic
|
|
92
94
|
end
|
93
95
|
|
94
96
|
# Increments a statistic that tracks total error rate
|
95
|
-
|
97
|
+
# Be sure not to double-count same exception. This clears per harvest.
|
98
|
+
def increment_error_count!(exception)
|
99
|
+
return if @seen_error_ids.include?(exception.object_id)
|
100
|
+
@seen_error_ids << exception.object_id
|
101
|
+
|
96
102
|
NewRelic::Agent.get_stats("Errors/all").increment_count
|
97
103
|
end
|
98
104
|
|
@@ -102,7 +108,7 @@ module NewRelic
|
|
102
108
|
def should_exit_notice_error?(exception)
|
103
109
|
if enabled?
|
104
110
|
if !error_is_ignored?(exception)
|
105
|
-
increment_error_count!
|
111
|
+
increment_error_count!(exception)
|
106
112
|
return exception.nil? # exit early if the exception is nil
|
107
113
|
end
|
108
114
|
end
|
@@ -240,6 +246,9 @@ module NewRelic
|
|
240
246
|
errors = @errors
|
241
247
|
@errors = []
|
242
248
|
|
249
|
+
# Only expect to re-see errors on same request, so clear on harvest
|
250
|
+
@seen_error_ids = []
|
251
|
+
|
243
252
|
if unsent_errors && !unsent_errors.empty?
|
244
253
|
errors = unsent_errors + errors
|
245
254
|
end
|
@@ -4,12 +4,12 @@ module NewRelic
|
|
4
4
|
class BrowserMonitoringTimings
|
5
5
|
|
6
6
|
def initialize(queue_time_in_seconds, transaction)
|
7
|
-
@now = Time.now
|
7
|
+
@now = Time.now.to_i
|
8
8
|
if transaction.nil?
|
9
9
|
@start_time_in_seconds = 0.0
|
10
10
|
else
|
11
11
|
@transaction_name = transaction.transaction_name
|
12
|
-
@start_time_in_seconds = transaction.start_time
|
12
|
+
@start_time_in_seconds = transaction.start_time.to_i
|
13
13
|
end
|
14
14
|
|
15
15
|
@queue_time_in_seconds = clamp_to_positive(queue_time_in_seconds)
|
@@ -149,7 +149,7 @@ DependencyDetection.defer do
|
|
149
149
|
|
150
150
|
def render_with_newrelic(context, options)
|
151
151
|
# This is needed for rails 3.2 compatibility
|
152
|
-
@details = extract_details(options) if respond_to? :extract_details
|
152
|
+
@details = extract_details(options) if respond_to? :extract_details, true
|
153
153
|
identifier = determine_template(options) ? determine_template(options).identifier : nil
|
154
154
|
str = "View/#{NewRelic::Agent::Instrumentation::Rails3::ActionView::NewRelic.template_metric(identifier, options)}/Rendering"
|
155
155
|
trace_execution_scoped str do
|
@@ -5,7 +5,8 @@ DependencyDetection.defer do
|
|
5
5
|
|
6
6
|
depends_on do
|
7
7
|
defined?(::Sinatra) && defined?(::Sinatra::Base) &&
|
8
|
-
Sinatra::Base.private_method_defined?(:dispatch!)
|
8
|
+
Sinatra::Base.private_method_defined?(:dispatch!) &&
|
9
|
+
Sinatra::Base.private_method_defined?(:process_route)
|
9
10
|
end
|
10
11
|
|
11
12
|
executes do
|
@@ -45,7 +46,14 @@ module NewRelic
|
|
45
46
|
perform_action_with_newrelic_trace(:category => :sinatra,
|
46
47
|
:name => txn_name,
|
47
48
|
:params => @request.params) do
|
48
|
-
dispatch_without_newrelic
|
49
|
+
result = dispatch_without_newrelic
|
50
|
+
|
51
|
+
# Will only see an error raised if :show_exceptions is true, but
|
52
|
+
# will always see them in the env hash if they occur
|
53
|
+
had_error = env.has_key?('sinatra.error')
|
54
|
+
::NewRelic::Agent.notice_error(env['sinatra.error']) if had_error
|
55
|
+
|
56
|
+
result
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
@@ -29,7 +29,16 @@ module NewRelic
|
|
29
29
|
Agent.config.register_callback(:'audit_log.enabled') do |enabled|
|
30
30
|
@audit_logger.enabled = enabled
|
31
31
|
end
|
32
|
-
|
32
|
+
Agent.config.register_callback(:ssl) do |ssl|
|
33
|
+
if !ssl
|
34
|
+
::NewRelic::Agent.logger.warn("Agent is configured not to use SSL when communicating with New Relic's servers")
|
35
|
+
elsif !Agent.config[:verify_certificate]
|
36
|
+
::NewRelic::Agent.logger.warn("Agent is configured to use SSL but to skip certificate validation when communicating with New Relic's servers")
|
37
|
+
else
|
38
|
+
::NewRelic::Agent.logger.debug("Agent is configured to use SSL")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
33
42
|
Agent.config.register_callback(:marshaller) do |marshaller|
|
34
43
|
begin
|
35
44
|
if marshaller == 'json'
|
@@ -106,6 +115,73 @@ module NewRelic
|
|
106
115
|
[data, encoding]
|
107
116
|
end
|
108
117
|
|
118
|
+
# One session with the service's endpoint. In this case the session
|
119
|
+
# represents 1 tcp connection which may transmit multiple HTTP requests
|
120
|
+
# via keep-alive.
|
121
|
+
def session(&block)
|
122
|
+
raise ArgumentError, "#{self.class}#shared_connection must be passed a block" unless block_given?
|
123
|
+
|
124
|
+
http = create_http_connection
|
125
|
+
|
126
|
+
# Immediately open a TCP connection to the server and leave it open for
|
127
|
+
# multiple requests.
|
128
|
+
::NewRelic::Agent.logger.debug("Opening TCP connection to #{http.address}:#{http.port}")
|
129
|
+
http.start
|
130
|
+
begin
|
131
|
+
@shared_tcp_connection = http
|
132
|
+
block.call
|
133
|
+
ensure
|
134
|
+
@shared_tcp_connection = nil
|
135
|
+
# Close the TCP socket
|
136
|
+
::NewRelic::Agent.logger.debug("Closing TCP connection to #{http.address}:#{http.port}")
|
137
|
+
http.finish
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Return a Net::HTTP connection object to make a call to the collector.
|
142
|
+
# We'll reuse the same handle for cases where we're using keep-alive, or
|
143
|
+
# otherwise create a new one.
|
144
|
+
def http_connection
|
145
|
+
@shared_tcp_connection || create_http_connection
|
146
|
+
end
|
147
|
+
|
148
|
+
# Return the Net::HTTP with proxy configuration given the NewRelic::Control::Server object.
|
149
|
+
def create_http_connection
|
150
|
+
proxy_server = control.proxy_server
|
151
|
+
# Proxy returns regular HTTP if @proxy_host is nil (the default)
|
152
|
+
http_class = Net::HTTP::Proxy(proxy_server.name, proxy_server.port,
|
153
|
+
proxy_server.user, proxy_server.password)
|
154
|
+
|
155
|
+
http = http_class.new((@collector.ip || @collector.name), @collector.port)
|
156
|
+
if Agent.config[:ssl]
|
157
|
+
begin
|
158
|
+
# Jruby 1.6.8 requires a gem for full ssl support and will throw
|
159
|
+
# an error when use_ssl=(true) is called and jruby-openssl isn't
|
160
|
+
# installed
|
161
|
+
http.use_ssl = true
|
162
|
+
if Agent.config[:verify_certificate]
|
163
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
164
|
+
http.ca_file = cert_file_path
|
165
|
+
else
|
166
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
167
|
+
end
|
168
|
+
rescue StandardError, LoadError
|
169
|
+
msg = "Agent is configured to use SSL, but SSL is not available in the environment. "
|
170
|
+
msg << "Either disable SSL in the agent configuration, or install SSL support."
|
171
|
+
raise UnrecoverableAgentException.new(msg)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
::NewRelic::Agent.logger.debug("Created net/http handle to #{http.address}:#{http.port}")
|
175
|
+
http
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
# The path to the certificate file used to verify the SSL
|
180
|
+
# connection if verify_peer is enabled
|
181
|
+
def cert_file_path
|
182
|
+
File.expand_path(File.join(control.newrelic_root, 'cert', 'cacert.pem'))
|
183
|
+
end
|
184
|
+
|
109
185
|
private
|
110
186
|
|
111
187
|
# A shorthand for NewRelic::Control.instance
|
@@ -183,31 +259,33 @@ module NewRelic
|
|
183
259
|
request.content_type = "application/octet-stream"
|
184
260
|
request.body = opts[:data]
|
185
261
|
|
186
|
-
::NewRelic::Agent.logger.debug "Connect to #{opts[:collector]}#{opts[:uri]}"
|
187
|
-
|
188
262
|
response = nil
|
189
|
-
http =
|
263
|
+
http = http_connection
|
190
264
|
http.read_timeout = nil
|
191
265
|
begin
|
192
266
|
NewRelic::TimerLib.timeout(@request_timeout) do
|
267
|
+
::NewRelic::Agent.logger.debug "Sending request to #{opts[:collector]}#{opts[:uri]}"
|
193
268
|
response = http.request(request)
|
194
269
|
end
|
195
270
|
rescue Timeout::Error
|
196
271
|
::NewRelic::Agent.logger.warn "Timed out trying to post data to New Relic (timeout = #{@request_timeout} seconds)" unless @request_timeout < 30
|
197
272
|
raise
|
198
273
|
end
|
199
|
-
|
274
|
+
case response
|
275
|
+
when Net::HTTPSuccess
|
276
|
+
true # fall through
|
277
|
+
when Net::HTTPUnauthorized
|
200
278
|
raise LicenseException, 'Invalid license key, please contact support@newrelic.com'
|
201
|
-
|
279
|
+
when Net::HTTPServiceUnavailable
|
202
280
|
raise ServerConnectionException, "Service unavailable (#{response.code}): #{response.message}"
|
203
|
-
|
281
|
+
when Net::HTTPGatewayTimeOut
|
204
282
|
::NewRelic::Agent.logger.warn("Timed out getting response: #{response.message}")
|
205
283
|
raise Timeout::Error, response.message
|
206
|
-
|
284
|
+
when Net::HTTPRequestEntityTooLarge
|
207
285
|
raise UnrecoverableServerException, '413 Request Entity Too Large'
|
208
|
-
|
286
|
+
when Net::HTTPUnsupportedMediaType
|
209
287
|
raise UnrecoverableServerException, '415 Unsupported Media Type'
|
210
|
-
|
288
|
+
else
|
211
289
|
raise ServerConnectionException, "Unexpected response from server (#{response.code}): #{response.message}"
|
212
290
|
end
|
213
291
|
response
|
@@ -216,6 +294,8 @@ module NewRelic
|
|
216
294
|
raise NewRelic::Agent::ServerConnectionException, "Recoverable error connecting to the server: #{e}"
|
217
295
|
end
|
218
296
|
|
297
|
+
|
298
|
+
|
219
299
|
# Decompresses the response from the server, if it is gzip
|
220
300
|
# encoded, otherwise returns it verbatim
|
221
301
|
def decompress_response(response)
|