newrelic_rpm 3.11.1.284 → 3.11.2.286
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +43 -2
- data/lib/new_relic/agent/agent.rb +1 -1
- data/lib/new_relic/agent/audit_logger.rb +27 -13
- data/lib/new_relic/agent/configuration/default_source.rb +20 -9
- data/lib/new_relic/agent/event_loop.rb +6 -2
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +10 -2
- data/lib/new_relic/agent/instrumentation/rack.rb +33 -0
- data/lib/new_relic/agent/new_relic_service.rb +9 -0
- data/lib/new_relic/control/frameworks/rails.rb +4 -0
- data/lib/new_relic/control/instance_methods.rb +17 -3
- data/lib/new_relic/environment_report.rb +1 -0
- data/lib/new_relic/version.rb +1 -1
- data/test/multiverse/suites/agent_only/config/newrelic.yml +5 -0
- data/test/multiverse/suites/agent_only/script/env_change.rb +10 -0
- data/test/multiverse/suites/agent_only/script/symbol_env.rb +10 -0
- data/test/multiverse/suites/agent_only/start_up_test.rb +17 -3
- data/test/multiverse/suites/rack/Envfile +11 -1
- data/test/multiverse/suites/rack/builder_map_test.rb +128 -0
- data/test/multiverse/suites/rack/url_map_test.rb +14 -18
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +2 -0
- data/test/new_relic/agent/audit_logger_test.rb +50 -0
- data/test/new_relic/agent/configuration/default_source_test.rb +3 -2
- data/test/new_relic/agent/new_relic_service_test.rb +12 -0
- data/test/new_relic/environment_report_test.rb +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24d158e960a984711fcd70df97914459118a2185
|
4
|
+
data.tar.gz: b13d960b29bf717bc74ae2352f94ca3d8f18a49c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac4abe0eb22876af9449ae733d5b9170254165687a0dea29570a98cb8b7e277be912c7b90909f37400a2cfa8aaa4751e2cf7bd3e60e884f61422009d2116abb5
|
7
|
+
data.tar.gz: 8c0782580d17557189e01654f2e7bf978e7e958df34d8c9f8aad58906995fa8c1137e5a78a96c9c0f25770a231b001617571875a71369bfd1d3dd9439fa2a163
|
data/CHANGELOG
CHANGED
@@ -1,8 +1,49 @@
|
|
1
1
|
# New Relic Ruby Agent Release Notes #
|
2
2
|
|
3
|
-
## v3.11.
|
3
|
+
## v3.11.2 ##
|
4
|
+
|
5
|
+
* Better naming for Rack::URLMap
|
6
|
+
|
7
|
+
If a Rack app made direct use of Rack::URLMap, instrumentation would miss
|
8
|
+
out on using the clearest naming based on the app class. This has been
|
9
|
+
fixed.
|
10
|
+
|
11
|
+
* Avoid performance regression in makara database adapter
|
12
|
+
|
13
|
+
Delegation in the makara database adapter caused performance issues when the
|
14
|
+
agent looked up a connection in the pool. The agent now uses a faster
|
15
|
+
lookup to work around this problem in makara, and allocates less as well.
|
16
|
+
Thanks Mike Nelson for the help in resolving this!
|
17
|
+
|
18
|
+
* Allow audit logging to STDOUT
|
19
|
+
|
20
|
+
Previously audit logs of the agent's communication with New Relic could only
|
21
|
+
write to a file. This prevented using the feature on cloud providers like
|
22
|
+
Heroku. Now STDOUT is an allowed destination for `audit_log.path`. Logging
|
23
|
+
can also be restricted to certain endpoints via `audit_log.endpoints`.
|
4
24
|
|
5
|
-
|
25
|
+
For more information see https://docs.newrelic.com/docs/agents/ruby-agent/installation-configuration/ruby-agent-configuration#audit_log
|
26
|
+
|
27
|
+
* Fix for crash during startup when Rails required but not used
|
28
|
+
|
29
|
+
If an application requires Rails but wasn't actually running it, the Ruby
|
30
|
+
agent would fail during startup. This has been fixed.
|
31
|
+
|
32
|
+
* Use IO.select explicitly in the event loop
|
33
|
+
|
34
|
+
If an application adds their own select method to Object/Kernel or mixes in a
|
35
|
+
module that overrides the select method (as with ActionView::Helpers) we would
|
36
|
+
previously have used their implementation instead of the intended IO.select,
|
37
|
+
leading to all sorts of unusual errors. We now explicitly reference IO.select
|
38
|
+
in the event loop to avoid these issues.
|
39
|
+
|
40
|
+
* Fix for background thread hangs on old Linux kernels
|
41
|
+
|
42
|
+
When running under Ruby 1.8.7 on Linux kernel versions 2.6.11 and earlier,
|
43
|
+
the background thread used by the agent to report data would hang, leading
|
44
|
+
to no data being reported. This has been be fixed.
|
45
|
+
|
46
|
+
## v3.11.1 ##
|
6
47
|
|
7
48
|
The Ruby agent incorrectly rescued exceptions at a point which caused
|
8
49
|
sequel_pg 1.6.11 to segfault. This has been fixed. Thanks to Oldrich
|
@@ -651,7 +651,7 @@ module NewRelic
|
|
651
651
|
def handle_force_restart(error)
|
652
652
|
::NewRelic::Agent.logger.debug error.message
|
653
653
|
drop_buffered_data
|
654
|
-
@service.
|
654
|
+
@service.force_restart if @service
|
655
655
|
@connect_state = :pending
|
656
656
|
sleep 30
|
657
657
|
end
|
@@ -11,6 +11,7 @@ module NewRelic
|
|
11
11
|
class AuditLogger
|
12
12
|
def initialize
|
13
13
|
@enabled = NewRelic::Agent.config[:'audit_log.enabled']
|
14
|
+
@endpoints = NewRelic::Agent.config[:'audit_log.endpoints']
|
14
15
|
@encoder = NewRelic::Agent::NewRelicService::Encoders::Identity
|
15
16
|
end
|
16
17
|
|
@@ -25,16 +26,16 @@ module NewRelic
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def log_request(uri, data, marshaller)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@log.info("REQUEST: #{uri}")
|
36
|
-
@log.info("REQUEST BODY: #{request_body}")
|
29
|
+
return unless enabled? && allowed_endpoint?(uri)
|
30
|
+
|
31
|
+
setup_logger unless setup?
|
32
|
+
request_body = if marshaller.class.human_readable?
|
33
|
+
marshaller.dump(data, :encoder => @encoder)
|
34
|
+
else
|
35
|
+
marshaller.prepare(data, :encoder => @encoder).inspect
|
37
36
|
end
|
37
|
+
@log.info("REQUEST: #{uri}")
|
38
|
+
@log.info("REQUEST BODY: #{request_body}")
|
38
39
|
rescue StandardError, SystemStackError, SystemCallError => e
|
39
40
|
::NewRelic::Agent.logger.warn("Failed writing to audit log", e)
|
40
41
|
rescue Exception => e
|
@@ -42,15 +43,23 @@ module NewRelic
|
|
42
43
|
raise
|
43
44
|
end
|
44
45
|
|
46
|
+
def allowed_endpoint?(uri)
|
47
|
+
@endpoints.any? { |endpoint| uri =~ endpoint }
|
48
|
+
end
|
49
|
+
|
45
50
|
def setup_logger
|
46
|
-
|
47
|
-
|
51
|
+
if wants_stdout?
|
52
|
+
# Using $stdout global for easier reassignment in testing
|
53
|
+
@log = ::Logger.new($stdout)
|
54
|
+
::NewRelic::Agent.logger.info("Audit log enabled to STDOUT")
|
55
|
+
elsif path = ensure_log_path
|
48
56
|
@log = ::Logger.new(path)
|
49
|
-
@log.formatter = create_log_formatter
|
50
57
|
::NewRelic::Agent.logger.info("Audit log enabled at '#{path}'")
|
51
58
|
else
|
52
59
|
@log = NewRelic::Agent::NullLogger.new
|
53
60
|
end
|
61
|
+
|
62
|
+
@log.formatter = create_log_formatter
|
54
63
|
end
|
55
64
|
|
56
65
|
def ensure_log_path
|
@@ -69,10 +78,15 @@ module NewRelic
|
|
69
78
|
path
|
70
79
|
end
|
71
80
|
|
81
|
+
def wants_stdout?
|
82
|
+
::NewRelic::Agent.config[:'audit_log.path'].upcase == "STDOUT"
|
83
|
+
end
|
84
|
+
|
72
85
|
def create_log_formatter
|
73
86
|
@hostname = NewRelic::Agent::Hostname.get
|
87
|
+
@prefix = wants_stdout? ? '** [NewRelic]' : ''
|
74
88
|
Proc.new do |severity, time, progname, msg|
|
75
|
-
"[#{time} #{@hostname} (#{$$})] : #{msg}\n"
|
89
|
+
"#{@prefix}[#{time} #{@hostname} (#{$$})] : #{msg}\n"
|
76
90
|
end
|
77
91
|
end
|
78
92
|
end
|
@@ -162,13 +162,10 @@ module NewRelic
|
|
162
162
|
}
|
163
163
|
end
|
164
164
|
|
165
|
-
def self.
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
rules.map do |rule|
|
170
|
-
/#{rule}/
|
171
|
-
end
|
165
|
+
def self.convert_to_regexp_list(raw_value)
|
166
|
+
value_list = convert_to_list(raw_value)
|
167
|
+
value_list.map do |value|
|
168
|
+
/#{value}/
|
172
169
|
end
|
173
170
|
end
|
174
171
|
|
@@ -469,7 +466,7 @@ module NewRelic
|
|
469
466
|
},
|
470
467
|
:'resque.use_harvest_lock' => {
|
471
468
|
:default => false,
|
472
|
-
:public =>
|
469
|
+
:public => false,
|
473
470
|
:type => Boolean,
|
474
471
|
:description => 'Enable or disable synchronizing Resque job forking with New Relic\'s harvest thread. The default is <code>false</code>. This helps prevent Resque jobs from deadlocking, but prevents New Relic from starting new jobs during harvest.'
|
475
472
|
},
|
@@ -529,6 +526,13 @@ module NewRelic
|
|
529
526
|
:type => String,
|
530
527
|
:description => 'Specifies a path to the audit log file (including the filename).'
|
531
528
|
},
|
529
|
+
:'audit_log.endpoints' => {
|
530
|
+
:default => [".*"],
|
531
|
+
:public => true,
|
532
|
+
:type => Array,
|
533
|
+
:transform => DefaultSource.method(:convert_to_regexp_list),
|
534
|
+
:description => 'List of allowed endpoints to include in audit log'
|
535
|
+
},
|
532
536
|
:disable_samplers => {
|
533
537
|
:default => false,
|
534
538
|
:public => true,
|
@@ -1049,6 +1053,13 @@ module NewRelic
|
|
1049
1053
|
:dynamic_name => true,
|
1050
1054
|
:description => 'Defines whether the agent will hook into Rack::Builder\'s <code>to_app</code> method to find gems to instrument during application startup.'
|
1051
1055
|
},
|
1056
|
+
:disable_rack_urlmap => {
|
1057
|
+
:default => false,
|
1058
|
+
:public => true,
|
1059
|
+
:type => Boolean,
|
1060
|
+
:dynamic_name => true,
|
1061
|
+
:description => 'Defines whether the agent will hook into Rack::URLMap to install middleware tracing.'
|
1062
|
+
},
|
1052
1063
|
:disable_rubyprof => {
|
1053
1064
|
:default => false,
|
1054
1065
|
:public => true,
|
@@ -1123,7 +1134,7 @@ module NewRelic
|
|
1123
1134
|
:default => [],
|
1124
1135
|
:public => true,
|
1125
1136
|
:type => Array,
|
1126
|
-
:transform => DefaultSource.
|
1137
|
+
:transform => DefaultSource.method(:convert_to_regexp_list),
|
1127
1138
|
:description => 'A list of patterns that will cause a transaction to be ignored if any of them match the URI.'
|
1128
1139
|
},
|
1129
1140
|
:'synthetics.traces_limit' => {
|
@@ -115,7 +115,7 @@ module NewRelic
|
|
115
115
|
|
116
116
|
def wait_to_run(nonblock)
|
117
117
|
timeout = nonblock ? 0 : next_timeout
|
118
|
-
ready = select([@self_pipe_rd], nil, nil, timeout)
|
118
|
+
ready = IO.select([@self_pipe_rd], nil, nil, timeout)
|
119
119
|
|
120
120
|
if ready && ready[0] && ready[0][0] && ready[0][0] == @self_pipe_rd
|
121
121
|
@self_pipe_rd.read(1)
|
@@ -182,7 +182,11 @@ module NewRelic
|
|
182
182
|
end
|
183
183
|
|
184
184
|
def wakeup
|
185
|
-
|
185
|
+
begin
|
186
|
+
@self_pipe_wr.write_nonblock '.'
|
187
|
+
rescue Errno::EAGAIN
|
188
|
+
::NewRelic::Agent.logger.debug "Failed to wakeup event loop"
|
189
|
+
end
|
186
190
|
end
|
187
191
|
end
|
188
192
|
end
|
@@ -78,8 +78,16 @@ module NewRelic
|
|
78
78
|
def active_record_config_for_event(event)
|
79
79
|
return unless event.payload[:connection_id]
|
80
80
|
|
81
|
-
|
82
|
-
|
81
|
+
connection = nil
|
82
|
+
connection_id = event.payload[:connection_id]
|
83
|
+
|
84
|
+
::ActiveRecord::Base.connection_handler.connection_pool_list.each do |handler|
|
85
|
+
connection = handler.connections.detect do |conn|
|
86
|
+
conn.object_id == connection_id
|
87
|
+
end
|
88
|
+
|
89
|
+
break if connection
|
90
|
+
end
|
83
91
|
|
84
92
|
connection.instance_variable_get(:@config) if connection
|
85
93
|
end
|
@@ -114,6 +114,15 @@ module NewRelic
|
|
114
114
|
result
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
module RackURLMap
|
119
|
+
def self.generate_traced_map(map)
|
120
|
+
map.inject({}) do |traced_map, (url, handler)|
|
121
|
+
traced_map[url] = NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(handler, true)
|
122
|
+
traced_map
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
117
126
|
end
|
118
127
|
end
|
119
128
|
end
|
@@ -148,6 +157,30 @@ DependencyDetection.defer do
|
|
148
157
|
alias_method :use, :use_with_newrelic
|
149
158
|
end
|
150
159
|
end
|
160
|
+
|
151
161
|
end
|
152
162
|
end
|
153
163
|
|
164
|
+
DependencyDetection.defer do
|
165
|
+
named :rack_urlmap
|
166
|
+
|
167
|
+
depends_on do
|
168
|
+
defined?(::Rack) && defined?(::Rack::URLMap)
|
169
|
+
end
|
170
|
+
|
171
|
+
depends_on do
|
172
|
+
::NewRelic::Agent::Instrumentation::RackHelpers.middleware_instrumentation_enabled? &&
|
173
|
+
!::NewRelic::Agent.config[:disable_rack]
|
174
|
+
end
|
175
|
+
|
176
|
+
executes do
|
177
|
+
class ::Rack::URLMap
|
178
|
+
alias_method :initialize_without_newrelic, :initialize
|
179
|
+
|
180
|
+
def initialize(map = {})
|
181
|
+
traced_map = ::NewRelic::Agent::Instrumentation::RackURLMap.generate_traced_map(map)
|
182
|
+
initialize_without_newrelic(traced_map)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -86,6 +86,11 @@ module NewRelic
|
|
86
86
|
@metric_id_cache = {}
|
87
87
|
end
|
88
88
|
|
89
|
+
def force_restart
|
90
|
+
reset_metric_id_cache
|
91
|
+
close_shared_connection
|
92
|
+
end
|
93
|
+
|
89
94
|
# takes an array of arrays of spec and id, adds it into the
|
90
95
|
# metric cache so we can save the collector some work by
|
91
96
|
# sending integers instead of strings the next time around
|
@@ -244,6 +249,10 @@ module NewRelic
|
|
244
249
|
end
|
245
250
|
end
|
246
251
|
|
252
|
+
def has_shared_connection?
|
253
|
+
!@shared_tcp_connection.nil?
|
254
|
+
end
|
255
|
+
|
247
256
|
def ssl_cert_store
|
248
257
|
path = cert_file_path
|
249
258
|
if !@ssl_cert_store || path != @cached_cert_store_path
|
@@ -62,6 +62,10 @@ module NewRelic
|
|
62
62
|
install_browser_monitoring(rails_config)
|
63
63
|
install_agent_hooks(rails_config)
|
64
64
|
end
|
65
|
+
rescue => e
|
66
|
+
::NewRelic::Agent.logger.error("Failure during init_config for Rails. Is Rails required in a non-Rails app? Set NEW_RELIC_FRAMEWORK=ruby to avoid this message.",
|
67
|
+
"The Ruby agent will continue running, but Rails-specific features may be missing.",
|
68
|
+
e)
|
65
69
|
end
|
66
70
|
|
67
71
|
def install_agent_hooks(config)
|
@@ -48,9 +48,7 @@ module NewRelic
|
|
48
48
|
# init_config({}) which is called one or more times.
|
49
49
|
#
|
50
50
|
def init_plugin(options={})
|
51
|
-
env = options
|
52
|
-
Agent.logger.info("Starting the New Relic agent in #{env.inspect} environment.")
|
53
|
-
Agent.logger.info("To prevent agent startup add a NEWRELIC_AGENT_ENABLED=false environment variable or modify the #{env.inspect} section of your newrelic.yml.")
|
51
|
+
env = determine_env(options)
|
54
52
|
|
55
53
|
configure_agent(env, options)
|
56
54
|
|
@@ -81,6 +79,21 @@ module NewRelic
|
|
81
79
|
end
|
82
80
|
end
|
83
81
|
|
82
|
+
def determine_env(options)
|
83
|
+
env = options[:env] || self.env
|
84
|
+
env = env.to_s
|
85
|
+
|
86
|
+
if @started_in_env && @started_in_env != env
|
87
|
+
Agent.logger.error("Attempted to start agent in #{env.inspect} environment, but agent was already running in #{@started_in_env.inspect}",
|
88
|
+
"The agent will continue running in #{@started_in_env.inspect}. To alter this, ensure the desired environment is set before the agent starts.")
|
89
|
+
else
|
90
|
+
Agent.logger.info("Starting the New Relic agent in #{env.inspect} environment.",
|
91
|
+
"To prevent agent startup add a NEWRELIC_AGENT_ENABLED=false environment variable or modify the #{env.inspect} section of your newrelic.yml.")
|
92
|
+
end
|
93
|
+
|
94
|
+
env
|
95
|
+
end
|
96
|
+
|
84
97
|
def configure_agent(env, options)
|
85
98
|
manual = Agent::Configuration::ManualSource.new(options)
|
86
99
|
Agent.config.replace_or_add_config(manual)
|
@@ -96,6 +109,7 @@ module NewRelic
|
|
96
109
|
|
97
110
|
# Install the real agent into the Agent module, and issue the start command.
|
98
111
|
def start_agent
|
112
|
+
@started_in_env = self.env
|
99
113
|
NewRelic::Agent.agent.start
|
100
114
|
end
|
101
115
|
|
data/lib/new_relic/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env 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
|
+
ENV["NEW_RELIC_LOG_FILE_PATH"] = "STDOUT"
|
7
|
+
|
8
|
+
require 'newrelic_rpm'
|
9
|
+
|
10
|
+
NewRelic::Agent.manual_start(:env => "production")
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env 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
|
+
ENV["NEW_RELIC_LOG_FILE_PATH"] = "STDOUT"
|
7
|
+
|
8
|
+
require 'newrelic_rpm'
|
9
|
+
|
10
|
+
NewRelic::Agent.manual_start(:env => :development)
|
@@ -25,10 +25,17 @@ class StartUpTest < Minitest::Test
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_instrumentation_loads_clean_even_without_dependencies
|
28
|
-
|
28
|
+
assert_runs_without_errors("bundle exec ruby script/loading.rb")
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
def test_manual_start_with_symbol_for_environment
|
32
|
+
assert_runs_without_errors("bundle exec ruby script/symbol_env.rb")
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_manual_start_logs_about_mismatched_environment
|
36
|
+
output = `bundle exec ruby script/env_change.rb`
|
37
|
+
|
38
|
+
assert_match(/ERROR.*Attempted to start agent.*production.*development/, output, output)
|
32
39
|
end
|
33
40
|
|
34
41
|
def test_after_fork_does_not_blow_away_manual_start_settings
|
@@ -38,4 +45,11 @@ class StartUpTest < Minitest::Test
|
|
38
45
|
|
39
46
|
assert_equal('my great app', NewRelic::Agent.config[:app_name])
|
40
47
|
end
|
48
|
+
|
49
|
+
def assert_runs_without_errors(command)
|
50
|
+
output = `#{command}`
|
51
|
+
|
52
|
+
problems = output.scan(/ERROR : .*/)
|
53
|
+
assert_empty problems
|
54
|
+
end
|
41
55
|
end
|
@@ -1,3 +1,8 @@
|
|
1
|
+
gemfile <<-RB
|
2
|
+
gem 'rack', '~>1.6.0'
|
3
|
+
gem 'rack-test'
|
4
|
+
RB
|
5
|
+
|
1
6
|
gemfile <<-RB
|
2
7
|
gem 'rack', '~>1.5.0'
|
3
8
|
gem 'rack-test'
|
@@ -8,6 +13,11 @@ gemfile <<-RB
|
|
8
13
|
gem 'rack-test'
|
9
14
|
RB
|
10
15
|
|
16
|
+
gemfile <<-RB
|
17
|
+
gem 'rack', '1.3.10'
|
18
|
+
gem 'rack-test'
|
19
|
+
RB
|
20
|
+
|
11
21
|
gemfile <<-RB
|
12
22
|
gem 'rack', '1.2.8'
|
13
23
|
gem 'rack-test'
|
@@ -22,4 +32,4 @@ RB
|
|
22
32
|
gemfile <<-RB
|
23
33
|
gem 'rack', '1.0.1'
|
24
34
|
gem 'rack-test'
|
25
|
-
RB
|
35
|
+
RB
|
@@ -0,0 +1,128 @@
|
|
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
|
+
# These tests confirm functionality when using the Rack::Builder class. In
|
6
|
+
# particular, combinations of map, use and run should result in the right
|
7
|
+
# metrics. In internals changed across Rack versions, so it's important to
|
8
|
+
# check as our middleware and Rack instrumentation has grown.
|
9
|
+
|
10
|
+
require 'multiverse_helpers'
|
11
|
+
|
12
|
+
if NewRelic::Agent::Instrumentation::RackHelpers.rack_version_supported?
|
13
|
+
|
14
|
+
class BuilderMapTest < Minitest::Test
|
15
|
+
include MultiverseHelpers
|
16
|
+
|
17
|
+
setup_and_teardown_agent
|
18
|
+
|
19
|
+
include Rack::Test::Methods
|
20
|
+
|
21
|
+
class SimpleMiddleware
|
22
|
+
def initialize(app)
|
23
|
+
@app = app
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(env)
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class MiddlewareOne < SimpleMiddleware; end
|
32
|
+
class MiddlewareTwo < SimpleMiddleware; end
|
33
|
+
class MiddlewareThree < SimpleMiddleware; end
|
34
|
+
|
35
|
+
class ExampleApp
|
36
|
+
def call(env)
|
37
|
+
[200, {}, [self.class.name]]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class PrefixAppOne < ExampleApp; end
|
42
|
+
class PrefixAppTwo < ExampleApp; end
|
43
|
+
|
44
|
+
def app
|
45
|
+
Rack::Builder.app do
|
46
|
+
use MiddlewareOne
|
47
|
+
use MiddlewareTwo
|
48
|
+
|
49
|
+
map '/prefix1' do
|
50
|
+
run PrefixAppOne.new
|
51
|
+
end
|
52
|
+
|
53
|
+
map '/prefix2' do
|
54
|
+
use MiddlewareThree
|
55
|
+
run PrefixAppTwo.new
|
56
|
+
end
|
57
|
+
|
58
|
+
# Rack versions prior to 1.4 did not support combining map and run at the
|
59
|
+
# top-level in the same Rack::Builder.
|
60
|
+
if Rack::VERSION[1] >= 4
|
61
|
+
run ExampleApp.new
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
if Rack::VERSION[1] >= 4
|
67
|
+
def test_metrics_for_default_prefix
|
68
|
+
get '/'
|
69
|
+
|
70
|
+
assert_metrics_recorded_exclusive([
|
71
|
+
'Apdex',
|
72
|
+
'ApdexAll',
|
73
|
+
'HttpDispatcher',
|
74
|
+
'Middleware/all',
|
75
|
+
'Controller/Rack/BuilderMapTest::ExampleApp/call',
|
76
|
+
'Apdex/Rack/BuilderMapTest::ExampleApp/call',
|
77
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareOne/call',
|
78
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareTwo/call',
|
79
|
+
'Nested/Controller/Rack/BuilderMapTest::ExampleApp/call',
|
80
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareOne/call', 'Controller/Rack/BuilderMapTest::ExampleApp/call'],
|
81
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareTwo/call', 'Controller/Rack/BuilderMapTest::ExampleApp/call'],
|
82
|
+
['Nested/Controller/Rack/BuilderMapTest::ExampleApp/call', 'Controller/Rack/BuilderMapTest::ExampleApp/call']
|
83
|
+
])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_metrics_for_mapped_prefix
|
88
|
+
get '/prefix1'
|
89
|
+
|
90
|
+
assert_metrics_recorded([
|
91
|
+
'Apdex',
|
92
|
+
'ApdexAll',
|
93
|
+
'HttpDispatcher',
|
94
|
+
'Middleware/all',
|
95
|
+
'Controller/Rack/BuilderMapTest::PrefixAppOne/call',
|
96
|
+
'Apdex/Rack/BuilderMapTest::PrefixAppOne/call',
|
97
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareOne/call',
|
98
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareTwo/call',
|
99
|
+
'Nested/Controller/Rack/BuilderMapTest::PrefixAppOne/call',
|
100
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareOne/call', 'Controller/Rack/BuilderMapTest::PrefixAppOne/call'],
|
101
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareTwo/call', 'Controller/Rack/BuilderMapTest::PrefixAppOne/call'],
|
102
|
+
['Nested/Controller/Rack/BuilderMapTest::PrefixAppOne/call', 'Controller/Rack/BuilderMapTest::PrefixAppOne/call']
|
103
|
+
])
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_metrics_for_mapped_prefix_with_extra_middleware
|
107
|
+
get '/prefix2'
|
108
|
+
|
109
|
+
assert_metrics_recorded([
|
110
|
+
'Apdex',
|
111
|
+
'ApdexAll',
|
112
|
+
'HttpDispatcher',
|
113
|
+
'Middleware/all',
|
114
|
+
'Controller/Rack/BuilderMapTest::PrefixAppTwo/call',
|
115
|
+
'Apdex/Rack/BuilderMapTest::PrefixAppTwo/call',
|
116
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareOne/call',
|
117
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareTwo/call',
|
118
|
+
'Middleware/Rack/BuilderMapTest::MiddlewareThree/call',
|
119
|
+
'Nested/Controller/Rack/BuilderMapTest::PrefixAppTwo/call',
|
120
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareOne/call', 'Controller/Rack/BuilderMapTest::PrefixAppTwo/call'],
|
121
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareTwo/call', 'Controller/Rack/BuilderMapTest::PrefixAppTwo/call'],
|
122
|
+
['Middleware/Rack/BuilderMapTest::MiddlewareThree/call', 'Controller/Rack/BuilderMapTest::PrefixAppTwo/call'],
|
123
|
+
['Nested/Controller/Rack/BuilderMapTest::PrefixAppTwo/call', 'Controller/Rack/BuilderMapTest::PrefixAppTwo/call']
|
124
|
+
])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -2,6 +2,10 @@
|
|
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
|
+
# These tests are for confirming that our direct support Rack::URLMap works
|
6
|
+
# properly. Tests against the builder interface more commonly used (i.e. map)
|
7
|
+
# can be found elsewhere in this suite.
|
8
|
+
|
5
9
|
if NewRelic::Agent::Instrumentation::RackHelpers.rack_version_supported?
|
6
10
|
|
7
11
|
class UrlMapTest < Minitest::Test
|
@@ -23,7 +27,6 @@ class UrlMapTest < Minitest::Test
|
|
23
27
|
|
24
28
|
class MiddlewareOne < SimpleMiddleware; end
|
25
29
|
class MiddlewareTwo < SimpleMiddleware; end
|
26
|
-
class MiddlewareThree < SimpleMiddleware; end
|
27
30
|
|
28
31
|
class ExampleApp
|
29
32
|
def call(env)
|
@@ -39,20 +42,9 @@ class UrlMapTest < Minitest::Test
|
|
39
42
|
use MiddlewareOne
|
40
43
|
use MiddlewareTwo
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
map '/prefix2' do
|
47
|
-
use MiddlewareThree
|
48
|
-
run PrefixAppTwo.new
|
49
|
-
end
|
50
|
-
|
51
|
-
# Rack versions prior to 1.4 did not support combining map and run at the
|
52
|
-
# top-level in the same Rack::Builder.
|
53
|
-
if Rack::VERSION[1] >= 4
|
54
|
-
run ExampleApp.new
|
55
|
-
end
|
45
|
+
run Rack::URLMap.new(
|
46
|
+
'/prefix1' => PrefixAppOne.new,
|
47
|
+
'/prefix2' => PrefixAppTwo.new)
|
56
48
|
end
|
57
49
|
end
|
58
50
|
|
@@ -69,10 +61,12 @@ class UrlMapTest < Minitest::Test
|
|
69
61
|
'Apdex/Rack/UrlMapTest::ExampleApp/call',
|
70
62
|
'Middleware/Rack/UrlMapTest::MiddlewareOne/call',
|
71
63
|
'Middleware/Rack/UrlMapTest::MiddlewareTwo/call',
|
64
|
+
'Nested/Controller/Rack/Rack::URLMap/call',
|
72
65
|
'Nested/Controller/Rack/UrlMapTest::ExampleApp/call',
|
73
66
|
['Middleware/Rack/UrlMapTest::MiddlewareOne/call', 'Controller/Rack/UrlMapTest::ExampleApp/call'],
|
74
67
|
['Middleware/Rack/UrlMapTest::MiddlewareTwo/call', 'Controller/Rack/UrlMapTest::ExampleApp/call'],
|
75
|
-
['Nested/Controller/Rack/UrlMapTest::ExampleApp/call', 'Controller/Rack/UrlMapTest::ExampleApp/call']
|
68
|
+
['Nested/Controller/Rack/UrlMapTest::ExampleApp/call', 'Controller/Rack/UrlMapTest::ExampleApp/call'],
|
69
|
+
['Nested/Controller/Rack/Rack::URLMap/call', 'Controller/Rack/UrlMapTest::ExampleApp/call']
|
76
70
|
])
|
77
71
|
end
|
78
72
|
end
|
@@ -89,9 +83,11 @@ class UrlMapTest < Minitest::Test
|
|
89
83
|
'Apdex/Rack/UrlMapTest::PrefixAppOne/call',
|
90
84
|
'Middleware/Rack/UrlMapTest::MiddlewareOne/call',
|
91
85
|
'Middleware/Rack/UrlMapTest::MiddlewareTwo/call',
|
86
|
+
'Nested/Controller/Rack/Rack::URLMap/call',
|
92
87
|
'Nested/Controller/Rack/UrlMapTest::PrefixAppOne/call',
|
93
88
|
['Middleware/Rack/UrlMapTest::MiddlewareOne/call', 'Controller/Rack/UrlMapTest::PrefixAppOne/call'],
|
94
89
|
['Middleware/Rack/UrlMapTest::MiddlewareTwo/call', 'Controller/Rack/UrlMapTest::PrefixAppOne/call'],
|
90
|
+
['Nested/Controller/Rack/Rack::URLMap/call', 'Controller/Rack/UrlMapTest::PrefixAppOne/call'],
|
95
91
|
['Nested/Controller/Rack/UrlMapTest::PrefixAppOne/call', 'Controller/Rack/UrlMapTest::PrefixAppOne/call']
|
96
92
|
])
|
97
93
|
end
|
@@ -108,11 +104,11 @@ class UrlMapTest < Minitest::Test
|
|
108
104
|
'Apdex/Rack/UrlMapTest::PrefixAppTwo/call',
|
109
105
|
'Middleware/Rack/UrlMapTest::MiddlewareOne/call',
|
110
106
|
'Middleware/Rack/UrlMapTest::MiddlewareTwo/call',
|
111
|
-
'
|
107
|
+
'Nested/Controller/Rack/Rack::URLMap/call',
|
112
108
|
'Nested/Controller/Rack/UrlMapTest::PrefixAppTwo/call',
|
113
109
|
['Middleware/Rack/UrlMapTest::MiddlewareOne/call', 'Controller/Rack/UrlMapTest::PrefixAppTwo/call'],
|
114
110
|
['Middleware/Rack/UrlMapTest::MiddlewareTwo/call', 'Controller/Rack/UrlMapTest::PrefixAppTwo/call'],
|
115
|
-
['
|
111
|
+
['Nested/Controller/Rack/Rack::URLMap/call', 'Controller/Rack/UrlMapTest::PrefixAppTwo/call'],
|
116
112
|
['Nested/Controller/Rack/UrlMapTest::PrefixAppTwo/call', 'Controller/Rack/UrlMapTest::PrefixAppTwo/call']
|
117
113
|
])
|
118
114
|
end
|
@@ -73,6 +73,18 @@ class AuditLoggerTest < Minitest::Test
|
|
73
73
|
assert_equal(expected, result)
|
74
74
|
end
|
75
75
|
|
76
|
+
def test_log_formatter_to_stdout
|
77
|
+
with_config(:'audit_log.path' => "STDOUT") do
|
78
|
+
Socket.stubs(:gethostname).returns('dummyhost')
|
79
|
+
formatter = NewRelic::Agent::AuditLogger.new.create_log_formatter
|
80
|
+
time = '2012-01-01 00:00:00'
|
81
|
+
msg = 'hello'
|
82
|
+
result = formatter.call(Logger::INFO, time, 'bleh', msg)
|
83
|
+
expected = "** [NewRelic][2012-01-01 00:00:00 dummyhost (#{$$})] : hello\n"
|
84
|
+
assert_equal(expected, result)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
76
88
|
def test_ensure_path_returns_nil_with_bogus_path
|
77
89
|
with_config(:'audit_log.path' => '/really/really/not/a/path') do
|
78
90
|
FileUtils.stubs(:mkdir_p).raises(SystemCallError, "i'd rather not")
|
@@ -130,6 +142,24 @@ class AuditLoggerTest < Minitest::Test
|
|
130
142
|
end
|
131
143
|
end
|
132
144
|
|
145
|
+
def test_allows_through_endpoints
|
146
|
+
fake_metrics = { 'metric' => 'yup' }
|
147
|
+
with_config(:'audit_log.endpoints' => ['metric_data']) do
|
148
|
+
setup_fake_logger
|
149
|
+
@logger.log_request('host/metric_data', fake_metrics, @marshaller)
|
150
|
+
assert_log_contains_string(fake_metrics.inspect)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_filters_endpoints
|
155
|
+
fake_txn = { 'txn' => 'nope' }
|
156
|
+
with_config(:'audit_log.endpoints' => ['metric_data']) do
|
157
|
+
setup_fake_logger
|
158
|
+
@logger.log_request('host/transaction_sample_data', fake_txn, @marshaller)
|
159
|
+
assert_empty read_log_body
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
133
163
|
def test_should_cache_hostname
|
134
164
|
Socket.expects(:gethostname).once.returns('cachey-mccaherson')
|
135
165
|
setup_fake_logger
|
@@ -160,4 +190,24 @@ class AuditLoggerTest < Minitest::Test
|
|
160
190
|
end
|
161
191
|
end
|
162
192
|
|
193
|
+
def test_writes_to_stdout
|
194
|
+
with_config(:'audit_log.path' => "STDOUT") do
|
195
|
+
output = capturing_stdout do
|
196
|
+
@logger = NewRelic::Agent::AuditLogger.new
|
197
|
+
@logger.log_request(@uri, @dummy_data, @marshaller)
|
198
|
+
end
|
199
|
+
|
200
|
+
assert_includes output, @dummy_data.inspect
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def capturing_stdout
|
205
|
+
orig = $stdout.dup
|
206
|
+
output = ""
|
207
|
+
$stdout = StringIO.new(output)
|
208
|
+
yield
|
209
|
+
output
|
210
|
+
ensure
|
211
|
+
$stdout = orig
|
212
|
+
end
|
163
213
|
end
|
@@ -80,8 +80,9 @@ module NewRelic::Agent::Configuration
|
|
80
80
|
nil
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
84
|
-
|
83
|
+
def test_transform_for_returns_something_callable
|
84
|
+
transform = DefaultSource.transform_for(:'rules.ignore_url_regexes')
|
85
|
+
assert transform.respond_to?(:call)
|
85
86
|
end
|
86
87
|
|
87
88
|
def test_transform_for_returns_nil_for_settings_that_do_not_have_a_transform
|
@@ -825,6 +825,18 @@ class NewRelicServiceTest < Minitest::Test
|
|
825
825
|
])
|
826
826
|
end
|
827
827
|
|
828
|
+
def test_force_restart_clears_metric_cache
|
829
|
+
@service.metric_id_cache[1] = "boo"
|
830
|
+
@service.force_restart
|
831
|
+
assert_empty @service.metric_id_cache
|
832
|
+
end
|
833
|
+
|
834
|
+
def test_force_restart_closes_shared_connections
|
835
|
+
@service.establish_shared_connection
|
836
|
+
@service.force_restart
|
837
|
+
refute @service.has_shared_connection?
|
838
|
+
end
|
839
|
+
|
828
840
|
def build_stats_hash(items={})
|
829
841
|
hash = NewRelic::Agent::StatsHash.new
|
830
842
|
items.each do |key, value|
|
@@ -59,6 +59,10 @@ class EnvironmentReportTest < Minitest::Test
|
|
59
59
|
assert_equal RUBY_VERSION, @report['Ruby version']
|
60
60
|
end
|
61
61
|
|
62
|
+
def test_gathers_openssl_version
|
63
|
+
refute_nil @report['OpenSSL version']
|
64
|
+
end
|
65
|
+
|
62
66
|
def test_gathers_system_info
|
63
67
|
NewRelic::Agent::SystemInfo.stubs({
|
64
68
|
:num_logical_processors => 8,
|
@@ -95,6 +99,7 @@ class EnvironmentReportTest < Minitest::Test
|
|
95
99
|
'Rails Env',
|
96
100
|
'Rails version',
|
97
101
|
'Rails threadsafe',
|
102
|
+
'OpenSSL version',
|
98
103
|
].each do |key|
|
99
104
|
assert NewRelic::EnvironmentReport.registered_reporters.has_key?(key), "Expected logic for #{key.inspect} in EnvironmentReport."
|
100
105
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic_rpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.11.
|
4
|
+
version: 3.11.2.286
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Clark
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2015-
|
15
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
@@ -811,7 +811,9 @@ files:
|
|
811
811
|
- test/multiverse/suites/agent_only/pipe_manager_test.rb
|
812
812
|
- test/multiverse/suites/agent_only/rename_rule_test.rb
|
813
813
|
- test/multiverse/suites/agent_only/rum_instrumentation_test.rb
|
814
|
+
- test/multiverse/suites/agent_only/script/env_change.rb
|
814
815
|
- test/multiverse/suites/agent_only/script/loading.rb
|
816
|
+
- test/multiverse/suites/agent_only/script/symbol_env.rb
|
815
817
|
- test/multiverse/suites/agent_only/service_timeout_test.rb
|
816
818
|
- test/multiverse/suites/agent_only/set_transaction_name_test.rb
|
817
819
|
- test/multiverse/suites/agent_only/ssl_test.rb
|
@@ -895,6 +897,7 @@ files:
|
|
895
897
|
- test/multiverse/suites/padrino/config/newrelic.yml
|
896
898
|
- test/multiverse/suites/padrino/padrino_test.rb
|
897
899
|
- test/multiverse/suites/rack/Envfile
|
900
|
+
- test/multiverse/suites/rack/builder_map_test.rb
|
898
901
|
- test/multiverse/suites/rack/example_app.rb
|
899
902
|
- test/multiverse/suites/rack/http_response_code_test.rb
|
900
903
|
- test/multiverse/suites/rack/nested_non_rack_app_test.rb
|