newrelic_rpm 3.9.4.245 → 3.9.5.251

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +57 -0
  3. data/Guardfile +1 -0
  4. data/lib/new_relic/agent/agent.rb +3 -3
  5. data/lib/new_relic/agent/audit_logger.rb +5 -2
  6. data/lib/new_relic/agent/configuration/default_source.rb +11 -5
  7. data/lib/new_relic/agent/error_collector.rb +14 -1
  8. data/lib/new_relic/agent/hostname.rb +22 -1
  9. data/lib/new_relic/agent/instrumentation/middleware_tracing.rb +8 -2
  10. data/lib/new_relic/agent/instrumentation/queue_time.rb +9 -6
  11. data/lib/new_relic/agent/method_tracer.rb +51 -172
  12. data/lib/new_relic/agent/method_tracer_helpers.rb +90 -0
  13. data/lib/new_relic/agent/new_relic_service.rb +33 -11
  14. data/lib/new_relic/agent/new_relic_service/encoders.rb +9 -5
  15. data/lib/new_relic/agent/request_sampler.rb +20 -12
  16. data/lib/new_relic/agent/rules_engine.rb +31 -78
  17. data/lib/new_relic/agent/rules_engine/replacement_rule.rb +76 -0
  18. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +48 -0
  19. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  20. data/lib/new_relic/agent/sql_sampler.rb +39 -10
  21. data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -0
  22. data/lib/new_relic/agent/stats_engine/stats_hash.rb +7 -13
  23. data/lib/new_relic/agent/system_info.rb +96 -10
  24. data/lib/new_relic/agent/threading/agent_thread.rb +4 -1
  25. data/lib/new_relic/agent/threading/backtrace_node.rb +67 -57
  26. data/lib/new_relic/agent/threading/thread_profile.rb +30 -15
  27. data/lib/new_relic/agent/transaction.rb +11 -4
  28. data/lib/new_relic/environment_report.rb +21 -20
  29. data/lib/new_relic/version.rb +1 -1
  30. data/test/agent_helper.rb +12 -0
  31. data/test/fixtures/cross_agent_tests/README.md +1 -0
  32. data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_1core_1logical.txt +3 -0
  33. data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_1core_2logical.txt +14 -0
  34. data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_2core_2logical.txt +14 -0
  35. data/test/fixtures/cross_agent_tests/proc_cpuinfo/1pack_4core_4logical.txt +28 -0
  36. data/test/fixtures/{proc_cpuinfo.txt → cross_agent_tests/proc_cpuinfo/2pack_12core_24logical.txt} +0 -0
  37. data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_20core_40logical.txt +999 -0
  38. data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_2core_2logical.txt +51 -0
  39. data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_2core_4logical.txt +28 -0
  40. data/test/fixtures/cross_agent_tests/proc_cpuinfo/2pack_4core_4logical.txt +28 -0
  41. data/test/fixtures/cross_agent_tests/proc_cpuinfo/4pack_4core_4logical.txt +103 -0
  42. data/test/fixtures/cross_agent_tests/proc_cpuinfo/8pack_8core_8logical.txt +199 -0
  43. data/test/fixtures/cross_agent_tests/proc_cpuinfo/README.md +24 -0
  44. data/test/fixtures/cross_agent_tests/proc_cpuinfo/Xpack_Xcore_2logical.txt +43 -0
  45. data/test/fixtures/cross_agent_tests/transaction_segment_terms.json +101 -0
  46. data/test/multiverse/lib/multiverse/suite.rb +1 -1
  47. data/test/multiverse/suites/agent_only/agent_run_id_handling_test.rb +40 -0
  48. data/test/multiverse/suites/agent_only/labels_test.rb +9 -14
  49. data/test/multiverse/suites/agent_only/marshaling_test.rb +4 -6
  50. data/test/multiverse/suites/agent_only/rename_rule_test.rb +41 -4
  51. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +11 -3
  52. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +8 -8
  53. data/test/multiverse/suites/rack/example_app.rb +20 -0
  54. data/test/multiverse/suites/rack/http_response_code_test.rb +51 -0
  55. data/test/multiverse/suites/sidekiq/Envfile +13 -6
  56. data/test/multiverse/suites/sidekiq/sidekiq_server.rb +4 -3
  57. data/test/new_relic/agent/audit_logger_test.rb +27 -0
  58. data/test/new_relic/agent/error_collector_test.rb +26 -5
  59. data/test/new_relic/agent/hostname_test.rb +66 -14
  60. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +8 -12
  61. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +7 -45
  62. data/test/new_relic/agent/method_tracer_test.rb +52 -1
  63. data/test/new_relic/agent/new_relic_service_test.rb +76 -0
  64. data/test/new_relic/agent/request_sampler_test.rb +7 -0
  65. data/test/new_relic/agent/rules_engine_test.rb +87 -56
  66. data/test/new_relic/agent/sql_sampler_test.rb +50 -14
  67. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +2 -2
  68. data/test/new_relic/agent/stats_engine/samplers_test.rb +1 -1
  69. data/test/new_relic/agent/{stats_hash_test.rb → stats_engine/stats_hash_test.rb} +1 -38
  70. data/test/new_relic/agent/system_info_test.rb +45 -0
  71. data/test/new_relic/agent/threading/agent_thread_test.rb +30 -0
  72. data/test/new_relic/agent/threading/backtrace_node_test.rb +27 -44
  73. data/test/new_relic/agent/threading/thread_profile_test.rb +35 -14
  74. data/test/new_relic/agent/transaction_test.rb +13 -10
  75. data/test/new_relic/environment_report_test.rb +7 -6
  76. data/test/new_relic/fake_collector.rb +10 -6
  77. data/test/new_relic/multiverse_helpers.rb +4 -11
  78. data/test/new_relic/rack/agent_hooks_test.rb +1 -1
  79. data/test/performance/lib/performance/baseline_compare_reporter.rb +24 -7
  80. data/test/performance/lib/performance/result.rb +3 -1
  81. data/test/performance/lib/performance/runner.rb +10 -0
  82. data/test/performance/lib/performance/timer.rb +6 -10
  83. data/test/performance/script/runner +18 -1
  84. data/test/performance/suites/queue_time.rb +21 -0
  85. data/test/performance/suites/stats_hash.rb +34 -0
  86. data/test/performance/suites/thread_profiling.rb +26 -0
  87. metadata +25 -4
  88. metadata.gz.sig +0 -0
@@ -236,6 +236,13 @@ class NewRelic::Agent::RequestSamplerTest < Minitest::Test
236
236
  end
237
237
  end
238
238
 
239
+ def test_includes_http_response_code_in_events
240
+ generate_request('whatever', :http_response_code => 404)
241
+ sample = single_sample
242
+ code = sample[EVENT_DATA_INDEX]['httpResponseCode']
243
+ assert_equal('404', code)
244
+ end
245
+
239
246
  #
240
247
  # Helpers
241
248
  #
@@ -5,13 +5,9 @@
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
6
 
7
7
  class RulesEngineTest < Minitest::Test
8
- def setup
9
- @engine = NewRelic::Agent::RulesEngine.new
10
- end
11
-
12
8
  def test_rule_defaults
13
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '.*',
14
- 'replacement' => '*')
9
+ rule = create_rule('match_expression' => '.*',
10
+ 'replacement' => '*')
15
11
  assert !rule.terminate_chain
16
12
  assert !rule.each_segment
17
13
  assert !rule.ignore
@@ -20,84 +16,119 @@ class RulesEngineTest < Minitest::Test
20
16
  end
21
17
 
22
18
  def test_rule_applies_regex_rename
23
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
24
- 'replacement' => '*')
25
- assert_equal(['foo/*/bar/22', true], rule.apply('foo/1/bar/22'))
19
+ rule = create_rule('match_expression' => '[0-9]+',
20
+ 'replacement' => '*')
21
+
22
+ input = 'foo/1/bar/22'
23
+
24
+ refute(rule.terminal?)
25
+ assert(rule.matches?(input))
26
+ assert_equal('foo/*/bar/22', rule.apply(input))
26
27
  end
27
28
 
28
29
  def test_rules_can_apply_to_frozen_strings
29
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
30
- 'replacement' => '*')
31
- assert_equal(['foo/*/bar/22', true], rule.apply('foo/1/bar/22'.freeze))
30
+ rule = create_rule('match_expression' => '[0-9]+',
31
+ 'replacement' => '*')
32
+
33
+ input = 'foo/1/bar/22'.freeze
34
+
35
+ refute(rule.terminal?)
36
+ assert(rule.matches?(input))
37
+ assert_equal('foo/*/bar/22', rule.apply('foo/1/bar/22'.freeze))
32
38
  end
33
39
 
34
40
  def test_rule_applies_grouping_with_replacements
35
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '([0-9]+)',
36
- 'replacement' => '\\1\\1')
37
- assert_equal(['foo/11/bar/22', true], rule.apply('foo/1/bar/22'))
41
+ rule = create_rule('match_expression' => '([0-9]+)',
42
+ 'replacement' => '\\1\\1')
43
+
44
+ input = 'foo/1/bar/22'
45
+
46
+ refute(rule.terminal?)
47
+ assert(rule.matches?(input))
48
+ assert_equal('foo/11/bar/22', rule.apply('foo/1/bar/22'))
38
49
  end
39
50
 
40
51
  def test_rule_renames_all_matches_when_replace_all_is_true
41
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
42
- 'replacement' => '*',
43
- 'replace_all' => true)
44
- assert_equal(['foo/*/bar/*', true], rule.apply('foo/1/bar/22'))
52
+ rule = create_rule('match_expression' => '[0-9]+',
53
+ 'replacement' => '*',
54
+ 'replace_all' => true)
55
+
56
+ refute(rule.terminal?)
57
+ assert(rule.matches?('foo/1/bar/22'))
58
+ assert_equal('foo/*/bar/*', rule.apply('foo/1/bar/22'))
45
59
  end
46
60
 
47
61
  def test_rule_with_no_match
48
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => 'QQ',
49
- 'replacement' => 'qq')
50
- assert_equal(['foo/1/bar/22', false], rule.apply('foo/1/bar/22'))
62
+ rule = create_rule('match_expression' => 'QQ',
63
+ 'replacement' => 'qq')
64
+
65
+ refute(rule.terminal?)
66
+ refute(rule.matches?('foo/1/bar/22'))
67
+ assert_equal('foo/1/bar/22', rule.apply('foo/1/bar/22'))
51
68
  end
52
69
 
53
70
  def test_applies_rules_in_order
54
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
55
- 'replacement' => '*',
56
- 'replace_all' => true,
57
- 'eval_order' => 0)
58
- rerule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '\*',
59
- 'replacement' => 'x',
60
- 'replace_all' => true,
61
- 'eval_order' => 1)
62
- @engine << rerule
63
- @engine << rule
64
-
65
- assert_equal('foo/x/bar/x', @engine.rename('foo/1/bar/22'))
71
+ rule = create_rule('match_expression' => '[0-9]+',
72
+ 'replacement' => '*',
73
+ 'replace_all' => true,
74
+ 'eval_order' => 0)
75
+
76
+ rerule = create_rule('match_expression' => '\*',
77
+ 'replacement' => 'x',
78
+ 'replace_all' => true,
79
+ 'eval_order' => 1)
80
+
81
+ engine = NewRelic::Agent::RulesEngine.new([rerule, rule])
82
+
83
+ assert_equal('foo/x/bar/x', engine.rename('foo/1/bar/22'))
66
84
  end
67
85
 
68
86
  def test_can_apply_rules_to_all_segments
69
- rule = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+.*',
70
- 'replacement' => '*',
71
- 'each_segment' => true)
72
- @engine << rule
87
+ rule = create_rule('match_expression' => '[0-9]+.*',
88
+ 'replacement' => '*',
89
+ 'each_segment' => true)
90
+
91
+ engine = NewRelic::Agent::RulesEngine.new([rule])
73
92
 
74
- assert_equal('foo/*/bar/*', @engine.rename('foo/1a/bar/22b'))
93
+ assert_equal('foo/*/bar/*', engine.rename('foo/1a/bar/22b'))
75
94
  end
76
95
 
77
96
  def test_stops_after_terminate_chain
78
- rule0 = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '[0-9]+',
79
- 'replacement' => '*',
80
- 'each_segment' => true,
81
- 'eval_order' => 0,
82
- 'terminate_chain' => true)
83
- rule1 = NewRelic::Agent::RulesEngine::Rule.new('match_expression' => '.*',
84
- 'replacement' => 'X',
85
- 'replace_all' => true,
86
- 'eval_order' => 1)
87
- @engine << rule0
88
- @engine << rule1
89
-
90
- assert_equal('foo/*/bar/*', @engine.rename('foo/1/bar/22'))
97
+ rule0 = create_rule('match_expression' => '[0-9]+',
98
+ 'replacement' => '*',
99
+ 'each_segment' => true,
100
+ 'eval_order' => 0,
101
+ 'terminate_chain' => true)
102
+
103
+ rule1 = create_rule('match_expression' => '.*',
104
+ 'replacement' => 'X',
105
+ 'replace_all' => true,
106
+ 'eval_order' => 1)
107
+
108
+ engine = NewRelic::Agent::RulesEngine.new([rule0, rule1])
109
+
110
+ assert_equal('foo/*/bar/*', engine.rename('foo/1/bar/22'))
111
+ end
112
+
113
+ def create_rule(spec)
114
+ NewRelic::Agent::RulesEngine::ReplacementRule.new(spec)
91
115
  end
92
116
 
93
117
  load_cross_agent_test('rules').each do |testcase|
94
118
  define_method("test_#{testcase['testname']}") do
95
- testcase["rules"].each do |rule|
96
- @engine << NewRelic::Agent::RulesEngine::Rule.new(rule)
97
- end
119
+ engine = NewRelic::Agent::RulesEngine.create_metric_rules('metric_name_rules' => testcase['rules'])
98
120
 
99
121
  testcase["tests"].each do |test|
100
- assert_equal(test["expected"], @engine.rename(test["input"]), "Input: #{test['input'].inspect}")
122
+ assert_equal(test["expected"], engine.rename(test["input"]), "Input: #{test['input'].inspect}")
123
+ end
124
+ end
125
+ end
126
+
127
+ load_cross_agent_test('transaction_segment_terms').each do |testcase|
128
+ define_method("test_app_segment_terms_#{testcase['testname']}") do
129
+ engine = NewRelic::Agent::RulesEngine.create_transaction_rules(testcase)
130
+ testcase['tests'].each do |test|
131
+ assert_equal(test["expected"], engine.rename(test["input"]), "Input: #{test['input'].inspect}")
101
132
  end
102
133
  end
103
134
  end
@@ -71,7 +71,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
71
71
  assert_equal('a' * 16_381 + '...', @sampler.tl_transaction_data.sql_data[0].sql)
72
72
  end
73
73
 
74
- def test_harvest_slow_sql
74
+ def test_save_slow_sql
75
75
  data = NewRelic::Agent::TransactionSqlData.new
76
76
  data.set_transaction_info("/c/a", 'guid')
77
77
  data.set_transaction_name("WebTransaction/Controller/c/a")
@@ -80,7 +80,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
80
80
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
81
81
  NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)
82
82
  ]
83
- @sampler.harvest_slow_sql data
83
+ @sampler.save_slow_sql data
84
84
 
85
85
  assert_equal 2, @sampler.sql_traces.size
86
86
  end
@@ -107,7 +107,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
107
107
  data.sql_data.concat [NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.5),
108
108
  NewRelic::Agent::SlowSql.new("select * from test", "Database/test/select", {}, 1.2),
109
109
  NewRelic::Agent::SlowSql.new("select * from test2", "Database/test2/select", {}, 1.1)]
110
- @sampler.harvest_slow_sql data
110
+ @sampler.save_slow_sql data
111
111
 
112
112
  sql_traces = @sampler.harvest!
113
113
  assert_equal 2, sql_traces.size
@@ -122,7 +122,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
122
122
  "Database/test#{(i+97).chr}/select", {}, i)
123
123
  end
124
124
 
125
- @sampler.harvest_slow_sql data
125
+ @sampler.save_slow_sql data
126
126
  result = @sampler.harvest!
127
127
 
128
128
  assert_equal(10, result.size)
@@ -139,7 +139,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
139
139
  NewRelic::Agent::SlowSql.new("select * from test2 where foo in (1,2)", "Database/test2/select", {}, 1.1)
140
140
  ]
141
141
  data.sql_data.concat(queries)
142
- @sampler.harvest_slow_sql data
142
+ @sampler.save_slow_sql data
143
143
 
144
144
  sql_traces = @sampler.harvest!
145
145
  assert_equal 2, sql_traces.size
@@ -168,8 +168,9 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
168
168
  1.1, nil, &explainer)
169
169
  ]
170
170
  data.sql_data.concat(queries)
171
- @sampler.harvest_slow_sql data
172
- sql_traces = @sampler.harvest!
171
+ @sampler.save_slow_sql data
172
+ sql_traces = @sampler.harvest!.sort_by(&:total_call_time).reverse
173
+
173
174
  assert_equal(["header0", "header1", "header2"],
174
175
  sql_traces[0].params[:explain_plan][0].sort)
175
176
  assert_equal(["header0", "header1", "header2"],
@@ -199,7 +200,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
199
200
  "Database/test/select", {}, 1.5)
200
201
  ]
201
202
  data.sql_data.concat(queries)
202
- @sampler.harvest_slow_sql data
203
+ @sampler.save_slow_sql data
203
204
  sql_traces = @sampler.harvest!
204
205
  assert_equal(nil, sql_traces[0].params[:explain_plan])
205
206
  end
@@ -244,8 +245,8 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
244
245
  "Database/test/select", {}, 1.5),
245
246
  NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
246
247
  "Database/test/select", {}, 1.2)])
247
- @sampler.harvest_slow_sql(data)
248
- sql_traces = @sampler.harvest!
248
+ @sampler.save_slow_sql(data)
249
+ sql_traces = @sampler.harvest!.sort_by(&:total_call_time).reverse
249
250
 
250
251
  assert_equal('select * from test where foo = ?', sql_traces[0].sql)
251
252
  assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
@@ -265,14 +266,34 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
265
266
  "Database/test/select", {}, 1.5),
266
267
  NewRelic::Agent::SlowSql.new("select * from test where foo in (1,2,3,4,5)",
267
268
  "Database/test/select", {}, 1.2)])
268
- @sampler.harvest_slow_sql(data)
269
- sql_traces = @sampler.harvest!
269
+ @sampler.save_slow_sql(data)
270
+ sql_traces = @sampler.harvest!.sort_by(&:total_call_time).reverse
270
271
 
271
272
  assert_equal('select * from test where foo = ?', sql_traces[0].sql)
272
273
  assert_equal('select * from test where foo in (?,?,?,?,?)', sql_traces[1].sql)
273
274
  end
274
275
  end
275
276
 
277
+ def test_takes_slowest_samples
278
+ data = NewRelic::Agent::TransactionSqlData.new
279
+ data.set_transaction_info("/c/a", 'guid')
280
+ data.set_transaction_name("WebTransaction/Controller/c/a")
281
+
282
+ count = NewRelic::Agent::SqlSampler::MAX_SAMPLES * 2
283
+ durations = (0...count).to_a.shuffle
284
+ durations.each do |i|
285
+ data.sql_data << NewRelic::Agent::SlowSql.new("SELECT * FROM table#{i}", "Database/table#{i}/select", {}, i)
286
+ end
287
+
288
+ @sampler.save_slow_sql(data)
289
+ sql_traces = @sampler.harvest!
290
+
291
+ harvested_durations = sql_traces.map(&:total_call_time).sort
292
+ expected_durations = durations.sort.last(10)
293
+
294
+ assert_equal expected_durations, harvested_durations
295
+ end
296
+
276
297
  def test_can_directly_marshal_traces_for_pipe_transmittal
277
298
  with_config(:'transaction_tracer.explain_enabled' => false) do
278
299
  data = NewRelic::Agent::TransactionSqlData.new
@@ -280,7 +301,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
280
301
  data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
281
302
  "Database/test/select",
282
303
  {}, 1.5, &explainer)])
283
- @sampler.harvest_slow_sql(data)
304
+ @sampler.save_slow_sql(data)
284
305
  sql_traces = @sampler.harvest!
285
306
 
286
307
  Marshal.dump(sql_traces)
@@ -295,7 +316,7 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
295
316
  data.sql_data.concat([NewRelic::Agent::SlowSql.new("select * from test",
296
317
  "Database/test/select",
297
318
  {}, 1.5)])
298
- @sampler.harvest_slow_sql(data)
319
+ @sampler.save_slow_sql(data)
299
320
  sql_traces = @sampler.harvest!
300
321
 
301
322
  if NewRelic::Agent::NewRelicService::JsonMarshaller.is_supported?
@@ -364,4 +385,19 @@ class NewRelic::Agent::SqlSamplerTest < Minitest::Test
364
385
  state = NewRelic::Agent::TransactionState.tl_get
365
386
  @sampler.on_finishing_transaction(state, "whatever", Time.now)
366
387
  end
388
+
389
+ def test_caps_collection_of_unique_statements
390
+ data = NewRelic::Agent::TransactionSqlData.new
391
+ data.set_transaction_info("/c/a", 'guid')
392
+ data.set_transaction_name("WebTransaction/Controller/c/a")
393
+
394
+ count = NewRelic::Agent::SqlSampler::MAX_SAMPLES + 1
395
+ count.times do |i|
396
+ data.sql_data << NewRelic::Agent::SlowSql.new("SELECT * FROM table#{i}", "Database/table#{i}/select", {}, i)
397
+ end
398
+
399
+ @sampler.save_slow_sql(data)
400
+
401
+ assert_equal NewRelic::Agent::SqlSampler::MAX_SAMPLES, @sampler.sql_traces.size
402
+ end
367
403
  end
@@ -246,7 +246,7 @@ class NewRelic::Agent::MetricStatsTest < Minitest::Test
246
246
  end
247
247
 
248
248
  def test_harvest_applies_metric_rename_rules
249
- rule = NewRelic::Agent::RulesEngine::Rule.new(
249
+ rule = NewRelic::Agent::RulesEngine::ReplacementRule.new(
250
250
  'match_expression' => '[0-9]+',
251
251
  'replacement' => '*',
252
252
  'replace_all' => true
@@ -268,7 +268,7 @@ class NewRelic::Agent::MetricStatsTest < Minitest::Test
268
268
  end
269
269
 
270
270
  def test_apply_rules_to_metric_data_respects_ignore_rules
271
- rule = NewRelic::Agent::RulesEngine::Rule.new(
271
+ rule = NewRelic::Agent::RulesEngine::ReplacementRule.new(
272
272
  'match_expression' => 'bar',
273
273
  'ignore' => 'true'
274
274
  )
@@ -33,7 +33,7 @@ class NewRelic::Agent::StatsEngine::SamplersTest < Minitest::Test
33
33
 
34
34
  freeze_time
35
35
  Process.stubs(:times).returns(timeinfo0, timeinfo1)
36
- NewRelic::Agent::SystemInfo.stubs(:processor_count).returns(4)
36
+ NewRelic::Agent::SystemInfo.stubs(:num_logical_processors).returns(4)
37
37
 
38
38
  s = NewRelic::Agent::Samplers::CpuSampler.new # this calls poll
39
39
  advance_time(elapsed)
@@ -2,7 +2,7 @@
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
- require File.expand_path(File.join(File.dirname(__FILE__),'..', '..','test_helper'))
5
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..','test_helper'))
6
6
 
7
7
  class NewRelic::Agent::StatsHashTest < Minitest::Test
8
8
  def setup
@@ -184,45 +184,8 @@ class NewRelic::Agent::StatsHashTest < Minitest::Test
184
184
  end
185
185
  end
186
186
 
187
- STAT_SETTERS = [:call_count=, :min_call_time=, :max_call_time=, :total_call_time=, :total_exclusive_time=, :sum_of_squares=]
188
187
  DEFAULT_SPEC = NewRelic::MetricSpec.new('foo')
189
188
 
190
- STAT_SETTERS.each do |setter|
191
- define_method("test_merge_allows_nil_destination_for_#{setter.to_s.gsub('=', '')}") do
192
- dest = NewRelic::Agent::Stats.new
193
- dest.send(setter, nil)
194
- expected = dest.dup
195
-
196
- @hash[DEFAULT_SPEC] = dest
197
-
198
- incoming = NewRelic::Agent::StatsHash.new
199
- incoming[DEFAULT_SPEC] = NewRelic::Agent::Stats.new
200
-
201
- @hash.merge!(incoming)
202
-
203
- assert_equal expected, @hash[DEFAULT_SPEC]
204
- assert_has_error NewRelic::Agent::StatsHash::StatsMergerError
205
- end
206
- end
207
-
208
- STAT_SETTERS.each do |setter|
209
- define_method("test_merge_allows_nil_source_for_#{setter.to_s.gsub('=', '')}") do
210
- dest = NewRelic::Agent::Stats.new
211
- expected = dest.dup
212
-
213
- @hash[DEFAULT_SPEC] = dest
214
-
215
- source = NewRelic::Agent::Stats.new
216
- source.send(setter, nil)
217
- incoming = NewRelic::Agent::StatsHash.new
218
- incoming[DEFAULT_SPEC] = source
219
-
220
- @hash.merge!(incoming)
221
-
222
- assert_equal expected, @hash[DEFAULT_SPEC]
223
- end
224
- end
225
-
226
189
  def fake_borked_default_proc(hash)
227
190
  exception = NoMethodError.new("borked default proc gives a NoMethodError on `yield'")
228
191
  if hash.respond_to?(:default_proc=)
@@ -0,0 +1,45 @@
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 NewRelic::Agent::SystemInfoTest < Minitest::Test
8
+
9
+ def setup
10
+ @sysinfo = ::NewRelic::Agent::SystemInfo
11
+ @sysinfo.clear_processor_info
12
+ end
13
+
14
+ test_dir = File.join(cross_agent_tests_dir, 'proc_cpuinfo')
15
+
16
+ Dir.chdir(test_dir) do
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(test_dir, file)
21
+
22
+ num_physical_packages = $2.to_i
23
+ num_physical_cores = $3.to_i
24
+ num_logical_processors = $4.to_i
25
+ num_physical_packages = nil if num_physical_packages < 1
26
+ num_physical_cores = nil if num_physical_cores < 1
27
+ num_logical_processors = nil if num_logical_processors < 1
28
+
29
+ define_method(test_name) do
30
+ cpuinfo = File.read(test_path)
31
+
32
+ info = @sysinfo.parse_cpuinfo(cpuinfo)
33
+
34
+ assert_equal(num_physical_packages , info[:num_physical_packages ])
35
+ assert_equal(num_physical_cores , info[:num_physical_cores ])
36
+ assert_equal(num_logical_processors, info[:num_logical_processors])
37
+ end
38
+ else
39
+ fail "Bad filename: cross_agent_tests/proc_cpuinfo/#{file}"
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+