newrelic_rpm 3.5.4.35.beta → 3.5.5.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/CHANGELOG +42 -0
  2. data/GUIDELINES_FOR_CONTRIBUTING.md +3 -0
  3. data/Rakefile +8 -0
  4. data/bin/mongrel_rpm +1 -1
  5. data/init.rb +1 -8
  6. data/lib/new_relic/agent.rb +11 -13
  7. data/lib/new_relic/agent/agent.rb +89 -110
  8. data/lib/new_relic/agent/agent_logger.rb +165 -0
  9. data/lib/new_relic/agent/audit_logger.rb +72 -0
  10. data/lib/new_relic/agent/beacon_configuration.rb +4 -4
  11. data/lib/new_relic/agent/browser_monitoring.rb +13 -7
  12. data/lib/new_relic/agent/busy_calculator.rb +2 -2
  13. data/lib/new_relic/agent/configuration.rb +25 -0
  14. data/lib/new_relic/agent/configuration/defaults.rb +45 -8
  15. data/lib/new_relic/agent/configuration/environment_source.rb +8 -15
  16. data/lib/new_relic/agent/configuration/manager.rb +22 -2
  17. data/lib/new_relic/agent/configuration/mask_defaults.rb +10 -0
  18. data/lib/new_relic/agent/configuration/yaml_source.rb +4 -2
  19. data/lib/new_relic/agent/cross_process_monitoring.rb +43 -0
  20. data/lib/new_relic/agent/database.rb +2 -4
  21. data/lib/new_relic/agent/error_collector.rb +4 -9
  22. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -1
  24. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/authlogic.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/browser_monitoring_timings.rb +41 -0
  27. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +7 -7
  28. data/lib/new_relic/agent/instrumentation/data_mapper.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/memcache.rb +4 -4
  31. data/lib/new_relic/agent/instrumentation/merb/controller.rb +1 -1
  32. data/lib/new_relic/agent/instrumentation/merb/errors.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/metric_frame/pop.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +2 -2
  36. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +4 -4
  37. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  38. data/lib/new_relic/agent/instrumentation/rails/errors.rb +1 -1
  39. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +3 -3
  40. data/lib/new_relic/agent/instrumentation/rails3/errors.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/resque.rb +3 -2
  42. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  43. data/lib/new_relic/agent/instrumentation/sunspot.rb +1 -1
  44. data/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb +2 -2
  45. data/lib/new_relic/agent/method_tracer.rb +6 -8
  46. data/lib/new_relic/agent/new_relic_service.rb +94 -106
  47. data/lib/new_relic/agent/pipe_channel_manager.rb +1 -1
  48. data/lib/new_relic/agent/samplers/memory_sampler.rb +4 -6
  49. data/lib/new_relic/agent/sql_sampler.rb +3 -18
  50. data/lib/new_relic/agent/stats_engine.rb +0 -5
  51. data/lib/new_relic/agent/stats_engine/metric_stats.rb +3 -3
  52. data/lib/new_relic/agent/stats_engine/samplers.rb +2 -4
  53. data/lib/new_relic/agent/thread.rb +8 -3
  54. data/lib/new_relic/agent/thread_profiler.rb +38 -27
  55. data/lib/new_relic/agent/transaction_info.rb +1 -1
  56. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -3
  57. data/lib/new_relic/agent/transaction_sampler.rb +3 -7
  58. data/lib/new_relic/agent/worker_loop.rb +3 -11
  59. data/lib/new_relic/control.rb +0 -2
  60. data/lib/new_relic/control/class_methods.rb +8 -2
  61. data/lib/new_relic/control/frameworks/merb.rb +0 -6
  62. data/lib/new_relic/control/frameworks/rails.rb +8 -29
  63. data/lib/new_relic/control/frameworks/rails3.rb +8 -20
  64. data/lib/new_relic/control/frameworks/rails4.rb +23 -0
  65. data/lib/new_relic/control/frameworks/ruby.rb +1 -22
  66. data/lib/new_relic/control/instance_methods.rb +12 -34
  67. data/lib/new_relic/control/instrumentation.rb +7 -12
  68. data/lib/new_relic/control/server_methods.rb +5 -8
  69. data/lib/new_relic/delayed_job_injection.rb +1 -1
  70. data/lib/new_relic/local_environment.rb +30 -64
  71. data/lib/new_relic/metric_data.rb +1 -1
  72. data/lib/new_relic/metric_spec.rb +1 -1
  73. data/lib/new_relic/noticed_error.rb +1 -1
  74. data/lib/new_relic/rack/browser_monitoring.rb +5 -5
  75. data/lib/new_relic/stats.rb +9 -7
  76. data/lib/new_relic/transaction_sample.rb +2 -7
  77. data/lib/new_relic/version.rb +1 -1
  78. data/lib/newrelic_rpm.rb +1 -1
  79. data/newrelic_rpm.gemspec.erb +15 -17
  80. data/test/config/newrelic.yml +1 -1
  81. data/test/config/test_control.rb +18 -18
  82. data/test/fixtures/gemspec_no_build.rb +0 -2
  83. data/test/fixtures/gemspec_with_build.rb +0 -2
  84. data/test/fixtures/gemspec_with_build_and_stage.rb +0 -2
  85. data/test/multiverse/README.md +3 -8
  86. data/test/multiverse/suites/agent_only/Envfile +1 -0
  87. data/test/multiverse/suites/agent_only/audit_log_test.rb +99 -0
  88. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  89. data/test/multiverse/suites/config_file_loading/Envfile +7 -0
  90. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +106 -0
  91. data/test/multiverse/suites/logging/Envfile +4 -0
  92. data/test/multiverse/suites/logging/config/newrelic.yml +22 -0
  93. data/test/multiverse/suites/logging/logging_test.rb +143 -0
  94. data/test/multiverse/suites/no_load/config/newrelic.yml +1 -2
  95. data/test/multiverse/suites/rum_auto_instrumentation/sanity_test.rb +0 -13
  96. data/test/new_relic/agent/agent/connect_test.rb +30 -92
  97. data/test/new_relic/agent/agent/start_test.rb +4 -84
  98. data/test/new_relic/agent/agent/start_worker_thread_test.rb +8 -43
  99. data/test/new_relic/agent/agent_logger_test.rb +153 -0
  100. data/test/new_relic/agent/agent_test.rb +10 -9
  101. data/test/new_relic/agent/audit_logger_test.rb +105 -0
  102. data/test/new_relic/agent/browser_monitoring_test.rb +2 -1
  103. data/test/new_relic/agent/busy_calculator_test.rb +7 -0
  104. data/test/new_relic/agent/configuration/environment_source_test.rb +25 -20
  105. data/test/new_relic/agent/configuration/manager_test.rb +59 -4
  106. data/test/new_relic/agent/configuration/yaml_source_test.rb +20 -1
  107. data/test/new_relic/agent/cross_process_monitoring_test.rb +77 -0
  108. data/test/new_relic/agent/database_test.rb +0 -11
  109. data/test/new_relic/agent/error_collector/notice_error_test.rb +1 -3
  110. data/test/new_relic/agent/error_collector_test.rb +11 -7
  111. data/test/new_relic/agent/instrumentation/active_record_instrumentation_test.rb +39 -19
  112. data/test/new_relic/agent/instrumentation/browser_monitoring_timings_test.rb +39 -0
  113. data/test/new_relic/agent/instrumentation/metric_frame/pop_test.rb +1 -1
  114. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +0 -6
  115. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +3 -15
  116. data/test/new_relic/agent/new_relic_service_test.rb +48 -8
  117. data/test/new_relic/agent/pipe_channel_manager_test.rb +1 -1
  118. data/test/new_relic/agent/sql_sampler_test.rb +1 -1
  119. data/test/new_relic/agent/thread_profiler_test.rb +46 -45
  120. data/test/new_relic/agent/thread_test.rb +13 -0
  121. data/test/new_relic/agent/transaction_sample_builder_test.rb +1 -1
  122. data/test/new_relic/agent/worker_loop_test.rb +4 -9
  123. data/test/new_relic/agent_test.rb +6 -9
  124. data/test/new_relic/control/class_methods_test.rb +0 -18
  125. data/test/new_relic/control_test.rb +6 -9
  126. data/test/new_relic/dispatcher_test.rb +54 -0
  127. data/test/new_relic/fake_collector.rb +15 -14
  128. data/test/new_relic/fake_service.rb +4 -1
  129. data/test/new_relic/fakes_sending_data.rb +30 -0
  130. data/test/new_relic/framework_test.rb +53 -0
  131. data/test/new_relic/local_environment_test.rb +5 -2
  132. data/test/new_relic/rack/browser_monitoring_test.rb +2 -1
  133. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  134. data/test/new_relic/stats_test.rb +10 -0
  135. data/test/new_relic/transaction_sample_test.rb +2 -2
  136. data/test/script/ci.sh +1 -1
  137. data/test/test_helper.rb +23 -0
  138. data/ui/views/newrelic/file/images/arrow-close.png +0 -0
  139. data/ui/views/newrelic/file/images/arrow-open.png +0 -0
  140. data/ui/views/newrelic/file/images/blue_bar.gif +0 -0
  141. data/ui/views/newrelic/file/images/file_icon.png +0 -0
  142. data/ui/views/newrelic/file/images/gray_bar.gif +0 -0
  143. metadata +47 -41
  144. data/InstallationNotes.md +0 -15
  145. data/lib/new_relic/control/logging_methods.rb +0 -125
  146. data/test/multiverse/Rakefile +0 -17
  147. data/test/multiverse/suites/rum_auto_instrumentation/problem_response.html +0 -422
  148. data/test/new_relic/control/logging_methods_test.rb +0 -211
@@ -16,20 +16,9 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
16
16
  self.expects(:catch_errors).yields
17
17
  self.expects(:connect).with('connection_options')
18
18
  @connected = false
19
- fake_log = mocked_log
20
- fake_log.expects(:debug).with("No connection. Worker thread ending.")
21
19
  deferred_work!('connection_options')
22
20
  end
23
21
 
24
- def test_log_worker_loop_start
25
- log = mocked_log
26
- log.expects(:info).with("Reporting performance data every 30 seconds.")
27
- log.expects(:debug).with("Running worker loop")
28
- with_config(:data_report_period => 30) do
29
- log_worker_loop_start
30
- end
31
- end
32
-
33
22
  def test_create_and_run_worker_loop
34
23
  @should_send_samples = true
35
24
  wl = mock('worker loop')
@@ -43,10 +32,8 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
43
32
 
44
33
  def test_handle_force_restart
45
34
  # hooray for methods with no branches
46
- error = mock('exception')
47
- log = mocked_log
48
- error.expects(:message).returns('a message')
49
- log.expects(:info).with('a message')
35
+ error = mock(:message => 'a message')
36
+
50
37
  self.expects(:reset_stats)
51
38
  self.expects(:sleep).with(30)
52
39
 
@@ -60,37 +47,22 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
60
47
  end
61
48
 
62
49
  def test_handle_force_disconnect
63
- error = mock('exception')
64
- error.expects(:message).returns('a message')
65
- log = mocked_log
66
- log.expects(:error).with("New Relic forced this agent to disconnect (a message)")
50
+ error = mock(:message => 'a message')
51
+
67
52
  self.expects(:disconnect)
68
53
  handle_force_disconnect(error)
69
54
  end
70
55
 
71
56
  def test_handle_server_connection_problem
72
- error_class = mock('class of exception')
73
- error = mock('exception')
74
- log = mocked_log
75
- log.expects(:error).with('Unable to establish connection with the server. Run with log level set to debug for more information.')
76
- error.expects(:class).returns(error_class)
77
- error_class.expects(:name).returns('an error class')
78
- error.expects(:message).returns('a message')
79
- error.expects(:backtrace).returns(['first line', 'second line'])
80
- log.expects(:debug).with("an error class: a message\nfirst line")
57
+ error = StandardError.new('a message')
58
+
81
59
  self.expects(:disconnect)
82
60
  handle_server_connection_problem(error)
83
61
  end
84
62
 
85
63
  def test_handle_other_error
86
- error_class = mock('class of exception')
87
- error = mock('exception')
88
- log = mocked_log
89
- error.expects(:class).returns(error_class)
90
- error_class.expects(:name).returns('an error class')
91
- error.expects(:message).returns('a message')
92
- error.expects(:backtrace).returns(['first line', 'second line'])
93
- log.expects(:error).with("Terminating worker loop: an error class: a message\n first line\n second line")
64
+ error = StandardError.new('a message')
65
+
94
66
  self.expects(:disconnect)
95
67
  handle_other_error(error)
96
68
  end
@@ -110,13 +82,6 @@ class NewRelic::Agent::Agent::StartWorkerThreadTest < Test::Unit::TestCase
110
82
 
111
83
  private
112
84
 
113
- def mocked_log
114
- fake_log = mock('log')
115
- self.stubs(:log).returns(fake_log)
116
- fake_log
117
- end
118
-
119
-
120
85
  def mocked_control
121
86
  fake_control = mock('control')
122
87
  self.stubs(:control).returns(fake_control)
@@ -0,0 +1,153 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'new_relic/agent/agent_logger'
3
+
4
+ class AgentLoggerTest < Test::Unit::TestCase
5
+ def setup
6
+ @config = {
7
+ :log_file_path => "log/",
8
+ :log_file_name => "testlog.log",
9
+ :log_level => :info,
10
+ }
11
+ end
12
+
13
+ def test_initalizes_from_config
14
+ override_logger = stub(:level=)
15
+ ::Logger.stubs(:new).with(any_parameters).returns(override_logger)
16
+
17
+ logger = NewRelic::Agent::AgentLogger.new(@config)
18
+ assert_equal(override_logger, logger.instance_variable_get(:@log))
19
+ end
20
+
21
+ def test_initalizes_from_override
22
+ override_logger = stub(:level=)
23
+ logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
24
+ assert_equal override_logger, logger.instance_variable_get(:@log)
25
+ end
26
+
27
+ def test_forwards_calls_to_logger
28
+ [:fatal, :error, :warn, :info, :debug].each do |level|
29
+ override_logger = stub(:level=)
30
+ override_logger.expects(level).with(any_parameters)
31
+
32
+ logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
33
+
34
+ logger.send(level, "Boo!")
35
+ end
36
+ end
37
+
38
+
39
+ def test_forwards_calls_to_logger_with_multiple_arguments
40
+ [:fatal, :error, :warn, :info, :debug].each do |level|
41
+ override_logger = stub(:level=)
42
+ override_logger.expects(level).with("What\nup?")
43
+
44
+ logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
45
+
46
+ logger.send(level, "What", "up?")
47
+ end
48
+ end
49
+
50
+ def test_passing_exceptions_gets_pretty_formatting
51
+ caught = nil
52
+ begin
53
+ raise Exception.new("Boo!")
54
+ rescue Exception => e
55
+ caught = e
56
+ end
57
+
58
+ # Checking if it looks like message includes backtrace
59
+ override_logger = stub(:level=)
60
+ override_logger.expects(:debug).with {|msg| msg.include?("test_") }
61
+
62
+ NewRelic::Agent::AgentLogger.new(@config, "", override_logger).debug(e)
63
+ end
64
+
65
+ def test_wont_log_if_agent_not_enabled
66
+ ::Logger.stubs(:new).with("/dev/null").returns(stub(:level=)).at_least_once
67
+
68
+ @config[:agent_enabled] = false
69
+ logger = NewRelic::Agent::AgentLogger.new(@config)
70
+ end
71
+
72
+ def test_logs_to_nul_if_dev_null_not_there
73
+ File.stubs(:exists?).with("/dev/null").returns(false)
74
+ File.stubs(:exists?).with("NUL").returns(true)
75
+
76
+ ::Logger.stubs(:new).with("NUL").returns(stub(:level=)).once
77
+
78
+ @config[:agent_enabled] = false
79
+ logger = NewRelic::Agent::AgentLogger.new(@config)
80
+ end
81
+
82
+ def test_maps_log_levels
83
+ assert_equal Logger::FATAL, NewRelic::Agent::AgentLogger.log_level_for(:fatal)
84
+ assert_equal Logger::ERROR, NewRelic::Agent::AgentLogger.log_level_for(:error)
85
+ assert_equal Logger::WARN, NewRelic::Agent::AgentLogger.log_level_for(:warn)
86
+ assert_equal Logger::INFO, NewRelic::Agent::AgentLogger.log_level_for(:info)
87
+ assert_equal Logger::DEBUG, NewRelic::Agent::AgentLogger.log_level_for(:debug)
88
+
89
+ assert_equal Logger::INFO, NewRelic::Agent::AgentLogger.log_level_for("")
90
+ assert_equal Logger::INFO, NewRelic::Agent::AgentLogger.log_level_for(:unknown)
91
+ end
92
+
93
+ def test_sets_log_level
94
+ override_logger = mock()
95
+ override_logger.expects(:level=).with(Logger::DEBUG)
96
+ @config[:log_level] = :debug
97
+
98
+ logger = NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
99
+ end
100
+
101
+ def test_log_to_stdout_and_warns_if_failed_on_create
102
+ NewRelic::Agent::AgentLogger.any_instance.stubs(:find_or_create_file_path).returns(nil)
103
+
104
+ stdout = stub(:level=)
105
+ stdout.expects(:warn)
106
+ ::Logger.stubs(:new).with(STDOUT).returns(stdout)
107
+
108
+ logger = NewRelic::Agent::AgentLogger.new(@config)
109
+ assert_equal stdout, logger.instance_variable_get(:@log)
110
+ end
111
+
112
+ def test_log_to_stdout_based_on_config
113
+ @config[:log_file_path] = "STDOUT"
114
+
115
+ stdout = stub(:level=)
116
+ stdout.expects(:warn).never
117
+ ::Logger.stubs(:new).with(STDOUT).returns(stdout)
118
+
119
+ logger = NewRelic::Agent::AgentLogger.new(@config)
120
+ assert_equal stdout, logger.instance_variable_get(:@log)
121
+ end
122
+
123
+ def test_startup_purges_memory_logger
124
+ [:fatal, :error, :warn, :info, :debug].each do |level|
125
+ ::NewRelic::Agent::StartupLogger.instance.send(level, "boo!")
126
+
127
+ override_logger = stub(:level=)
128
+ override_logger.expects(level).with("boo!")
129
+
130
+ NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
131
+ end
132
+ end
133
+
134
+ def test_format_message_allows_nil_backtrace
135
+ override_logger = stub(:level=)
136
+ override_logger.expects(:debug)
137
+
138
+ logger = ::NewRelic::Agent::AgentLogger.new(@config, "", override_logger)
139
+
140
+ logger.debug(Exception.new("Look Ma, no backtrace!"))
141
+ end
142
+
143
+
144
+ def test_logs_to_stdout_if_fails_on_file
145
+ stdout = stub_everything()
146
+ ::Logger.stubs(:new).with(STDOUT).returns(stdout)
147
+ ::Logger.stubs(:new).with(instance_of(String)).raises(Errno::EACCES)
148
+
149
+ logger = NewRelic::Agent::AgentLogger.new(@config, "")
150
+
151
+ assert_equal stdout, logger.instance_variable_get(:@log)
152
+ end
153
+ end
@@ -127,11 +127,7 @@ module NewRelic
127
127
 
128
128
  def test_check_for_agent_commands
129
129
  @agent.send :check_for_agent_commands
130
-
131
- expected = RUBY_VERSION >= "1.9.2" ? 1 : 0
132
- assert_equal(expected,
133
- @agent.service.agent_data \
134
- .select {|data| data.action == :get_agent_commands }.size)
130
+ assert_equal(1, @agent.service.calls_for(:get_agent_commands).size)
135
131
  end
136
132
 
137
133
  def test_merge_data_from_empty
@@ -204,10 +200,15 @@ module NewRelic
204
200
  @agent.merge_data_from([{}, [1,2,3], [4,5,6]])
205
201
  end
206
202
 
207
- def test_should_not_log_log_file_location_if_no_log_file
208
- NewRelic::Control.instance.stubs(:log_file).returns('/vasrkjn4b3b4')
209
- @agent.expects(:log).never
210
- @agent.notify_log_file_location
203
+ def test_fill_metric_id_cache_from_collect_response
204
+ response = [[{"scope"=>"Controller/blogs/index", "name"=>"Database/SQL/other"}, 1328],
205
+ [{"scope"=>"", "name"=>"WebFrontend/QueueTime"}, 10],
206
+ [{"scope"=>"", "name"=>"ActiveRecord/Blog/find"}, 1017]]
207
+
208
+ @agent.send(:fill_metric_id_cache, response)
209
+ assert_equal 1328, @agent.metric_ids[MetricSpec.new('Database/SQL/other', 'Controller/blogs/index')]
210
+ assert_equal 10, @agent.metric_ids[MetricSpec.new('WebFrontend/QueueTime')]
211
+ assert_equal 1017, @agent.metric_ids[MetricSpec.new('ActiveRecord/Blog/find')]
211
212
  end
212
213
 
213
214
  def test_fill_metric_id_cache_from_collect_response
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'new_relic/agent/audit_logger'
3
+
4
+ class AuditLoggerTest < Test::Unit::TestCase
5
+ def setup
6
+ @config = {
7
+ :'audit_log.enabled' => true
8
+ }
9
+ @uri = "http://really.notreal"
10
+ @marshaller = NewRelic::Agent::NewRelicService::Marshaller.new
11
+ @hostname = 'dummyhost'
12
+ @dummy_data = {
13
+ 'foo' => [1, 2, 3],
14
+ 'bar' => {
15
+ 'baz' => 'qux',
16
+ 'jingle' => 'bells'
17
+ }
18
+ }
19
+ Socket.stubs(:gethostname).returns(@hostname)
20
+ end
21
+
22
+ def setup_fake_logger
23
+ @fakelog = StringIO.new
24
+ @logger = NewRelic::Agent::AuditLogger.new(@config)
25
+ @logger.stubs(:ensure_log_path).returns(@fakelog)
26
+ end
27
+
28
+ def assert_log_contains_string(str)
29
+ @fakelog.rewind
30
+ log_body = @fakelog.read
31
+ assert(log_body.include?(str), "Expected log to contain string '#{str}'")
32
+ end
33
+
34
+ def test_never_setup_if_disabled
35
+ config = { :'audit_log.enabled' => false }
36
+ logger = NewRelic::Agent::AuditLogger.new(config)
37
+ logger.log_request(@uri, "hi there", @marshaller)
38
+ assert(!logger.setup?, "Expected logger to not have been setup")
39
+ end
40
+
41
+ def test_never_prepare_if_disabled
42
+ config = { :'audit_log.enabled' => false }
43
+ logger = NewRelic::Agent::AuditLogger.new(config)
44
+ marshaller = NewRelic::Agent::NewRelicService::Marshaller.new
45
+ marshaller.expects(:prepare).never
46
+ logger.log_request(@uri, "hi there", @marshaller)
47
+ end
48
+
49
+ def test_log_formatter
50
+ formatter = NewRelic::Agent::AuditLogger.new(@config).log_formatter
51
+ time = '2012-01-01 00:00:00'
52
+ msg = 'hello'
53
+ result = formatter.call(Logger::INFO, time, 'bleh', msg)
54
+ expected = "[2012-01-01 00:00:00 #{@hostname} (#{$$})] : hello\n"
55
+ assert_equal(expected, result)
56
+ end
57
+
58
+ def test_ensure_path_returns_nil_with_bogus_path
59
+ opts = { :'audit_log.path' => '/really/really/not/a/path' }
60
+ FileUtils.stubs(:mkdir_p).raises(SystemCallError, "i'd rather not")
61
+ logger = NewRelic::Agent::AuditLogger.new(@config.merge(opts))
62
+ assert_nil(logger.ensure_log_path)
63
+ end
64
+
65
+ def test_log_request_captures_system_call_errors
66
+ logger = NewRelic::Agent::AuditLogger.new(@config)
67
+ dummy_sink = StringIO.new
68
+ dummy_sink.stubs(:write).raises(SystemCallError, "nope")
69
+ logger.stubs(:ensure_log_path).returns(dummy_sink)
70
+
71
+ # In 1.9.2 and later, Logger::LogDevice#write captures any errors during
72
+ # writing and spits them out with Kernel#warn.
73
+ # This just silences that output to keep the test output uncluttered.
74
+ Logger::LogDevice.any_instance.stubs(:warn)
75
+
76
+ assert_nothing_raised do
77
+ logger.log_request(@uri, 'whatever', @marshaller)
78
+ end
79
+ end
80
+
81
+ def test_prepares_data_with_identity_encoder
82
+ setup_fake_logger
83
+ data = { 'foo' => 'bar' }
84
+ identity_encoder = NewRelic::Agent::NewRelicService::Encoders::Identity
85
+ @marshaller.expects(:prepare).with(data, { :encoder => identity_encoder })
86
+ @logger.log_request(@uri, data, @marshaller)
87
+ end
88
+
89
+ def test_logs_inspect_with_pruby_marshaller
90
+ setup_fake_logger
91
+ pruby_marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new
92
+ @logger.log_request(@uri, @dummy_data, pruby_marshaller)
93
+ assert_log_contains_string(@dummy_data.inspect)
94
+ end
95
+
96
+ def test_logs_json_with_json_marshaller
97
+ marshaller_cls = NewRelic::Agent::NewRelicService::JsonMarshaller
98
+ if marshaller_cls.is_supported?
99
+ setup_fake_logger
100
+ json_marshaller = marshaller_cls.new
101
+ @logger.log_request(@uri, @dummy_data, json_marshaller)
102
+ assert_log_contains_string(JSON.dump(@dummy_data))
103
+ end
104
+ end
105
+ end
@@ -17,7 +17,8 @@ class NewRelic::Agent::BrowserMonitoringTest < Test::Unit::TestCase
17
17
  :application_id => '5, 6', # collector can return app multiple ids
18
18
  :'rum.enabled' => true,
19
19
  :episodes_file => 'this_is_my_file',
20
- :'rum.jsonp' => true
20
+ :'rum.jsonp' => true,
21
+ :license_key => 'a' * 40
21
22
  }
22
23
  NewRelic::Agent.config.apply_config(@config)
23
24
  @episodes_file = "this_is_my_file"
@@ -78,4 +78,11 @@ class NewRelic::Agent::BusyCalculatorTest < Test::Unit::TestCase
78
78
  NewRelic::Agent::BusyCalculator.harvest_busy
79
79
  assert_equal 3, @instance_busy.call_count
80
80
  end
81
+ def test_can_turn_off_recording
82
+ with_config(:report_instance_busy => false) do
83
+ assert_equal 0, @instance_busy.call_count, "Problem with test--instance busy not starting off at zero."
84
+ NewRelic::Agent::BusyCalculator.harvest_busy
85
+ assert_equal 0, @instance_busy.call_count
86
+ end
87
+ end
81
88
  end
@@ -3,16 +3,31 @@ require 'new_relic/agent/configuration/environment_source'
3
3
 
4
4
  module NewRelic::Agent::Configuration
5
5
  class EnvironmentSourceTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @original_env = {}
9
+ @original_env.replace(ENV)
10
+ end
11
+
12
+ def teardown
13
+ ENV.replace(@original_env)
14
+ end
15
+
6
16
  def test_environment_strings_are_applied
7
17
  assert_applied_string 'NRCONFIG', 'config_path'
8
18
  assert_applied_string 'NEW_RELIC_LICENSE_KEY', 'license_key'
9
19
  assert_applied_string 'NEWRELIC_LICENSE_KEY', 'license_key'
10
20
  assert_applied_string 'NEW_RELIC_APP_NAME', 'app_name'
11
21
  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'
22
+ assert_applied_string 'NEW_RELIC_HOST', 'host'
23
+ assert_applied_string 'NEW_RELIC_PORT', 'port'
24
+ end
25
+
26
+ def test_environment_symbols_are_applied
27
+ assert_applied_symbol 'NEW_RELIC_DISPATCHER', 'dispatcher'
28
+ assert_applied_symbol 'NEWRELIC_DISPATCHER', 'dispatcher'
29
+ assert_applied_symbol 'NEW_RELIC_FRAMEWORK', 'framework'
30
+ assert_applied_symbol 'NEWRELIC_FRAMEWORK', 'framework'
16
31
  end
17
32
 
18
33
  def test_environment_booleans_truths_are_applied
@@ -49,26 +64,16 @@ module NewRelic::Agent::Configuration
49
64
  assert_equal 'STDOUT', source[:log_file_path]
50
65
  end
51
66
 
52
- def test_thread_profiler_is_supported
53
- source = EnvironmentSource.new
54
-
55
- assert_equal(
56
- NewRelic::Agent::ThreadProfiler.is_supported?,
57
- source[:'thread_profiler.is_supported'])
58
- end
59
-
60
- def test_thread_profiler_enabled_depending_on_support
61
- source = EnvironmentSource.new
62
-
63
- expected = false unless NewRelic::Agent::ThreadProfiler.is_supported?
64
-
65
- assert_equal expected, source[:'thread_profiler.enabled']
66
- end
67
-
68
67
  def assert_applied_string(env_var, config_var)
69
68
  ENV[env_var] = 'test value'
70
69
  assert_equal 'test value', EnvironmentSource.new[config_var.to_sym]
71
70
  ENV.delete(env_var)
72
71
  end
72
+
73
+ def assert_applied_symbol(env_var, config_var)
74
+ ENV[env_var] = 'test value'
75
+ assert_equal :'test value', EnvironmentSource.new[config_var.to_sym]
76
+ ENV.delete(env_var)
77
+ end
73
78
  end
74
79
  end