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.

Files changed (81) hide show
  1. data/CHANGELOG +7 -0
  2. data/ReleaseNotes.md +638 -0
  3. data/lib/new_relic/agent/agent.rb +44 -56
  4. data/lib/new_relic/agent/beacon_configuration.rb +1 -1
  5. data/lib/new_relic/agent/browser_monitoring.rb +80 -42
  6. data/lib/new_relic/agent/configuration/defaults.rb +75 -0
  7. data/lib/new_relic/agent/configuration/environment_source.rb +42 -0
  8. data/lib/new_relic/agent/configuration/manager.rb +100 -0
  9. data/lib/new_relic/agent/configuration/server_source.rb +24 -0
  10. data/lib/new_relic/agent/configuration/yaml_source.rb +61 -0
  11. data/lib/new_relic/agent/configuration.rb +48 -0
  12. data/lib/new_relic/agent/error_collector.rb +10 -14
  13. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -5
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +20 -4
  15. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  16. data/lib/new_relic/agent/instrumentation/memcache.rb +2 -2
  17. data/lib/new_relic/agent/instrumentation/metric_frame.rb +1 -1
  18. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +3 -3
  19. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -2
  20. data/lib/new_relic/agent/instrumentation/resque.rb +1 -1
  21. data/lib/new_relic/agent/method_tracer.rb +1 -1
  22. data/lib/new_relic/agent/new_relic_service.rb +18 -9
  23. data/lib/new_relic/agent/pipe_channel_manager.rb +5 -6
  24. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +2 -5
  25. data/lib/new_relic/agent/sql_sampler.rb +11 -35
  26. data/lib/new_relic/agent/stats_engine/transactions.rb +2 -2
  27. data/lib/new_relic/agent/transaction_info.rb +24 -4
  28. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  29. data/lib/new_relic/agent/transaction_sampler.rb +9 -16
  30. data/lib/new_relic/agent.rb +4 -1
  31. data/lib/new_relic/collection_helper.rb +1 -1
  32. data/lib/new_relic/commands/deployments.rb +5 -3
  33. data/lib/new_relic/control/class_methods.rb +2 -3
  34. data/lib/new_relic/control/frameworks/rails.rb +8 -8
  35. data/lib/new_relic/control/frameworks/ruby.rb +2 -2
  36. data/lib/new_relic/control/instance_methods.rb +26 -32
  37. data/lib/new_relic/control/logging_methods.rb +5 -23
  38. data/lib/new_relic/control/server_methods.rb +11 -18
  39. data/lib/new_relic/control.rb +0 -1
  40. data/lib/new_relic/delayed_job_injection.rb +1 -1
  41. data/lib/new_relic/language_support.rb +8 -0
  42. data/lib/new_relic/noticed_error.rb +1 -1
  43. data/lib/new_relic/rack/browser_monitoring.rb +18 -6
  44. data/lib/new_relic/version.rb +2 -2
  45. data/newrelic.yml +0 -4
  46. data/newrelic_rpm.gemspec +16 -6
  47. data/test/config/newrelic.yml +3 -2
  48. data/test/new_relic/agent/agent/connect_test.rb +88 -83
  49. data/test/new_relic/agent/agent/start_test.rb +75 -80
  50. data/test/new_relic/agent/agent/start_worker_thread_test.rb +18 -18
  51. data/test/new_relic/agent/beacon_configuration_test.rb +13 -11
  52. data/test/new_relic/agent/browser_monitoring_test.rb +69 -14
  53. data/test/new_relic/agent/configuration/environment_source_test.rb +58 -0
  54. data/test/new_relic/agent/configuration/manager_test.rb +120 -0
  55. data/test/new_relic/agent/configuration/server_source_test.rb +28 -0
  56. data/test/new_relic/agent/configuration/yaml_source_test.rb +56 -0
  57. data/test/new_relic/agent/error_collector/notice_error_test.rb +63 -50
  58. data/test/new_relic/agent/error_collector_test.rb +10 -12
  59. data/test/new_relic/agent/new_relic_service_test.rb +11 -3
  60. data/test/new_relic/agent/pipe_channel_manager_test.rb +19 -16
  61. data/test/new_relic/agent/rpm_agent_test.rb +21 -19
  62. data/test/new_relic/agent/sql_sampler_test.rb +55 -56
  63. data/test/new_relic/agent/transaction_info_test.rb +45 -4
  64. data/test/new_relic/agent/transaction_sampler_test.rb +48 -44
  65. data/test/new_relic/agent_test.rb +68 -41
  66. data/test/new_relic/collection_helper_test.rb +7 -8
  67. data/test/new_relic/command/deployments_test.rb +12 -1
  68. data/test/new_relic/control/frameworks/rails_test.rb +26 -0
  69. data/test/new_relic/control/logging_methods_test.rb +77 -52
  70. data/test/new_relic/control_test.rb +103 -126
  71. data/test/new_relic/local_environment_test.rb +4 -6
  72. data/test/new_relic/rack/browser_monitoring_test.rb +4 -4
  73. data/test/new_relic/rack/developer_mode_test.rb +13 -7
  74. data/test/new_relic/transaction_sample_test.rb +8 -2
  75. data/test/script/build_test_gem.sh +9 -3
  76. data/test/script/ci.sh +13 -3
  77. data/test/test_helper.rb +9 -2
  78. data/ui/helpers/developer_mode_helper.rb +2 -7
  79. metadata +26 -11
  80. data/lib/new_relic/control/configuration.rb +0 -206
  81. data/test/new_relic/control/configuration_test.rb +0 -77
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'/../../../test_helper'))
2
+
3
+ class NewRelic::Control::Frameworks::RailsTest < Test::Unit::TestCase
4
+ def test_install_browser_monitoring
5
+ require(File.expand_path(File.join(File.dirname(__FILE__),
6
+ '/../../../../lib/new_relic/rack/browser_monitoring')))
7
+ middleware = stub('middleware config')
8
+ config = stub('rails config', :middleware => middleware)
9
+ middleware.expects(:use).with(NewRelic::Rack::BrowserMonitoring)
10
+ NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
11
+ with_config(:'browser_monitoring.auto_instrument' => true) do
12
+ NewRelic::Control.instance.install_browser_monitoring(config)
13
+ end
14
+ end
15
+
16
+ def test_install_browser_monitoring_should_not_install_when_not_configured
17
+ middleware = stub('middleware config')
18
+ config = stub('rails config', :middleware => middleware)
19
+ middleware.expects(:use).never
20
+ NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
21
+
22
+ with_config(:'browser_monitoring.auto_instrument' => false) do
23
+ NewRelic::Control.instance.install_browser_monitoring(config)
24
+ end
25
+ end
26
+ end
@@ -5,15 +5,15 @@ require 'fileutils'
5
5
  class BaseLoggingMethods
6
6
  # stub class to enable testing of the module
7
7
  include NewRelic::Control::LoggingMethods
8
- include NewRelic::Control::Configuration
9
8
  def root; "."; end
10
9
  end
11
10
 
12
11
  class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
13
12
  def setup
14
13
  @base = BaseLoggingMethods.new
15
- @base.settings['log_file_path'] = 'log/'
16
- @base.settings['log_file_name'] = 'newrelic_agent.log'
14
+ NewRelic::Control.instance.instance_variable_set '@log_path', nil
15
+ NewRelic::Control.instance.instance_variable_set '@log_file', nil
16
+ @root = ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT
17
17
  super
18
18
  end
19
19
 
@@ -60,30 +60,34 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
60
60
 
61
61
  def test_should_log_agent_disabled
62
62
  @base.instance_eval { @settings = true }
63
- @base.expects(:agent_enabled?).returns(false)
64
- assert !@base.should_log?
63
+ with_config(:agent_enabled => false) do
64
+ assert !@base.should_log?
65
+ end
65
66
  end
66
67
 
67
68
  def test_should_log_agent_enabled
68
69
  @base.instance_eval { @settings = true }
69
- @base.expects(:agent_enabled?).returns(true)
70
- assert @base.should_log?
70
+ with_config(:agent_enabled => true) do
71
+ assert @base.should_log?
72
+ end
71
73
  end
72
74
 
73
75
  def test_set_log_level_base
74
76
  fake_logger = mock('logger')
75
77
  # bad configuration
76
- @base.expects(:fetch).with('log_level', 'info').returns('whee')
77
- fake_logger.expects(:level=).with(Logger::INFO)
78
- assert_equal fake_logger, @base.set_log_level!(fake_logger)
78
+ with_config(:log_level => 'whee') do
79
+ fake_logger.expects(:level=).with(Logger::INFO)
80
+ assert_equal fake_logger, @base.set_log_level!(fake_logger)
81
+ end
79
82
  end
80
83
 
81
84
  def test_set_log_level_with_each_level
82
85
  fake_logger = mock('logger')
83
86
  %w[debug info warn error fatal].each do |level|
84
- @base.expects(:fetch).with('log_level', 'info').returns(level)
85
- fake_logger.expects(:level=).with(Logger.const_get(level.upcase))
86
- assert_equal fake_logger, @base.set_log_level!(fake_logger)
87
+ with_config(:log_level => level) do
88
+ fake_logger.expects(:level=).with(Logger.const_get(level.upcase))
89
+ assert_equal fake_logger, @base.set_log_level!(fake_logger)
90
+ end
87
91
  end
88
92
  end
89
93
 
@@ -96,14 +100,14 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
96
100
 
97
101
  def test_setup_log_existing_file
98
102
  fake_logger = mock('logger')
99
- Logger.expects(:new).with('logpath/logfilename').returns(fake_logger)
100
- @base.expects(:log_path).returns('logpath').at_least_once
101
- @base.expects(:log_file_name).returns('logfilename')
103
+ Logger.expects(:new).returns(fake_logger)
102
104
  @base.expects(:set_log_format!).with(fake_logger)
103
105
  @base.expects(:set_log_level!).with(fake_logger)
104
- assert_equal fake_logger, @base.setup_log
105
- assert_equal fake_logger, @base.instance_eval { @log }
106
- assert_equal 'logpath/logfilename', @base.instance_eval { @log_file }
106
+ with_config(:log_file_path => 'logpath', :log_file_name => 'logfilename') do
107
+ assert_equal fake_logger, @base.setup_log
108
+ assert_equal fake_logger, @base.instance_eval { @log }
109
+ assert_match(/logpath\/logfilename$/, @base.instance_eval { @log_file })
110
+ end
107
111
  end
108
112
 
109
113
  def test_to_stdout
@@ -117,69 +121,90 @@ class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
117
121
  end
118
122
 
119
123
  def test_log_path_path_exists
120
- @base.settings['log_file_path'] = 'log'
121
- assert File.directory?('log')
122
- assert_equal File.expand_path('log'), @base.log_path
124
+ with_config(:log_file_path => 'log') do
125
+ assert File.directory?('log')
126
+ assert_equal File.expand_path('log'), @base.log_path
127
+ end
123
128
  end
124
129
 
125
130
  def test_log_path_path_created
126
131
  path = File.expand_path('tmp/log_path_test')
127
132
  @base.instance_eval { @log_path = nil }
128
- @base.settings['log_file_path'] = 'tmp/log_path_test'
129
- assert !File.directory?(path) || FileUtils.rmdir(path)
130
- @base.expects(:log!).never
131
- assert_equal path, @base.log_path
132
- assert File.directory?(path)
133
+ with_config(:log_file_path => 'tmp/log_path_test') do
134
+ assert !File.directory?(path) || FileUtils.rmdir(path)
135
+ @base.expects(:log!).never
136
+ assert_equal path, @base.log_path
137
+ assert File.directory?(path)
138
+ end
133
139
  end
134
140
 
135
141
  def test_log_path_path_unable_to_create
136
142
  path = File.expand_path('tmp/log_path_test')
137
143
  @base.instance_eval { @log_path = nil }
138
- @base.settings['log_file_path'] = 'tmp/log_path_test'
139
- assert !File.directory?(path) || FileUtils.rmdir(path)
140
- @base.expects(:log!).with("Error creating log directory tmp/log_path_test, using standard out for logging.", :warn)
141
- Dir.expects(:mkdir).with(path).raises('cannot make directory bro!').twice # once for the relative directory, once for the directory relative to Rails.root
142
- assert_nil @base.log_path
143
- assert !File.directory?(path)
144
- assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
145
- end
146
-
147
- def test_log_file_name
148
- @base.expects(:fetch).with('log_file_name', 'newrelic_agent.log').returns('log_file_name')
149
- assert_equal 'log_file_name', @base.log_file_name
144
+ with_config(:log_file_path => 'tmp/log_path_test') do
145
+ assert !File.directory?(path) || FileUtils.rmdir(path)
146
+ @base.expects(:log!).with("Error creating log directory tmp/log_path_test, using standard out for logging.", :warn)
147
+ # once for the relative directory, once for the directory relative to Rails.root
148
+ Dir.expects(:mkdir).with(path).raises('cannot make directory bro!').twice
149
+ assert_nil @base.log_path
150
+ assert !File.directory?(path)
151
+ assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
152
+ end
150
153
  end
151
154
 
152
155
  def test_log_to_stdout_when_log_file_path_set_to_STDOUT
153
- @base.stubs(:fetch).returns('whatever')
154
- @base.expects(:fetch).with('log_file_path', 'log').returns('STDOUT')
155
156
  Dir.expects(:mkdir).never
156
- @base.setup_log
157
- assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
157
+ with_config(:log_file_path => 'STDOUT') do
158
+ @base.setup_log
159
+ assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
160
+ end
158
161
  end
159
162
 
160
163
  def test_logs_to_stdout_include_newrelic_prefix
161
- @base.stubs(:fetch).returns('whatever')
162
- @base.expects(:fetch).with('log_file_path', 'log').returns('STDOUT')
163
- STDOUT.expects(:write).with(regexp_matches(/\*\* \[NewRelic\].*whee/))
164
- @base.setup_log
165
- @base.log.info('whee')
164
+ with_config(:log_file_path => 'STDOUT') do
165
+ STDOUT.expects(:write).with(regexp_matches(/\*\* \[NewRelic\].*whee/))
166
+ @base.setup_log
167
+ @base.log.info('whee')
168
+ end
166
169
  end
167
170
 
168
171
  def test_set_stdout_destination_from_NEW_RELIC_LOG_env_var
169
- @base.stubs(:fetch).returns('whatever')
170
172
  ENV['NEW_RELIC_LOG'] = 'stdout'
173
+ reset_environment_config
171
174
  Dir.expects(:mkdir).never
172
175
  @base.setup_log
173
176
  assert_equal STDOUT, @base.log.instance_eval { @logdev }.dev
174
177
  ENV['NEW_RELIC_LOG'] = nil
178
+ reset_environment_config
175
179
  end
176
180
 
177
181
  def test_set_file_destination_from_NEW_RELIC_LOG_env_var
178
- @base.stubs(:fetch).returns('whatever')
179
182
  ENV['NEW_RELIC_LOG'] = 'log/file.log'
183
+ reset_environment_config
180
184
  @base.setup_log
181
185
  assert_equal 'log', File.basename(@base.log_path)
182
- assert_equal 'file.log', @base.log_file_name
183
- ENV['NEW_RELIC_LOG'] = nil
186
+ assert_equal 'file.log', NewRelic::Agent.config['log_file_name']
187
+ ENV['NEW_RELIC_LOG'] = nil
188
+ reset_environment_config
189
+ end
190
+
191
+ def test_log_path_uses_default_if_not_set
192
+ NewRelic::Control.instance.setup_log
193
+ assert_match(/log\/newrelic_agent.log$/,
194
+ NewRelic::Control.instance.log_file)
195
+ end
196
+
197
+ def test_log_file_path_uses_given_value
198
+ Dir.stubs(:mkdir).returns(true)
199
+ with_config(:log_file_path => 'lerg') do
200
+ NewRelic::Control.instance.setup_log
201
+ assert_match(/\/lerg\/newrelic_agent.log$/,
202
+ NewRelic::Control.instance.log_file)
203
+ end
204
+ end
205
+
206
+ def reset_environment_config
207
+ NewRelic::Agent::Configuration.manager.config_stack[0] =
208
+ NewRelic::Agent::Configuration::EnvironmentSource.new
184
209
  end
185
210
  end
@@ -4,7 +4,6 @@ class NewRelic::ControlTest < Test::Unit::TestCase
4
4
  attr_reader :control
5
5
 
6
6
  def setup
7
- NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
8
7
  @control = NewRelic::Control.instance
9
8
  raise 'oh geez, wrong class' unless NewRelic::Control.instance.is_a?(::NewRelic::Control::Frameworks::Test)
10
9
  end
@@ -17,12 +16,11 @@ class NewRelic::ControlTest < Test::Unit::TestCase
17
16
  assert @control.cert_file_path
18
17
  assert_equal File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'cert', 'cacert.pem')), @control.cert_file_path
19
18
  end
20
-
19
+
21
20
  # This test does not actually use the ruby agent in any way - it's
22
21
  # testing that the CA file we ship actually validates our server's
23
22
  # certificate. It's used for customers who enable verify_certificate
24
23
  def test_cert_file
25
- return if ::RUBY_VERSION == '1.9.3'
26
24
  require 'socket'
27
25
  require 'openssl'
28
26
 
@@ -34,12 +32,11 @@ class NewRelic::ControlTest < Test::Unit::TestCase
34
32
  s.connect
35
33
  # should not raise an error
36
34
  end
37
-
35
+
38
36
  # see above, but for staging, as well. This allows us to test new
39
37
  # certificates in a non-customer-facing place before setting them
40
38
  # live.
41
39
  def test_staging_cert_file
42
- return if ::RUBY_VERSION == '1.9.3'
43
40
  require 'socket'
44
41
  require 'openssl'
45
42
 
@@ -52,26 +49,6 @@ class NewRelic::ControlTest < Test::Unit::TestCase
52
49
  # should not raise an error
53
50
  end
54
51
 
55
- def test_monitor_mode
56
- assert ! @control.monitor_mode?
57
- @control.settings.delete 'enabled'
58
- @control.settings.delete 'monitor_mode'
59
- assert !@control.monitor_mode?
60
- @control['enabled'] = false
61
- assert ! @control.monitor_mode?
62
- @control['enabled'] = true
63
- assert @control.monitor_mode?
64
- @control['monitor_mode'] = nil
65
- assert !@control.monitor_mode?
66
- @control['monitor_mode'] = false
67
- assert !@control.monitor_mode?
68
- @control['monitor_mode'] = true
69
- assert @control.monitor_mode?
70
- ensure
71
- @control['enabled'] = false
72
- @control['monitor_mode'] = false
73
- end
74
-
75
52
  def test_test_config
76
53
  if defined?(Rails) && Rails::VERSION::MAJOR.to_i == 3
77
54
  assert_equal :rails3, control.app
@@ -81,10 +58,10 @@ class NewRelic::ControlTest < Test::Unit::TestCase
81
58
  assert_equal :test, control.app
82
59
  end
83
60
  assert_equal :test, control.framework
84
- assert_match /test/i, control.dispatcher_instance_id
85
- assert("" == control.dispatcher.to_s, "Expected dispatcher to be empty, but was #{control.dispatcher.to_s}")
86
- assert !control['enabled']
87
- assert_equal false, control['monitor_mode']
61
+ assert_match /test/i, control.local_env.dispatcher_instance_id
62
+ assert("" == NewRelic::Agent.config[:dispatcher].to_s,
63
+ "Expected dispatcher to be empty, but was #{NewRelic::Agent.config[:dispatcher].to_s}")
64
+ assert_equal false, NewRelic::Agent.config[:monitor_mode]
88
65
  control.local_env
89
66
  end
90
67
 
@@ -96,6 +73,7 @@ class NewRelic::ControlTest < Test::Unit::TestCase
96
73
  end
97
74
 
98
75
  def test_info
76
+ NewRelic::Agent.manual_start(:dispatcher_instance_id => 'test')
99
77
  props = NewRelic::Control.instance.local_env.snapshot
100
78
  if defined?(Rails)
101
79
  assert_match /jdbc|postgres|mysql|sqlite/, props.assoc('Database adapter').last, props.inspect
@@ -109,6 +87,36 @@ class NewRelic::ControlTest < Test::Unit::TestCase
109
87
  assert_equal '204.93.223.153', control.send(:convert_to_ip_address, 'collector.newrelic.com')
110
88
  end
111
89
 
90
+ def test_do_not_resolve_if_we_need_to_verify_a_cert
91
+ assert_equal nil, control.send(:convert_to_ip_address, 'localhost')
92
+ with_config(:ssl => true, :verify_certificate => true) do
93
+ assert_equal 'localhost', control.send(:convert_to_ip_address, 'localhost')
94
+ end
95
+ end
96
+
97
+ def test_api_server_uses_configured_values
98
+ control.instance_variable_set(:@api_server, nil)
99
+ with_config(:api_host => 'somewhere', :api_port => 8080) do
100
+ assert_equal 'somewhere', control.api_server.name
101
+ assert_equal 8080, control.api_server.port
102
+ end
103
+ end
104
+
105
+ def test_proxy_server_uses_configured_values
106
+ control.instance_variable_set(:@proxy_server, nil)
107
+ with_config(:proxy_host => 'proxytown', :proxy_port => 81) do
108
+ assert_equal 'proxytown', control.proxy_server.name
109
+ assert_equal 81, control.proxy_server.port
110
+ end
111
+ end
112
+
113
+ def test_server_from_host_uses_configured_values
114
+ with_config(:host => 'donkeytown', :port => 8080) do
115
+ assert_equal 'donkeytown', control.server_from_host.name
116
+ assert_equal 8080, control.server_from_host.port
117
+ end
118
+ end
119
+
112
120
  class FakeResolv
113
121
  def self.getaddress(host)
114
122
  raise 'deliberately broken'
@@ -131,126 +139,95 @@ class NewRelic::ControlTest < Test::Unit::TestCase
131
139
  assert_equal old_ipsocket, IPSocket
132
140
  end
133
141
 
134
- def test_config_yaml_erb
135
- assert_equal 'heyheyhey', control['erb_value']
136
- assert_equal '', control['message']
137
- assert_equal '', control['license_key']
138
- end
139
-
140
- def test_appnames
141
- assert_equal %w[a b c], NewRelic::Control.instance.app_names
142
- end
143
-
144
- def test_config_booleans
145
- assert_equal control['tval'], true
146
- assert_equal control['fval'], false
147
- assert_nil control['not_in_yaml_val']
148
- assert_equal control['yval'], true
149
- assert_equal control['sval'], 'sure'
150
- end
151
-
152
- def test_config_apdex
153
- assert_equal 1.1, control.apdex_t
154
- end
155
-
156
- # def test_transaction_threshold
157
- # assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
158
- # assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
159
- # end
160
-
161
142
  def test_log_file_name
162
143
  NewRelic::Control.instance.setup_log
163
144
  assert_match /newrelic_agent.log$/, control.instance_variable_get('@log_file')
164
145
  end
165
146
 
166
- # def test_transaction_threshold__apdex
167
- # forced_start
168
- # assert_equal 'Apdex_f', c['transaction_tracer']['transaction_threshold']
169
- # assert_equal 4.4, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
170
- # end
171
-
172
- def test_transaction_threshold__default
173
- forced_start :transaction_tracer => { :transaction_threshold => nil}
174
- assert_nil control['transaction_tracer']['transaction_threshold']
175
- assert_equal 2.0, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
176
- end
177
-
178
147
  def test_transaction_threshold__override
179
- forced_start :transaction_tracer => { :transaction_threshold => 1}
180
- assert_equal 1, control['transaction_tracer']['transaction_threshold']
181
- assert_equal 1, NewRelic::Agent::Agent.instance.instance_variable_get('@slowest_transaction_threshold')
148
+ with_config(:transaction_tracer => { :transaction_threshold => 1}) do
149
+ NewRelic::Agent.instance.config_transaction_tracer
150
+ assert_equal 1, NewRelic::Agent.config[:'transaction_tracer.transaction_threshold']
151
+ assert_equal 1, NewRelic::Agent.instance \
152
+ .instance_variable_get(:@slowest_transaction_threshold)
153
+ end
182
154
  end
183
155
 
184
156
  def test_transaction_tracer_disabled
185
- forced_start(:transaction_tracer => { :enabled => false },
186
- :developer_mode => false, :monitor_mode => true)
187
- NewRelic::Agent::Agent.instance.check_transaction_sampler_status
188
-
189
- assert(!NewRelic::Agent::Agent.instance.transaction_sampler.enabled?,
190
- 'transaction tracer enabled when config calls for disabled')
191
-
192
- @control['developer_mode'] = true
193
- @control['monitor_mode'] = false
157
+ with_config(:'transaction_tracer.enabled' => false,
158
+ :developer_mode => false, :monitor_mode => true) do
159
+ NewRelic::Agent::Agent.instance.config_transaction_tracer
160
+ NewRelic::Agent::Agent.instance.check_transaction_sampler_status
161
+
162
+ assert(!NewRelic::Agent::Agent.instance.transaction_sampler.enabled?,
163
+ 'transaction tracer enabled when config calls for disabled')
164
+ end
194
165
  end
195
-
166
+
196
167
  def test_sql_tracer_disabled
197
- forced_start(:slow_sql => { :enabled => false }, :monitor_mode => true)
198
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
199
-
200
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
201
- 'sql tracer enabled when config calls for disabled')
202
-
203
- @control['monitor_mode'] = false
168
+ with_config(:'slow_sql.enabled' => false, :monitor_mode => true) do
169
+ NewRelic::Agent.instance.sql_sampler.configure!
170
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
171
+
172
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
173
+ 'sql tracer enabled when config calls for disabled')
174
+ end
204
175
  end
205
-
176
+
206
177
  def test_sql_tracer_disabled_with_record_sql_false
207
- forced_start(:slow_sql => { :enabled => true, :record_sql => 'off' })
208
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
209
-
210
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
211
- 'sql tracer enabled when config calls for disabled')
178
+ with_config(:slow_sql => { :enabled => true, :record_sql => 'off' }) do
179
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
180
+
181
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
182
+ 'sql tracer enabled when config calls for disabled')
183
+ end
212
184
  end
213
185
 
214
186
  def test_sql_tracer_disabled_when_tt_disabled
215
- forced_start(:transaction_tracer => { :enabled => false },
216
- :slow_sql => { :enabled => true },
217
- :developer_mode => false, :monitor_mode => true)
218
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
219
-
220
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
221
- 'sql enabled when transaction tracer disabled')
222
-
223
- @control['developer_mode'] = true
224
- @control['monitor_mode'] = false
187
+ with_config(:'transaction_tracer.enabled' => false,
188
+ :'slow_sql.enabled' => true,
189
+ :developer_mode => false, :monitor_mode => true) do
190
+ NewRelic::Agent::Agent.instance.check_sql_sampler_status
191
+
192
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
193
+ 'sql enabled when transaction tracer disabled')
194
+ end
225
195
  end
226
196
 
227
197
  def test_sql_tracer_disabled_when_tt_disabled_by_server
228
- forced_start(:slow_sql => { :enabled => true },
229
- :transaction_tracer => { :enabled => true },
230
- :monitor_mode => true)
231
- NewRelic::Agent::Agent.instance.check_sql_sampler_status
232
- NewRelic::Agent::Agent.instance.finish_setup('collect_traces' => false)
233
-
234
- assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
235
- 'sql enabled when tracing disabled by server')
236
-
237
- @control['monitor_mode'] = false
198
+ with_config({:'slow_sql.enabled' => true,
199
+ :'transaction_tracer.enabled' => true,
200
+ :monitor_mode => true}, 2) do
201
+
202
+ NewRelic::Agent.instance.check_sql_sampler_status
203
+ NewRelic::Agent.instance.finish_setup('collect_traces' => false,
204
+ 'listen_to_server_config' => true)
205
+
206
+ assert(!NewRelic::Agent::Agent.instance.sql_sampler.enabled?,
207
+ 'sql enabled when tracing disabled by server')
208
+ end
238
209
  end
239
210
 
240
- def test_merging_options
241
- NewRelic::Control.send :public, :merge_options
242
- @control.merge_options :api_port => 66, :transaction_tracer => { :explain_threshold => 2.0 }
243
- assert_equal 66, NewRelic::Control.instance['api_port']
244
- assert_equal 2.0, NewRelic::Control.instance['transaction_tracer']['explain_threshold']
245
- assert_equal 'raw', NewRelic::Control.instance['transaction_tracer']['record_sql']
211
+ def test_init_plugin_loads_samplers_enabled
212
+ NewRelic::Agent.shutdown
213
+ with_config(:disable_samplers => false, :agent_enabled => true) do
214
+ NewRelic::Control.instance.init_plugin
215
+ assert NewRelic::Agent.instance.stats_engine.send(:harvest_samplers).any?
216
+ end
217
+ end
218
+
219
+ def test_init_plugin_loads_samplers_disabled
220
+ NewRelic::Agent.shutdown
221
+ with_config(:disable_samplers => true, :agent_enabled => true) do
222
+ NewRelic::Control.instance.init_plugin
223
+ assert_equal [], NewRelic::Agent.instance.stats_engine.send(:harvest_samplers)
224
+ end
246
225
  end
247
-
226
+
248
227
  private
249
228
 
250
- def forced_start(overrides={})
251
- NewRelic::Agent.manual_start overrides
252
- # This is to force the agent to start again.
253
- NewRelic::Agent.instance.stubs(:started?).returns(nil)
254
- NewRelic::Agent.instance.start
229
+ def reset_environment_config
230
+ NewRelic::Agent::Configuration.manager.config_stack[0] =
231
+ NewRelic::Agent::Configuration::EnvironmentSource.new
255
232
  end
256
233
  end