newrelic_rpm 3.12.0.288 → 3.12.1.298
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +42 -0
- data/Rakefile +5 -5
- data/lib/new_relic/agent.rb +23 -11
- data/lib/new_relic/agent/agent.rb +17 -67
- data/lib/new_relic/agent/agent_logger.rb +9 -33
- data/lib/new_relic/agent/attribute_processing.rb +2 -2
- data/lib/new_relic/agent/autostart.rb +1 -18
- data/lib/new_relic/agent/aws_info.rb +90 -0
- data/lib/new_relic/agent/configuration/default_source.rb +45 -16
- data/lib/new_relic/agent/configuration/dotted_hash.rb +0 -2
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
- data/lib/new_relic/agent/configuration/manager.rb +1 -31
- data/lib/new_relic/agent/configuration/server_source.rb +0 -1
- data/lib/new_relic/agent/configuration/yaml_source.rb +26 -7
- data/lib/new_relic/agent/database.rb +5 -5
- data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +0 -1
- data/lib/new_relic/agent/datastores/metric_helper.rb +15 -3
- data/lib/new_relic/agent/error_collector.rb +28 -18
- data/lib/new_relic/agent/instrumentation/active_record.rb +8 -2
- data/lib/new_relic/agent/instrumentation/active_record_4.rb +1 -0
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +49 -1
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +2 -2
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +9 -0
- data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
- data/lib/new_relic/agent/instrumentation/resque.rb +8 -20
- data/lib/new_relic/agent/instrumentation/sequel.rb +0 -2
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -0
- data/lib/new_relic/agent/log_once.rb +39 -0
- data/lib/new_relic/agent/memory_logger.rb +8 -1
- data/lib/new_relic/agent/method_tracer.rb +5 -1
- data/lib/new_relic/agent/new_relic_service.rb +13 -14
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -0
- data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -3
- data/lib/new_relic/agent/sql_sampler.rb +4 -15
- data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -1
- data/lib/new_relic/agent/stats_engine/samplers.rb +0 -6
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +92 -35
- data/lib/new_relic/agent/system_info.rb +53 -6
- data/lib/new_relic/agent/transaction.rb +4 -13
- data/lib/new_relic/agent/transaction/attributes.rb +2 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +1 -1
- data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -9
- data/lib/new_relic/agent/transaction_sample_builder.rb +0 -6
- data/lib/new_relic/agent/transaction_sampler.rb +1 -13
- data/lib/new_relic/agent/utilization_data.rb +29 -42
- data/lib/new_relic/agent/worker_loop.rb +2 -3
- data/lib/new_relic/cli/commands/deployments.rb +5 -0
- data/lib/new_relic/coerce.rb +1 -1
- data/lib/new_relic/collection_helper.rb +0 -2
- data/lib/new_relic/control/instance_methods.rb +4 -1
- data/lib/new_relic/control/instrumentation.rb +1 -9
- data/lib/new_relic/control/server_methods.rb +3 -56
- data/lib/new_relic/helper.rb +1 -0
- data/lib/new_relic/language_support.rb +21 -0
- data/lib/new_relic/local_environment.rb +1 -0
- data/lib/new_relic/metric_data.rb +1 -1
- data/lib/new_relic/noticed_error.rb +1 -1
- data/lib/new_relic/rack/agent_middleware.rb +9 -0
- data/lib/new_relic/version.rb +1 -1
- data/lib/sequel/extensions/newrelic_instrumentation.rb +2 -2
- data/lib/tasks/multiverse.rake +2 -0
- data/lib/tasks/multiverse.rb +50 -0
- data/test/agent_helper.rb +24 -5
- data/test/fixtures/cross_agent_tests/aws.json +218 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/cases.json +40 -11
- data/test/fixtures/cross_agent_tests/docker_container_id/invalid-characters.txt +9 -0
- data/test/fixtures/cross_agent_tests/docker_container_id/invalid-length.txt +9 -0
- data/test/multiverse/lib/multiverse/suite.rb +3 -0
- data/test/multiverse/suites/active_record/Envfile +18 -12
- data/test/multiverse/suites/active_record/active_record_test.rb +203 -9
- data/test/multiverse/suites/active_record/app/models/models.rb +16 -9
- data/test/multiverse/suites/active_record/config/database.rb +3 -2
- data/test/multiverse/suites/active_record/db/migrate/20150413011200_add_timestamps_to_orders.rb +16 -0
- data/test/multiverse/suites/active_record/db/migrate/20150414084400_create_groups.rb +21 -0
- data/test/multiverse/suites/agent_only/agent_attributes_test.rb +26 -3
- data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -1
- data/test/multiverse/suites/agent_only/script/public_api_when_disabled.rb +68 -0
- data/test/multiverse/suites/agent_only/service_timeout_test.rb +1 -1
- data/test/multiverse/suites/agent_only/ssl_test.rb +2 -1
- data/test/multiverse/suites/agent_only/start_up_test.rb +20 -1
- data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +43 -104
- data/test/multiverse/suites/bare/standalone_instrumentation_test.rb +2 -2
- data/test/multiverse/suites/high_security/high_security_test.rb +2 -2
- data/test/multiverse/suites/rack/http_response_code_test.rb +4 -4
- data/test/multiverse/suites/rails/error_tracing_test.rb +1 -1
- data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +38 -0
- data/test/multiverse/suites/sidekiq/test_worker.rb +13 -1
- data/test/new_relic/agent/agent_test.rb +0 -70
- data/test/new_relic/agent/attribute_processing_test.rb +10 -5
- data/test/new_relic/agent/autostart_test.rb +0 -31
- data/test/new_relic/agent/aws_info_test.rb +61 -0
- data/test/new_relic/agent/configuration/manager_test.rb +1 -1
- data/test/new_relic/agent/configuration/yaml_source_test.rb +25 -1
- data/test/new_relic/agent/database_test.rb +16 -15
- data/test/new_relic/agent/datastores/metric_helper_test.rb +35 -0
- data/test/new_relic/agent/error_collector_test.rb +28 -5
- data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +23 -20
- data/test/new_relic/agent/memory_logger_test.rb +18 -0
- data/test/new_relic/agent/new_relic_service_test.rb +2 -9
- data/test/new_relic/agent/rpm_agent_test.rb +0 -10
- data/test/new_relic/agent/sql_sampler_test.rb +4 -4
- data/test/new_relic/agent/stats_engine/stats_hash_test.rb +18 -22
- data/test/new_relic/agent/system_info_test.rb +81 -23
- data/test/new_relic/agent/transaction_event_aggregator_test.rb +0 -7
- data/test/new_relic/agent/transaction_test.rb +1 -1
- data/test/new_relic/agent/utilization_data_test.rb +135 -6
- data/test/new_relic/cli/commands/deployments_test.rb +12 -2
- data/test/new_relic/control/instrumentation_test.rb +0 -15
- data/test/new_relic/control_test.rb +0 -63
- data/test/new_relic/fake_collector.rb +4 -17
- data/test/new_relic/language_support_test.rb +30 -0
- data/test/new_relic/license_test.rb +2 -0
- data/test/new_relic/multiverse_helpers.rb +12 -0
- data/test/performance/suites/stats_hash.rb +6 -5
- data/test/test_helper.rb +1 -2
- metadata +13 -4
- data/lib/new_relic/agent/shim_agent.rb +0 -33
- data/test/new_relic/agent/shim_agent_test.rb +0 -20
@@ -85,18 +85,11 @@ module NewRelic::Agent::Instrumentation
|
|
85
85
|
def test_children_respect_parental_ignore_rules_with_only
|
86
86
|
parent = Class.new do
|
87
87
|
include ControllerInstrumentation
|
88
|
-
|
89
88
|
newrelic_ignore(:only => :foo)
|
90
|
-
|
91
|
-
def foo(*args); end
|
92
|
-
def foo2(*args); end
|
93
89
|
end
|
94
90
|
|
95
91
|
child = Class.new(parent) do
|
96
92
|
newrelic_ignore(:only => :bar)
|
97
|
-
|
98
|
-
def bar(*args); end
|
99
|
-
def bar2(*args); end
|
100
93
|
end
|
101
94
|
|
102
95
|
key = ControllerInstrumentation::NR_DO_NOT_TRACE_KEY
|
@@ -110,18 +103,11 @@ module NewRelic::Agent::Instrumentation
|
|
110
103
|
def test_children_respect_parental_ignore_rules_with_except
|
111
104
|
parent = Class.new do
|
112
105
|
include ControllerInstrumentation
|
113
|
-
|
114
106
|
newrelic_ignore(:except => :foo)
|
115
|
-
|
116
|
-
def foo(*args); end
|
117
|
-
def foo2(*args); end
|
118
107
|
end
|
119
108
|
|
120
109
|
child = Class.new(parent) do
|
121
110
|
newrelic_ignore(:except => :bar)
|
122
|
-
|
123
|
-
def bar(*args); end
|
124
|
-
def bar2(*args); end
|
125
111
|
end
|
126
112
|
|
127
113
|
key = ControllerInstrumentation::NR_DO_NOT_TRACE_KEY
|
@@ -135,17 +121,11 @@ module NewRelic::Agent::Instrumentation
|
|
135
121
|
def test_children_respect_parental_ignore_rules_with_except_and_only
|
136
122
|
parent = Class.new do
|
137
123
|
include ControllerInstrumentation
|
138
|
-
|
139
124
|
newrelic_ignore(:only => :foo)
|
140
|
-
|
141
|
-
def foo(*args); end
|
142
|
-
def foo2(*args); end
|
143
125
|
end
|
144
126
|
|
145
127
|
child = Class.new(parent) do
|
146
128
|
newrelic_ignore(:except => :foo)
|
147
|
-
|
148
|
-
def bar(*args); end
|
149
129
|
end
|
150
130
|
|
151
131
|
key = ControllerInstrumentation::NR_DO_NOT_TRACE_KEY
|
@@ -155,6 +135,29 @@ module NewRelic::Agent::Instrumentation
|
|
155
135
|
assert IgnoreActions.is_filtered?(key, child, :foo2)
|
156
136
|
end
|
157
137
|
|
138
|
+
def test_ignore_allows_strings
|
139
|
+
controller = Class.new do
|
140
|
+
include ControllerInstrumentation
|
141
|
+
|
142
|
+
newrelic_ignore(:only => "foo")
|
143
|
+
end
|
144
|
+
|
145
|
+
key = ControllerInstrumentation::NR_DO_NOT_TRACE_KEY
|
146
|
+
assert IgnoreActions.is_filtered?(key, controller, :foo)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_ignore_allows_mixed_strings_and_symbols
|
150
|
+
controller = Class.new do
|
151
|
+
include ControllerInstrumentation
|
152
|
+
|
153
|
+
newrelic_ignore(:only => ["foo", :bar])
|
154
|
+
end
|
155
|
+
|
156
|
+
key = ControllerInstrumentation::NR_DO_NOT_TRACE_KEY
|
157
|
+
assert IgnoreActions.is_filtered?(key, controller, :foo)
|
158
|
+
assert IgnoreActions.is_filtered?(key, controller, :bar)
|
159
|
+
end
|
160
|
+
|
158
161
|
def test_transaction_name_calls_newrelic_metric_path
|
159
162
|
@object.stubs(:newrelic_metric_path).returns('some/wacky/path')
|
160
163
|
assert_equal('Controller/some/wacky/path', @txn_namer.name_for(nil, @object, :controller))
|
@@ -64,4 +64,22 @@ class MemoryLoggerTest < Minitest::Test
|
|
64
64
|
|
65
65
|
@logger.dump(real_logger)
|
66
66
|
end
|
67
|
+
|
68
|
+
def test_log_once
|
69
|
+
@logger.log_once(:debug, :once, "Once")
|
70
|
+
@logger.log_once(:debug, :once, "Twice?")
|
71
|
+
|
72
|
+
real_logger = stub
|
73
|
+
real_logger.expects(:debug).once
|
74
|
+
|
75
|
+
@logger.dump(real_logger)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_implemented_agent_logger_interface
|
79
|
+
agent_logger_methods = NewRelic::Agent::AgentLogger.instance_methods(false)
|
80
|
+
memory_logger_methods = NewRelic::Agent::MemoryLogger.instance_methods(false)
|
81
|
+
|
82
|
+
unimplemented = agent_logger_methods - memory_logger_methods
|
83
|
+
assert_empty unimplemented
|
84
|
+
end
|
67
85
|
end
|
@@ -8,8 +8,7 @@ require 'new_relic/agent/commands/thread_profiler_session'
|
|
8
8
|
|
9
9
|
class NewRelicServiceTest < Minitest::Test
|
10
10
|
def setup
|
11
|
-
@server = NewRelic::Control::Server.new('somewhere.example.com',
|
12
|
-
30303, '10.10.10.10')
|
11
|
+
@server = NewRelic::Control::Server.new('somewhere.example.com', 30303)
|
13
12
|
@service = NewRelic::Agent::NewRelicService.new('license-key', @server)
|
14
13
|
|
15
14
|
@http_handle = create_http_handle
|
@@ -228,12 +227,6 @@ class NewRelicServiceTest < Minitest::Test
|
|
228
227
|
assert_equal 'localhost', @service.collector.name
|
229
228
|
end
|
230
229
|
|
231
|
-
def test_connect_resets_cached_ip_address
|
232
|
-
assert_equal '10.10.10.10', @service.collector.ip
|
233
|
-
@service.connect
|
234
|
-
assert_equal 'localhost', @service.collector.ip # 'localhost' resolves to nil
|
235
|
-
end
|
236
|
-
|
237
230
|
def test_connect_uses_proxy_collector_if_no_redirect_host
|
238
231
|
@http_handle.reset
|
239
232
|
@http_handle.respond_to(:get_redirect_host, nil)
|
@@ -726,7 +719,7 @@ class NewRelicServiceTest < Minitest::Test
|
|
726
719
|
spec1 = NewRelic::MetricSpec.new('foo')
|
727
720
|
spec2 = NewRelic::MetricSpec.new('bar')
|
728
721
|
hash.record(spec1, 1)
|
729
|
-
hash
|
722
|
+
hash.record(spec2) { |s| s.call_count = 0 }
|
730
723
|
|
731
724
|
metric_data_array = @service.build_metric_data_array(hash)
|
732
725
|
assert_equal(1, metric_data_array.size)
|
@@ -32,16 +32,6 @@ class NewRelic::Agent::RpmAgentTest < Minitest::Test
|
|
32
32
|
assert(ignore_called)
|
33
33
|
end
|
34
34
|
|
35
|
-
def test_startup_shutdown_shim
|
36
|
-
with_config(:agent_enabled => true) do
|
37
|
-
shim_agent = NewRelic::Agent::ShimAgent.instance
|
38
|
-
shim_agent.shutdown
|
39
|
-
refute shim_agent.started?
|
40
|
-
shim_agent.start
|
41
|
-
refute shim_agent.started?
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
35
|
def test_startup_shutdown_real
|
46
36
|
with_config(:agent_enabled => true, :monitor_mode => true) do
|
47
37
|
NewRelic::Agent.manual_start :monitor_mode => true, :license_key => ('x' * 40)
|
@@ -159,13 +159,13 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
159
159
|
queries = [
|
160
160
|
NewRelic::Agent::SlowSql.new("select * from test",
|
161
161
|
"Database/test/select", config,
|
162
|
-
1.5, nil,
|
162
|
+
1.5, nil, explainer),
|
163
163
|
NewRelic::Agent::SlowSql.new("select * from test",
|
164
164
|
"Database/test/select", config,
|
165
|
-
1.2, nil,
|
165
|
+
1.2, nil, explainer),
|
166
166
|
NewRelic::Agent::SlowSql.new("select * from test2",
|
167
167
|
"Database/test2/select", config,
|
168
|
-
1.1, nil,
|
168
|
+
1.1, nil, explainer)
|
169
169
|
]
|
170
170
|
data.sql_data.concat(queries)
|
171
171
|
@sampler.save_slow_sql data
|
@@ -300,7 +300,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
|
|
300
300
|
explainer = NewRelic::Agent::Instrumentation::ActiveRecord::EXPLAINER
|
301
301
|
data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
|
302
302
|
"Database/test/select",
|
303
|
-
{}, 1.5,
|
303
|
+
{}, 1.5, nil, explainer)])
|
304
304
|
@sampler.save_slow_sql(data)
|
305
305
|
sql_traces = @sampler.harvest!
|
306
306
|
|
@@ -11,7 +11,7 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_creates_default_entries
|
14
|
-
stats = @hash['a/b/c/d']
|
14
|
+
stats = @hash[NewRelic::MetricSpec.new('a/b/c/d')]
|
15
15
|
assert_kind_of(NewRelic::Agent::Stats, stats)
|
16
16
|
end
|
17
17
|
|
@@ -148,31 +148,31 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
|
|
148
148
|
end
|
149
149
|
|
150
150
|
def test_marshal_dump
|
151
|
-
@hash.record('foo', 1)
|
152
|
-
@hash.record('bar', 2)
|
151
|
+
@hash.record(NewRelic::MetricSpec.new('foo'), 1)
|
152
|
+
@hash.record(NewRelic::MetricSpec.new('bar'), 2)
|
153
153
|
copy = Marshal.load(Marshal.dump(@hash))
|
154
154
|
assert_equal(@hash, copy)
|
155
155
|
assert_equal(@hash.started_at, copy.started_at)
|
156
156
|
end
|
157
157
|
|
158
|
-
|
159
|
-
|
158
|
+
# We can only fix up the default proc on Rubies that let us set it
|
159
|
+
if {}.respond_to?(:default_proc=)
|
160
|
+
def test_borked_default_proc_can_record_metric
|
161
|
+
fake_borked_default_proc(@hash)
|
160
162
|
|
161
|
-
|
163
|
+
@hash.record(DEFAULT_SPEC, 1)
|
162
164
|
|
163
|
-
|
164
|
-
|
165
|
+
assert_equal(1, @hash[DEFAULT_SPEC].call_count)
|
166
|
+
end
|
165
167
|
|
166
|
-
|
167
|
-
|
168
|
+
def test_borked_default_proc_notices_agent_error
|
169
|
+
fake_borked_default_proc(@hash)
|
168
170
|
|
169
|
-
|
171
|
+
@hash.record(DEFAULT_SPEC, 1)
|
170
172
|
|
171
|
-
|
172
|
-
|
173
|
+
assert_has_error NewRelic::Agent::StatsHash::StatsHashLookupError
|
174
|
+
end
|
173
175
|
|
174
|
-
# We can only fix up the default proc on Rubies that let us set it
|
175
|
-
if {}.respond_to?(:default_proc=)
|
176
176
|
def test_borked_default_proc_heals_thyself
|
177
177
|
fake_borked_default_proc(@hash)
|
178
178
|
|
@@ -186,13 +186,9 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
|
|
186
186
|
|
187
187
|
DEFAULT_SPEC = NewRelic::MetricSpec.new('foo')
|
188
188
|
|
189
|
-
def fake_borked_default_proc(
|
189
|
+
def fake_borked_default_proc(stats_hash)
|
190
190
|
exception = NoMethodError.new("borked default proc gives a NoMethodError on `yield'")
|
191
|
-
|
192
|
-
|
193
|
-
else
|
194
|
-
hash.stubs(:[]).raises(exception)
|
195
|
-
end
|
191
|
+
hash = stats_hash.instance_variable_get(:@unscoped)
|
192
|
+
hash.default_proc = Proc.new { raise exception }
|
196
193
|
end
|
197
|
-
|
198
194
|
end
|
@@ -5,39 +5,34 @@
|
|
5
5
|
require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','test_helper'))
|
6
6
|
|
7
7
|
class NewRelic::Agent::SystemInfoTest < Minitest::Test
|
8
|
-
|
9
8
|
def setup
|
9
|
+
NewRelic::Agent.instance.stats_engine.clear_stats
|
10
10
|
@sysinfo = ::NewRelic::Agent::SystemInfo
|
11
11
|
@sysinfo.clear_processor_info
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Dir.glob("*.txt") do |file|
|
18
|
-
if file =~ /^((\d+|X)pack_(\d+|X)core_(\d+|X)logical).txt$/
|
19
|
-
test_name = "test_#{$1}"
|
20
|
-
test_path = File.join(cpuinfo_test_dir, file)
|
14
|
+
each_cross_agent_test :dir => 'proc_cpuinfo', :pattern => "*.txt" do |file|
|
15
|
+
if File.basename(file) =~ /^((\d+|X)pack_(\d+|X)core_(\d+|X)logical).txt$/
|
16
|
+
test_name = "test_#{$1}"
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
num_physical_packages = $2.to_i
|
19
|
+
num_physical_cores = $3.to_i
|
20
|
+
num_logical_processors = $4.to_i
|
21
|
+
num_physical_packages = nil if num_physical_packages < 1
|
22
|
+
num_physical_cores = nil if num_physical_cores < 1
|
23
|
+
num_logical_processors = nil if num_logical_processors < 1
|
28
24
|
|
29
|
-
|
30
|
-
|
25
|
+
define_method(test_name) do
|
26
|
+
cpuinfo = File.read(file)
|
31
27
|
|
32
|
-
|
28
|
+
info = @sysinfo.parse_cpuinfo(cpuinfo)
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
else
|
39
|
-
fail "Bad filename: cross_agent_tests/proc_cpuinfo/#{file}"
|
30
|
+
assert_equal(num_physical_packages , info[:num_physical_packages ])
|
31
|
+
assert_equal(num_physical_cores , info[:num_physical_cores ])
|
32
|
+
assert_equal(num_logical_processors, info[:num_logical_processors])
|
40
33
|
end
|
34
|
+
else
|
35
|
+
fail "Bad filename: cross_agent_tests/proc_cpuinfo/#{file}"
|
41
36
|
end
|
42
37
|
end
|
43
38
|
|
@@ -55,7 +50,70 @@ class NewRelic::Agent::SystemInfoTest < Minitest::Test
|
|
55
50
|
|
56
51
|
message = "Parsed incorrect Docker container ID from #{filename}"
|
57
52
|
assert_equal(test_case['containerId'], container_id, message)
|
53
|
+
|
54
|
+
if test_case['expectedMetrics']
|
55
|
+
assert_metrics_recorded test_case['expectedMetrics']
|
56
|
+
else
|
57
|
+
refute_metrics_recorded "Supportability/utilization/docker/error"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
each_cross_agent_test :dir => 'proc_meminfo', :pattern => '*.txt' do |file|
|
64
|
+
if File.basename(file) =~ /^meminfo_(\d+)MB.txt$/
|
65
|
+
test_name = "test_#{file}"
|
66
|
+
|
67
|
+
mem_total_expected = $1.to_f
|
68
|
+
|
69
|
+
define_method(test_name) do
|
70
|
+
meminfo = File.read(file)
|
71
|
+
|
72
|
+
mem_total_actual = @sysinfo.parse_linux_meminfo_in_mib(meminfo)
|
73
|
+
|
74
|
+
assert_equal(mem_total_expected, mem_total_actual)
|
75
|
+
end
|
76
|
+
else
|
77
|
+
fail "Bad filename: cross_agent_tests/proc_meminfo/#{file}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_proc_meminfo_unparsable
|
82
|
+
assert_nil @sysinfo.parse_linux_meminfo_in_mib("")
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_system_info_darwin_predicate
|
86
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("darwin13")
|
87
|
+
assert NewRelic::Agent::SystemInfo.darwin?, "Expected OS to match darwin"
|
88
|
+
|
89
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("linux")
|
90
|
+
refute NewRelic::Agent::SystemInfo.darwin?, "Did not expect OS to match darwin"
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_system_info_linux_predicate
|
94
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("linux")
|
95
|
+
assert NewRelic::Agent::SystemInfo.linux?, "Expected OS to match linux"
|
96
|
+
|
97
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("darwin13")
|
98
|
+
refute NewRelic::Agent::SystemInfo.linux?, "Did not expect OS to match linux"
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_system_info_bsd_predicate
|
102
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("freebsd")
|
103
|
+
assert NewRelic::Agent::SystemInfo.bsd?, "Expected OS to match bsd"
|
104
|
+
|
105
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("darwin13")
|
106
|
+
refute NewRelic::Agent::SystemInfo.bsd?, "Did not expect OS to match bsd"
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_supportability_metric_recorded_when_docker_id_unavailable
|
110
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns("linux")
|
111
|
+
cgroup_info = File.read File.join(cross_agent_tests_dir, 'docker_container_id', 'invalid-length.txt')
|
112
|
+
NewRelic::Agent::SystemInfo.expects(:proc_try_read).with('/proc/self/cgroup').returns(cgroup_info)
|
113
|
+
in_transaction('txn') do
|
114
|
+
assert_nil NewRelic::Agent::SystemInfo.docker_container_id
|
58
115
|
end
|
116
|
+
assert_metrics_recorded "Supportability/utilization/docker/error"
|
59
117
|
end
|
60
118
|
end
|
61
119
|
|
@@ -294,13 +294,6 @@ class NewRelic::Agent::TransactionEventAggregatorTest < Minitest::Test
|
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
|
-
def test_includes_http_response_code_in_events
|
298
|
-
generate_request('whatever', :http_response_code => 404)
|
299
|
-
sample = captured_transaction_event
|
300
|
-
code = sample[EVENT_DATA_INDEX]['httpResponseCode']
|
301
|
-
assert_equal('404', code)
|
302
|
-
end
|
303
|
-
|
304
297
|
def test_synthetics_aggregation_limits
|
305
298
|
with_sampler_config(:'synthetics.events_limit' => 10,
|
306
299
|
:'analytics_events.max_samples_stored' => 0) do
|
@@ -1412,7 +1412,7 @@ class NewRelic::Agent::TransactionTest < Minitest::Test
|
|
1412
1412
|
end
|
1413
1413
|
|
1414
1414
|
actual = txn.attributes.agent_attributes_for(NewRelic::Agent::AttributeFilter::DST_TRANSACTION_TRACER)
|
1415
|
-
assert_equal 418, actual[:
|
1415
|
+
assert_equal "418", actual[:"httpResponseCode"]
|
1416
1416
|
end
|
1417
1417
|
|
1418
1418
|
def test_referer_in_agent_attributes
|
@@ -3,16 +3,145 @@
|
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
5
|
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
|
6
|
-
require
|
6
|
+
require 'new_relic/agent/utilization_data'
|
7
7
|
|
8
8
|
module NewRelic::Agent
|
9
9
|
class UtilizationDataTest < Minitest::Test
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def setup
|
11
|
+
stub_aws_info
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_aws_information_is_included_when_available
|
15
|
+
stub_aws_info(
|
16
|
+
:instance_id => "i-e7e85ce1",
|
17
|
+
:instance_type => "m3.medium",
|
18
|
+
:availability_zone => "us-west-2b"
|
19
|
+
)
|
20
|
+
|
21
|
+
utilization_data = UtilizationData.new
|
22
|
+
|
23
|
+
expected = {
|
24
|
+
:aws => {
|
25
|
+
:id => "i-e7e85ce1",
|
26
|
+
:type => "m3.medium",
|
27
|
+
:zone => "us-west-2b"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_equal expected, utilization_data.to_collector_hash[:vendors]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_aws_information_is_omitted_when_available_but_disabled_by_config
|
35
|
+
stub_aws_info(
|
36
|
+
:instance_id => "i-e7e85ce1",
|
37
|
+
:instance_type => "m3.medium",
|
38
|
+
:availability_zone => "us-west-2b"
|
39
|
+
)
|
40
|
+
|
41
|
+
with_config(:'utilization.detect_aws' => false) do
|
42
|
+
utilization_data = UtilizationData.new
|
43
|
+
assert_nil utilization_data.to_collector_hash[:vendors]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_docker_information_is_included_when_available
|
48
|
+
NewRelic::Agent::SystemInfo.stubs(:docker_container_id).returns("47cbd16b77c50cbf71401")
|
49
|
+
|
50
|
+
utilization_data = UtilizationData.new
|
51
|
+
|
52
|
+
expected = {
|
53
|
+
:docker => {
|
54
|
+
:id => "47cbd16b77c50cbf71401"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
assert_equal expected, utilization_data.to_collector_hash[:vendors]
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_docker_information_is_omitted_when_available_but_disabled_by_config
|
62
|
+
NewRelic::Agent::SystemInfo.stubs(:docker_container_id).returns("47cbd16b77c50cbf71401")
|
63
|
+
with_config(:'utilization.detect_docker' => false) do
|
64
|
+
utilization_data = UtilizationData.new
|
65
|
+
assert_nil utilization_data.to_collector_hash[:vendors]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_logged_when_docker_container_id_is_unrecognized
|
70
|
+
NewRelic::Agent::SystemInfo.stubs(:ruby_os_identifier).returns('linux')
|
71
|
+
NewRelic::Agent::SystemInfo.stubs(:ram_in_mib).returns(128)
|
72
|
+
NewRelic::Agent::SystemInfo.stubs(:proc_try_read).returns('whatever')
|
73
|
+
NewRelic::Agent::SystemInfo.stubs(:parse_cgroup_ids).returns('cpu' => "*****YOLO*******")
|
74
|
+
|
75
|
+
expects_logging(:debug, includes("YOLO"))
|
76
|
+
utilization_data = UtilizationData.new
|
77
|
+
assert_nil utilization_data.to_collector_hash[:vendors]
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_aws_and_docker_information_is_included_when_both_available
|
81
|
+
stub_aws_info(
|
82
|
+
:instance_id => "i-e7e85ce1",
|
83
|
+
:instance_type => "m3.medium",
|
84
|
+
:availability_zone => "us-west-2b"
|
85
|
+
)
|
86
|
+
|
87
|
+
NewRelic::Agent::SystemInfo.stubs(:docker_container_id).returns("47cbd16b77c50cbf71401")
|
88
|
+
|
89
|
+
utilization_data = UtilizationData.new
|
90
|
+
|
91
|
+
expected = {
|
92
|
+
:aws => {
|
93
|
+
:id => "i-e7e85ce1",
|
94
|
+
:type => "m3.medium",
|
95
|
+
:zone => "us-west-2b"
|
96
|
+
},
|
97
|
+
:docker => {
|
98
|
+
:id => "47cbd16b77c50cbf71401"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
assert_equal expected, utilization_data.to_collector_hash[:vendors]
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_vendor_information_is_omitted_if_unavailable
|
106
|
+
utilization_data = UtilizationData.new
|
107
|
+
|
108
|
+
assert_nil utilization_data.to_collector_hash[:vendors]
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_hostname_is_present_in_collector_hash
|
112
|
+
NewRelic::Agent::Hostname.stubs(:get).returns("host")
|
113
|
+
|
114
|
+
utilization_data = UtilizationData.new
|
115
|
+
|
116
|
+
assert_equal "host", utilization_data.to_collector_hash[:hostname]
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_cpu_count_is_present_in_collector_hash
|
120
|
+
NewRelic::Agent::SystemInfo.stubs(:num_logical_processors).returns(5)
|
121
|
+
|
122
|
+
utilization_data = UtilizationData.new
|
123
|
+
|
124
|
+
assert_equal 5, utilization_data.to_collector_hash[:logical_processors]
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_memory_is_present_in_collector_hash
|
128
|
+
NewRelic::Agent::SystemInfo.stubs(:ram_in_mib).returns(128)
|
129
|
+
|
130
|
+
utilization_data = UtilizationData.new
|
131
|
+
|
132
|
+
assert_equal 128, utilization_data.to_collector_hash[:total_ram_mib]
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_metadata_version_is_present_in_collector_hash
|
136
|
+
utilization_data = UtilizationData.new
|
137
|
+
|
138
|
+
assert_equal UtilizationData::METADATA_VERSION, utilization_data.to_collector_hash[:metadata_version]
|
139
|
+
end
|
13
140
|
|
14
|
-
def
|
15
|
-
|
141
|
+
def stub_aws_info(responses = {})
|
142
|
+
AWSInfo.any_instance.stubs(:remote_fetch).with("instance-id").returns(responses[:instance_id])
|
143
|
+
AWSInfo.any_instance.stubs(:remote_fetch).with("instance-type").returns(responses[:instance_type])
|
144
|
+
AWSInfo.any_instance.stubs(:remote_fetch).with("placement/availability-zone").returns(responses[:availability_zone])
|
16
145
|
end
|
17
146
|
end
|
18
147
|
end
|