newrelic_rpm 3.4.1 → 3.4.2.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of newrelic_rpm might be problematic. Click here for more details.
- data/CHANGELOG +7 -0
- data/ReleaseNotes.md +638 -0
- data/lib/new_relic/agent/agent.rb +44 -56
- data/lib/new_relic/agent/beacon_configuration.rb +1 -1
- data/lib/new_relic/agent/browser_monitoring.rb +80 -42
- data/lib/new_relic/agent/configuration/defaults.rb +75 -0
- data/lib/new_relic/agent/configuration/environment_source.rb +42 -0
- data/lib/new_relic/agent/configuration/manager.rb +100 -0
- data/lib/new_relic/agent/configuration/server_source.rb +24 -0
- data/lib/new_relic/agent/configuration/yaml_source.rb +61 -0
- data/lib/new_relic/agent/configuration.rb +48 -0
- data/lib/new_relic/agent/error_collector.rb +10 -14
- data/lib/new_relic/agent/instrumentation/active_record.rb +1 -5
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +20 -4
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/memcache.rb +2 -2
- data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -1
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +3 -3
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
- data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
- data/lib/new_relic/agent/method_tracer.rb +1 -1
- data/lib/new_relic/agent/new_relic_service.rb +18 -9
- data/lib/new_relic/agent/pipe_channel_manager.rb +5 -6
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -5
- data/lib/new_relic/agent/sql_sampler.rb +11 -35
- data/lib/new_relic/agent/stats_engine/transactions.rb +2 -2
- data/lib/new_relic/agent/transaction_info.rb +24 -4
- data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
- data/lib/new_relic/agent/transaction_sampler.rb +9 -16
- data/lib/new_relic/agent.rb +4 -1
- data/lib/new_relic/collection_helper.rb +1 -1
- data/lib/new_relic/commands/deployments.rb +5 -3
- data/lib/new_relic/control/class_methods.rb +2 -3
- data/lib/new_relic/control/frameworks/rails.rb +8 -8
- data/lib/new_relic/control/frameworks/ruby.rb +2 -2
- data/lib/new_relic/control/instance_methods.rb +26 -32
- data/lib/new_relic/control/logging_methods.rb +5 -23
- data/lib/new_relic/control/server_methods.rb +11 -18
- data/lib/new_relic/control.rb +0 -1
- data/lib/new_relic/delayed_job_injection.rb +1 -1
- data/lib/new_relic/language_support.rb +8 -0
- data/lib/new_relic/noticed_error.rb +1 -1
- data/lib/new_relic/rack/browser_monitoring.rb +18 -6
- data/lib/new_relic/version.rb +2 -2
- data/newrelic.yml +0 -4
- data/newrelic_rpm.gemspec +16 -6
- data/test/config/newrelic.yml +3 -2
- data/test/new_relic/agent/agent/connect_test.rb +88 -83
- data/test/new_relic/agent/agent/start_test.rb +75 -80
- data/test/new_relic/agent/agent/start_worker_thread_test.rb +18 -18
- data/test/new_relic/agent/beacon_configuration_test.rb +13 -11
- data/test/new_relic/agent/browser_monitoring_test.rb +69 -14
- data/test/new_relic/agent/configuration/environment_source_test.rb +58 -0
- data/test/new_relic/agent/configuration/manager_test.rb +120 -0
- data/test/new_relic/agent/configuration/server_source_test.rb +28 -0
- data/test/new_relic/agent/configuration/yaml_source_test.rb +56 -0
- data/test/new_relic/agent/error_collector/notice_error_test.rb +63 -50
- data/test/new_relic/agent/error_collector_test.rb +10 -12
- data/test/new_relic/agent/new_relic_service_test.rb +11 -3
- data/test/new_relic/agent/pipe_channel_manager_test.rb +19 -16
- data/test/new_relic/agent/rpm_agent_test.rb +21 -19
- data/test/new_relic/agent/sql_sampler_test.rb +55 -56
- data/test/new_relic/agent/transaction_info_test.rb +45 -4
- data/test/new_relic/agent/transaction_sampler_test.rb +48 -44
- data/test/new_relic/agent_test.rb +68 -41
- data/test/new_relic/collection_helper_test.rb +7 -8
- data/test/new_relic/command/deployments_test.rb +12 -1
- data/test/new_relic/control/frameworks/rails_test.rb +26 -0
- data/test/new_relic/control/logging_methods_test.rb +77 -52
- data/test/new_relic/control_test.rb +103 -126
- data/test/new_relic/local_environment_test.rb +4 -6
- data/test/new_relic/rack/browser_monitoring_test.rb +4 -4
- data/test/new_relic/rack/developer_mode_test.rb +13 -7
- data/test/new_relic/transaction_sample_test.rb +8 -2
- data/test/script/build_test_gem.sh +9 -3
- data/test/script/ci.sh +13 -3
- data/test/test_helper.rb +9 -2
- data/ui/helpers/developer_mode_helper.rb +2 -7
- metadata +26 -11
- data/lib/new_relic/control/configuration.rb +0 -206
- data/test/new_relic/control/configuration_test.rb +0 -77
@@ -24,30 +24,30 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_check_transaction_sampler_status_enabled
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
with_config(:developer_mode => false) do
|
28
|
+
@should_send_samples = true
|
29
|
+
@transaction_sampler = mock('transaction_sampler')
|
30
|
+
@transaction_sampler.expects(:enable)
|
31
|
+
check_transaction_sampler_status
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_check_transaction_sampler_status_devmode
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
with_config(:developer_mode => true) do
|
37
|
+
@should_send_samples = false
|
38
|
+
@transaction_sampler = mock('transaction_sampler')
|
39
|
+
@transaction_sampler.expects(:enable)
|
40
|
+
check_transaction_sampler_status
|
41
|
+
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_check_transaction_sampler_status_disabled
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
with_config(:developer_mode => false) do
|
46
|
+
@should_send_samples = false
|
47
|
+
@transaction_sampler = mock('transaction_sampler')
|
48
|
+
@transaction_sampler.expects(:disable)
|
49
|
+
check_transaction_sampler_status
|
50
|
+
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_log_worker_loop_start
|
@@ -24,27 +24,29 @@ class NewRelic::Agent::BeaconConfigurationTest < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_license_bytes_nil
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
with_config(:license_key => 'a' * 40) do
|
28
|
+
connect_data = {}
|
29
|
+
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
30
|
+
assert_equal([97] * 40, bc.license_bytes, 'should return the bytes of the license key')
|
31
|
+
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def test_license_bytes_existing_bytes
|
34
35
|
connect_data = {}
|
35
36
|
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
36
37
|
bc.instance_eval { @license_bytes = [97] * 40 }
|
37
|
-
NewRelic::
|
38
|
+
NewRelic::Agent.config.expects(:[]).with('license_key').never
|
38
39
|
assert_equal([97] * 40, bc.license_bytes, "should return the cached value if it exists")
|
39
40
|
end
|
40
41
|
|
41
42
|
def test_license_bytes_should_set_instance_cache
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
with_config(:license_key => 'a' * 40) do
|
44
|
+
connect_data = {}
|
45
|
+
bc = NewRelic::Agent::BeaconConfiguration.new(connect_data)
|
46
|
+
bc.instance_eval { @license_bytes = nil }
|
47
|
+
bc.license_bytes
|
48
|
+
assert_equal([97] * 40, bc.instance_variable_get('@license_bytes'), "should cache the license bytes for later")
|
49
|
+
end
|
48
50
|
end
|
49
51
|
|
50
52
|
def test_build_browser_timing_header_disabled
|
@@ -1,6 +1,7 @@
|
|
1
1
|
ENV['SKIP_RAILS'] = 'true'
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
3
3
|
require "new_relic/agent/browser_monitoring"
|
4
|
+
require 'ostruct'
|
4
5
|
|
5
6
|
class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
6
7
|
include NewRelic::Agent::BrowserMonitoring
|
@@ -8,6 +9,8 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
8
9
|
|
9
10
|
def setup
|
10
11
|
NewRelic::Agent.manual_start
|
12
|
+
config = {:disable_mobile_headers => false }
|
13
|
+
NewRelic::Agent.config.apply_config(config)
|
11
14
|
@browser_monitoring_key = "fred"
|
12
15
|
@episodes_file = "this_is_my_file"
|
13
16
|
NewRelic::Agent.instance.instance_eval do
|
@@ -15,6 +18,7 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
15
18
|
end
|
16
19
|
Thread.current[:last_metric_frame] = nil
|
17
20
|
NewRelic::Agent::TransactionInfo.clear
|
21
|
+
NewRelic::Agent.config.remove_config(config)
|
18
22
|
end
|
19
23
|
|
20
24
|
def teardown
|
@@ -29,16 +33,17 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
29
33
|
def controller.newrelic_metric_path; "foo"; end
|
30
34
|
controller.extend ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
31
35
|
controller.extend ::NewRelic::Agent::BrowserMonitoring
|
32
|
-
NewRelic::Control.instance['browser_monitoring'] = { 'auto_instrument' => false }
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
with_config(:'browser_monitoring.auto_instrument' => false) do
|
38
|
+
controller.perform_action_with_newrelic_trace(:index)
|
39
|
+
first_request_start_time = controller.send(:browser_monitoring_start_time)
|
40
|
+
controller.perform_action_with_newrelic_trace(:index)
|
41
|
+
second_request_start_time = controller.send(:browser_monitoring_start_time)
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
# assert that these aren't the same time object
|
44
|
+
# the start time should be reinitialized each request to the controller
|
45
|
+
assert !(first_request_start_time.equal? second_request_start_time)
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
49
|
def test_browser_timing_header_with_no_beacon_configuration
|
@@ -81,14 +86,14 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
|
|
81
86
|
end
|
82
87
|
|
83
88
|
def test_browser_timing_footer
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
|
89
|
+
with_config(:license_key => 'a' * 13) do
|
90
|
+
browser_timing_header
|
91
|
+
footer = browser_timing_footer
|
92
|
+
snippet = '<script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
|
89
93
|
NREUMQ.push(["load",new Date().getTime()]);
|
90
94
|
var e=document.createElement("script");'
|
91
|
-
|
95
|
+
assert footer.include?(snippet), "Expected footer to include snippet: #{snippet}, but instead was #{footer}"
|
96
|
+
end
|
92
97
|
end
|
93
98
|
|
94
99
|
def test_browser_timing_footer_with_no_browser_key_rum_enabled
|
@@ -320,4 +325,54 @@ var e=document.createElement("script");'
|
|
320
325
|
output = obfuscate(NewRelic::Agent.instance.beacon_configuration, text)
|
321
326
|
assert_equal('YCJrZXV2fih5Y25vaCFtZSR2a2ZkZSp/aXV1YyNsZHZ3cSl6YmluZCJsYiV1amllZit4aHl2YiRtZ3d4cCp7ZWhiZyNrYyZ0ZWhmZyx5ZHp3ZSVuZnh5cyt8ZGRhZiRqYCd7ZGtnYC11Z3twZCZvaXl6cix9aGdgYSVpYSh6Z2pgYSF2Znxx', output, "should output obfuscated text")
|
322
327
|
end
|
328
|
+
|
329
|
+
def test_no_mobile_response_header_if_no_mobile_request_header_given
|
330
|
+
request = Rack::Request.new({})
|
331
|
+
response = Rack::Response.new
|
332
|
+
|
333
|
+
NewRelic::Agent::BrowserMonitoring.insert_mobile_response_header(request, response)
|
334
|
+
assert_nil response['X-NewRelic-Beacon-Url']
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_no_mobile_response_header_if_mobile_request_header_is_false
|
338
|
+
request = Rack::Request.new('HTTP_X_NEWRELIC_MOBILE_TRACE' => 'false')
|
339
|
+
response = Rack::Response.new
|
340
|
+
|
341
|
+
NewRelic::Agent::BrowserMonitoring.insert_mobile_response_header(request, response)
|
342
|
+
assert_nil response['X-NewRelic-Beacon-Url']
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_place_beacon_url_header_when_given_mobile_request_header
|
346
|
+
response = mobile_transaction
|
347
|
+
assert_equal('http://beacon/mobile/1/browserKey',
|
348
|
+
response['X-NewRelic-Beacon-Url'])
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_place_beacon_url_header_when_given_mobile_request_header_with_https
|
352
|
+
request = Rack::Request.new('X_NEWRELIC_MOBILE_TRACE' => 'true',
|
353
|
+
'rack.url_scheme' => 'https')
|
354
|
+
response = mobile_transaction(request)
|
355
|
+
assert_equal('https://beacon/mobile/1/browserKey',
|
356
|
+
response['X-NewRelic-Beacon-Url'])
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_place_beacon_payload_head_when_given_mobile_request_header
|
360
|
+
Time.stubs(:now).returns(6)
|
361
|
+
response = mobile_transaction
|
362
|
+
txn_name = obfuscate(NewRelic::Agent.instance.beacon_configuration,
|
363
|
+
browser_monitoring_transaction_name)
|
364
|
+
expected_payload = %|["apId","#{txn_name}",#{browser_monitoring_queue_time},#{browser_monitoring_app_time}]|
|
365
|
+
|
366
|
+
assert_equal expected_payload, response['X-NewRelic-App-Server-Metrics'].strip
|
367
|
+
end
|
368
|
+
|
369
|
+
def mobile_transaction(request=nil)
|
370
|
+
request ||= Rack::Request.new('X-NewRelic-Mobile-Trace' => 'true')
|
371
|
+
response = Rack::Response.new
|
372
|
+
txn_data = OpenStruct.new(:transaction_name => 'a transaction name',
|
373
|
+
:start_time => 5)
|
374
|
+
NewRelic::Agent::TransactionInfo.set(txn_data)
|
375
|
+
NewRelic::Agent::BrowserMonitoring.insert_mobile_response_header(request, response)
|
376
|
+
response
|
377
|
+
end
|
323
378
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/configuration/environment_source'
|
3
|
+
|
4
|
+
module NewRelic::Agent::Configuration
|
5
|
+
class EnvironmentSourceTest < Test::Unit::TestCase
|
6
|
+
def test_environment_strings_are_applied
|
7
|
+
assert_applied_string 'NRCONFIG', 'config_path'
|
8
|
+
assert_applied_string 'NEW_RELIC_LICENSE_KEY', 'license_key'
|
9
|
+
assert_applied_string 'NEWRELIC_LICENSE_KEY', 'license_key'
|
10
|
+
assert_applied_string 'NEW_RELIC_APP_NAME', 'app_name'
|
11
|
+
assert_applied_string 'NEWRELIC_APP_NAME', 'app_name'
|
12
|
+
assert_applied_string 'NEW_RELIC_DISPATCHER', 'dispatcher'
|
13
|
+
assert_applied_string 'NEWRELIC_DISPATCHER', 'dispatcher'
|
14
|
+
assert_applied_string 'NEW_RELIC_FRAMEWORK', 'framework'
|
15
|
+
assert_applied_string 'NEWRELIC_FRAMEWORK', 'framework'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_environment_booleans_truths_are_applied
|
19
|
+
ENV['NEWRELIC_ENABLE'] = 'true'
|
20
|
+
assert EnvironmentSource.new[:agent_enabled]
|
21
|
+
ENV['NEWRELIC_ENABLE'] = 'on'
|
22
|
+
assert EnvironmentSource.new[:agent_enabled]
|
23
|
+
ENV['NEWRELIC_ENABLE'] = 'yes'
|
24
|
+
assert EnvironmentSource.new[:agent_enabled]
|
25
|
+
ENV.delete('NEWRELIC_ENABLE')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_environment_booleans_falsehoods_are_applied
|
29
|
+
ENV['NEWRELIC_ENABLE'] = 'false'
|
30
|
+
assert !EnvironmentSource.new[:agent_enabled]
|
31
|
+
ENV['NEWRELIC_ENABLE'] = 'off'
|
32
|
+
assert !EnvironmentSource.new[:agent_enabled]
|
33
|
+
ENV['NEWRELIC_ENABLE'] = 'no'
|
34
|
+
assert !EnvironmentSource.new[:agent_enabled]
|
35
|
+
ENV.delete('NEWRELIC_ENABLE')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_set_log_config_from_environment
|
39
|
+
ENV['NEW_RELIC_LOG'] = 'off/in/space.log'
|
40
|
+
source = EnvironmentSource.new
|
41
|
+
assert_equal 'off/in', source[:log_file_path]
|
42
|
+
assert_equal 'space.log', source[:log_file_name]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_set_log_config_STDOUT_from_environment
|
46
|
+
ENV['NEW_RELIC_LOG'] = 'STDOUT'
|
47
|
+
source = EnvironmentSource.new
|
48
|
+
assert_equal 'STDOUT', source[:log_file_name]
|
49
|
+
assert_equal 'STDOUT', source[:log_file_path]
|
50
|
+
end
|
51
|
+
|
52
|
+
def assert_applied_string(env_var, config_var)
|
53
|
+
ENV[env_var] = 'test value'
|
54
|
+
assert_equal 'test value', EnvironmentSource.new[config_var.to_sym]
|
55
|
+
ENV.delete(env_var)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/configuration/manager'
|
3
|
+
|
4
|
+
module NewRelic::Agent::Configuration
|
5
|
+
class ManagerTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@manager = NewRelic::Agent::Configuration::Manager.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_use_indifferent_access
|
11
|
+
config = NewRelic::Agent::Configuration::DottedHash.new('string' => 'string', :symbol => 'symbol')
|
12
|
+
@manager.apply_config(config)
|
13
|
+
assert_equal 'string', @manager[:string]
|
14
|
+
assert_equal 'symbol', @manager['symbol']
|
15
|
+
@manager.remove_config(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_apply_config_sources_in_order
|
19
|
+
config0 = {
|
20
|
+
:foo => 'default foo',
|
21
|
+
:bar => 'default bar',
|
22
|
+
:baz => 'default baz'
|
23
|
+
}
|
24
|
+
@manager.apply_config(config0)
|
25
|
+
config1 = { :foo => 'real foo' }
|
26
|
+
@manager.apply_config(config1)
|
27
|
+
config2 = { :foo => 'wrong foo', :bar => 'real bar' }
|
28
|
+
@manager.apply_config(config2, 1)
|
29
|
+
|
30
|
+
assert_equal 'real foo', @manager['foo']
|
31
|
+
assert_equal 'real bar', @manager['bar']
|
32
|
+
assert_equal 'default baz', @manager['baz']
|
33
|
+
|
34
|
+
@manager.remove_config(config0)
|
35
|
+
@manager.remove_config(config1)
|
36
|
+
@manager.remove_config(config2)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_identifying_config_source
|
40
|
+
hash_source = {:foo => 'foo', :bar => 'default'}
|
41
|
+
@manager.apply_config(hash_source)
|
42
|
+
test_source = TestSource.new
|
43
|
+
test_source[:bar] = 'bar'
|
44
|
+
test_source[:baz] = 'baz'
|
45
|
+
@manager.apply_config(test_source)
|
46
|
+
|
47
|
+
assert_not_equal test_source, @manager.source(:foo)
|
48
|
+
assert_equal test_source, @manager.source(:bar)
|
49
|
+
assert_equal test_source, @manager.source(:baz)
|
50
|
+
|
51
|
+
@manager.remove_config(hash_source)
|
52
|
+
@manager.remove_config(test_source)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_callable_value_for_config_should_return_computed_value
|
56
|
+
source = {
|
57
|
+
:foo => 'bar',
|
58
|
+
:simple_value => Proc.new { '666' },
|
59
|
+
:reference => Proc.new { self['foo'] }
|
60
|
+
}
|
61
|
+
@manager.apply_config(source)
|
62
|
+
|
63
|
+
assert_equal 'bar', @manager[:foo]
|
64
|
+
assert_equal '666', @manager[:simple_value]
|
65
|
+
assert_equal 'bar', @manager[:reference]
|
66
|
+
|
67
|
+
@manager.remove_config(source)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_source_accessors_should_be_available_as_keys
|
71
|
+
source = TestSource.new
|
72
|
+
@manager.apply_config(source)
|
73
|
+
|
74
|
+
assert_equal 'some value', @manager[:test_config_accessor]
|
75
|
+
|
76
|
+
@manager.remove_config(source)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_should_not_apply_removed_sources
|
80
|
+
test_source = TestSource.new
|
81
|
+
@manager.apply_config(test_source)
|
82
|
+
@manager.remove_config(test_source)
|
83
|
+
|
84
|
+
assert_equal nil, @manager['test_config_accessor']
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_should_read_license_key_from_env
|
88
|
+
ENV['NEWRELIC_LICENSE_KEY'] = 'right'
|
89
|
+
manager = NewRelic::Agent::Configuration::Manager.new
|
90
|
+
manager.apply_config({:license_key => 'wrong'}, 1)
|
91
|
+
|
92
|
+
assert_equal 'right', manager['license_key']
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_config_values_should_be_memoized
|
96
|
+
@manager.apply_config(:setting => 'correct value')
|
97
|
+
assert_equal 'correct value', @manager[:setting]
|
98
|
+
|
99
|
+
@manager.config_stack.unshift(:setting => 'wrong value')
|
100
|
+
assert_equal 'correct value', @manager[:setting]
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_flattened_config
|
104
|
+
@manager.instance_variable_set(:@config_stack, [])
|
105
|
+
@manager.apply_config(:eins => Proc.new { self[:one] })
|
106
|
+
@manager.apply_config(:one => 1)
|
107
|
+
@manager.apply_config(:two => 2)
|
108
|
+
@manager.apply_config(:three => 3)
|
109
|
+
|
110
|
+
assert_equal({ :eins => 1, :one => 1, :two => 2, :three => 3 },
|
111
|
+
@manager.flattened_config)
|
112
|
+
end
|
113
|
+
|
114
|
+
class TestSource < ::Hash
|
115
|
+
def test_config_accessor
|
116
|
+
'some value'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/configuration/server_source'
|
3
|
+
|
4
|
+
module NewRelic::Agent::Configuration
|
5
|
+
class ServerSourceTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
config = {
|
8
|
+
'slow_sql.enabled' => true,
|
9
|
+
'transaction_tracer.transaction_threshold' => 'apdex_f',
|
10
|
+
'error_collector.enabled' => true,
|
11
|
+
'collect_errors' => false
|
12
|
+
}
|
13
|
+
@source = ServerSource.new(config)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_enable_tracer_as_configured
|
17
|
+
assert @source[:'slow_sql.enabled']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_disable_tracer_as_configured
|
21
|
+
assert !@source[:'error_collector.enabled']
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_ignore_apdex_f_setting_for_transaction_threshold
|
25
|
+
assert_equal nil, @source[:'transaction_tracer.transaction_threshold']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
|
2
|
+
require 'new_relic/agent/configuration/yaml_source'
|
3
|
+
|
4
|
+
module NewRelic::Agent::Configuration
|
5
|
+
class YamlSourceTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
test_yml_path = File.expand_path(File.join(File.dirname(__FILE__),
|
8
|
+
'..','..','..',
|
9
|
+
'config','newrelic.yml'))
|
10
|
+
@source = YamlSource.new(test_yml_path, 'test')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_load_given_yaml_file
|
14
|
+
assert_equal '127.0.0.1', @source[:api_host]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_apply_erb_transformations
|
18
|
+
assert_equal 'heyheyhey', @source[:erb_value]
|
19
|
+
assert_equal '', @source[:message]
|
20
|
+
assert_equal '', @source[:license_key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_config_booleans
|
24
|
+
assert_equal true, @source[:tval]
|
25
|
+
assert_equal false, @source[:fval]
|
26
|
+
assert_nil @source[:not_in_yaml_val]
|
27
|
+
assert_equal true, @source[:yval]
|
28
|
+
assert_equal 'sure', @source[:sval]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_appnames
|
32
|
+
assert_equal %w[a b c], @source[:app_name]
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_load_the_config_for_the_correct_env
|
36
|
+
assert_not_equal 'the.wrong.host', @source[:host]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_convert_to_dot_notation
|
40
|
+
assert_equal 'raw', @source[:'transaction_tracer.record_sql']
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_ignore_apdex_f_setting_for_transaction_threshold
|
44
|
+
assert_equal nil, @source[:'transaction_tracer.transaction_threshold']
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_correctly_handle_floats
|
48
|
+
assert_equal 1.1, @source[:apdex_t]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_log_if_no_file_is_found
|
52
|
+
NewRelic::Control.instance.log.expects(:error)
|
53
|
+
source = YamlSource.new('no_such_file.yml', 'test')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|