newrelic_rpm 3.6.4.122 → 3.6.5.130
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +14 -1
- data/lib/new_relic/agent.rb +8 -7
- data/lib/new_relic/agent/agent.rb +2 -0
- data/lib/new_relic/agent/configuration/defaults.rb +1 -1
- data/lib/new_relic/agent/configuration/server_source.rb +2 -1
- data/lib/new_relic/agent/cross_app_tracing.rb +52 -26
- data/lib/new_relic/agent/event_listener.rb +1 -1
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +61 -0
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +46 -0
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +72 -0
- data/lib/new_relic/agent/{uri_util.rb → http_clients/uri_util.rb} +11 -17
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -11
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -2
- data/lib/new_relic/agent/instrumentation/excon.rb +72 -0
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +33 -0
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +45 -0
- data/lib/new_relic/agent/instrumentation/net.rb +3 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +73 -0
- data/lib/new_relic/agent/method_tracer.rb +3 -6
- data/lib/new_relic/agent/new_relic_service.rb +1 -1
- data/lib/new_relic/agent/samplers/object_sampler.rb +1 -1
- data/lib/new_relic/agent/stats.rb +12 -10
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +24 -6
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +9 -11
- data/lib/new_relic/agent/transaction.rb +34 -33
- data/lib/new_relic/agent/transaction_sampler.rb +15 -6
- data/lib/new_relic/language_support.rb +8 -0
- data/lib/new_relic/local_environment.rb +10 -14
- data/lib/new_relic/version.rb +1 -1
- data/test/agent_helper.rb +43 -0
- data/test/config/test.cert.crt +14 -0
- data/test/config/test.cert.csr +11 -0
- data/test/config/test.cert.key +15 -0
- data/test/config/testing-privkey.pem +18 -0
- data/test/multiverse/lib/multiverse/color.rb +9 -3
- data/test/multiverse/lib/multiverse/suite.rb +11 -1
- data/test/multiverse/suites/agent_only/audit_log_test.rb +1 -0
- data/test/multiverse/suites/agent_only/config/newrelic.yml +4 -0
- data/test/multiverse/suites/agent_only/http_response_code_test.rb +1 -1
- data/test/multiverse/suites/agent_only/rename_rule_test.rb +2 -1
- data/test/multiverse/suites/agent_only/start_up_test.rb +3 -2
- data/test/multiverse/suites/config_file_loading/Envfile +2 -0
- data/test/multiverse/suites/excon/Envfile +15 -0
- data/test/multiverse/suites/excon/config/newrelic.yml +21 -0
- data/test/multiverse/suites/excon/excon_test.rb +60 -0
- data/test/multiverse/suites/net_http/Envfile +6 -0
- data/test/multiverse/suites/net_http/config/newrelic.yml +21 -0
- data/test/multiverse/suites/net_http/net_http_test.rb +102 -0
- data/test/multiverse/suites/rails/Envfile +1 -1
- data/test/multiverse/suites/rails/view_instrumentation_test.rb +6 -0
- data/test/multiverse/suites/resque/Envfile +0 -9
- data/test/multiverse/suites/resque/instrumentation_test.rb +21 -6
- data/test/multiverse/suites/typhoeus/Envfile +46 -0
- data/test/multiverse/suites/typhoeus/config/newrelic.yml +21 -0
- data/test/multiverse/suites/typhoeus/typhoeus_test.rb +77 -0
- data/test/new_relic/agent/agent_test_controller_test.rb +11 -10
- data/test/new_relic/agent/configuration/server_source_test.rb +23 -9
- data/test/new_relic/agent/database_test.rb +6 -0
- data/test/new_relic/agent/http_clients/uri_util_test.rb +64 -0
- data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +0 -406
- data/test/new_relic/agent/new_relic_service_test.rb +23 -19
- data/test/new_relic/agent/stats_engine/metric_stats_test.rb +29 -12
- data/test/new_relic/agent/stats_hash_test.rb +24 -3
- data/test/new_relic/agent/stats_test.rb +4 -4
- data/test/new_relic/agent/transaction/pop_test.rb +1 -1
- data/test/new_relic/agent/transaction_sampler_test.rb +18 -0
- data/test/new_relic/agent/transaction_test.rb +64 -69
- data/test/new_relic/agent_test.rb +20 -0
- data/test/new_relic/dependency_detection_test.rb +99 -0
- data/test/new_relic/evil_server.rb +56 -0
- data/test/new_relic/fake_collector.rb +12 -96
- data/test/new_relic/fake_external_server.rb +55 -0
- data/test/new_relic/fake_server.rb +97 -0
- data/test/new_relic/http_client_test_cases.rb +444 -0
- data/test/new_relic/language_support_test.rb +45 -0
- data/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb +25 -4
- metadata +37 -35
- metadata.gz.sig +0 -0
- data/test/multiverse/suites/resque/resque_setup.rb +0 -19
- data/test/new_relic/agent/uri_util_test.rb +0 -75
@@ -112,32 +112,36 @@ class NewRelicServiceTest < Test::Unit::TestCase
|
|
112
112
|
# testing that the CA file we ship actually validates our server's
|
113
113
|
# certificate. It's used for customers who enable verify_certificate
|
114
114
|
def test_cert_file
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
if internet_connection?
|
116
|
+
require 'socket'
|
117
|
+
require 'openssl'
|
118
|
+
|
119
|
+
s = TCPSocket.new 'collector.newrelic.com', 443
|
120
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
121
|
+
ctx.ca_file = @service.cert_file_path
|
122
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
123
|
+
s = OpenSSL::SSL::SSLSocket.new s, ctx
|
124
|
+
s.connect
|
124
125
|
# should not raise an error
|
126
|
+
end
|
125
127
|
end
|
126
128
|
|
127
129
|
# see above, but for staging, as well. This allows us to test new
|
128
130
|
# certificates in a non-customer-facing place before setting them
|
129
131
|
# live.
|
130
132
|
def test_staging_cert_file
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
133
|
+
if internet_connection?
|
134
|
+
require 'socket'
|
135
|
+
require 'openssl'
|
136
|
+
|
137
|
+
s = TCPSocket.new 'staging-collector.newrelic.com', 443
|
138
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
139
|
+
ctx.ca_file = @service.cert_file_path
|
140
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
141
|
+
s = OpenSSL::SSL::SSLSocket.new s, ctx
|
142
|
+
s.connect
|
143
|
+
# should not raise an error
|
144
|
+
end
|
141
145
|
end
|
142
146
|
|
143
147
|
def test_initialize_uses_correct_license_key_settings
|
@@ -143,18 +143,6 @@ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
|
|
143
143
|
assert_equal(1, @engine.metrics.size)
|
144
144
|
end
|
145
145
|
|
146
|
-
def test_record_metrics_accepts_explicit_scope
|
147
|
-
in_transaction('scopey') do
|
148
|
-
@engine.record_metrics('foo', 42, :scoped => true, :scope => 'not scopey')
|
149
|
-
end
|
150
|
-
unscoped_stats = @engine.get_stats('foo', false)
|
151
|
-
scoped_stats_scopey = @engine.get_stats('foo', true, true, 'scopey')
|
152
|
-
scoped_stats_not_scopey = @engine.get_stats('foo', true, true, 'not scopey')
|
153
|
-
assert_equal(1, unscoped_stats.call_count)
|
154
|
-
assert_equal(0, scoped_stats_scopey.call_count)
|
155
|
-
assert_equal(1, scoped_stats_not_scopey.call_count)
|
156
|
-
end
|
157
|
-
|
158
146
|
def test_record_metrics_accepts_block
|
159
147
|
@engine.record_metrics('foo') do |stats|
|
160
148
|
stats.call_count = 999
|
@@ -183,6 +171,35 @@ class NewRelic::Agent::MetricStatsTest < Test::Unit::TestCase
|
|
183
171
|
assert_equal(nthreads * iterations, stats_m2.call_count)
|
184
172
|
end
|
185
173
|
|
174
|
+
def test_record_metrics_internal_writes_to_global_stats_hash_if_no_txn
|
175
|
+
specs = [
|
176
|
+
NewRelic::MetricSpec.new('foo'),
|
177
|
+
NewRelic::MetricSpec.new('foo', 'scope')
|
178
|
+
]
|
179
|
+
|
180
|
+
2.times { @engine.record_metrics_internal(specs, 10, 5) }
|
181
|
+
|
182
|
+
expected = { :call_count => 2, :total_call_time => 20, :total_exclusive_time => 10 }
|
183
|
+
assert_metrics_recorded('foo' => expected, ['foo', 'scope'] => expected)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_record_metrics_internal_writes_to_transaction_stats_hash_if_txn
|
187
|
+
specs = [
|
188
|
+
NewRelic::MetricSpec.new('foo'),
|
189
|
+
NewRelic::MetricSpec.new('foo', 'scope')
|
190
|
+
]
|
191
|
+
|
192
|
+
in_transaction do
|
193
|
+
2.times { @engine.record_metrics_internal(specs, 10, 5) }
|
194
|
+
# still in the txn, so metrics should not be visible in the global stats
|
195
|
+
# hash yet
|
196
|
+
assert_metrics_not_recorded(['foo', ['foo, scope']])
|
197
|
+
end
|
198
|
+
|
199
|
+
expected = { :call_count => 2, :total_call_time => 20, :total_exclusive_time => 10 }
|
200
|
+
assert_metrics_recorded('foo' => expected, ['foo', 'scope'] => expected)
|
201
|
+
end
|
202
|
+
|
186
203
|
def test_transaction_stats_are_tracked_separately
|
187
204
|
in_transaction do
|
188
205
|
@engine.record_metrics('foo', 1)
|
@@ -17,7 +17,7 @@ class NewRelic::Agent::StatsHashTest < Test::Unit::TestCase
|
|
17
17
|
def test_record_accpets_single_metric_spec
|
18
18
|
spec = NewRelic::MetricSpec.new('foo/bar')
|
19
19
|
stats = @hash[spec]
|
20
|
-
stats.expects(:record_data_point).with(42)
|
20
|
+
stats.expects(:record_data_point).with(42, 42)
|
21
21
|
@hash.record(spec, 42)
|
22
22
|
end
|
23
23
|
|
@@ -26,8 +26,8 @@ class NewRelic::Agent::StatsHashTest < Test::Unit::TestCase
|
|
26
26
|
spec2 = NewRelic::MetricSpec.new('foo/bar', 'scope2')
|
27
27
|
stats1 = @hash[spec1]
|
28
28
|
stats2 = @hash[spec2]
|
29
|
-
stats1.expects(:record_data_point).with(42)
|
30
|
-
stats2.expects(:record_data_point).with(42)
|
29
|
+
stats1.expects(:record_data_point).with(42, 42)
|
30
|
+
stats2.expects(:record_data_point).with(42, 42)
|
31
31
|
@hash.record([spec1, spec2], 42)
|
32
32
|
end
|
33
33
|
|
@@ -60,6 +60,27 @@ class NewRelic::Agent::StatsHashTest < Test::Unit::TestCase
|
|
60
60
|
@hash.record(spec, other_stats)
|
61
61
|
end
|
62
62
|
|
63
|
+
def test_record_accepts_exclusive_time_with_numeric
|
64
|
+
spec = NewRelic::MetricSpec.new('foo')
|
65
|
+
stats = @hash[spec]
|
66
|
+
stats.expects(:record_data_point).with(42, 10)
|
67
|
+
@hash.record(spec, 42, 10)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_record_accepts_apdex_t_with_symbol
|
71
|
+
spec = NewRelic::MetricSpec.new('foo')
|
72
|
+
apdex_t = 99
|
73
|
+
1.times { @hash.record(spec, :apdex_s, apdex_t) }
|
74
|
+
2.times { @hash.record(spec, :apdex_t, apdex_t) }
|
75
|
+
3.times { @hash.record(spec, :apdex_f, apdex_t) }
|
76
|
+
stats = @hash[spec]
|
77
|
+
assert_equal(1, stats.apdex_s)
|
78
|
+
assert_equal(2, stats.apdex_t)
|
79
|
+
assert_equal(3, stats.apdex_f)
|
80
|
+
assert_equal(99, stats.min_call_time)
|
81
|
+
assert_equal(99, stats.max_call_time)
|
82
|
+
end
|
83
|
+
|
63
84
|
def test_merge_merges
|
64
85
|
specs = [
|
65
86
|
NewRelic::MetricSpec.new('foo'),
|
@@ -68,11 +68,11 @@ class NewRelic::Agent::StatsTest < Test::Unit::TestCase
|
|
68
68
|
def test_apdex_recording
|
69
69
|
s = NewRelic::Agent::Stats.new
|
70
70
|
|
71
|
-
s.
|
72
|
-
s.
|
71
|
+
s.record_apdex(:apdex_s, 1)
|
72
|
+
s.record_apdex(:apdex_t, 1)
|
73
73
|
|
74
|
-
s.
|
75
|
-
s.
|
74
|
+
s.record_apdex(:apdex_f, 1)
|
75
|
+
s.record_apdex(:apdex_t, 1)
|
76
76
|
|
77
77
|
assert_equal(1, s.apdex_s)
|
78
78
|
assert_equal(1, s.apdex_f)
|
@@ -67,7 +67,7 @@ class NewRelic::Agent::Transaction::PopTest < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_record_jruby_cpu_burn
|
70
|
-
NewRelic::Agent.get_stats_no_scope(NewRelic::Metrics::USER_TIME).expects(:record_data_point).with(1.0)
|
70
|
+
NewRelic::Agent.get_stats_no_scope(NewRelic::Metrics::USER_TIME).expects(:record_data_point).with(1.0, 1.0)
|
71
71
|
record_jruby_cpu_burn(1.0)
|
72
72
|
end
|
73
73
|
|
@@ -954,6 +954,24 @@ class NewRelic::Agent::TransactionSamplerTest < Test::Unit::TestCase
|
|
954
954
|
end
|
955
955
|
end
|
956
956
|
|
957
|
+
def test_build_database_statement_uses_override_obfuscation_adapter_if_connection_config_is_nil
|
958
|
+
with_config(:override_sql_obfuscation_adapter => 'GumbyDB') do
|
959
|
+
config = nil
|
960
|
+
sql = "SELECT * FROM \"horses\" WHERE \"name\" = 'pokey'"
|
961
|
+
statement = @sampler.build_database_statement(sql, config, Proc.new {})
|
962
|
+
assert_equal 'GumbyDB', statement.adapter
|
963
|
+
end
|
964
|
+
end
|
965
|
+
|
966
|
+
def test_build_database_statement_uses_override_obfuscation_adapter_if_connection_config_adapter_is_mysql
|
967
|
+
with_config(:override_sql_obfuscation_adapter => 'GumbyDB') do
|
968
|
+
config = {:adapter => 'mysql'}
|
969
|
+
sql = "SELECT * FROM \"horses\" WHERE \"name\" = 'pokey'"
|
970
|
+
statement = @sampler.build_database_statement(sql, config, nil)
|
971
|
+
assert_equal 'GumbyDB', statement.adapter
|
972
|
+
end
|
973
|
+
end
|
974
|
+
|
957
975
|
class Dummy
|
958
976
|
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
959
977
|
def run(n)
|
@@ -10,6 +10,8 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
def setup
|
12
12
|
@txn = NewRelic::Agent::Transaction.new
|
13
|
+
@stats_engine = NewRelic::Agent.instance.stats_engine
|
14
|
+
@stats_engine.reset_stats
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_request_parsing__none
|
@@ -63,47 +65,29 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
63
65
|
assert_equal 500, txn.queue_time
|
64
66
|
end
|
65
67
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
assert_equal 0, stats.apdex_s
|
70
|
-
assert_equal 0, stats.apdex_t
|
71
|
-
assert_equal 1, stats.apdex_f
|
68
|
+
def test_apdex_bucket_counts_errors_as_frustrating
|
69
|
+
bucket = NewRelic::Agent::Transaction.apdex_bucket(0.1, true, 2)
|
70
|
+
assert_equal(:apdex_f, bucket)
|
72
71
|
end
|
73
72
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 0.5, false)
|
78
|
-
end
|
79
|
-
assert_equal 1, stats.apdex_s
|
80
|
-
assert_equal 0, stats.apdex_t
|
81
|
-
assert_equal 0, stats.apdex_f
|
73
|
+
def test_apdex_bucket_counts_values_under_apdex_t_as_satisfying
|
74
|
+
bucket = NewRelic::Agent::Transaction.apdex_bucket(0.5, false, 1)
|
75
|
+
assert_equal(:apdex_s, bucket)
|
82
76
|
end
|
83
77
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
assert_equal 0, stats.apdex_s
|
90
|
-
assert_equal 1, stats.apdex_t
|
91
|
-
assert_equal 0, stats.apdex_f
|
78
|
+
def test_apdex_bucket_counts_values_of_1_to_4x_apdex_t_as_tolerating
|
79
|
+
bucket = NewRelic::Agent::Transaction.apdex_bucket(1.01, false, 1)
|
80
|
+
assert_equal(:apdex_t, bucket)
|
81
|
+
bucket = NewRelic::Agent::Transaction.apdex_bucket(3.99, false, 1)
|
82
|
+
assert_equal(:apdex_t, bucket)
|
92
83
|
end
|
93
84
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 4.5, false)
|
98
|
-
end
|
99
|
-
assert_equal 0, stats.apdex_s
|
100
|
-
assert_equal 0, stats.apdex_t
|
101
|
-
assert_equal 1, stats.apdex_f
|
85
|
+
def test_apdex_bucket_count_values_over_4x_apdex_t_as_frustrating
|
86
|
+
bucket = NewRelic::Agent::Transaction.apdex_bucket(4.01, false, 1)
|
87
|
+
assert_equal(:apdex_f, bucket)
|
102
88
|
end
|
103
89
|
|
104
90
|
def test_update_apdex_records_correct_apdex_for_key_transaction
|
105
|
-
txn_info = NewRelic::Agent::TransactionInfo.get
|
106
|
-
stats = NewRelic::Agent::Stats.new
|
107
91
|
config = {
|
108
92
|
:web_transactions_apdex => {
|
109
93
|
'Controller/slow/txn' => 4,
|
@@ -112,50 +96,61 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
112
96
|
:apdex => 1
|
113
97
|
}
|
114
98
|
|
115
|
-
|
116
|
-
|
117
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 3.5, false)
|
118
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 5.5, false)
|
119
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 16.5, false)
|
120
|
-
end
|
121
|
-
assert_equal 1, stats.apdex_s
|
122
|
-
assert_equal 1, stats.apdex_t
|
123
|
-
assert_equal 1, stats.apdex_f
|
124
|
-
|
125
|
-
txn_info.transaction.name = 'Controller/fast/txn'
|
126
|
-
with_config(config, :do_not_cast => true) do
|
127
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 0.05, false)
|
128
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 0.2, false)
|
129
|
-
NewRelic::Agent::Transaction.update_apdex(stats, 0.5, false)
|
130
|
-
end
|
131
|
-
assert_equal 2, stats.apdex_s
|
132
|
-
assert_equal 2, stats.apdex_t
|
133
|
-
assert_equal 2, stats.apdex_f
|
99
|
+
freeze_time
|
100
|
+
t0 = Time.now
|
134
101
|
|
135
|
-
|
102
|
+
# Setting the transaction name from within the in_transaction block seems
|
103
|
+
# like cheating, but it mimics the way things are actually done, where we
|
104
|
+
# finalize the transaction name before recording the Apdex metrics.
|
136
105
|
with_config(config, :do_not_cast => true) do
|
137
|
-
|
138
|
-
|
139
|
-
|
106
|
+
in_web_transaction('Controller/slow/txn') do
|
107
|
+
NewRelic::Agent::Transaction.current.name = 'Controller/slow/txn'
|
108
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 3.5, false)
|
109
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 5.5, false)
|
110
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 16.5, false)
|
111
|
+
end
|
112
|
+
assert_metrics_recorded(
|
113
|
+
'Apdex' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 },
|
114
|
+
'Apdex/slow/txn' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 }
|
115
|
+
)
|
116
|
+
|
117
|
+
in_web_transaction('Controller/fast/txn') do
|
118
|
+
NewRelic::Agent::Transaction.current.name = 'Controller/fast/txn'
|
119
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 0.05, false)
|
120
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 0.2, false)
|
121
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 0.5, false)
|
122
|
+
end
|
123
|
+
assert_metrics_recorded(
|
124
|
+
'Apdex' => { :apdex_s => 2, :apdex_t => 2, :apdex_f => 2 },
|
125
|
+
'Apdex/fast/txn' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 }
|
126
|
+
)
|
127
|
+
|
128
|
+
in_web_transaction('Controller/other/txn') do
|
129
|
+
NewRelic::Agent::Transaction.current.name = 'Controller/other/txn'
|
130
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 0.5, false)
|
131
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 2, false)
|
132
|
+
NewRelic::Agent::Transaction.record_apdex(t0 + 5, false)
|
133
|
+
end
|
134
|
+
assert_metrics_recorded(
|
135
|
+
'Apdex' => { :apdex_s => 3, :apdex_t => 3, :apdex_f => 3 },
|
136
|
+
'Apdex/other/txn' => { :apdex_s => 1, :apdex_t => 1, :apdex_f => 1 }
|
137
|
+
)
|
140
138
|
end
|
141
|
-
assert_equal 3, stats.apdex_s
|
142
|
-
assert_equal 3, stats.apdex_t
|
143
|
-
assert_equal 3, stats.apdex_f
|
144
139
|
end
|
145
140
|
|
146
141
|
def test_record_apdex_stores_apdex_t_in_min_and_max
|
147
|
-
stats_engine = NewRelic::Agent.instance.stats_engine
|
148
|
-
stats_engine.reset_stats
|
149
|
-
metric = stub(:apdex_metric_path => 'Apdex/Controller/some/txn')
|
150
|
-
NewRelic::Agent.instance.instance_variable_set(:@stats_engine, stats_engine)
|
151
|
-
|
152
142
|
with_config(:apdex_t => 2.5) do
|
153
|
-
|
143
|
+
in_web_transaction('Controller/some/txn') do
|
144
|
+
NewRelic::Agent::Transaction.current.name = 'Controller/some/txn'
|
145
|
+
NewRelic::Agent::Transaction.record_apdex(Time.now, false)
|
146
|
+
end
|
154
147
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
148
|
+
|
149
|
+
expected = { :min_call_time => 2.5, :max_call_time => 2.5 }
|
150
|
+
assert_metrics_recorded(
|
151
|
+
'Apdex' => expected,
|
152
|
+
'Apdex/some/txn' => expected
|
153
|
+
)
|
159
154
|
end
|
160
155
|
|
161
156
|
def test_start_adds_controller_context_to_txn_stack
|
@@ -213,7 +208,7 @@ class NewRelic::Agent::TransactionTest < Test::Unit::TestCase
|
|
213
208
|
NewRelic::Agent.record_metric("HttpDispatcher", 2.1)
|
214
209
|
NewRelic::Agent::Transaction.stop('txn')
|
215
210
|
|
216
|
-
assert_equal 2.1, options[:
|
211
|
+
assert_equal 2.1, options[:webDuration]
|
217
212
|
end
|
218
213
|
|
219
214
|
def test_parent_returns_parent_transaction_if_there_is_one
|
@@ -254,6 +254,26 @@ module NewRelic
|
|
254
254
|
NewRelic::Agent.record_metric('foo', stats_hash)
|
255
255
|
end
|
256
256
|
|
257
|
+
def test_record_metric_sets_default_hash_values_for_missing_keys
|
258
|
+
dummy_engine = NewRelic::Agent.agent.stats_engine
|
259
|
+
incomplete_stats_hash = {
|
260
|
+
:count => 12,
|
261
|
+
:max => 5,
|
262
|
+
:sum_of_squares => 999
|
263
|
+
}
|
264
|
+
|
265
|
+
expected_stats = NewRelic::Agent::Stats.new()
|
266
|
+
expected_stats.call_count = 12
|
267
|
+
expected_stats.total_call_time = 0.0
|
268
|
+
expected_stats.total_exclusive_time = 0.0
|
269
|
+
expected_stats.min_call_time = 0.0
|
270
|
+
expected_stats.max_call_time = 5
|
271
|
+
expected_stats.sum_of_squares = 999
|
272
|
+
|
273
|
+
dummy_engine.expects(:record_metrics).with('foo', expected_stats)
|
274
|
+
NewRelic::Agent.record_metric('foo', incomplete_stats_hash)
|
275
|
+
end
|
276
|
+
|
257
277
|
def test_increment_metric
|
258
278
|
dummy_engine = NewRelic::Agent.agent.stats_engine
|
259
279
|
dummy_stats = mock
|
@@ -0,0 +1,99 @@
|
|
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 File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
|
6
|
+
|
7
|
+
class DependencyDetectionTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@original_items = DependencyDetection.items
|
11
|
+
DependencyDetection.items = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
DependencyDetection.items = @original_items
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_passes_dependency
|
19
|
+
executed = false
|
20
|
+
|
21
|
+
DependencyDetection.defer do
|
22
|
+
depends_on { true }
|
23
|
+
executes { executed = true }
|
24
|
+
end
|
25
|
+
DependencyDetection.detect!
|
26
|
+
|
27
|
+
assert executed
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_fails_dependency
|
31
|
+
executed = false
|
32
|
+
|
33
|
+
DependencyDetection.defer do
|
34
|
+
depends_on { true }
|
35
|
+
depends_on { false }
|
36
|
+
executes { executed = true }
|
37
|
+
end
|
38
|
+
DependencyDetection.detect!
|
39
|
+
|
40
|
+
assert !executed
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_short_circuits_on_failure
|
44
|
+
executed = false
|
45
|
+
|
46
|
+
# Requires that depends_on would let failures pass through, which it does
|
47
|
+
DependencyDetection.defer do
|
48
|
+
depends_on { false }
|
49
|
+
depends_on { raise "OH NOES"}
|
50
|
+
executes { executed = true }
|
51
|
+
end
|
52
|
+
DependencyDetection.detect!
|
53
|
+
|
54
|
+
assert !executed
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_named_disabling_defaults_to_allowed
|
58
|
+
executed = false
|
59
|
+
|
60
|
+
DependencyDetection.defer do
|
61
|
+
named :testing
|
62
|
+
executes { executed = true }
|
63
|
+
end
|
64
|
+
DependencyDetection.detect!
|
65
|
+
|
66
|
+
assert executed
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_named_disabling_allows_with_explicit_value
|
70
|
+
executed = false
|
71
|
+
|
72
|
+
DependencyDetection.defer do
|
73
|
+
named :testing
|
74
|
+
executes { executed = true }
|
75
|
+
end
|
76
|
+
|
77
|
+
with_config(:disable_testing => false) do
|
78
|
+
DependencyDetection.detect!
|
79
|
+
end
|
80
|
+
|
81
|
+
assert executed
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_named_disabling
|
85
|
+
executed = false
|
86
|
+
|
87
|
+
DependencyDetection.defer do
|
88
|
+
named :testing
|
89
|
+
executes { executed = true }
|
90
|
+
end
|
91
|
+
|
92
|
+
with_config(:disable_testing => true) do
|
93
|
+
DependencyDetection.detect!
|
94
|
+
end
|
95
|
+
|
96
|
+
assert !executed
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|