newrelic_rpm 3.6.3.104 → 3.6.3.105.beta
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/lib/new_relic/agent/agent.rb +5 -16
- data/lib/new_relic/agent/sampler.rb +3 -12
- data/lib/new_relic/agent/sampler_collection.rb +53 -0
- data/lib/new_relic/agent/stats_engine.rb +1 -2
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +0 -1
- data/lib/new_relic/agent/stats_engine/samplers.rb +8 -84
- data/lib/new_relic/local_environment.rb +5 -2
- data/test/new_relic/agent/agent_test.rb +8 -0
- data/test/new_relic/agent/method_tracer_test.rb +20 -30
- data/test/new_relic/agent/rpm_agent_test.rb +1 -0
- data/test/new_relic/agent/sampler_collection_test.rb +73 -0
- data/test/new_relic/agent/stats_engine/samplers_test.rb +0 -26
- data/test/new_relic/agent_test.rb +1 -0
- data/test/new_relic/control_test.rb +2 -2
- data/test/new_relic/local_environment_test.rb +37 -0
- metadata +5 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
@@ -17,6 +17,7 @@ require 'new_relic/agent/thread_profiler'
|
|
17
17
|
require 'new_relic/agent/event_listener'
|
18
18
|
require 'new_relic/agent/cross_app_monitor'
|
19
19
|
require 'new_relic/agent/request_sampler'
|
20
|
+
require 'new_relic/agent/sampler_collection'
|
20
21
|
require 'new_relic/environment_report'
|
21
22
|
|
22
23
|
module NewRelic
|
@@ -42,6 +43,7 @@ module NewRelic
|
|
42
43
|
@transaction_rules = NewRelic::Agent::RulesEngine.new
|
43
44
|
@metric_rules = NewRelic::Agent::RulesEngine.new
|
44
45
|
@request_sampler = NewRelic::Agent::RequestSampler.new(@events)
|
46
|
+
@harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events)
|
45
47
|
|
46
48
|
@connect_state = :pending
|
47
49
|
@connect_attempts = 0
|
@@ -79,6 +81,7 @@ module NewRelic
|
|
79
81
|
attr_reader :thread_profiler
|
80
82
|
# error collector is a simple collection of recorded errors
|
81
83
|
attr_reader :error_collector
|
84
|
+
attr_reader :harvest_samplers
|
82
85
|
# whether we should record raw, obfuscated, or no sql
|
83
86
|
attr_reader :record_sql
|
84
87
|
# a configuration for the Real User Monitoring system -
|
@@ -203,7 +206,6 @@ module NewRelic
|
|
203
206
|
# Don't ever check to see if this is a spawner. If we're in a forked process
|
204
207
|
# I'm pretty sure we're not also forking new instances.
|
205
208
|
start_worker_thread(options)
|
206
|
-
@stats_engine.start_sampler_thread
|
207
209
|
end
|
208
210
|
|
209
211
|
# True if we have initialized and completed 'start'
|
@@ -521,21 +523,7 @@ module NewRelic
|
|
521
523
|
end
|
522
524
|
|
523
525
|
def add_harvest_sampler(subclass)
|
524
|
-
|
525
|
-
::NewRelic::Agent.logger.debug "#{subclass.name} not supported on this platform." and return unless subclass.supported_on_this_platform?
|
526
|
-
sampler = subclass.new
|
527
|
-
if subclass.use_harvest_sampler?
|
528
|
-
stats_engine.add_harvest_sampler sampler
|
529
|
-
::NewRelic::Agent.logger.debug "Registered #{subclass.name} for harvest time sampling"
|
530
|
-
else
|
531
|
-
stats_engine.add_sampler sampler
|
532
|
-
::NewRelic::Agent.logger.debug "Registered #{subclass.name} for periodic sampling"
|
533
|
-
end
|
534
|
-
rescue NewRelic::Agent::Sampler::Unsupported => e
|
535
|
-
::NewRelic::Agent.logger.info "#{subclass} sampler not available: #{e}"
|
536
|
-
rescue => e
|
537
|
-
::NewRelic::Agent.logger.error "Error registering sampler:", e
|
538
|
-
end
|
526
|
+
@harvest_samplers.add_sampler(subclass)
|
539
527
|
end
|
540
528
|
|
541
529
|
private
|
@@ -1054,6 +1042,7 @@ module NewRelic
|
|
1054
1042
|
now = Time.now
|
1055
1043
|
::NewRelic::Agent.logger.debug "Sending data to New Relic Service"
|
1056
1044
|
|
1045
|
+
@events.notify(:before_harvest)
|
1057
1046
|
@service.session do # use http keep-alive
|
1058
1047
|
harvest_and_send_errors
|
1059
1048
|
harvest_and_send_slowest_sample
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
-
|
4
|
+
#
|
5
5
|
# A Sampler is used to capture meaningful metrics in a background thread
|
6
|
-
# periodically. They will
|
7
|
-
# data
|
8
|
-
# returns false.
|
6
|
+
# periodically. They will be invoked about once a minute, each time the agent
|
7
|
+
# sends data to New Relic's servers.
|
9
8
|
#
|
10
9
|
# Samplers can be added to New Relic by subclassing NewRelic::Agent::Sampler.
|
11
10
|
# Instances are created when the agent is enabled and installed. Subclasses
|
@@ -29,12 +28,6 @@ module NewRelic
|
|
29
28
|
true
|
30
29
|
end
|
31
30
|
|
32
|
-
# Override to use the periodic sampler instead of running the sampler on the
|
33
|
-
# minute during harvests.
|
34
|
-
def self.use_harvest_sampler?
|
35
|
-
true
|
36
|
-
end
|
37
|
-
|
38
31
|
def self.sampler_classes
|
39
32
|
@sampler_classes
|
40
33
|
end
|
@@ -46,8 +39,6 @@ module NewRelic
|
|
46
39
|
def poll
|
47
40
|
raise "Implement in the subclass"
|
48
41
|
end
|
49
|
-
|
50
|
-
|
51
42
|
end
|
52
43
|
end
|
53
44
|
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
module NewRelic
|
6
|
+
module Agent
|
7
|
+
class SamplerCollection
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
def initialize(event_listener)
|
11
|
+
@samplers = []
|
12
|
+
event_listener.subscribe(:before_harvest) { poll_samplers }
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(&blk)
|
16
|
+
@samplers.each(&blk)
|
17
|
+
end
|
18
|
+
|
19
|
+
def sampler_class_registered?(sampler_class)
|
20
|
+
self.any? { |s| s.class == sampler_class }
|
21
|
+
end
|
22
|
+
|
23
|
+
def poll_samplers
|
24
|
+
@samplers.delete_if do |sampler|
|
25
|
+
begin
|
26
|
+
sampler.poll
|
27
|
+
false # it's okay. don't delete it.
|
28
|
+
rescue => e
|
29
|
+
::NewRelic::Agent.logger.warn("Removing #{sampler} from list", e)
|
30
|
+
true # remove the sampler
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_sampler(sampler_class)
|
36
|
+
if sampler_class.supported_on_this_platform?
|
37
|
+
if !sampler_class_registered?(sampler_class)
|
38
|
+
@samplers << sampler_class.new
|
39
|
+
::NewRelic::Agent.logger.debug("Registered #{sampler_class.name} for harvest time sampling.")
|
40
|
+
else
|
41
|
+
::NewRelic::Agent.logger.warn("Ignoring addition of #{sampler_class.name} because it is already registered.")
|
42
|
+
end
|
43
|
+
else
|
44
|
+
::NewRelic::Agent.logger.debug("#{sampler_class.name} not supported on this platform.")
|
45
|
+
end
|
46
|
+
rescue NewRelic::Agent::Sampler::Unsupported => e
|
47
|
+
::NewRelic::Agent.logger.info("#{sampler_class.name} not available: #{e}")
|
48
|
+
rescue => e
|
49
|
+
::NewRelic::Agent.logger.error("Error registering sampler:", e)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -21,11 +21,10 @@ module NewRelic
|
|
21
21
|
Thread::current[:newrelic_scope_stack] = nil
|
22
22
|
@stats_lock = Mutex.new
|
23
23
|
@stats_hash = StatsHash.new
|
24
|
-
start_sampler_thread
|
25
24
|
end
|
26
25
|
|
27
26
|
# All access to the @stats_hash ivar should be funnelled through this
|
28
|
-
# method to ensure thread-safety.
|
27
|
+
# method to ensure thread-safety.
|
29
28
|
def with_stats_lock
|
30
29
|
@stats_lock.synchronize { yield }
|
31
30
|
end
|
@@ -118,7 +118,6 @@ module NewRelic
|
|
118
118
|
# unsent metrics, clear out stats cache, and return the current
|
119
119
|
# stats.
|
120
120
|
def harvest_timeslice_data(old_stats_hash, rules_engine=RulesEngine.new)
|
121
|
-
poll harvest_samplers
|
122
121
|
snapshot = reset_stats
|
123
122
|
snapshot = apply_rules_to_metric_data(rules_engine, snapshot)
|
124
123
|
snapshot.merge!(old_stats_hash)
|
@@ -4,100 +4,24 @@
|
|
4
4
|
|
5
5
|
module NewRelic
|
6
6
|
module Agent
|
7
|
+
# This module exists only for backwards-compatibility reasons.
|
8
|
+
# Sampler functionality is now controlled by the SamplerManager class.
|
9
|
+
# @deprecated
|
7
10
|
class StatsEngine
|
8
11
|
module Shim # :nodoc:
|
9
12
|
def add_sampler(*args); end
|
10
13
|
def add_harvest_sampler(*args); end
|
11
14
|
def start_sampler_thread(*args); end
|
12
15
|
end
|
13
|
-
|
14
|
-
# Contains statistics engine extensions to support the concept of samplers
|
15
|
-
module Samplers
|
16
|
-
|
17
|
-
# By default a sampler polls on harvest time, once a minute. However you can
|
18
|
-
# override #use_harvest_sampler? to return false and it will sample
|
19
|
-
# every POLL_PERIOD seconds on a background thread.
|
20
|
-
POLL_PERIOD = 20
|
21
|
-
|
22
|
-
# starts the sampler thread which runs periodically, rather than
|
23
|
-
# at harvest time. This is deprecated, and should not actually
|
24
|
-
# be used - mo threads mo problems
|
25
|
-
#
|
26
|
-
# returns unless there are actually periodic samplers to run
|
27
|
-
def start_sampler_thread
|
28
|
-
|
29
|
-
return if @sampler_thread && @sampler_thread.alive?
|
30
|
-
|
31
|
-
# start up a thread that will periodically poll for metric samples
|
32
|
-
return if periodic_samplers.empty?
|
33
|
-
|
34
|
-
@sampler_thread = NewRelic::Agent::AgentThread.new('Sampler Tasks') do
|
35
|
-
loop do
|
36
|
-
now = Time.now
|
37
|
-
begin
|
38
|
-
sleep POLL_PERIOD
|
39
|
-
poll periodic_samplers
|
40
|
-
ensure
|
41
|
-
duration = (Time.now - now).to_f
|
42
|
-
NewRelic::Agent.record_metric('Supportability/Samplers', duration)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
public
|
50
|
-
|
51
|
-
# Add an instance of Sampler to be invoked about every 10 seconds on a background
|
52
|
-
# thread.
|
53
|
-
def add_sampler(sampler)
|
54
|
-
add_sampler_to(periodic_samplers, sampler)
|
55
|
-
log_added_sampler('periodic', sampler)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Add a sampler to be invoked just before each harvest.
|
59
|
-
def add_harvest_sampler(sampler)
|
60
|
-
add_sampler_to(harvest_samplers, sampler)
|
61
|
-
log_added_sampler('harvest-time', sampler)
|
62
|
-
end
|
63
|
-
|
64
|
-
def harvest_samplers
|
65
|
-
@harvest_samplers ||= []
|
66
|
-
end
|
67
|
-
|
68
|
-
def periodic_samplers
|
69
|
-
@periodic_samplers ||= []
|
70
|
-
end
|
71
|
-
|
72
16
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
if sampler_array.any? { |s| s.class == sampler.class }
|
77
|
-
NewRelic::Agent.logger.warn "Ignoring addition of #{sampler.inspect} because it is already registered."
|
78
|
-
else
|
79
|
-
sampler_array << sampler
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def log_added_sampler(type, sampler)
|
84
|
-
::NewRelic::Agent.logger.debug "Adding #{type} sampler: #{sampler.id}"
|
17
|
+
module Samplers
|
18
|
+
def add_sampler(*args)
|
19
|
+
NewRelic::Agent.logger.warn("Ignoring request to add periodic sampler - add_sampler is deprecated")
|
85
20
|
end
|
86
21
|
|
87
|
-
|
88
|
-
|
89
|
-
def poll(samplers)
|
90
|
-
samplers.delete_if do |sampled_item|
|
91
|
-
begin
|
92
|
-
sampled_item.poll
|
93
|
-
false # it's okay. don't delete it.
|
94
|
-
rescue => e
|
95
|
-
::NewRelic::Agent.logger.warn "Removing #{sampled_item} from list", e
|
96
|
-
true # remove the sampler
|
97
|
-
end
|
98
|
-
end
|
22
|
+
def add_harvest_sampler
|
23
|
+
NewRelic::Agent.logger.warn("Ignoring request to add harvest sampler - add_harvest_sampler is deprecated")
|
99
24
|
end
|
100
|
-
|
101
25
|
end
|
102
26
|
end
|
103
27
|
end
|
@@ -66,7 +66,8 @@ module NewRelic
|
|
66
66
|
|
67
67
|
# Sets the @mongrel instance variable if we can find a Mongrel::HttpServer
|
68
68
|
def mongrel
|
69
|
-
return @mongrel if @
|
69
|
+
return @mongrel if @looked_for_mongrel
|
70
|
+
@looked_for_mongrel = true
|
70
71
|
if defined?(::Mongrel) && defined?(::Mongrel::HttpServer) && working_jruby?
|
71
72
|
@mongrel = find_class_in_object_space(::Mongrel::HttpServer)
|
72
73
|
end
|
@@ -129,7 +130,6 @@ module NewRelic
|
|
129
130
|
@discovered_dispatcher = :mongrel
|
130
131
|
|
131
132
|
# Get the port from the server if it's started
|
132
|
-
|
133
133
|
if mongrel && mongrel.respond_to?(:port)
|
134
134
|
@dispatcher_instance_id = mongrel.port.to_s
|
135
135
|
end
|
@@ -143,6 +143,9 @@ module NewRelic
|
|
143
143
|
|
144
144
|
# Still can't find the port. Let's look at ARGV to fall back
|
145
145
|
@dispatcher_instance_id = default_port if @dispatcher_instance_id.nil?
|
146
|
+
|
147
|
+
# Might not have server yet, so allow one more check later on first request
|
148
|
+
@looked_for_mongrel = false
|
146
149
|
end
|
147
150
|
|
148
151
|
def check_for_unicorn
|
@@ -13,6 +13,7 @@ module NewRelic
|
|
13
13
|
super
|
14
14
|
@agent = NewRelic::Agent::Agent.new
|
15
15
|
@agent.service = default_service
|
16
|
+
@agent.stubs(:start_worker_thread)
|
16
17
|
end
|
17
18
|
|
18
19
|
#
|
@@ -65,6 +66,13 @@ module NewRelic
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
69
|
+
def test_transmit_data_should_emit_before_harvest_event
|
70
|
+
got_it = false
|
71
|
+
@agent.events.subscribe(:before_harvest) { got_it = true }
|
72
|
+
@agent.instance_eval { transmit_data }
|
73
|
+
assert(got_it)
|
74
|
+
end
|
75
|
+
|
68
76
|
def test_transmit_data_should_transmit
|
69
77
|
@agent.service.expects(:metric_data).at_least_once
|
70
78
|
@agent.instance_eval { transmit_data }
|
@@ -70,6 +70,9 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
70
70
|
@scope_listener = NewRelic::Agent::MockScopeListener.new
|
71
71
|
@old_sampler = NewRelic::Agent.instance.transaction_sampler
|
72
72
|
NewRelic::Agent.instance.stubs(:transaction_sampler).returns(@scope_listener)
|
73
|
+
|
74
|
+
freeze_time
|
75
|
+
|
73
76
|
super
|
74
77
|
end
|
75
78
|
|
@@ -91,14 +94,13 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
91
94
|
|
92
95
|
def test_trace_execution_scoped_records_metric_data
|
93
96
|
metric = "hello"
|
94
|
-
|
97
|
+
freeze_time
|
95
98
|
self.class.trace_execution_scoped(metric) do
|
96
|
-
|
99
|
+
advance_time 0.05
|
97
100
|
end
|
98
|
-
elapsed = Time.now - t1
|
99
101
|
|
100
102
|
stats = @stats_engine.get_stats(metric)
|
101
|
-
check_time stats.total_call_time
|
103
|
+
check_time 0.05, stats.total_call_time
|
102
104
|
assert_equal 1, stats.call_count
|
103
105
|
end
|
104
106
|
|
@@ -111,14 +113,12 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
111
113
|
|
112
114
|
def test_basic__original_api
|
113
115
|
metric = "hello"
|
114
|
-
t1 = Time.now
|
115
116
|
self.class.trace_method_execution(metric, true, true, true) do
|
116
|
-
|
117
|
+
advance_time(0.05)
|
117
118
|
end
|
118
|
-
elapsed = Time.now - t1
|
119
119
|
|
120
120
|
stats = @stats_engine.get_stats(metric)
|
121
|
-
check_time stats.total_call_time
|
121
|
+
check_time 0.05, stats.total_call_time
|
122
122
|
assert_equal 1, stats.call_count
|
123
123
|
assert_equal metric, @scope_listener.scopes.last
|
124
124
|
end
|
@@ -128,9 +128,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
128
128
|
@metric_name = METRIC
|
129
129
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
130
130
|
|
131
|
-
t1 = Time.now
|
132
131
|
method_to_be_traced 1,2,3,true,METRIC
|
133
|
-
elapsed = Time.now - t1
|
134
132
|
|
135
133
|
begin
|
136
134
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
@@ -140,7 +138,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
140
138
|
|
141
139
|
|
142
140
|
stats = @stats_engine.get_stats(METRIC)
|
143
|
-
check_time stats.total_call_time
|
141
|
+
check_time 0.05, stats.total_call_time
|
144
142
|
assert_equal 1, stats.call_count
|
145
143
|
assert_equal METRIC, @scope_listener.scopes.last
|
146
144
|
end
|
@@ -216,9 +214,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
216
214
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
217
215
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
218
216
|
|
219
|
-
t1 = Time.now
|
220
217
|
method_to_be_traced 1,2,3,true,METRIC
|
221
|
-
elapsed = Time.now - t1
|
222
218
|
|
223
219
|
begin
|
224
220
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
@@ -227,7 +223,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
227
223
|
end
|
228
224
|
|
229
225
|
stats = @stats_engine.get_stats(METRIC)
|
230
|
-
check_time stats.total_call_time
|
226
|
+
check_time 0.05, stats.total_call_time
|
231
227
|
assert_equal 1, stats.call_count
|
232
228
|
assert_equal METRIC, @scope_listener.scopes.last
|
233
229
|
assert(METRIC != @scope_listener.scopes[-2],
|
@@ -240,9 +236,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
240
236
|
expected_metric = "1.2"
|
241
237
|
self.class.add_method_tracer :method_to_be_traced, metric_code
|
242
238
|
|
243
|
-
t1 = Time.now
|
244
239
|
method_to_be_traced 1,2,3,true,expected_metric
|
245
|
-
elapsed = Time.now - t1
|
246
240
|
|
247
241
|
begin
|
248
242
|
self.class.remove_method_tracer :method_to_be_traced, metric_code
|
@@ -251,7 +245,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
251
245
|
end
|
252
246
|
|
253
247
|
stats = @stats_engine.get_stats(expected_metric)
|
254
|
-
check_time stats.total_call_time
|
248
|
+
check_time 0.05, stats.total_call_time
|
255
249
|
assert_equal 1, stats.call_count
|
256
250
|
assert_equal expected_metric, @scope_listener.scopes.last
|
257
251
|
end
|
@@ -259,15 +253,12 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
259
253
|
def test_trace_method_with_block
|
260
254
|
self.class.add_method_tracer :method_with_block, METRIC
|
261
255
|
|
262
|
-
|
263
|
-
|
264
|
-
assert_equal METRIC, scope
|
265
|
-
sleep 0.1 # pad the test a bit to increase the margin of error
|
256
|
+
method_with_block(1,2,3,true,METRIC) do
|
257
|
+
advance_time 0.1
|
266
258
|
end
|
267
|
-
elapsed = Time.now - t1
|
268
259
|
|
269
260
|
stats = @stats_engine.get_stats(METRIC)
|
270
|
-
check_time stats.total_call_time
|
261
|
+
check_time 0.15, stats.total_call_time
|
271
262
|
assert_equal 1, stats.call_count
|
272
263
|
assert_equal METRIC, @scope_listener.scopes.last
|
273
264
|
end
|
@@ -282,9 +273,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
282
273
|
self.class.add_method_tracer :method_to_be_traced, METRIC
|
283
274
|
self.class.remove_method_tracer :method_to_be_traced, METRIC
|
284
275
|
|
285
|
-
t1 = Time.now
|
286
276
|
method_to_be_traced 1,2,3,false,METRIC
|
287
|
-
elapsed = Time.now - t1
|
288
277
|
|
289
278
|
stats = @stats_engine.get_stats(METRIC)
|
290
279
|
assert stats.call_count == 0
|
@@ -307,7 +296,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
307
296
|
def test_multiple_metrics__scoped
|
308
297
|
metrics = %w[first second third]
|
309
298
|
self.class.trace_execution_scoped metrics do
|
310
|
-
|
299
|
+
advance_time 0.05
|
311
300
|
end
|
312
301
|
elapsed = @stats_engine.get_stats('first').total_call_time
|
313
302
|
metrics.map{|name| @stats_engine.get_stats name}.each do | m |
|
@@ -320,7 +309,7 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
320
309
|
def test_multiple_metrics__unscoped
|
321
310
|
metrics = %w[first second third]
|
322
311
|
self.class.trace_execution_unscoped metrics do
|
323
|
-
|
312
|
+
advance_time 0.05
|
324
313
|
end
|
325
314
|
elapsed = @stats_engine.get_stats('first').total_call_time
|
326
315
|
metrics.map{|name| @stats_engine.get_stats name}.each do | m |
|
@@ -370,23 +359,24 @@ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
|
|
370
359
|
end
|
371
360
|
|
372
361
|
def check_time(t1, t2)
|
373
|
-
assert_in_delta t2, t1, 0.
|
362
|
+
assert_in_delta t2, t1, 0.001
|
374
363
|
end
|
375
364
|
|
376
365
|
# =======================================================
|
377
366
|
# test methods to be traced
|
378
367
|
def method_to_be_traced(x, y, z, is_traced, expected_metric)
|
379
|
-
|
368
|
+
advance_time 0.05
|
380
369
|
assert x == 1
|
381
370
|
assert y == 2
|
382
371
|
assert z == 3
|
383
372
|
end
|
384
373
|
|
385
374
|
def method_with_block(x, y, z, is_traced, expected_metric, &block)
|
386
|
-
|
375
|
+
advance_time 0.05
|
387
376
|
assert x == 1
|
388
377
|
assert y == 2
|
389
378
|
assert z == 3
|
379
|
+
yield
|
390
380
|
end
|
391
381
|
|
392
382
|
def method_c1
|
@@ -0,0 +1,73 @@
|
|
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 SamplerCollectionTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
class DummySampler
|
10
|
+
attr_reader :id
|
11
|
+
def self.supported_on_this_platform?; true; end
|
12
|
+
def poll; end
|
13
|
+
end
|
14
|
+
class DummySampler2 < DummySampler; end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@events = NewRelic::Agent::EventListener.new
|
18
|
+
@collection = NewRelic::Agent::SamplerCollection.new(@events)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_add_sampler_adds_a_sampler_of_requested_class
|
22
|
+
@collection.add_sampler(DummySampler)
|
23
|
+
assert_equal(1, @collection.to_a.size)
|
24
|
+
assert_equal(DummySampler, @collection.to_a.first.class)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_add_sampler_does_add_non_dups
|
28
|
+
@collection.add_sampler(DummySampler)
|
29
|
+
@collection.add_sampler(DummySampler2)
|
30
|
+
assert_equal(2, @collection.to_a.size)
|
31
|
+
assert_equal([DummySampler, DummySampler2], @collection.map { |s| s.class })
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_add_sampler_does_not_add_dups
|
35
|
+
@collection.add_sampler(DummySampler)
|
36
|
+
@collection.add_sampler(DummySampler)
|
37
|
+
assert_equal(1, @collection.to_a.size)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_add_sampler_omits_unsupported_samplers
|
41
|
+
DummySampler.stubs(:supported_on_this_platform?).returns(false)
|
42
|
+
@collection.add_sampler(DummySampler)
|
43
|
+
assert_equal(0, @collection.to_a.size)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_add_sampler_swallows_exceptions_during_sampler_creation
|
47
|
+
DummySampler.stubs(:new).raises(StandardError)
|
48
|
+
assert_nothing_raised { @collection.add_sampler(DummySampler) }
|
49
|
+
assert_equal(0, @collection.to_a.size)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_poll_samplers_polls_samplers
|
53
|
+
@collection.add_sampler(DummySampler)
|
54
|
+
@collection.add_sampler(DummySampler2)
|
55
|
+
@collection.each { |s| s.expects(:poll) }
|
56
|
+
@collection.poll_samplers
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_poll_samplers_removes_busted_samplers_and_keeps_happy_ones
|
60
|
+
@collection.add_sampler(DummySampler)
|
61
|
+
@collection.add_sampler(DummySampler2)
|
62
|
+
good_sampler, bad_sampler = @collection.to_a
|
63
|
+
bad_sampler.stubs(:poll).raises('boo')
|
64
|
+
assert_nothing_raised { @collection.poll_samplers }
|
65
|
+
assert_equal(1, @collection.to_a.size)
|
66
|
+
assert_equal([good_sampler], @collection.to_a)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_polls_samplers_on_before_harvest_event
|
70
|
+
@collection.expects(:poll_samplers)
|
71
|
+
@events.notify(:before_harvest)
|
72
|
+
end
|
73
|
+
end
|
@@ -20,24 +20,6 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
20
20
|
NewRelic::Agent.instance.stubs(:stats_engine).returns(@stats_engine)
|
21
21
|
end
|
22
22
|
|
23
|
-
def test_can_add_harvest_sampler
|
24
|
-
samplers = OurSamplers.new
|
25
|
-
sampler = OurSampler.new
|
26
|
-
|
27
|
-
samplers.add_harvest_sampler(sampler)
|
28
|
-
|
29
|
-
assert_equal [sampler], samplers.harvest_samplers
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_cannot_add_harvest_sampler_twice
|
33
|
-
samplers = OurSamplers.new
|
34
|
-
samplers.add_harvest_sampler(OurSampler.new)
|
35
|
-
first_list = samplers.harvest_samplers.dup
|
36
|
-
|
37
|
-
samplers.add_harvest_sampler(OurSampler.new)
|
38
|
-
assert_equal first_list, samplers.harvest_samplers
|
39
|
-
end
|
40
|
-
|
41
23
|
def test_cpu_sampler_records_user_and_system_time
|
42
24
|
timeinfo0 = mock
|
43
25
|
timeinfo0.stubs(:utime).returns(10.0)
|
@@ -108,14 +90,6 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Test::Unit::TestCase
|
|
108
90
|
end
|
109
91
|
end
|
110
92
|
|
111
|
-
def test_load_samplers
|
112
|
-
@stats_engine.expects(:add_harvest_sampler).at_least_once unless defined? JRuby
|
113
|
-
@stats_engine.expects(:add_sampler).never
|
114
|
-
NewRelic::Control.instance.load_samplers
|
115
|
-
sampler_count = 4
|
116
|
-
assert_equal sampler_count, NewRelic::Agent::Sampler.sampler_classes.size, NewRelic::Agent::Sampler.sampler_classes.inspect
|
117
|
-
end
|
118
|
-
|
119
93
|
def test_memory__is_supported
|
120
94
|
NewRelic::Agent::Samplers::MemorySampler.stubs(:platform).returns 'windows'
|
121
95
|
assert !NewRelic::Agent::Samplers::MemorySampler.supported_on_this_platform? || defined? JRuby
|
@@ -183,7 +183,7 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
183
183
|
NewRelic::Agent.shutdown
|
184
184
|
with_config(:disable_samplers => false, :agent_enabled => true) do
|
185
185
|
NewRelic::Control.instance.init_plugin
|
186
|
-
assert NewRelic::Agent.instance.
|
186
|
+
assert NewRelic::Agent.instance.harvest_samplers.any?
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
@@ -191,7 +191,7 @@ class NewRelic::ControlTest < Test::Unit::TestCase
|
|
191
191
|
NewRelic::Agent.shutdown
|
192
192
|
with_config(:disable_samplers => true, :agent_enabled => true) do
|
193
193
|
NewRelic::Control.instance.init_plugin
|
194
|
-
assert NewRelic::Agent.instance.
|
194
|
+
assert !NewRelic::Agent.instance.harvest_samplers.any?
|
195
195
|
end
|
196
196
|
end
|
197
197
|
end
|
@@ -51,6 +51,43 @@ class NewRelic::LocalEnvironmentTest < Test::Unit::TestCase
|
|
51
51
|
Object.send(:remove_const, :PhusionPassenger)
|
52
52
|
end
|
53
53
|
|
54
|
+
# LocalEnvironment won't talk to ObjectSpace on JRuby, and these tests are
|
55
|
+
# around that interaction, so we don't run them on JRuby.
|
56
|
+
unless defined?(JRuby)
|
57
|
+
def test_mongrel_only_checks_once
|
58
|
+
define_mongrel
|
59
|
+
|
60
|
+
# One call from LocalEnvironment's initialize, second from first #mongrel call.
|
61
|
+
# All the rest shouldn't call into ObjectSpace
|
62
|
+
ObjectSpace.expects(:each_object).with(::Mongrel::HttpServer).twice
|
63
|
+
|
64
|
+
e = NewRelic::LocalEnvironment.new
|
65
|
+
5.times { e.mongrel }
|
66
|
+
assert_nil e.mongrel
|
67
|
+
ensure
|
68
|
+
Object.send(:remove_const, :Mongrel)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_check_for_mongrel_allows_one_more_check
|
72
|
+
define_mongrel
|
73
|
+
|
74
|
+
ObjectSpace.expects(:each_object).with(::Mongrel::HttpServer).at_least(2)
|
75
|
+
|
76
|
+
e = NewRelic::LocalEnvironment.new
|
77
|
+
e.send(:check_for_mongrel)
|
78
|
+
ensure
|
79
|
+
Object.send(:remove_const, :Mongrel)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def define_mongrel
|
84
|
+
class << self
|
85
|
+
module ::Mongrel
|
86
|
+
class HttpServer
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
54
91
|
|
55
92
|
def test_default_port
|
56
93
|
e = NewRelic::LocalEnvironment.new
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic_rpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.3.
|
5
|
-
prerelease:
|
4
|
+
version: 3.6.3.105.beta
|
5
|
+
prerelease: 10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jason Clark
|
@@ -41,7 +41,7 @@ cert_chain:
|
|
41
41
|
cHUySWFQWE92bTNUOEc0TzZxWnZobkxoL1VpZW4rK0RqOGVGQmVjVFBvTThw
|
42
42
|
VmpLM3BoNQpuL0V3dVpDY0U2Z2h0Q0NNCi0tLS0tRU5EIENFUlRJRklDQVRF
|
43
43
|
LS0tLS0K
|
44
|
-
date: 2013-
|
44
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
45
45
|
dependencies: []
|
46
46
|
description: ! 'New Relic is a performance management system, developed by New Relic,
|
47
47
|
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/new_relic/agent/request_sampler.rb
|
162
162
|
- lib/new_relic/agent/rules_engine.rb
|
163
163
|
- lib/new_relic/agent/sampler.rb
|
164
|
+
- lib/new_relic/agent/sampler_collection.rb
|
164
165
|
- lib/new_relic/agent/samplers/cpu_sampler.rb
|
165
166
|
- lib/new_relic/agent/samplers/delayed_job_sampler.rb
|
166
167
|
- lib/new_relic/agent/samplers/memory_sampler.rb
|
@@ -385,6 +386,7 @@ files:
|
|
385
386
|
- test/new_relic/agent/request_sampler_test.rb
|
386
387
|
- test/new_relic/agent/rpm_agent_test.rb
|
387
388
|
- test/new_relic/agent/rules_engine_test.rb
|
389
|
+
- test/new_relic/agent/sampler_collection_test.rb
|
388
390
|
- test/new_relic/agent/sampler_test.rb
|
389
391
|
- test/new_relic/agent/shim_agent_test.rb
|
390
392
|
- test/new_relic/agent/sql_sampler_test.rb
|
metadata.gz.sig
CHANGED
Binary file
|