newrelic_rpm 3.6.2.96 → 3.6.3.103.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG +33 -1
- data/README.md +7 -7
- data/lib/new_relic/agent/agent.rb +51 -22
- data/lib/new_relic/agent/agent_logger.rb +22 -11
- data/lib/new_relic/agent/configuration/defaults.rb +6 -1
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -6
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record.rb +8 -48
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +9 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -3
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +4 -4
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +10 -8
- data/lib/new_relic/agent/instrumentation/padrino.rb +32 -0
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +52 -0
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +56 -0
- data/lib/new_relic/agent/instrumentation/sinatra.rb +113 -48
- data/lib/new_relic/agent/new_relic_service.rb +6 -0
- data/lib/new_relic/agent/pipe_channel_manager.rb +13 -8
- data/lib/new_relic/agent/request_sampler.rb +205 -0
- data/lib/new_relic/agent/sampler.rb +0 -1
- data/lib/new_relic/agent/stats_engine/samplers.rb +0 -1
- data/lib/new_relic/agent/stats_engine/transactions.rb +12 -16
- data/lib/new_relic/agent/transaction.rb +27 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +47 -6
- data/lib/new_relic/agent/transaction_sampler.rb +0 -5
- data/lib/new_relic/agent.rb +17 -0
- data/lib/new_relic/build.rb +2 -2
- data/lib/new_relic/coerce.rb +3 -1
- data/lib/new_relic/rack/agent_hooks.rb +17 -3
- data/lib/new_relic/rack/browser_monitoring.rb +8 -3
- data/lib/new_relic/rack/error_collector.rb +2 -0
- data/lib/new_relic/transaction_sample/segment.rb +0 -23
- data/lib/new_relic/transaction_sample.rb +0 -9
- data/lib/new_relic/version.rb +1 -1
- data/test/agent_helper.rb +204 -0
- data/test/config/newrelic.yml +0 -1
- data/test/config/test_control.rb +3 -1
- data/test/multiverse/suites/agent_only/key_transactions_test.rb +8 -5
- data/test/multiverse/suites/agent_only/logging_test.rb +1 -1
- data/test/multiverse/suites/agent_only/thread_profiling_test.rb +7 -8
- data/test/multiverse/suites/datamapper/Envfile +7 -0
- data/test/multiverse/suites/datamapper/datamapper_test.rb +105 -0
- data/test/multiverse/suites/padrino/Envfile +16 -0
- data/test/multiverse/suites/padrino/config/newrelic.yml +24 -0
- data/test/multiverse/suites/padrino/padrino_test.rb +54 -0
- data/test/multiverse/suites/rails/Envfile +5 -5
- data/test/multiverse/suites/rails/app.rb +1 -0
- data/test/multiverse/suites/rails/request_statistics_test.rb +118 -0
- data/test/multiverse/suites/sinatra/Envfile +8 -2
- data/test/multiverse/suites/sinatra/ignoring_test.rb +185 -0
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +92 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +0 -3
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +89 -0
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +120 -0
- data/test/new_relic/agent/agent_logger_test.rb +149 -56
- data/test/new_relic/agent/agent_test.rb +23 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +8 -1
- data/test/new_relic/agent/autostart_test.rb +10 -6
- data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +36 -31
- data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +7 -0
- data/test/new_relic/agent/instrumentation/active_record_helper_test.rb +20 -4
- data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +20 -9
- data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +23 -19
- data/test/new_relic/agent/instrumentation/sequel_test.rb +118 -79
- data/test/new_relic/agent/instrumentation/sinatra/transaction_namer_test.rb +55 -0
- data/test/new_relic/agent/instrumentation/sinatra_test.rb +60 -11
- data/test/new_relic/agent/method_tracer_test.rb +7 -4
- data/test/new_relic/agent/new_relic_service_test.rb +6 -0
- data/test/new_relic/agent/pipe_channel_manager_test.rb +6 -2
- data/test/new_relic/agent/request_sampler_test.rb +159 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +1 -5
- data/test/new_relic/agent/stats_engine_test.rb +14 -0
- data/test/new_relic/agent/transaction_sample_builder_test.rb +43 -6
- data/test/new_relic/agent/transaction_sampler_test.rb +31 -1
- data/test/new_relic/agent/transaction_test.rb +29 -0
- data/test/new_relic/agent_test.rb +7 -0
- data/test/new_relic/coerce_test.rb +13 -0
- data/test/new_relic/fake_collector.rb +31 -1
- data/test/new_relic/metric_spec_test.rb +14 -10
- data/test/new_relic/rack/agent_hooks_test.rb +9 -2
- data/test/new_relic/rack/browser_monitoring_test.rb +16 -7
- data/test/new_relic/rack/developer_mode_test.rb +7 -0
- data/test/new_relic/rack/error_collector_test.rb +10 -6
- data/test/new_relic/transaction_sample/segment_test.rb +0 -61
- data/test/new_relic/transaction_sample_subtest_test.rb +0 -19
- data/test/script/ci.sh +14 -0
- data/test/test_helper.rb +79 -203
- data.tar.gz.sig +0 -0
- metadata +50 -18
- metadata.gz.sig +0 -0
- data/test/multiverse/suites/datamapper/encoding_test.rb +0 -40
- data/test/multiverse/suites/sinatra/sinatra_test.rb +0 -143
@@ -0,0 +1,92 @@
|
|
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 'mocha'
|
6
|
+
require 'sinatra'
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'sinatra_test_cases'))
|
8
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper'))
|
9
|
+
|
10
|
+
configure do
|
11
|
+
# display exceptions so we see what's going on
|
12
|
+
disable :show_exceptions
|
13
|
+
|
14
|
+
# create a condition (sintra's version of a before_filter) that returns the
|
15
|
+
# value that was passed into it.
|
16
|
+
set :my_condition do |boolean|
|
17
|
+
condition do
|
18
|
+
halt 404 unless boolean
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
get '/user/login' do
|
24
|
+
"please log in"
|
25
|
+
end
|
26
|
+
|
27
|
+
# this action will always return 404 because of the condition.
|
28
|
+
get '/user/:id', :my_condition => false do |id|
|
29
|
+
"Welcome #{id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
get '/raise' do
|
33
|
+
raise "Uh-oh"
|
34
|
+
end
|
35
|
+
|
36
|
+
# check that pass works properly
|
37
|
+
set(:pass_condition) { |_| condition { pass { halt 418, "I'm a teapot." } } }
|
38
|
+
get('/pass', :pass_condition => true) { }
|
39
|
+
|
40
|
+
get '/pass' do
|
41
|
+
"I'm not a teapot."
|
42
|
+
end
|
43
|
+
|
44
|
+
class Error < StandardError; end
|
45
|
+
error(Error) { halt 200, 'nothing happened' }
|
46
|
+
set(:error_condition) { |_| condition { raise Error } }
|
47
|
+
get('/error', :error_condition => true) { }
|
48
|
+
|
49
|
+
set(:precondition_check) do |_|
|
50
|
+
condition do
|
51
|
+
raise "Boo" if $precondition_already_checked
|
52
|
+
$precondition_already_checked = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
get('/precondition', :precondition_check => true) do
|
56
|
+
'precondition only happened once'
|
57
|
+
end
|
58
|
+
|
59
|
+
get '/route/:name' do |name|
|
60
|
+
# usually this would be a db test or something
|
61
|
+
pass if name != 'match'
|
62
|
+
'first route'
|
63
|
+
end
|
64
|
+
|
65
|
+
get '/route/no_match' do
|
66
|
+
'second route'
|
67
|
+
end
|
68
|
+
|
69
|
+
before '/filtered' do
|
70
|
+
@filtered = true
|
71
|
+
end
|
72
|
+
|
73
|
+
get '/filtered' do
|
74
|
+
@filtered ? 'got filtered' : 'nope'
|
75
|
+
end
|
76
|
+
|
77
|
+
newrelic_ignore '/ignored'
|
78
|
+
get '/ignored' do
|
79
|
+
"don't trace me bro"
|
80
|
+
end
|
81
|
+
|
82
|
+
get /\/regex.*/ do
|
83
|
+
"Yeah, regex's!"
|
84
|
+
end
|
85
|
+
|
86
|
+
class SinatraClassicTest < Test::Unit::TestCase
|
87
|
+
include SinatraTestCases
|
88
|
+
|
89
|
+
def app
|
90
|
+
Sinatra::Application
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,89 @@
|
|
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 'mocha'
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'sinatra_test_cases'))
|
7
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'agent_helper'))
|
8
|
+
|
9
|
+
class SinatraModularTestApp < Sinatra::Base
|
10
|
+
configure do
|
11
|
+
# display exceptions so we see what's going on
|
12
|
+
disable :show_exceptions
|
13
|
+
|
14
|
+
# create a condition (sintra's version of a before_filter) that returns the
|
15
|
+
# value that was passed into it.
|
16
|
+
set :my_condition do |boolean|
|
17
|
+
condition do
|
18
|
+
halt 404 unless boolean
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
get '/user/login' do
|
24
|
+
"please log in"
|
25
|
+
end
|
26
|
+
|
27
|
+
# this action will always return 404 because of the condition.
|
28
|
+
get '/user/:id', :my_condition => false do |id|
|
29
|
+
"Welcome #{id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
get '/raise' do
|
33
|
+
raise "Uh-oh"
|
34
|
+
end
|
35
|
+
|
36
|
+
# check that pass works properly
|
37
|
+
condition { pass { halt 418, "I'm a teapot." } }
|
38
|
+
get('/pass') { }
|
39
|
+
|
40
|
+
get '/pass' do
|
41
|
+
"I'm not a teapot."
|
42
|
+
end
|
43
|
+
|
44
|
+
class Error < StandardError; end
|
45
|
+
error(Error) { halt 200, 'nothing happened' }
|
46
|
+
condition { raise Error }
|
47
|
+
get('/error') { }
|
48
|
+
|
49
|
+
condition do
|
50
|
+
raise "Boo" if $precondition_already_checked
|
51
|
+
$precondition_already_checked = true
|
52
|
+
end
|
53
|
+
get('/precondition') { 'precondition only happened once' }
|
54
|
+
|
55
|
+
get '/route/:name' do |name|
|
56
|
+
# usually this would be a db test or something
|
57
|
+
pass if name != 'match'
|
58
|
+
'first route'
|
59
|
+
end
|
60
|
+
|
61
|
+
get '/route/no_match' do
|
62
|
+
'second route'
|
63
|
+
end
|
64
|
+
|
65
|
+
before '/filtered' do
|
66
|
+
@filtered = true
|
67
|
+
end
|
68
|
+
|
69
|
+
get '/filtered' do
|
70
|
+
@filtered ? 'got filtered' : 'nope'
|
71
|
+
end
|
72
|
+
|
73
|
+
newrelic_ignore '/ignored'
|
74
|
+
get '/ignored' do
|
75
|
+
"don't trace me bro"
|
76
|
+
end
|
77
|
+
|
78
|
+
get /\/regex.*/ do
|
79
|
+
"Yeah, regex's!"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class SinatraModularTest < Test::Unit::TestCase
|
84
|
+
include SinatraTestCases
|
85
|
+
|
86
|
+
def app
|
87
|
+
SinatraModularTestApp
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,120 @@
|
|
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
|
+
# This module brings the base test cases that should run against both classic and
|
6
|
+
# module Sinatra apps. The sinatra_class_test and sinatra_modular_test files
|
7
|
+
# both maintain the same app structure in both forms, and this exercises them.
|
8
|
+
module SinatraTestCases
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
def app
|
12
|
+
raise "Must implement app on your test case"
|
13
|
+
end
|
14
|
+
|
15
|
+
def app_name
|
16
|
+
app.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
$precondition_already_checked = false
|
21
|
+
::NewRelic::Agent.manual_start
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
reset
|
26
|
+
end
|
27
|
+
|
28
|
+
def reset
|
29
|
+
::NewRelic::Agent.agent.stats_engine.reset_stats
|
30
|
+
::NewRelic::Agent.agent.error_collector.harvest_errors([])
|
31
|
+
end
|
32
|
+
|
33
|
+
# https://support.newrelic.com/tickets/24779
|
34
|
+
def test_lower_priority_route_conditions_arent_applied_to_higher_priority_routes
|
35
|
+
get '/user/login'
|
36
|
+
assert_equal 200, last_response.status
|
37
|
+
assert_equal 'please log in', last_response.body
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_conditions_are_applied_to_an_action_that_uses_them
|
41
|
+
get '/user/1'
|
42
|
+
assert_equal 404, last_response.status
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_queue_time_headers_are_passed_to_agent
|
46
|
+
get '/user/login', {}, { 'HTTP_X_REQUEST_START' => 't=1360973845' }
|
47
|
+
assert_metrics_recorded(["WebFrontend/QueueTime"])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_shown_errors_get_caught
|
51
|
+
get '/raise'
|
52
|
+
assert_equal 1, ::NewRelic::Agent.agent.error_collector.errors.size
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_does_not_break_pass
|
56
|
+
get '/pass'
|
57
|
+
assert_equal 200, last_response.status
|
58
|
+
assert_equal "I'm not a teapot.", last_response.body
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_does_not_break_error_handling
|
62
|
+
get '/error'
|
63
|
+
assert_equal 200, last_response.status
|
64
|
+
assert_equal "nothing happened", last_response.body
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_sees_handled_error
|
68
|
+
get '/error'
|
69
|
+
assert_equal 1, ::NewRelic::Agent.agent.error_collector.errors.size
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_correct_pattern
|
73
|
+
get '/route/match'
|
74
|
+
assert_equal 'first route', last_response.body
|
75
|
+
assert_metrics_recorded(["Controller/Sinatra/#{app_name}/GET route/([^/?#]+)"])
|
76
|
+
|
77
|
+
reset
|
78
|
+
|
79
|
+
get '/route/no_match'
|
80
|
+
assert_equal 'second route', last_response.body
|
81
|
+
assert_metrics_recorded(["Controller/Sinatra/#{app_name}/GET route/no_match"])
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_with_regex_pattern
|
85
|
+
get '/regexes'
|
86
|
+
assert_equal "Yeah, regex's!", last_response.body
|
87
|
+
assert_metrics_recorded(["Controller/Sinatra/#{app_name}/GET regex.*"])
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_set_unknown_transaction_name_if_error_in_routing
|
91
|
+
::NewRelic::Agent::Instrumentation::Sinatra::TransactionNamer \
|
92
|
+
.stubs(:http_verb).raises(StandardError.new('madness'))
|
93
|
+
|
94
|
+
get '/user/login'
|
95
|
+
assert_metrics_recorded(["Controller/Sinatra/#{app_name}/(unknown)"])
|
96
|
+
end
|
97
|
+
|
98
|
+
# https://support.newrelic.com/tickets/31061
|
99
|
+
def test_precondition_not_over_called
|
100
|
+
get '/precondition'
|
101
|
+
|
102
|
+
assert_equal 200, last_response.status
|
103
|
+
assert_equal 'precondition only happened once', last_response.body
|
104
|
+
assert_metrics_recorded(["Controller/Sinatra/#{app_name}/GET precondition"])
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_filter
|
108
|
+
get '/filtered'
|
109
|
+
|
110
|
+
assert_equal 200, last_response.status
|
111
|
+
assert_equal 'got filtered', last_response.body
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_ignores_route_metrics
|
115
|
+
get '/ignored'
|
116
|
+
|
117
|
+
assert_equal 200, last_response.status
|
118
|
+
assert_metrics_not_recorded(["Controller/Sinatra/#{app_name}/GET ignored"])
|
119
|
+
end
|
120
|
+
end
|
@@ -6,7 +6,24 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
6
6
|
require 'new_relic/agent/agent_logger'
|
7
7
|
require 'new_relic/agent/null_logger'
|
8
8
|
|
9
|
+
class ArrayLogDevice
|
10
|
+
def initialize( array=[] )
|
11
|
+
@array = array
|
12
|
+
end
|
13
|
+
attr_reader :array
|
14
|
+
|
15
|
+
def write( message )
|
16
|
+
@array << message
|
17
|
+
end
|
18
|
+
|
19
|
+
def close; end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
9
23
|
class AgentLoggerTest < Test::Unit::TestCase
|
24
|
+
|
25
|
+
LEVELS = [:fatal, :error, :warn, :info, :debug]
|
26
|
+
|
10
27
|
def setup
|
11
28
|
@config = {
|
12
29
|
:log_file_path => "log/",
|
@@ -15,66 +32,77 @@ class AgentLoggerTest < Test::Unit::TestCase
|
|
15
32
|
}
|
16
33
|
end
|
17
34
|
|
18
|
-
def test_initalizes_from_config
|
19
|
-
override_logger = stub(:level=)
|
20
|
-
::Logger.stubs(:new).with(any_parameters).returns(override_logger)
|
21
35
|
|
36
|
+
#
|
37
|
+
# Tests
|
38
|
+
#
|
39
|
+
|
40
|
+
def test_initalizes_from_config
|
22
41
|
logger = NewRelic::Agent::AgentLogger.new(@config)
|
23
|
-
|
42
|
+
|
43
|
+
wrapped_logger = logger.instance_variable_get( :@log )
|
44
|
+
logdev = wrapped_logger.instance_variable_get( :@logdev )
|
45
|
+
expected_logpath = File.expand_path( @config[:log_file_path] + @config[:log_file_name] )
|
46
|
+
|
47
|
+
assert_kind_of( Logger, wrapped_logger )
|
48
|
+
assert_kind_of( File, logdev.dev )
|
49
|
+
assert_equal( expected_logpath, logdev.filename )
|
24
50
|
end
|
25
51
|
|
26
52
|
def test_initalizes_from_override
|
27
|
-
override_logger =
|
53
|
+
override_logger = Logger.new( '/dev/null' )
|
28
54
|
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
29
55
|
assert_equal override_logger, logger.instance_variable_get(:@log)
|
30
56
|
end
|
31
57
|
|
32
|
-
def test_forwards_calls_to_logger
|
33
|
-
[:fatal, :error, :warn, :info, :debug].each do |level|
|
34
|
-
override_logger = stub(:level=)
|
35
|
-
override_logger.expects(level).with(any_parameters)
|
36
58
|
|
37
|
-
|
59
|
+
def test_forwards_calls_to_logger
|
60
|
+
logdev = ArrayLogDevice.new
|
61
|
+
override_logger = Logger.new( logdev )
|
62
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
38
63
|
|
64
|
+
LEVELS.each do |level|
|
39
65
|
logger.send(level, "Boo!")
|
40
66
|
end
|
67
|
+
|
68
|
+
assert_equal 4, logdev.array.length # No DEBUG
|
69
|
+
|
70
|
+
assert_match( /FATAL/, logdev.array[0] )
|
71
|
+
assert_match( /ERROR/, logdev.array[1] )
|
72
|
+
assert_match( /WARN/, logdev.array[2] )
|
73
|
+
assert_match( /INFO/, logdev.array[3] )
|
41
74
|
end
|
42
75
|
|
43
76
|
|
44
77
|
def test_forwards_calls_to_logger_with_multiple_arguments
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
78
|
+
logdev = ArrayLogDevice.new
|
79
|
+
override_logger = Logger.new( logdev )
|
80
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
50
81
|
|
82
|
+
LEVELS.each do |level|
|
51
83
|
logger.send(level, "What", "up?")
|
52
84
|
end
|
53
|
-
end
|
54
85
|
|
55
|
-
|
56
|
-
caught = nil
|
57
|
-
begin
|
58
|
-
raise Exception.new("Boo!")
|
59
|
-
rescue Exception => e
|
60
|
-
caught = e
|
61
|
-
end
|
62
|
-
|
63
|
-
# Checking if it looks like message includes backtrace
|
64
|
-
override_logger = stub(:level=)
|
65
|
-
override_logger.expects(:debug).with {|msg| msg.include?("test_") }
|
86
|
+
assert_equal 8, logdev.array.length # No DEBUG, two per level
|
66
87
|
|
67
|
-
|
88
|
+
assert_match( /FATAL/, logdev.array[0] )
|
89
|
+
assert_match( /FATAL/, logdev.array[1] )
|
90
|
+
assert_match( /ERROR/, logdev.array[2] )
|
91
|
+
assert_match( /ERROR/, logdev.array[3] )
|
92
|
+
assert_match( /WARN/, logdev.array[4] )
|
93
|
+
assert_match( /WARN/, logdev.array[5] )
|
94
|
+
assert_match( /INFO/, logdev.array[6] )
|
95
|
+
assert_match( /INFO/, logdev.array[7] )
|
68
96
|
end
|
69
97
|
|
70
98
|
def test_wont_log_if_agent_not_enabled
|
71
|
-
null_logger = NewRelic::Agent::NullLogger.new
|
72
|
-
NewRelic::Agent::NullLogger.expects(:new).returns(null_logger)
|
73
99
|
@config[:agent_enabled] = false
|
74
100
|
logger = NewRelic::Agent::AgentLogger.new(@config)
|
75
101
|
assert_nothing_raised do
|
76
102
|
logger.warn('hi there')
|
77
103
|
end
|
104
|
+
|
105
|
+
assert_kind_of NewRelic::Agent::NullLogger, logger.instance_variable_get( :@log )
|
78
106
|
end
|
79
107
|
|
80
108
|
def test_does_not_touch_dev_null
|
@@ -95,64 +123,114 @@ class AgentLoggerTest < Test::Unit::TestCase
|
|
95
123
|
end
|
96
124
|
|
97
125
|
def test_sets_log_level
|
98
|
-
override_logger = mock()
|
99
|
-
override_logger.expects(:level=).with(Logger::DEBUG)
|
100
126
|
@config[:log_level] = :debug
|
101
127
|
|
128
|
+
override_logger = Logger.new( $stderr )
|
129
|
+
override_logger.level = Logger::FATAL
|
130
|
+
|
102
131
|
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
132
|
+
|
133
|
+
assert_equal Logger::DEBUG, override_logger.level
|
103
134
|
end
|
104
135
|
|
105
136
|
def test_log_to_stdout_and_warns_if_failed_on_create
|
106
|
-
|
137
|
+
Dir.stubs(:mkdir).returns(nil)
|
138
|
+
config = @config.merge( :log_file_path => '/someplace/non/existant' )
|
107
139
|
|
108
|
-
|
109
|
-
|
110
|
-
|
140
|
+
logger = with_squelched_stdout do
|
141
|
+
NewRelic::Agent::AgentLogger.new(config)
|
142
|
+
end
|
111
143
|
|
112
|
-
|
113
|
-
|
144
|
+
wrapped_logger = logger.instance_variable_get(:@log)
|
145
|
+
logdev = wrapped_logger.instance_variable_get(:@logdev)
|
146
|
+
|
147
|
+
assert_equal $stdout, logdev.dev
|
114
148
|
end
|
115
149
|
|
116
150
|
def test_log_to_stdout_based_on_config
|
117
151
|
@config[:log_file_path] = "STDOUT"
|
118
152
|
|
119
|
-
stdout = stub(:level=)
|
120
|
-
stdout.expects(:warn).never
|
121
|
-
::Logger.stubs(:new).with(STDOUT).returns(stdout)
|
122
|
-
|
123
153
|
logger = NewRelic::Agent::AgentLogger.new(@config)
|
124
|
-
|
154
|
+
wrapped_logger = logger.instance_variable_get(:@log)
|
155
|
+
logdev = wrapped_logger.instance_variable_get(:@logdev)
|
156
|
+
|
157
|
+
assert_equal $stdout, logdev.dev
|
125
158
|
end
|
126
159
|
|
127
160
|
def test_startup_purges_memory_logger
|
128
|
-
|
161
|
+
LEVELS.each do |level|
|
129
162
|
::NewRelic::Agent::StartupLogger.instance.send(level, "boo!")
|
163
|
+
end
|
130
164
|
|
131
|
-
|
132
|
-
|
165
|
+
logdev = ArrayLogDevice.new
|
166
|
+
override_logger = Logger.new( logdev )
|
167
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
168
|
+
|
169
|
+
assert_equal 4, logdev.array.length # No DEBUG
|
170
|
+
|
171
|
+
assert_match( /FATAL/, logdev.array[0] )
|
172
|
+
assert_match( /ERROR/, logdev.array[1] )
|
173
|
+
assert_match( /WARN/, logdev.array[2] )
|
174
|
+
assert_match( /INFO/, logdev.array[3] )
|
175
|
+
end
|
133
176
|
|
134
|
-
|
177
|
+
def test_passing_exceptions_only_logs_the_message_at_levels_higher_than_debug
|
178
|
+
logdev = ArrayLogDevice.new
|
179
|
+
override_logger = Logger.new( logdev )
|
180
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
181
|
+
|
182
|
+
begin
|
183
|
+
raise "Something bad happened"
|
184
|
+
rescue => err
|
185
|
+
logger.error( err )
|
135
186
|
end
|
187
|
+
|
188
|
+
assert_equal 1, logdev.array.length
|
189
|
+
assert_match( /ERROR : RuntimeError: Something bad happened/i, logdev.array[0] )
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_passing_exceptions_logs_the_backtrace_at_debug_level
|
193
|
+
config = @config.merge(:log_level => :debug)
|
194
|
+
|
195
|
+
logdev = ArrayLogDevice.new
|
196
|
+
override_logger = Logger.new( logdev )
|
197
|
+
logger = NewRelic::Agent::AgentLogger.new(config, "", override_logger)
|
198
|
+
|
199
|
+
begin
|
200
|
+
raise "Something bad happened"
|
201
|
+
rescue => err
|
202
|
+
logger.error( err )
|
203
|
+
end
|
204
|
+
|
205
|
+
assert_equal 2, logdev.array.length
|
206
|
+
assert_match( /ERROR : RuntimeError: Something bad happened/i, logdev.array[0] )
|
207
|
+
assert_match( /DEBUG : Debugging backtrace:\n.*test_passing_exceptions/i,
|
208
|
+
logdev.array[1] )
|
136
209
|
end
|
137
210
|
|
138
211
|
def test_format_message_allows_nil_backtrace
|
139
|
-
|
140
|
-
override_logger.
|
212
|
+
logdev = ArrayLogDevice.new
|
213
|
+
override_logger = Logger.new( logdev )
|
214
|
+
logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
|
141
215
|
|
142
|
-
logger
|
216
|
+
logger.error(Exception.new("Look Ma, no backtrace!"))
|
143
217
|
|
144
|
-
|
218
|
+
assert_equal 1, logdev.array.length
|
219
|
+
assert_match( /ERROR : Exception: Look Ma, no backtrace!/i, logdev.array[0] )
|
145
220
|
end
|
146
221
|
|
147
222
|
|
148
223
|
def test_logs_to_stdout_if_fails_on_file
|
149
|
-
|
150
|
-
|
151
|
-
|
224
|
+
Logger::LogDevice.any_instance.stubs(:open).raises(Errno::EACCES)
|
225
|
+
|
226
|
+
logger = with_squelched_stdout do
|
227
|
+
NewRelic::Agent::AgentLogger.new(@config, "")
|
228
|
+
end
|
152
229
|
|
153
|
-
|
230
|
+
wrapped_logger = logger.instance_variable_get(:@log)
|
231
|
+
logdev = wrapped_logger.instance_variable_get(:@logdev)
|
154
232
|
|
155
|
-
assert_equal stdout,
|
233
|
+
assert_equal $stdout, logdev.dev
|
156
234
|
end
|
157
235
|
|
158
236
|
def test_null_logger_works_with_impolite_gems_that_add_stuff_to_kernel
|
@@ -169,4 +247,19 @@ class AgentLoggerTest < Test::Unit::TestCase
|
|
169
247
|
remove_method :debug
|
170
248
|
end
|
171
249
|
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
#
|
254
|
+
# Helpers
|
255
|
+
#
|
256
|
+
|
257
|
+
def with_squelched_stdout
|
258
|
+
orig = $stdout.dup
|
259
|
+
$stdout.reopen( '/dev/null' )
|
260
|
+
yield
|
261
|
+
ensure
|
262
|
+
$stdout.reopen( orig )
|
263
|
+
end
|
264
|
+
|
172
265
|
end
|