newrelic_rpm 3.14.1.311 → 3.14.2.312
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +174 -11
- data/CHANGELOG +22 -0
- data/Rakefile +5 -0
- data/lib/new_relic/agent/agent.rb +22 -7
- data/lib/new_relic/agent/aws_info.rb +1 -1
- data/lib/new_relic/agent/custom_event_aggregator.rb +19 -44
- data/lib/new_relic/agent/error_event_aggregator.rb +11 -103
- data/lib/new_relic/agent/event_aggregator.rb +130 -0
- data/lib/new_relic/agent/event_buffer.rb +7 -0
- data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +18 -2
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +12 -4
- data/lib/new_relic/agent/new_relic_service.rb +6 -4
- data/lib/new_relic/agent/sampled_buffer.rb +9 -6
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -2
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +2 -1
- data/lib/new_relic/agent/supported_versions.rb +1 -1
- data/lib/new_relic/agent/synthetics_event_aggregator.rb +52 -0
- data/lib/new_relic/agent/synthetics_event_buffer.rb +0 -2
- data/lib/new_relic/agent/transaction.rb +14 -7
- data/lib/new_relic/agent/transaction/request_attributes.rb +7 -2
- data/lib/new_relic/agent/transaction_error_primitive.rb +72 -0
- data/lib/new_relic/agent/transaction_event_aggregator.rb +33 -210
- data/lib/new_relic/agent/transaction_event_primitive.rb +106 -0
- data/lib/new_relic/agent/transaction_event_recorder.rb +48 -0
- data/lib/new_relic/agent/transaction_metrics.rb +9 -1
- data/lib/new_relic/agent/transction_event_recorder.rb +35 -0
- data/lib/new_relic/recipes/capistrano3.rb +1 -1
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/versions.html.erb +13 -11
- data/lib/tasks/versions.postface.html +8 -0
- data/lib/tasks/versions.preface.html +3 -0
- data/lib/tasks/versions.rake +15 -5
- data/test/agent_helper.rb +1 -1
- data/test/environments/rails31/Gemfile +2 -0
- data/test/environments/rails32/Gemfile +2 -0
- data/test/environments/rails32/Rakefile +2 -1
- data/test/environments/rails32/config/database.yml +1 -6
- data/test/multiverse/suites/active_record/Envfile +1 -0
- data/test/multiverse/suites/agent_only/agent_attributes_test.rb +18 -0
- data/test/multiverse/suites/agent_only/custom_analytics_events_test.rb +21 -6
- data/test/multiverse/suites/agent_only/error_events_test.rb +14 -6
- data/test/multiverse/suites/agent_only/transaction_events_test.rb +31 -0
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +2 -0
- data/test/multiverse/suites/capistrano/Envfile +9 -3
- data/test/multiverse/suites/capistrano2/Envfile +4 -0
- data/test/multiverse/suites/config_file_loading/Envfile +1 -1
- data/test/multiverse/suites/curb/Envfile +1 -1
- data/test/multiverse/suites/datamapper/Envfile +3 -0
- data/test/multiverse/suites/deferred_instrumentation/sinatra_test.rb +7 -3
- data/test/multiverse/suites/grape/grape_test.rb +2 -0
- data/test/multiverse/suites/padrino/Envfile +4 -3
- data/test/multiverse/suites/padrino/config/newrelic.yml +2 -0
- data/test/multiverse/suites/rack/config/newrelic.yml +18 -0
- data/test/multiverse/suites/rack/nested_non_rack_app_test.rb +1 -1
- data/test/multiverse/suites/rack/puma_rack_builder_test.rb +17 -14
- data/test/multiverse/suites/rack/rack_auto_instrumentation_test.rb +16 -13
- data/test/multiverse/suites/rack/rack_unsupported_version_test.rb +1 -1
- data/test/multiverse/suites/rails/Envfile +5 -0
- data/test/multiverse/suites/rails/parameter_capture_test.rb +9 -0
- data/test/multiverse/suites/rake/Envfile +2 -1
- data/test/multiverse/suites/redis/redis_instrumentation_test.rb +1 -1
- data/test/multiverse/suites/sidekiq/Envfile +18 -0
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +11 -10
- data/test/multiverse/suites/sidekiq/test_model.rb +12 -0
- data/test/multiverse/suites/sinatra/ignoring_test.rb +43 -25
- data/test/multiverse/suites/sinatra/nested_middleware_test.rb +10 -2
- data/test/multiverse/suites/sinatra/sinatra_classic_test.rb +4 -0
- data/test/multiverse/suites/sinatra/sinatra_metric_explosion_test.rb +8 -2
- data/test/multiverse/suites/sinatra/sinatra_modular_test.rb +4 -0
- data/test/multiverse/suites/sinatra/sinatra_parameter_capture_test.rb +2 -0
- data/test/multiverse/suites/sinatra/sinatra_test_cases.rb +79 -10
- data/test/new_relic/agent/agent_test.rb +3 -3
- data/test/new_relic/agent/aws_info_test.rb +1 -2
- data/test/new_relic/agent/configuration/orphan_configuration_test.rb +2 -0
- data/test/new_relic/agent/custom_event_aggregator_test.rb +43 -4
- data/test/new_relic/agent/error_collector_test.rb +1 -1
- data/test/new_relic/agent/error_event_aggregator_test.rb +13 -81
- data/test/new_relic/agent/event_aggregator_test.rb +178 -0
- data/test/new_relic/agent/event_buffer_test_cases.rb +16 -0
- data/test/new_relic/agent/instrumentation/sinatra/transaction_namer_test.rb +7 -0
- data/test/new_relic/agent/new_relic_service_test.rb +7 -1
- data/test/new_relic/agent/pipe_channel_manager_test.rb +45 -3
- data/test/new_relic/agent/rpm_agent_test.rb +1 -0
- data/test/new_relic/agent/stats_engine/stats_hash_test.rb +2 -2
- data/test/new_relic/agent/synthetics_event_aggregator_test.rb +179 -0
- data/test/new_relic/agent/transaction/request_attributes_test.rb +8 -0
- data/test/new_relic/agent/transaction_error_primitive_test.rb +117 -0
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +148 -374
- data/test/new_relic/agent/transaction_event_primitive_test.rb +195 -0
- data/test/new_relic/agent/transaction_event_recorder_test.rb +80 -0
- data/test/new_relic/agent/transaction_metrics_test.rb +7 -7
- data/test/new_relic/agent/transaction_test.rb +4 -4
- data/test/new_relic/agent/utilization_data_test.rb +7 -7
- data/test/new_relic/fake_collector.rb +10 -17
- data/test/new_relic/license_test.rb +2 -0
- data/test/new_relic/marshalling_test_cases.rb +1 -1
- data/test/nullverse/default_source_require_test.rb +21 -0
- data/test/nullverse/nullverse_helper.rb +10 -0
- data/test/performance/suites/active_record.rb +1 -1
- data/test/performance/suites/sql_obfuscation.rb +7 -6
- data/test/script/ci.sh +10 -165
- data/test/script/install_mongodb.sh +6 -0
- metadata +21 -6
- data/test/script/build_test_gem.sh +0 -57
- data/test/script/ci_agent-tests_runner.sh +0 -82
- data/test/script/ci_bench.sh +0 -52
- data/test/script/ci_multiverse_runner.sh +0 -63
@@ -17,6 +17,7 @@ module NewRelic
|
|
17
17
|
assert_equal "/", attrs.request_path
|
18
18
|
assert_nil attrs.referer
|
19
19
|
assert_nil attrs.content_length
|
20
|
+
assert_nil attrs.content_type
|
20
21
|
assert_nil attrs.host
|
21
22
|
assert_nil attrs.user_agent
|
22
23
|
assert_nil attrs.request_method
|
@@ -43,6 +44,13 @@ module NewRelic
|
|
43
44
|
assert_equal 111, attrs.content_length
|
44
45
|
end
|
45
46
|
|
47
|
+
def test_sets_content_type_from_request
|
48
|
+
request = stub 'request', :content_type => "application/json"
|
49
|
+
attrs = RequestAttributes.new request
|
50
|
+
|
51
|
+
assert_equal "application/json", attrs.content_type
|
52
|
+
end
|
53
|
+
|
46
54
|
def test_sets_host_from_request
|
47
55
|
request = stub 'request', :host => "localhost"
|
48
56
|
attrs = RequestAttributes.new request
|
@@ -0,0 +1,117 @@
|
|
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
|
+
require 'new_relic/agent/attribute_filter'
|
7
|
+
require 'new_relic/agent/transaction/attributes'
|
8
|
+
require 'new_relic/agent/transaction_error_primitive'
|
9
|
+
|
10
|
+
module NewRelic
|
11
|
+
module Agent
|
12
|
+
class TransactionErrorPrimitiveTest < Minitest::Test
|
13
|
+
def setup
|
14
|
+
freeze_time
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def test_event_includes_expected_intrinsics
|
19
|
+
intrinsics, *_ = create_event
|
20
|
+
|
21
|
+
assert_equal 'TransactionError', intrinsics['type']
|
22
|
+
assert_in_delta Time.now.to_f, intrinsics['timestamp'], 0.001
|
23
|
+
assert_equal "RuntimeError", intrinsics['error.class']
|
24
|
+
assert_equal "Big Controller!", intrinsics['error.message']
|
25
|
+
assert_equal "Controller/blogs/index", intrinsics['transactionName']
|
26
|
+
assert_equal 0.1, intrinsics['duration']
|
27
|
+
assert_equal 80, intrinsics['port']
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_event_includes_synthetics
|
31
|
+
intrinsics, *_ = create_event :payload_options => {
|
32
|
+
:synthetics_resource_id=>3,
|
33
|
+
:synthetics_job_id=>4,
|
34
|
+
:synthetics_monitor_id=>5
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_equal 3, intrinsics['nr.syntheticsResourceId']
|
38
|
+
assert_equal 4, intrinsics['nr.syntheticsJobId']
|
39
|
+
assert_equal 5, intrinsics['nr.syntheticsMonitorId']
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_includes_mapped_metrics
|
43
|
+
metrics = NewRelic::Agent::TransactionMetrics.new
|
44
|
+
metrics.record_unscoped 'Datastore/all', 10
|
45
|
+
metrics.record_unscoped 'GC/Transaction/all', 11
|
46
|
+
metrics.record_unscoped 'WebFrontend/QueueTime', 12
|
47
|
+
metrics.record_unscoped 'External/allWeb', 13
|
48
|
+
|
49
|
+
intrinsics, *_ = create_event :payload_options => {:metrics => metrics}
|
50
|
+
|
51
|
+
assert_equal 10.0, intrinsics["databaseDuration"]
|
52
|
+
assert_equal 1, intrinsics["databaseCallCount"]
|
53
|
+
assert_equal 11.0, intrinsics["gcCumulative"]
|
54
|
+
assert_equal 12.0, intrinsics["queueDuration"]
|
55
|
+
assert_equal 13.0, intrinsics["externalDuration"]
|
56
|
+
assert_equal 1, intrinsics["externalCallCount"]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_includes_cat_attributes
|
60
|
+
intrinsics, *_ = create_event :payload_options => {:guid => "GUID", :referring_transaction_guid=>"REFERRING_GUID"}
|
61
|
+
|
62
|
+
assert_equal "GUID", intrinsics["nr.transactionGuid"]
|
63
|
+
assert_equal "REFERRING_GUID", intrinsics["nr.referringTransactionGuid"]
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_includes_custom_attributes
|
67
|
+
attrs = {"user" => "Wes Mantooth", "channel" => 9}
|
68
|
+
|
69
|
+
attributes = Transaction::Attributes.new(NewRelic::Agent.instance.attribute_filter)
|
70
|
+
attributes.merge_custom_attributes attrs
|
71
|
+
|
72
|
+
_, custom_attrs, _ = create_event :error_options => {:attributes => attributes}
|
73
|
+
|
74
|
+
assert_equal attrs, custom_attrs
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_includes_agent_attributes
|
78
|
+
attributes = Transaction::Attributes.new(NewRelic::Agent.instance.attribute_filter)
|
79
|
+
attributes.add_agent_attribute :'request.headers.referer', "http://blog.site/home", AttributeFilter::DST_ERROR_COLLECTOR
|
80
|
+
attributes.add_agent_attribute :httpResponseCode, "200", AttributeFilter::DST_ERROR_COLLECTOR
|
81
|
+
|
82
|
+
_, _, agent_attrs = create_event :error_options => {:attributes => attributes}
|
83
|
+
|
84
|
+
expected = {:"request.headers.referer" => "http://blog.site/home", :httpResponseCode => "200"}
|
85
|
+
assert_equal expected, agent_attrs
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_event options = {}
|
89
|
+
payload = generate_payload options[:payload_options] || {}
|
90
|
+
error = create_noticed_error options[:error_options] || {}
|
91
|
+
TransactionErrorPrimitive.create error, payload
|
92
|
+
end
|
93
|
+
|
94
|
+
def generate_payload options = {}
|
95
|
+
{
|
96
|
+
:name => "Controller/blogs/index",
|
97
|
+
:type => :controller,
|
98
|
+
:start_timestamp => Time.now.to_f,
|
99
|
+
:duration => 0.1
|
100
|
+
}.update(options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_noticed_error options = {}
|
104
|
+
exception = options.delete(:exception) || RuntimeError.new("Big Controller!")
|
105
|
+
txn_name = "Controller/blogs/index"
|
106
|
+
noticed_error = NewRelic::NoticedError.new(txn_name, exception)
|
107
|
+
noticed_error.request_uri = "http://site.com/blogs"
|
108
|
+
noticed_error.request_port = 80
|
109
|
+
noticed_error.attributes = options.delete(:attributes)
|
110
|
+
noticed_error.attributes_from_notice_error = options.delete(:custom_params) || {}
|
111
|
+
noticed_error.attributes_from_notice_error.merge!(options)
|
112
|
+
|
113
|
+
noticed_error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -7,431 +7,205 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper
|
|
7
7
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','data_container_tests'))
|
8
8
|
require 'new_relic/agent/transaction_event_aggregator'
|
9
9
|
require 'new_relic/agent/transaction/attributes'
|
10
|
+
require 'new_relic/agent/transaction_event_primitive'
|
10
11
|
|
11
|
-
|
12
|
+
module NewRelic
|
13
|
+
module Agent
|
14
|
+
class TransactionEventAggregatorTest < Minitest::Test
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@event_aggregator = NewRelic::Agent::TransactionEventAggregator.new(@event_listener)
|
16
|
+
def setup
|
17
|
+
freeze_time
|
18
|
+
@event_aggregator = TransactionEventAggregator.new
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Helpers for DataContainerTests
|
22
|
-
|
23
|
-
def create_container
|
24
|
-
@event_aggregator
|
25
|
-
end
|
26
|
-
|
27
|
-
def populate_container(sampler, n)
|
28
|
-
n.times do |i|
|
29
|
-
generate_request("whatever#{i}")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
include NewRelic::DataContainerTests
|
34
|
-
|
35
|
-
# Tests
|
36
|
-
|
37
|
-
def test_samples_on_transaction_finished_event
|
38
|
-
with_sampler_config do
|
39
|
-
generate_request
|
40
|
-
assert_equal 1, @event_aggregator.samples.length
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
EVENT_DATA_INDEX = 0
|
45
|
-
CUSTOM_ATTRIBUTES_INDEX = 1
|
46
|
-
AGENT_ATTRIBUTES_INDEX = 2
|
47
|
-
|
48
|
-
def test_custom_attributes_in_event_are_normalized_to_string_keys
|
49
|
-
with_sampler_config do
|
50
|
-
attributes.merge_custom_attributes(:bing => 2, 1 => 3)
|
51
|
-
generate_request('whatever')
|
52
|
-
|
53
|
-
result = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
|
54
|
-
assert_equal 2, result['bing']
|
55
|
-
assert_equal 3, result['1']
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_agent_attributes_in_event_are_normalized_to_string_keys
|
60
|
-
with_sampler_config do
|
61
|
-
attributes.add_agent_attribute(:yahoo, 7, NewRelic::Agent::AttributeFilter::DST_ALL)
|
62
|
-
attributes.add_agent_attribute(4, 2, NewRelic::Agent::AttributeFilter::DST_ALL)
|
63
|
-
generate_request('puce')
|
64
|
-
|
65
|
-
result = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
|
66
|
-
assert_equal 7, result[:yahoo]
|
67
|
-
assert_equal 2, result[4]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_error_is_included_in_event_data
|
72
|
-
with_sampler_config do
|
73
|
-
generate_request('whatever', :error => true)
|
74
|
-
|
75
|
-
event_data, *_ = captured_transaction_event
|
76
|
-
|
77
|
-
assert event_data['error']
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_includes_custom_attributes_in_event
|
82
|
-
with_sampler_config do
|
83
|
-
attributes.merge_custom_attributes('bing' => 2)
|
84
|
-
generate_request('whatever')
|
85
|
-
|
86
|
-
custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
|
87
|
-
assert_equal 2, custom_attrs['bing']
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_includes_agent_attributes_in_event
|
92
|
-
with_sampler_config do
|
93
|
-
attributes.add_agent_attribute('bing', 2, NewRelic::Agent::AttributeFilter::DST_ALL)
|
94
|
-
generate_request('whatever')
|
95
|
-
|
96
|
-
agent_attrs = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
|
97
|
-
assert_equal 2, agent_attrs['bing']
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_doesnt_include_custom_attributes_in_event_when_configured_not_to
|
102
|
-
with_sampler_config('transaction_events.attributes.enabled' => false) do
|
103
|
-
attributes.merge_custom_attributes('bing' => 2)
|
104
|
-
generate_request('whatever')
|
105
|
-
|
106
|
-
custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
|
107
|
-
assert_empty custom_attrs
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_doesnt_include_agent_attributes_in_event_when_configured_not_to
|
112
|
-
with_sampler_config('transaction_events.attributes.enabled' => false) do
|
113
|
-
attributes.add_agent_attribute('bing', 2, NewRelic::Agent::AttributeFilter::DST_ALL)
|
114
|
-
generate_request('whatever')
|
115
|
-
|
116
|
-
agent_attrs = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
|
117
|
-
assert_empty agent_attrs
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
|
122
|
-
def test_doesnt_include_custom_attributes_in_event_when_configured_not_to_with_legacy_setting
|
123
|
-
with_sampler_config('analytics_events.capture_attributes' => false) do
|
124
|
-
attributes.merge_custom_attributes('bing' => 2)
|
125
|
-
generate_request('whatever')
|
126
|
-
|
127
|
-
custom_attrs = captured_transaction_event[CUSTOM_ATTRIBUTES_INDEX]
|
128
|
-
assert_empty custom_attrs
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_doesnt_include_agent_attributes_in_event_when_configured_not_to_with_legacy_setting
|
133
|
-
with_sampler_config('analytics_events.capture_attributes' => false) do
|
134
|
-
attributes.add_agent_attribute('bing', 2, NewRelic::Agent::AttributeFilter::DST_ALL)
|
135
|
-
generate_request('whatever')
|
136
|
-
|
137
|
-
agent_attrs = captured_transaction_event[AGENT_ATTRIBUTES_INDEX]
|
138
|
-
assert_empty agent_attrs
|
139
|
-
end
|
140
|
-
end
|
20
|
+
@attributes = nil
|
21
|
+
end
|
141
22
|
|
142
|
-
|
143
|
-
with_sampler_config do
|
144
|
-
metrics = NewRelic::Agent::TransactionMetrics.new()
|
145
|
-
metrics.record_unscoped('HttpDispatcher', 0.01)
|
23
|
+
# Helpers for DataContainerTests
|
146
24
|
|
147
|
-
|
148
|
-
|
25
|
+
def create_container
|
26
|
+
@event_aggregator
|
27
|
+
end
|
149
28
|
|
150
|
-
|
151
|
-
|
152
|
-
|
29
|
+
def populate_container(sampler, n)
|
30
|
+
n.times do |i|
|
31
|
+
generate_request("whatever#{i}")
|
32
|
+
end
|
33
|
+
end
|
153
34
|
|
154
|
-
|
155
|
-
assert_equal 'giraffe', custom_attrs['type']
|
156
|
-
assert_equal 'hippo', custom_attrs['duration']
|
157
|
-
end
|
158
|
-
end
|
35
|
+
include NewRelic::DataContainerTests
|
159
36
|
|
160
|
-
|
161
|
-
txn_metrics = NewRelic::Agent::TransactionMetrics.new
|
162
|
-
txn_metrics.record_unscoped('WebFrontend/QueueTime', 13)
|
163
|
-
txn_metrics.record_unscoped('External/allWeb', 14)
|
164
|
-
txn_metrics.record_unscoped('Datastore/all', 15)
|
165
|
-
txn_metrics.record_unscoped("GC/Transaction/all", 16)
|
166
|
-
|
167
|
-
with_sampler_config do
|
168
|
-
generate_request('name', :metrics => txn_metrics)
|
169
|
-
event_data = captured_transaction_event[EVENT_DATA_INDEX]
|
170
|
-
assert_equal 13, event_data["queueDuration"]
|
171
|
-
assert_equal 14, event_data["externalDuration"]
|
172
|
-
assert_equal 15, event_data["databaseDuration"]
|
173
|
-
assert_equal 16, event_data["gcCumulative"]
|
174
|
-
|
175
|
-
assert_equal 1, event_data["externalCallCount"]
|
176
|
-
assert_equal 1, event_data["databaseCallCount"]
|
177
|
-
end
|
178
|
-
end
|
37
|
+
# Tests
|
179
38
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
txn_metrics.record_unscoped("GC/Transaction/all", 14)
|
39
|
+
def test_samples_on_transaction_finished_event
|
40
|
+
generate_request
|
41
|
+
assert_equal 1, last_transaction_events.length
|
42
|
+
end
|
185
43
|
|
186
|
-
|
187
|
-
|
44
|
+
def test_records_background_tasks
|
45
|
+
generate_request('a', :type => :controller)
|
46
|
+
generate_request('b', :type => :background)
|
47
|
+
assert_equal 2, last_transaction_events.size
|
48
|
+
end
|
188
49
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
50
|
+
def test_can_disable_sampling_for_analytics
|
51
|
+
with_config( :'analytics_events.enabled' => false ) do
|
52
|
+
generate_request
|
53
|
+
assert last_transaction_events.empty?
|
54
|
+
end
|
55
|
+
end
|
193
56
|
|
194
|
-
|
195
|
-
|
196
|
-
end
|
197
|
-
end
|
57
|
+
def test_harvest_returns_previous_sample_list
|
58
|
+
5.times { generate_request }
|
198
59
|
|
199
|
-
|
200
|
-
with_sampler_config do
|
201
|
-
generate_request('name', :apdex_perf_zone => 'S')
|
60
|
+
_, old_samples = @event_aggregator.harvest!
|
202
61
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
62
|
+
assert_equal 5, old_samples.size
|
63
|
+
assert_equal 0, last_transaction_events.size
|
64
|
+
end
|
207
65
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
end
|
213
|
-
end
|
66
|
+
def test_merge_merges_samples_back_into_buffer
|
67
|
+
5.times { generate_request }
|
68
|
+
old_samples = @event_aggregator.harvest!
|
69
|
+
5.times { generate_request }
|
214
70
|
|
215
|
-
|
216
|
-
with_sampler_config do
|
217
|
-
generate_request('name', :referring_transaction_guid=> "REFER")
|
218
|
-
assert_equal "REFER", captured_transaction_event[EVENT_DATA_INDEX]["nr.referringTransactionGuid"]
|
219
|
-
end
|
220
|
-
end
|
71
|
+
@event_aggregator.merge!(old_samples)
|
221
72
|
|
222
|
-
|
223
|
-
|
224
|
-
generate_request('a', :type => :controller)
|
225
|
-
generate_request('b', :type => :background)
|
226
|
-
assert_equal 2, @event_aggregator.samples.size
|
227
|
-
end
|
228
|
-
end
|
73
|
+
assert_equal(10, last_transaction_events.size)
|
74
|
+
end
|
229
75
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
76
|
+
def test_merge_abides_by_max_samples_limit
|
77
|
+
with_config(:'analytics_events.max_samples_stored' => 5) do
|
78
|
+
4.times { generate_request }
|
79
|
+
old_samples = @event_aggregator.harvest!
|
80
|
+
4.times { generate_request }
|
236
81
|
|
237
|
-
|
238
|
-
|
239
|
-
|
82
|
+
@event_aggregator.merge!(old_samples)
|
83
|
+
assert_equal(5, last_transaction_events.size)
|
84
|
+
end
|
85
|
+
end
|
240
86
|
|
241
|
-
|
87
|
+
def test_sample_counts_are_correct_after_merge
|
88
|
+
with_config :'analytics_events.max_samples_stored' => 5 do
|
89
|
+
buffer = @event_aggregator.instance_variable_get :@buffer
|
242
90
|
|
243
|
-
|
244
|
-
|
245
|
-
end
|
246
|
-
end
|
91
|
+
4.times { generate_request }
|
92
|
+
last_harvest = @event_aggregator.harvest!
|
247
93
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
old_samples = @event_aggregator.harvest!
|
252
|
-
5.times { generate_request }
|
94
|
+
assert_equal 4, buffer.seen_lifetime
|
95
|
+
assert_equal 4, buffer.captured_lifetime
|
96
|
+
assert_equal 4, last_harvest[0][:events_seen]
|
253
97
|
|
254
|
-
|
255
|
-
|
256
|
-
end
|
257
|
-
end
|
98
|
+
4.times { generate_request }
|
99
|
+
@event_aggregator.merge! last_harvest
|
258
100
|
|
259
|
-
|
260
|
-
with_sampler_config(:'analytics_events.max_samples_stored' => 5) do
|
261
|
-
4.times { generate_request }
|
262
|
-
old_samples = @event_aggregator.harvest!
|
263
|
-
4.times { generate_request }
|
101
|
+
reservoir_stats, samples = @event_aggregator.harvest!
|
264
102
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
with_sampler_config( :'analytics_events.max_samples_stored' => 100 ) do
|
272
|
-
150.times { generate_request }
|
273
|
-
assert_equal 100, @event_aggregator.samples.size
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_resets_limits_on_harvest
|
278
|
-
with_sampler_config( :'analytics_events.max_samples_stored' => 100 ) do
|
279
|
-
50.times { generate_request('before') }
|
280
|
-
samples_before = @event_aggregator.samples
|
281
|
-
assert_equal 50, samples_before.size
|
103
|
+
assert_equal 5, samples.size
|
104
|
+
assert_equal 8, reservoir_stats[:events_seen]
|
105
|
+
assert_equal 8, buffer.seen_lifetime
|
106
|
+
assert_equal 5, buffer.captured_lifetime
|
107
|
+
end
|
108
|
+
end
|
282
109
|
|
283
|
-
|
110
|
+
def test_limits_total_number_of_samples_to_max_samples_stored
|
111
|
+
with_config( :'analytics_events.max_samples_stored' => 100 ) do
|
112
|
+
150.times { generate_request }
|
113
|
+
assert_equal 100, last_transaction_events.size
|
114
|
+
end
|
115
|
+
end
|
284
116
|
|
285
|
-
|
286
|
-
|
287
|
-
|
117
|
+
def test_resets_limits_on_harvest
|
118
|
+
with_config( :'analytics_events.max_samples_stored' => 100 ) do
|
119
|
+
50.times { generate_request('before') }
|
120
|
+
samples_before = last_transaction_events
|
121
|
+
assert_equal 50, samples_before.size
|
288
122
|
|
289
|
-
|
290
|
-
|
291
|
-
|
123
|
+
150.times { generate_request('after') }
|
124
|
+
samples_after = last_transaction_events
|
125
|
+
assert_equal 100, samples_after.size
|
292
126
|
|
293
|
-
|
294
|
-
with_sampler_config( :'analytics_events.max_samples_stored' => 100 * 100 ) do
|
295
|
-
threads = []
|
296
|
-
25.times do
|
297
|
-
threads << Thread.new do
|
298
|
-
100.times { generate_request }
|
127
|
+
assert_equal 0, (samples_before & samples_after).size
|
299
128
|
end
|
300
129
|
end
|
301
|
-
threads.each { |t| t.join }
|
302
|
-
|
303
|
-
assert_equal(25 * 100, @event_aggregator.samples.size)
|
304
|
-
end
|
305
|
-
end
|
306
130
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
131
|
+
def test_does_not_drop_samples_when_used_from_multiple_threads
|
132
|
+
with_config( :'analytics_events.max_samples_stored' => 100 * 100 ) do
|
133
|
+
threads = []
|
134
|
+
25.times do
|
135
|
+
threads << Thread.new do
|
136
|
+
100.times { generate_request }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
threads.each { |t| t.join }
|
140
|
+
|
141
|
+
assert_equal(25 * 100, last_transaction_events.size)
|
142
|
+
end
|
312
143
|
end
|
313
144
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
def test_synthetics_events_overflow_to_transaction_buffer
|
319
|
-
with_sampler_config(:'synthetics.events_limit' => 10) do
|
320
|
-
20.times do
|
321
|
-
generate_request('synthetic', :synthetics_resource_id => 100)
|
145
|
+
def test_append_accepts_a_block
|
146
|
+
payload = generate_payload
|
147
|
+
@event_aggregator.append { TransactionEventPrimitive.create(payload) }
|
148
|
+
assert_equal 1, last_transaction_events.size
|
322
149
|
end
|
323
150
|
|
324
|
-
|
325
|
-
|
326
|
-
end
|
151
|
+
def test_block_is_not_executed_unless_buffer_admits_event
|
152
|
+
event = nil
|
327
153
|
|
328
|
-
|
329
|
-
|
330
|
-
:'analytics_events.max_samples_stored' => 0) do
|
331
|
-
10.times do |i|
|
332
|
-
generate_request('synthetic', :timestamp => i + 10, :synthetics_resource_id => 100)
|
333
|
-
end
|
154
|
+
with_config :'analytics_events.max_samples_stored' => 5 do
|
155
|
+
5.times { generate_request }
|
334
156
|
|
335
|
-
|
157
|
+
#cause sample to be discarded by the sampled buffer
|
158
|
+
buffer = @event_aggregator.instance_variable_get :@buffer
|
159
|
+
buffer.stubs(:rand).returns(6)
|
336
160
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
assert_equal ([1] + (10..18).to_a), timestamps
|
343
|
-
end
|
344
|
-
end
|
161
|
+
payload = generate_payload
|
162
|
+
@event_aggregator.append do
|
163
|
+
event = TransactionEventPrimitive.create(payload)
|
164
|
+
end
|
165
|
+
end
|
345
166
|
|
346
|
-
|
347
|
-
|
348
|
-
10.times do |i|
|
349
|
-
generate_request('synthetic', :timestamp => i + 10, :synthetics_resource_id => 100)
|
167
|
+
assert_nil event, "Did not expect block to be executed"
|
168
|
+
refute_includes last_transaction_events, event
|
350
169
|
end
|
351
170
|
|
352
|
-
|
171
|
+
#
|
172
|
+
# Helpers
|
173
|
+
#
|
353
174
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
def test_merging_synthetics_still_applies_limit
|
359
|
-
samples = with_sampler_config(:'synthetics.events_limit' => 20) do
|
360
|
-
20.times do
|
361
|
-
generate_request('synthetic', :synthetics_resource_id => 100)
|
175
|
+
def generate_request(name='whatever', options={})
|
176
|
+
payload = generate_payload name, options
|
177
|
+
@event_aggregator.append TransactionEventPrimitive.create(payload)
|
362
178
|
end
|
363
|
-
@event_aggregator.harvest!
|
364
|
-
end
|
365
179
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
20.times do
|
376
|
-
generate_request('synthetic', :synthetics_resource_id => 100)
|
180
|
+
def generate_payload(name='whatever', options={})
|
181
|
+
{
|
182
|
+
:name => "Controller/#{name}",
|
183
|
+
:type => :controller,
|
184
|
+
:start_timestamp => options[:timestamp] || Time.now.to_f,
|
185
|
+
:duration => 0.1,
|
186
|
+
:attributes => attributes,
|
187
|
+
:error => false
|
188
|
+
}.merge(options)
|
377
189
|
end
|
378
190
|
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
end
|
191
|
+
def attributes
|
192
|
+
if @attributes.nil?
|
193
|
+
filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
|
194
|
+
@attributes = NewRelic::Agent::Transaction::Attributes.new(filter)
|
195
|
+
end
|
385
196
|
|
386
|
-
|
387
|
-
with_sampler_config(:'synthetics.events_limit' => 10) do
|
388
|
-
20.times do
|
389
|
-
generate_request('synthetic', :synthetics_resource_id => 100)
|
197
|
+
@attributes
|
390
198
|
end
|
391
199
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
assert_metrics_recorded(metric => { :call_count => 10 })
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
#
|
400
|
-
# Helpers
|
401
|
-
#
|
402
|
-
|
403
|
-
def generate_request(name='whatever', options={})
|
404
|
-
payload = {
|
405
|
-
:name => "Controller/#{name}",
|
406
|
-
:type => :controller,
|
407
|
-
:start_timestamp => options[:timestamp] || Time.now.to_f,
|
408
|
-
:duration => 0.1,
|
409
|
-
:attributes => attributes,
|
410
|
-
:error => false
|
411
|
-
}.merge(options)
|
412
|
-
@event_listener.notify(:transaction_finished, payload)
|
413
|
-
end
|
414
|
-
|
415
|
-
def with_sampler_config(options = {})
|
416
|
-
defaults = { :'analytics_events.max_samples_stored' => 100 }
|
417
|
-
defaults.merge!(options)
|
418
|
-
with_config(defaults) do
|
419
|
-
@event_listener.notify( :finished_configuring )
|
420
|
-
yield
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
def captured_transaction_event
|
425
|
-
assert_equal 1, @event_aggregator.samples.size
|
426
|
-
@event_aggregator.samples.first
|
427
|
-
end
|
200
|
+
def last_transaction_events
|
201
|
+
@event_aggregator.harvest![1]
|
202
|
+
end
|
428
203
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
204
|
+
def last_transaction_event
|
205
|
+
events = last_transaction_events
|
206
|
+
assert_equal 1, events.size
|
207
|
+
events.first
|
208
|
+
end
|
433
209
|
end
|
434
|
-
|
435
|
-
@attributes
|
436
210
|
end
|
437
211
|
end
|