Skip to content

Commit f42b5f5

Browse files
committed
RUBY-868 moved apdex_t accessor and cleaned up tests
1 parent bad3ff4 commit f42b5f5

File tree

8 files changed

+30
-53
lines changed

8 files changed

+30
-53
lines changed

config.dot

+4-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ digraph AgentEnabled {
6060

6161
node[shape=box,color=orange]
6262
"Control#init_plugin"
63-
"Control#apdex_t"
6463
"Control#api_server"
6564
"Control#proxy_server"
6665
"Control#server_from_host"
@@ -157,7 +156,6 @@ digraph AgentEnabled {
157156
"Control#init_plugin" -> "Control#setup_log"
158157
"Control#init_plugin" -> "[disable_samplers]"
159158
"Control#should_log?" -> "[agent_enabled]"
160-
"Control#apdex_t" -> "[apdex_t]"
161159
"Control#api_server" -> "[api_host]"
162160
"Control#api_server" -> "[api_port]"
163161
"Control#proxy_server" -> "[proxy_host]"
@@ -193,7 +191,7 @@ digraph AgentEnabled {
193191
"Agent#using_forking_dispatcher?" -> "[dispatcher]"
194192
"Agent#has_license_key?" -> "[license_key]"
195193
"Agent#correct_license_length" -> "[license_key]"
196-
"Agent#apdex_f" -> "Control#apdex_t"
194+
"Agent#apdex_f" -> "[apdex_t]"
197195
"Agent#check_config_and_start_agent" -> "[sync_startup]"
198196
"Agent#install_exit_handler" -> "[send_data_on_exit]"
199197
"Agent#log_app_names" -> "Config#app_names"
@@ -269,10 +267,10 @@ digraph AgentEnabled {
269267
"DelayedJobInjection#depends_on" -> "[disable_dj]"
270268
"DelayedJobInjection#executes" -> "Control#init_plugin"
271269

272-
"MetricFrame.update_apdex" -> "Control#apdex_t"
270+
"MetricFrame.update_apdex" -> "[apdex_t]"
273271

274-
"TranactionInfo#force_persist_sample?" -> "Control#apdex_t"
275-
"TranactionInfo#include_guid?" -> "Control#apdex_t"
272+
"TranactionInfo#force_persist_sample?" -> "[apdex_t]"
273+
"TranactionInfo#include_guid?" -> "[apdex_t]"
276274

277275
"TransactionSampleBuilder#initialize" -> "[transaction_tracer.limit_segments]"
278276
"TransactionSampleBuilder#set_transaction_info" -> "[capture_params]"

lib/new_relic/agent/agent.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def configure_transaction_tracer!(server_enabled, sample_rate)
796796

797797
# apdex_f is always 4 times the apdex_t
798798
def apdex_f
799-
(4 * NewRelic::Control.instance.apdex_t).to_f
799+
(4 * Agent.config[:apdex_t]).to_f
800800
end
801801

802802
# Sets the sql recording configuration by trying to detect

lib/new_relic/agent/instrumentation/metric_frame.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def self.record_apdex(current_metric, action_duration, total_duration, is_error)
320320
# the apdex should be recorded as a failure regardless of duration.
321321
def self.update_apdex(stat, duration, failed)
322322
duration = duration.to_f
323-
apdex_t = NewRelic::Control.instance.apdex_t
323+
apdex_t = Agent.config[:apdex_t]
324324
case
325325
when failed
326326
stat.record_apdex_f

lib/new_relic/agent/transaction_info.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def initialize
1515
end
1616

1717
def force_persist_sample?(sample)
18-
token && sample.duration > NewRelic::Control.instance.apdex_t
18+
token && sample.duration > Agent.config[:apdex_t]
1919
end
2020

2121
def include_guid?
22-
token && duration > NewRelic::Control.instance.apdex_t
22+
token && duration > Agent.config[:apdex_t]
2323
end
2424

2525
def guid

lib/new_relic/control.rb

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
require 'new_relic/control/frameworks'
1313
require 'new_relic/control/profiling'
1414
require 'new_relic/control/logging_methods'
15-
require 'new_relic/control/configuration'
1615
require 'new_relic/control/server_methods'
1716
require 'new_relic/control/instrumentation'
1817
require 'new_relic/control/class_methods'

lib/new_relic/control/configuration.rb

-12
This file was deleted.

test/new_relic/control/configuration_test.rb test/new_relic/control/frameworks/rails_test.rb

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
1-
require File.expand_path(File.join(File.dirname(__FILE__),'/../../test_helper'))
2-
3-
class NewRelic::Control::ConfigurationTest < Test::Unit::TestCase
4-
require 'new_relic/control/configuration'
5-
include NewRelic::Control::Configuration
6-
7-
def setup
8-
# The log stuff is memoized so let's clear it each time.
9-
NewRelic::Control.instance.instance_variable_set '@log_path', nil
10-
NewRelic::Control.instance.instance_variable_set '@log_file', nil
11-
@root = ::Rails::VERSION::MAJOR == 3 ? Rails.root : RAILS_ROOT
12-
end
13-
14-
def test_log_path_uses_default_if_not_set
15-
NewRelic::Control.instance.setup_log
16-
assert_match(/log\/newrelic_agent.log$/,
17-
NewRelic::Control.instance.log_file)
18-
end
19-
20-
def test_log_file_path_uses_given_value
21-
Dir.stubs(:mkdir).returns(true)
22-
with_config(:log_file_path => 'lerg') do
23-
NewRelic::Control.instance.setup_log
24-
assert_match(/\/lerg\/newrelic_agent.log$/,
25-
NewRelic::Control.instance.log_file)
26-
end
27-
end
1+
require File.expand_path(File.join(File.dirname(__FILE__),'/../../../test_helper'))
282

3+
class NewRelic::Control::Frameworks::RailsTest < Test::Unit::TestCase
294
def test_install_browser_monitoring
305
require(File.expand_path(File.join(File.dirname(__FILE__),
31-
'/../../../lib/new_relic/rack/browser_monitoring')))
6+
'/../../../../lib/new_relic/rack/browser_monitoring')))
327
middleware = stub('middleware config')
338
config = stub('rails config', :middleware => middleware)
349
middleware.expects(:use).with(NewRelic::Rack::BrowserMonitoring)
@@ -43,7 +18,7 @@ def test_install_browser_monitoring_should_not_install_when_not_configured
4318
config = stub('rails config', :middleware => middleware)
4419
middleware.expects(:use).never
4520
NewRelic::Control.instance.instance_eval { @browser_monitoring_installed = false }
46-
21+
4722
with_config(:'browser_monitoring.auto_instrument' => false) do
4823
NewRelic::Control.instance.install_browser_monitoring(config)
4924
end

test/new_relic/control/logging_methods_test.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
class BaseLoggingMethods
66
# stub class to enable testing of the module
77
include NewRelic::Control::LoggingMethods
8-
include NewRelic::Control::Configuration
98
def root; "."; end
109
end
1110

1211
class NewRelic::Control::LoggingMethodsTest < Test::Unit::TestCase
1312
def setup
1413
@base = BaseLoggingMethods.new
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
1517
super
1618
end
1719

@@ -186,6 +188,21 @@ def test_set_file_destination_from_NEW_RELIC_LOG_env_var
186188
reset_environment_config
187189
end
188190

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+
189206
def reset_environment_config
190207
NewRelic::Agent::Configuration.manager.config_stack[0] =
191208
NewRelic::Agent::Configuration::EnvironmentSource.new

0 commit comments

Comments
 (0)