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/newrelic_rpm.gemspec
CHANGED
@@ -40,4 +40,11 @@ EOS
|
|
40
40
|
s.rubygems_version = Gem::VERSION
|
41
41
|
s.summary = "New Relic Ruby Agent"
|
42
42
|
s.post_install_message = NewRelic::LatestChanges.read
|
43
|
+
|
44
|
+
# Only sign with our private key if you can find it
|
45
|
+
signing_key_path = File.expand_path('~/.ssh/newrelic_rpm-private_key.pem')
|
46
|
+
if File.exists?(signing_key_path)
|
47
|
+
s.signing_key = signing_key_path
|
48
|
+
s.cert_chain = ['gem-public_cert.pem']
|
49
|
+
end
|
43
50
|
end
|
@@ -4,7 +4,7 @@ module Multiverse
|
|
4
4
|
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
5
5
|
$: << File.expand_path(File.join(ROOT, 'lib'))
|
6
6
|
|
7
|
-
# Include from our unit testing path to share fake_collector
|
7
|
+
# Include from our unit testing path to share fake_collector
|
8
8
|
$: << File.expand_path(File.join(ROOT, '..', 'new_relic'))
|
9
9
|
|
10
10
|
SUITES_DIRECTORY = ENV['SUITES_DIRECTORY'] || File.join(ROOT, '/suites')
|
@@ -45,6 +45,25 @@ class LoggingTest < Test::Unit::TestCase
|
|
45
45
|
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_logs_ssl_warning
|
49
|
+
running_agent_writes_to_log(
|
50
|
+
{:ssl => false},
|
51
|
+
"Agent is configured not to use SSL when communicating with New Relic's servers") do
|
52
|
+
|
53
|
+
NewRelic::Agent.config.apply_config(:ssl => false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_logs_ssl_verify_cert_warning
|
58
|
+
running_agent_writes_to_log(
|
59
|
+
{:ssl => false, :verify_certificate => false},
|
60
|
+
"Agent is configured to use SSL but to skip certificate validation when communicating with New Relic's servers") do
|
61
|
+
|
62
|
+
NewRelic::Agent.config.apply_config(:ssl => true, :verify_certificate => false)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
48
67
|
def test_logs_if_sending_errors_on_change
|
49
68
|
running_agent_writes_to_log(
|
50
69
|
{:'error_collector.enabled' => false},
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class SSLTest < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
# This is similar to how jruby 1.6.8 behaves when jruby-openssl isn't
|
5
|
+
# installed
|
6
|
+
@original_ssl_config = NewRelic::Agent.config[:ssl]
|
7
|
+
NewRelic::Agent.config.apply_config(:ssl => true)
|
8
|
+
NewRelic::Agent.agent = NewRelic::Agent::Agent.new
|
9
|
+
Net::HTTPSession.any_instance.stubs('use_ssl=').raises(LoadError)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
NewRelic::Agent.config.apply_config(:ssl => @original_ssl_config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_agent_shuts_down_when_ssl_is_on_but_unavailable
|
17
|
+
::NewRelic::Agent.agent.expects(:shutdown)
|
18
|
+
::NewRelic::Agent.expects(:finish_setup).never
|
19
|
+
::NewRelic::Agent.agent.connect_in_foreground
|
20
|
+
ensure
|
21
|
+
end
|
22
|
+
end
|
@@ -1,165 +1,32 @@
|
|
1
|
-
#
|
2
|
-
# This file configures the NewRelic RPM Agent, NewRelic RPM monitors Rails
|
3
|
-
# applications with deep visibility and low overhead. For more information,
|
4
|
-
# visit www.newrelic.com.
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# here are the settings that are common to all environments
|
9
1
|
common: &default_settings
|
10
|
-
|
11
|
-
# ============================== LICENSE KEY ===============================
|
12
|
-
# You must specify the licence key associated with your New Relic account.
|
13
|
-
# This key binds your Agent's data to your account in the New Relic RPM service.
|
14
|
-
|
15
|
-
#license_key: 'bootstrap_newrelic_admin_license_key_000'
|
16
|
-
#host: localhost
|
17
|
-
#port: 3000
|
18
|
-
|
19
2
|
license_key: 'bd0e1d52adade840f7ca727d29a86249e89a6f1c'
|
20
|
-
host:
|
21
|
-
|
22
|
-
# Agent Enabled
|
23
|
-
# Use this setting to force the agent to run or not run.
|
24
|
-
# Default is 'auto' which means the agent will install and run only if a
|
25
|
-
# valid dispatcher such as Mongrel is running. This prevents it from running
|
26
|
-
# with Rake or the console. Set to false to completely turn the agent off
|
27
|
-
# regardless of the other settings. Valid values are true, false and auto.
|
28
|
-
# agent_enabled: auto
|
29
|
-
|
30
|
-
# Application Name
|
31
|
-
# Set this to be the name of your application as you'd like it show up in RPM.
|
32
|
-
# RPM will then auto-map instances of your application into a RPM "application"
|
33
|
-
# on your home dashboard page. This setting does not prevent you from manually
|
34
|
-
# defining applications.
|
3
|
+
host: 127.0.0.1
|
4
|
+
port: <%= 30_000 + ($$ % 10_000) %>
|
35
5
|
app_name: Rails 3 view test ap
|
36
|
-
|
37
|
-
# When 'enabled' is turned on, the agent collects performance data by inserting lightweight
|
38
|
-
# tracers on key methods inside the rails framework and asynchronously aggregating
|
39
|
-
# and reporting this performance data to the NewRelic RPM service at newrelic.com.
|
40
|
-
enabled: false
|
41
|
-
|
42
|
-
# The newrelic agent generates its own log file to keep its logging information
|
43
|
-
# separate from that of your application. Specify its log level here.
|
6
|
+
enabled: true
|
44
7
|
log_level: debug
|
45
|
-
|
46
|
-
# The newrelic agent communicates with the RPM service via http by default.
|
47
|
-
# If you want to communicate via https to increase security, then turn on
|
48
|
-
# SSL by setting this value to true. Note, this will result in increased
|
49
|
-
# CPU overhead to perform the encryption involved in SSL communication, but this
|
50
|
-
# work is done asynchronously to the threads that process your application code, so
|
51
|
-
# it should not impact response times.
|
52
8
|
ssl: false
|
53
|
-
|
54
|
-
# Set your application's Apdex threshold value with the 'apdex_t' setting, in seconds. The
|
55
|
-
# apdex_t value determines the buckets used to compute your overall Apdex score. Requests
|
56
|
-
# that take less than apdex_t seconds to process will be classified as Satisfying transactions;
|
57
|
-
# more than apdex_t seconds as Tolerating transactions; and more than four times the apdex_t
|
58
|
-
# value as Frustrating transactions. For more
|
59
|
-
# about the Apdex standard, see http://support.newrelic.com/faqs/general/apdex
|
60
9
|
apdex_t: 1.0
|
61
|
-
|
62
|
-
|
63
|
-
# Proxy settings for connecting to the RPM server.
|
64
|
-
#
|
65
|
-
# If a proxy is used, the host setting is required. Other settings are optional. Default
|
66
|
-
# port is 8080.
|
67
|
-
#
|
68
|
-
# proxy_host: hostname
|
69
|
-
# proxy_port: 8080
|
70
|
-
# proxy_user:
|
71
|
-
# proxy_pass:
|
72
|
-
|
73
|
-
|
74
|
-
# Tells transaction tracer and error collector (when enabled) whether or not to capture HTTP params.
|
75
|
-
# When true, the RoR filter_parameter_logging mechanism is used so that sensitive parameters are not recorded
|
76
10
|
capture_params: true
|
77
|
-
|
78
|
-
|
79
|
-
# Transaction tracer captures deep information about slow
|
80
|
-
# transactions and sends this to the RPM service once a minute. Included in the
|
81
|
-
# transaction is the exact call sequence of the transactions including any SQL statements
|
82
|
-
# issued.
|
83
11
|
transaction_tracer:
|
84
|
-
|
85
|
-
# Transaction tracer is enabled by default. Set this to false to turn it off. This feature
|
86
|
-
# is only available at the Silver and above product levels.
|
87
12
|
enabled: true
|
88
|
-
|
89
|
-
# Threshold in seconds for when to collect a transaction trace. When the response time of
|
90
|
-
# a controller action exceeds this threshold, a transaction trace will be recorded and sent
|
91
|
-
# to RPM. Valid values are any float value, or (default) "apdex_f", which will use the
|
92
|
-
# threshold for an dissatisfying Apdex controller action - four times the Apdex T value.
|
93
13
|
transaction_threshold: apdex_f
|
94
|
-
|
95
|
-
# When transaction tracer is on, SQL statements can optionally be recorded. The recorder
|
96
|
-
# has three modes, "off" which sends no SQL, "raw" which sends the SQL statement in its
|
97
|
-
# original form, and "obfuscated", which strips out numeric and string literals
|
98
14
|
record_sql: obfuscated
|
99
|
-
|
100
|
-
# Threshold in seconds for when to collect stack trace for a SQL call. In other words,
|
101
|
-
# when SQL statements exceed this threshold, then capture and send to RPM the current
|
102
|
-
# stack trace. This is helpful for pinpointing where long SQL calls originate from
|
103
15
|
stack_trace_threshold: 0.500
|
104
|
-
|
105
|
-
# Error collector captures information about uncaught exceptions and sends them to RPM for
|
106
|
-
# viewing
|
107
16
|
error_collector:
|
108
|
-
|
109
|
-
# Error collector is enabled by default. Set this to false to turn it off. This feature
|
110
|
-
# is only available at the Silver and above product levels
|
111
17
|
enabled: true
|
112
|
-
|
113
|
-
# Tells error collector whether or not to capture a source snippet around the place of the
|
114
|
-
# error when errors are View related.
|
115
18
|
capture_source: true
|
116
|
-
|
117
|
-
# To stop specific errors from reporting to RPM, set this property to comma separated
|
118
|
-
# values
|
119
|
-
#
|
120
|
-
#ignore_errors: ActionController::RoutingError, ...
|
121
19
|
ignore_errors: IgnoredError
|
122
20
|
|
123
|
-
# (Advanced) Uncomment this to ensure the cpu and memory samplers won't run. Useful when you
|
124
|
-
# are using the agent to monitor an external resource
|
125
|
-
# disable_samplers: true
|
126
|
-
|
127
|
-
# override default settings based on your application's environment
|
128
|
-
|
129
|
-
# NOTE if your application has other named environments, you should
|
130
|
-
# provide newrelic conifguration settings for these enviromnents here.
|
131
|
-
|
132
21
|
development:
|
133
22
|
<<: *default_settings
|
134
|
-
# turn off communication to RPM service in development mode.
|
135
|
-
# NOTE: for initial evaluation purposes, you may want to temporarily turn
|
136
|
-
# the agent on in development mode.
|
137
|
-
enabled: true
|
138
|
-
|
139
|
-
# When running in Developer Mode, the New Relic Agent will present
|
140
|
-
# performance information on the last 100 transactions you have
|
141
|
-
# executed since starting the mongrel. to view this data, go to
|
142
|
-
# http://localhost:3000/newrelic
|
143
23
|
developer: true
|
144
24
|
|
145
25
|
test:
|
146
26
|
<<: *default_settings
|
147
|
-
# it almost never makes sense to turn on the agent when running unit, functional or
|
148
|
-
# integration tests or the like.
|
149
|
-
enabled: true
|
150
|
-
log_level: debug
|
151
27
|
|
152
|
-
# Turn on the agent in production for 24x7 monitoring. NewRelic testing shows
|
153
|
-
# an average performance impact of < 5 ms per transaction, you you can leave this on
|
154
|
-
# all the time without incurring any user-visible performance degredation.
|
155
28
|
production:
|
156
29
|
<<: *default_settings
|
157
|
-
enabled: true
|
158
30
|
|
159
|
-
# many applications have a staging environment which behaves identically to production.
|
160
|
-
# Support for that environment is provided here. By default, the staging environment has
|
161
|
-
# the agent turned on.
|
162
31
|
staging:
|
163
32
|
<<: *default_settings
|
164
|
-
enabled: true
|
165
|
-
app_name: My Application (Staging)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# https://newrelic.atlassian.net/browse/RUBY-747
|
2
2
|
|
3
3
|
require 'rails/test_help'
|
4
|
-
require '
|
4
|
+
require 'fake_collector'
|
5
5
|
|
6
6
|
class ErrorController < ApplicationController
|
7
7
|
include Rails.application.routes.url_helpers
|
@@ -42,24 +42,31 @@ class ServerIgnoredError < StandardError; end
|
|
42
42
|
|
43
43
|
class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
44
44
|
def setup
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
$collector ||= NewRelic::FakeCollector.new
|
46
|
+
$collector.reset
|
47
|
+
setup_collector
|
48
|
+
$collector.run
|
49
|
+
|
50
|
+
NewRelic::Agent.reset_config
|
51
|
+
NewRelic::Agent.instance_variable_set(:@agent, nil)
|
52
|
+
NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
|
50
53
|
NewRelic::Agent.manual_start
|
51
54
|
|
52
55
|
reset_error_collector
|
53
56
|
end
|
54
57
|
|
58
|
+
# Let base class override this without moving where we start the agent
|
59
|
+
def setup_collector
|
60
|
+
$collector.mock['connect'] = [200, {'return_value' => {"agent_run_id" => 666 }}]
|
61
|
+
end
|
62
|
+
|
55
63
|
def teardown
|
56
64
|
NewRelic::Agent::Agent.instance.shutdown if NewRelic::Agent::Agent.instance
|
65
|
+
NewRelic::Agent::Agent.instance_variable_set(:@instance, nil)
|
57
66
|
end
|
58
67
|
|
59
68
|
def reset_error_collector
|
60
|
-
@error_collector = NewRelic::Agent.instance.error_collector
|
61
|
-
NewRelic::Agent.instance.error_collector \
|
62
|
-
.instance_variable_set(:@ignore_filter, nil)
|
69
|
+
@error_collector = NewRelic::Agent::Agent.instance.error_collector
|
63
70
|
|
64
71
|
# sanity checks
|
65
72
|
assert(@error_collector.enabled?,
|
@@ -96,6 +103,16 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
|
96
103
|
assert_error_reported_once('this error should be noticed')
|
97
104
|
end
|
98
105
|
|
106
|
+
# Important choice of controllor_error, since this goes through both the
|
107
|
+
# metric_frame and the rack error collector, so risks multiple counting!
|
108
|
+
def test_should_capture_multiple_errors
|
109
|
+
40.times do
|
110
|
+
get '/error/controller_error'
|
111
|
+
end
|
112
|
+
|
113
|
+
assert_errors_reported('this is an uncaught controller error', 20, 40)
|
114
|
+
end
|
115
|
+
|
99
116
|
def test_should_capture_manually_noticed_error
|
100
117
|
NewRelic::Agent.notice_error(RuntimeError.new('this is a noticed error'))
|
101
118
|
assert_error_reported_once('this is a noticed error')
|
@@ -143,29 +160,30 @@ class ErrorsWithoutSSCTest < ActionDispatch::IntegrationTest
|
|
143
160
|
|
144
161
|
protected
|
145
162
|
|
163
|
+
def assert_errors_reported(message, queued_count, total_count=queued_count)
|
164
|
+
error_count = NewRelic::Agent::Agent.instance.stats_engine.get_stats("Errors/all")
|
165
|
+
assert_equal total_count, error_count.call_count
|
166
|
+
|
167
|
+
assert_equal(queued_count,
|
168
|
+
@error_collector.errors.select{|error| error.message == message}.size,
|
169
|
+
"Wrong number of errors with message '#{message} found'")
|
170
|
+
end
|
171
|
+
|
146
172
|
def assert_error_reported_once(message)
|
147
|
-
|
148
|
-
@error_collector.errors[0].message,
|
149
|
-
'This error type was not detected')
|
150
|
-
assert_equal(1, @error_collector.errors.size,
|
151
|
-
'Too many of this error type was detected')
|
173
|
+
assert_errors_reported(message, 1)
|
152
174
|
end
|
153
175
|
end
|
154
176
|
|
155
177
|
class ErrorsWithSSCTest < ErrorsWithoutSSCTest
|
156
|
-
def
|
157
|
-
|
158
|
-
@service.mock['connect'] = {
|
178
|
+
def setup_collector
|
179
|
+
$collector.mock['connect'] = [200, {'return_value' => {
|
159
180
|
"listen_to_server_config" => true,
|
160
181
|
"agent_run_id" => 1,
|
161
182
|
"error_collector.ignore_errors" => 'IgnoredError,ServerIgnoredError',
|
162
183
|
"error_collector.enabled" => true,
|
163
184
|
"error_collector.capture_source" => true,
|
164
185
|
"collect_errors" => true
|
165
|
-
}
|
166
|
-
|
167
|
-
# Force us to apply the mocked connect values to our configuration
|
168
|
-
NewRelic::Agent.instance.query_server_for_configuration
|
186
|
+
}}]
|
169
187
|
end
|
170
188
|
|
171
189
|
def test_should_notice_server_ignored_error_if_no_server_side_config
|
@@ -7,22 +7,13 @@ if (defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise/) ||
|
|
7
7
|
class GcController < ApplicationController
|
8
8
|
include Rails.application.routes.url_helpers
|
9
9
|
def gc_action
|
10
|
-
GC.disable
|
11
|
-
|
12
10
|
long_string = "01234567" * 100_000
|
13
11
|
long_string = nil
|
14
12
|
another_long_string = "01234567" * 100_000
|
15
13
|
|
16
|
-
start = Time.now
|
17
|
-
GC.enable
|
18
14
|
GC.start
|
19
|
-
stop = Time.now
|
20
|
-
|
21
|
-
@duration = stop.to_f - start.to_f
|
22
15
|
|
23
|
-
render :text =>
|
24
|
-
ensure
|
25
|
-
GC.enable
|
16
|
+
render :text => 'ha'
|
26
17
|
end
|
27
18
|
end
|
28
19
|
|
@@ -33,8 +24,7 @@ class GCRailsInstrumentationTest < ActionController::TestCase
|
|
33
24
|
|
34
25
|
@controller = GcController.new
|
35
26
|
NewRelic::Agent.instance.stats_engine.reset_stats
|
36
|
-
NewRelic::Agent.instance.transaction_sampler
|
37
|
-
.instance_variable_set(:@samples, [])
|
27
|
+
NewRelic::Agent.instance.transaction_sampler.instance_variable_set(:@samples, [])
|
38
28
|
NewRelic::Agent.manual_start
|
39
29
|
end
|
40
30
|
|
@@ -43,26 +33,38 @@ class GCRailsInstrumentationTest < ActionController::TestCase
|
|
43
33
|
end
|
44
34
|
|
45
35
|
def test_records_accurate_time_for_gc_activity
|
36
|
+
start = Time.now
|
46
37
|
get :gc_action
|
38
|
+
elapsed = Time.now.to_f - start.to_f
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
.get_stats('GC/cumulative') \
|
51
|
-
.total_call_time, 0.2,
|
52
|
-
'problem with unscoped GC metric')
|
53
|
-
assert_in_delta(assigns[:duration],
|
54
|
-
NewRelic::Agent.agent.stats_engine \
|
55
|
-
.get_stats('GC/cumulative', true, false,
|
56
|
-
'Controller/gc/gc_action') \
|
57
|
-
.total_call_time, 0.2,
|
58
|
-
'problem with scoped GC metric')
|
40
|
+
assert_in_range(elapsed, get_call_time('GC/cumulative'))
|
41
|
+
assert_in_range(elapsed, get_call_time('GC/cumulative', 'Controller/gc/gc_action'))
|
59
42
|
end
|
60
43
|
|
61
44
|
def test_records_transaction_param_for_gc_activity
|
45
|
+
start = Time.now.to_f
|
62
46
|
get :gc_action
|
47
|
+
elapsed = Time.now.to_f - start
|
63
48
|
|
64
49
|
trace = NewRelic::Agent.instance.transaction_sampler.last_sample
|
65
|
-
|
50
|
+
assert_in_range(elapsed, trace.params[:custom_params][:gc_time])
|
51
|
+
end
|
52
|
+
|
53
|
+
def assert_in_range(duration, gc_time)
|
54
|
+
assert gc_time > 0.0, "GC Time wasn't recorded!"
|
55
|
+
|
56
|
+
# This is a guess for a reasonable threshold here.
|
57
|
+
# Since these are timing based, we can revise or ditch as evidence ditacts
|
58
|
+
# One CI failure we saw at least had duration=0.314 and gc_time=0.088
|
59
|
+
ratio = gc_time / duration
|
60
|
+
assert(ratio > 0.1 && ratio < 1.0,
|
61
|
+
"Problem with GC/duration ratio. #{gc_time}/#{duration} = #{ratio} not between 0.1 and 1.0")
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_call_time(name, scope=nil)
|
65
|
+
NewRelic::Agent.agent.stats_engine.
|
66
|
+
get_stats(name, true, false, scope).
|
67
|
+
total_call_time
|
66
68
|
end
|
67
69
|
|
68
70
|
def enable_gc_stats
|
@@ -28,15 +28,19 @@ class ResqueTest < Test::Unit::TestCase
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def start_worker(opts={})
|
31
|
-
opts[:background]
|
31
|
+
if opts[:background]
|
32
|
+
start_worker_background(opts[:env_vars])
|
33
|
+
else
|
34
|
+
start_worker_child(opts[:env_vars])
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
def stop_worker(opts={})
|
35
39
|
opts[:background] ? stop_worker_background : stop_worker_child
|
36
40
|
end
|
37
41
|
|
38
|
-
def start_worker_child
|
39
|
-
worker_cmd = "NEWRELIC_DISPATCHER=resque QUEUE=* bundle exec rake resque:work"
|
42
|
+
def start_worker_child(env_vars=nil)
|
43
|
+
worker_cmd = "NEWRELIC_DISPATCHER=resque #{env_vars} QUEUE=* bundle exec rake resque:work"
|
40
44
|
@worker_pid = Process.fork
|
41
45
|
Process.exec(worker_cmd) if @worker_pid.nil?
|
42
46
|
end
|
@@ -46,9 +50,9 @@ class ResqueTest < Test::Unit::TestCase
|
|
46
50
|
Process.waitpid(@worker_pid)
|
47
51
|
end
|
48
52
|
|
49
|
-
def start_worker_background
|
53
|
+
def start_worker_background(env_vars=nil)
|
50
54
|
worker_cmd = "PIDFILE=#{@pidfile} TERM_CHILD=1 RESQUE_TERM_TIMEOUT=1 BACKGROUND=1 " +
|
51
|
-
"NEWRELIC_DISPATCHER=resque QUEUE=* bundle exec rake resque:work"
|
55
|
+
"NEWRELIC_DISPATCHER=resque #{env_vars} QUEUE=* bundle exec rake resque:work"
|
52
56
|
system(worker_cmd)
|
53
57
|
end
|
54
58
|
|
@@ -123,6 +127,15 @@ class ResqueTest < Test::Unit::TestCase
|
|
123
127
|
assert_metric_and_call_count('OtherTransaction/ResqueJob/all', JOB_COUNT)
|
124
128
|
end
|
125
129
|
|
130
|
+
def test_log_properly_when_fork_callbacks_are_broken
|
131
|
+
log_path = File.join(File.dirname(__FILE__), 'agent.log', 'newrelic_agent.log')
|
132
|
+
File.delete(log_path)
|
133
|
+
|
134
|
+
run_worker(:env_vars => 'BROKEN_AFTER_FORK=true')
|
135
|
+
|
136
|
+
assert File.read(log_path).include?('Unable to send data to parent process')
|
137
|
+
end
|
138
|
+
|
126
139
|
if RUBY_VERSION >= '1.9'
|
127
140
|
def test_all_jobs_ran_background
|
128
141
|
run_worker(:background => true)
|