newrelic_rpm 3.6.7.159 → 3.6.8.164

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/CHANGELOG +14 -0
  2. data/lib/new_relic/agent/agent.rb +38 -35
  3. data/lib/new_relic/agent/agent_logger.rb +6 -47
  4. data/lib/new_relic/agent/beacon_configuration.rb +10 -4
  5. data/lib/new_relic/agent/browser_monitoring.rb +39 -33
  6. data/lib/new_relic/agent/commands/agent_command.rb +4 -4
  7. data/lib/new_relic/agent/commands/agent_command_router.rb +72 -10
  8. data/lib/new_relic/agent/commands/thread_profiler_session.rb +110 -0
  9. data/lib/new_relic/agent/commands/xray_session.rb +55 -0
  10. data/lib/new_relic/agent/commands/xray_session_collection.rb +158 -0
  11. data/lib/new_relic/agent/configuration/default_source.rb +61 -24
  12. data/lib/new_relic/agent/configuration/mask_defaults.rb +2 -2
  13. data/lib/new_relic/agent/configuration/server_source.rb +1 -1
  14. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +2 -0
  15. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +4 -10
  16. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +10 -11
  17. data/lib/new_relic/agent/memory_logger.rb +52 -0
  18. data/lib/new_relic/agent/new_relic_service.rb +4 -0
  19. data/lib/new_relic/agent/request_sampler.rb +32 -13
  20. data/lib/new_relic/agent/samplers/cpu_sampler.rb +6 -3
  21. data/lib/new_relic/agent/threading/agent_thread.rb +2 -1
  22. data/lib/new_relic/agent/threading/backtrace_node.rb +80 -27
  23. data/lib/new_relic/agent/threading/backtrace_service.rb +264 -0
  24. data/lib/new_relic/agent/threading/thread_profile.rb +79 -118
  25. data/lib/new_relic/agent/transaction/developer_mode_sample_buffer.rb +56 -0
  26. data/lib/new_relic/agent/transaction/force_persist_sample_buffer.rb +25 -0
  27. data/lib/new_relic/agent/transaction/slowest_sample_buffer.rb +25 -0
  28. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +86 -0
  29. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +64 -0
  30. data/lib/new_relic/agent/transaction.rb +25 -4
  31. data/lib/new_relic/agent/transaction_sample_builder.rb +6 -10
  32. data/lib/new_relic/agent/transaction_sampler.rb +47 -202
  33. data/lib/new_relic/agent/worker_loop.rb +47 -39
  34. data/lib/new_relic/agent.rb +1 -1
  35. data/lib/new_relic/build.rb +2 -2
  36. data/lib/new_relic/coerce.rb +8 -0
  37. data/lib/new_relic/control/instance_methods.rb +1 -0
  38. data/lib/new_relic/rack/browser_monitoring.rb +15 -1
  39. data/lib/new_relic/rack/developer_mode.rb +1 -1
  40. data/lib/new_relic/transaction_sample.rb +20 -5
  41. data/lib/new_relic/version.rb +1 -1
  42. data/newrelic.yml +4 -6
  43. data/newrelic_rpm.gemspec +1 -1
  44. data/test/agent_helper.rb +11 -0
  45. data/test/environments/lib/environments/runner.rb +5 -1
  46. data/test/environments/rails21/Gemfile +2 -2
  47. data/test/environments/rails22/Gemfile +2 -2
  48. data/test/environments/rails23/Gemfile +2 -2
  49. data/test/environments/rails31/Gemfile +2 -2
  50. data/test/environments/rails32/Gemfile +2 -2
  51. data/test/multiverse/suites/agent_only/marshaling_test.rb +1 -1
  52. data/test/multiverse/suites/agent_only/testing_app.rb +6 -0
  53. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +5 -5
  54. data/test/multiverse/suites/agent_only/xray_sessions_test.rb +163 -0
  55. data/test/multiverse/suites/rails/request_statistics_test.rb +2 -2
  56. data/test/multiverse/suites/rails/view_instrumentation_test.rb +20 -21
  57. data/test/new_relic/agent/agent/connect_test.rb +0 -10
  58. data/test/new_relic/agent/agent_test.rb +27 -44
  59. data/test/new_relic/agent/browser_monitoring_test.rb +0 -52
  60. data/test/new_relic/agent/commands/agent_command_router_test.rb +150 -12
  61. data/test/new_relic/agent/commands/{thread_profiler_test.rb → thread_profiler_session_test.rb} +58 -19
  62. data/test/new_relic/agent/commands/xray_session_collection_test.rb +332 -0
  63. data/test/new_relic/agent/commands/xray_session_test.rb +42 -0
  64. data/test/new_relic/agent/configuration/manager_test.rb +2 -1
  65. data/test/new_relic/agent/configuration/server_source_test.rb +10 -10
  66. data/test/new_relic/agent/cpu_sampler_test.rb +50 -0
  67. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +31 -0
  68. data/test/new_relic/agent/instrumentation/queue_time_test.rb +0 -1
  69. data/test/new_relic/agent/instrumentation/sequel_test.rb +1 -1
  70. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +0 -1
  71. data/test/new_relic/agent/memory_logger_test.rb +53 -0
  72. data/test/new_relic/agent/new_relic_service_test.rb +1 -1
  73. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -5
  74. data/test/new_relic/agent/request_sampler_test.rb +70 -20
  75. data/test/new_relic/agent/rules_engine_test.rb +6 -0
  76. data/test/new_relic/agent/threading/agent_thread_test.rb +2 -2
  77. data/test/new_relic/agent/threading/backtrace_node_test.rb +110 -17
  78. data/test/new_relic/agent/threading/backtrace_service_test.rb +567 -0
  79. data/test/new_relic/agent/threading/fake_thread.rb +4 -0
  80. data/test/new_relic/agent/threading/thread_profile_test.rb +141 -217
  81. data/test/new_relic/agent/threading/threaded_test_case.rb +3 -8
  82. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +69 -0
  83. data/test/new_relic/agent/transaction/force_persist_sample_buffer_test.rb +52 -0
  84. data/test/new_relic/agent/transaction/slowest_sample_buffer_test.rb +67 -0
  85. data/test/new_relic/agent/transaction/xray_sample_buffer_test.rb +71 -0
  86. data/test/new_relic/agent/transaction_sampler_test.rb +171 -307
  87. data/test/new_relic/agent/transaction_test.rb +33 -5
  88. data/test/new_relic/agent/worker_loop_test.rb +33 -11
  89. data/test/new_relic/coerce_test.rb +13 -0
  90. data/test/new_relic/fake_collector.rb +26 -3
  91. data/test/new_relic/multiverse_helpers.rb +2 -0
  92. data/test/new_relic/rack/browser_monitoring_test.rb +12 -0
  93. data/test/new_relic/rack/developer_mode_test.rb +2 -2
  94. data/test/new_relic/transaction_sample_test.rb +19 -2
  95. data/test/performance/lib/performance/console_reporter.rb +1 -1
  96. data/test/performance/lib/performance/test_case.rb +7 -3
  97. data/test/performance/script/runner +3 -0
  98. data/test/performance/suites/thread_profiling.rb +83 -0
  99. data/test/test_helper.rb +2 -2
  100. data.tar.gz.sig +0 -0
  101. metadata +32 -32
  102. metadata.gz.sig +1 -1
  103. data/lib/new_relic/agent/commands/thread_profiler.rb +0 -80
@@ -0,0 +1,42 @@
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/commands/xray_session'
7
+
8
+ module NewRelic::Agent::Commands
9
+ class XraySessionTest < Test::Unit::TestCase
10
+ def test_run_profiler
11
+ session = XraySession.new('run_profiler' => true)
12
+ assert session.run_profiler?
13
+ end
14
+
15
+ def test_run_profiler_respects_config
16
+ with_config(:'xray_session.allow_profiles' => false) do
17
+ session = XraySession.new('run_profiler' => true)
18
+ assert_false session.run_profiler?
19
+ end
20
+ end
21
+
22
+ def test_not_finished
23
+ freeze_time
24
+
25
+ session = XraySession.new({})
26
+ session.activate
27
+
28
+ assert_false session.finished?
29
+ end
30
+
31
+ def test_finished
32
+ freeze_time
33
+
34
+ session = XraySession.new('duration' => 1.0)
35
+ session.activate
36
+
37
+ advance_time(2.0)
38
+
39
+ assert session.finished?
40
+ end
41
+ end
42
+ end
@@ -5,6 +5,7 @@
5
5
  require File.expand_path(File.join(File.dirname(__FILE__),'..','..','..','test_helper'))
6
6
  require 'new_relic/agent/configuration/manager'
7
7
  require 'new_relic/agent/configuration/mask_defaults'
8
+ require 'new_relic/agent/threading/backtrace_service'
8
9
 
9
10
  module NewRelic::Agent::Configuration
10
11
  class ManagerTest < Test::Unit::TestCase
@@ -153,7 +154,7 @@ module NewRelic::Agent::Configuration
153
154
  end
154
155
 
155
156
  def test_config_masks_thread_profiler
156
- supported = NewRelic::Agent::Commands::ThreadProfiler.is_supported?
157
+ supported = NewRelic::Agent::Threading::BacktraceService.is_supported?
157
158
  reported_config = @manager.to_collector_hash
158
159
 
159
160
  if supported
@@ -61,7 +61,7 @@ module NewRelic::Agent::Configuration
61
61
  :'error_collector.enabled' => true,
62
62
  :'slow_sql.enabled' => true,
63
63
  :'transaction_tracer.enabled' => true,
64
- :'request_sampler.enabled' => true
64
+ :'analytics_events.enabled' => true
65
65
  }
66
66
  @source = ServerSource.new(rsp, existing_config)
67
67
  assert !@source[:'error_collector.enabled']
@@ -79,13 +79,13 @@ module NewRelic::Agent::Configuration
79
79
  :'error_collector.enabled' => true,
80
80
  :'slow_sql.enabled' => true,
81
81
  :'transaction_tracer.enabled' => true,
82
- :'request_sampler.enabled' => true
82
+ :'analytics_events.enabled' => true
83
83
  }
84
84
  @source = ServerSource.new(rsp, existing_config)
85
85
  assert @source[:'error_collector.enabled']
86
86
  assert @source[:'slow_sql.enabled']
87
87
  assert @source[:'transaction_tracer.enabled']
88
- assert @source[:'request_sampler.enabled']
88
+ assert @source[:'analytics_events.enabled']
89
89
  end
90
90
 
91
91
  def test_should_allow_manual_disable_of_gated_features
@@ -98,13 +98,13 @@ module NewRelic::Agent::Configuration
98
98
  :'error_collector.enabled' => false,
99
99
  :'slow_sql.enabled' => false,
100
100
  :'transaction_tracer.enabled' => false,
101
- :'request_sampler.enabled' => false
101
+ :'analytics_events.enabled' => false
102
102
  }
103
103
  @source = ServerSource.new(rsp, existing_config)
104
104
  assert !@source[:'error_collector.enabled']
105
105
  assert !@source[:'slow_sql.enabled']
106
106
  assert !@source[:'transaction_tracer.enabled']
107
- assert !@source[:'request_sampler.enabled']
107
+ assert !@source[:'analytics_events.enabled']
108
108
  end
109
109
 
110
110
  def test_should_enable_gated_features_when_server_says_yes_and_existing_says_no
@@ -116,20 +116,20 @@ module NewRelic::Agent::Configuration
116
116
  'transaction_tracer.enabled' => true,
117
117
  'slow_sql.enabled' => true,
118
118
  'error_collector.enabled' => true,
119
- 'request_sampler.enabled' => true
119
+ 'analytics_events.enabled' => true
120
120
  }
121
121
  }
122
122
  existing_config = {
123
123
  :'error_collector.enabled' => false,
124
124
  :'slow_sql.enabled' => false,
125
125
  :'transaction_tracer.enabled' => false,
126
- :'reqeust_sampler.enabled' => false
126
+ :'analytics_events.enabled' => false
127
127
  }
128
128
  @source = ServerSource.new(rsp, existing_config)
129
129
  assert @source[:'error_collector.enabled']
130
130
  assert @source[:'slow_sql.enabled']
131
131
  assert @source[:'transaction_tracer.enabled']
132
- assert @source[:'request_sampler.enabled']
132
+ assert @source[:'analytics_events.enabled']
133
133
  end
134
134
 
135
135
  def test_should_not_gate_when_gating_keys_absent
@@ -138,14 +138,14 @@ module NewRelic::Agent::Configuration
138
138
  'transaction_tracer.enabled' => true,
139
139
  'slow_sql.enabled' => true,
140
140
  'error_collector.enabled' => true,
141
- 'request_sampler.enabled' => true
141
+ 'analytics_events.enabled' => true
142
142
  }
143
143
  }
144
144
  @source = ServerSource.new(rsp, {})
145
145
  assert @source[:'error_collector.enabled']
146
146
  assert @source[:'slow_sql.enabled']
147
147
  assert @source[:'transaction_tracer.enabled']
148
- assert @source[:'request_sampler.enabled']
148
+ assert @source[:'analytics_events.enabled']
149
149
  end
150
150
  end
151
151
  end
@@ -0,0 +1,50 @@
1
+ # -*- ruby -*-
2
+ # encoding: utf-8
3
+ # This file is distributed under New Relic's license terms.
4
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+
6
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
7
+ require 'new_relic/agent/samplers/cpu_sampler'
8
+
9
+ class NewRelic::Agent::Samplers::CpuSamplerTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @original_jruby_version = JRUBY_VERSION if defined?(JRuby)
13
+ end
14
+
15
+ def teardown
16
+ set_jruby_version_constant(@original_jruby_version) if defined?(JRuby)
17
+ end
18
+
19
+ def test_correcly_detecting_jruby_support_for_correct_cpu_sampling
20
+ if defined?(JRuby)
21
+ set_jruby_version_constant '1.6.8'
22
+ refute_supported_on_platform
23
+
24
+ set_jruby_version_constant '1.7.0'
25
+ assert_supported_on_platform
26
+
27
+ set_jruby_version_constant '1.7.4'
28
+ assert_supported_on_platform
29
+ else
30
+ assert_supported_on_platform
31
+ end
32
+ end
33
+
34
+ #
35
+ # Helpers
36
+ #
37
+
38
+ def assert_supported_on_platform
39
+ assert_equal NewRelic::Agent::Samplers::CpuSampler.supported_on_this_platform?, true, "should be supported on this platform"
40
+ end
41
+
42
+ def refute_supported_on_platform
43
+ assert_equal NewRelic::Agent::Samplers::CpuSampler.supported_on_this_platform?, false, "should not be supported on this platform"
44
+ end
45
+
46
+ def set_jruby_version_constant(string)
47
+ Object.const_set('JRUBY_VERSION', string)
48
+ end
49
+
50
+ end
@@ -40,6 +40,7 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Test::U
40
40
  @stats_engine = NewRelic::Agent.instance.stats_engine
41
41
  @stats_engine.clear_stats
42
42
  NewRelic::Agent.manual_start
43
+ NewRelic::Agent::TransactionState.clear
43
44
  end
44
45
 
45
46
  def teardown
@@ -102,6 +103,36 @@ class NewRelic::Agent::Instrumentation::ActionControllerSubscriberTest < Test::U
102
103
  )
103
104
  end
104
105
 
106
+ def test_sets_default_transaction_name_on_start
107
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
108
+ assert_equal 'Controller/test/index', NewRelic::Agent::Transaction.current.name
109
+ ensure
110
+ @subscriber.finish('process_action.action_controller', :id, @entry_payload)
111
+ end
112
+
113
+ def test_sets_default_transaction_keeps_name_through_stop
114
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
115
+ txn = NewRelic::Agent::Transaction.current
116
+ @subscriber.finish('process_action.action_controller', :id, @entry_payload)
117
+ assert_equal 'Controller/test/index', txn.name
118
+ end
119
+
120
+ def test_sets_transaction_name
121
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
122
+ NewRelic::Agent.set_transaction_name('something/else')
123
+ assert_equal 'Controller/something/else', NewRelic::Agent::Transaction.current.name
124
+ ensure
125
+ @subscriber.finish('process_action.action_controller', :id, @entry_payload)
126
+ end
127
+
128
+ def test_sets_transaction_name_holds_through_stop
129
+ @subscriber.start('process_action.action_controller', :id, @entry_payload)
130
+ txn = NewRelic::Agent::Transaction.current
131
+ NewRelic::Agent.set_transaction_name('something/else')
132
+ @subscriber.finish('process_action.action_controller', :id, @entry_payload)
133
+ assert_equal 'Controller/something/else', txn.name
134
+ end
135
+
105
136
  def test_record_nothing_for_ignored_action
106
137
  @entry_payload[:action] = 'ignored_action'
107
138
  @exit_payload[:action] = 'ignored_action'
@@ -59,7 +59,6 @@ class NewRelic::Agent::Instrumentation::QueueTimeTest < Test::Unit::TestCase
59
59
 
60
60
  def test_parse_frontend_timestamp_from_header_missing_t_equals
61
61
  header = { 'HTTP_X_REQUEST_START' => (Time.now.to_f - 60).to_s }
62
- sleep 2
63
62
  assert_in_delta(seconds_ago(60), QueueTime.parse_frontend_timestamp(header), 0.001)
64
63
  end
65
64
 
@@ -295,7 +295,7 @@ class NewRelic::Agent::Instrumentation::SequelInstrumentationTest < Test::Unit::
295
295
 
296
296
  sampler.notice_pop_scope "Controller/sandwiches/index"
297
297
  sampler.notice_scope_empty(stub('txn', :name => '/', :custom_parameters => {}))
298
- sampler.samples
298
+ [sampler.last_sample]
299
299
  end
300
300
 
301
301
  def last_segment_for(options={})
@@ -105,7 +105,6 @@ class NewRelic::Agent::Instrumentation::TaskInstrumentationTest < Test::Unit::Te
105
105
  def test_transaction
106
106
  run_task_outer(10)
107
107
 
108
- assert_equal 0, @agent.transaction_sampler.scope_depth, "existing unfinished sample"
109
108
  assert_metrics_recorded({
110
109
  'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/outer_task' => { :call_count => 1 },
111
110
  'Controller/NewRelic::Agent::Instrumentation::TaskInstrumentationTest/inner_task_0' => { :call_count => 2 }
@@ -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
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
6
+ require 'new_relic/agent/memory_logger'
7
+
8
+ class MemoryLoggerTest < Test::Unit::TestCase
9
+ LEVELS = [:fatal, :error, :warn, :info, :debug]
10
+
11
+ def setup
12
+ @logger = NewRelic::Agent::MemoryLogger.new
13
+ end
14
+
15
+ def test_proxies_messages_to_real_logger_on_dump
16
+ LEVELS.each do |level|
17
+ @logger.send(level, "message at #{level}")
18
+ end
19
+
20
+ real_logger = mock
21
+
22
+ # This is needed for the expectation on #warn (also defined in Kernel) to
23
+ # work with old versions of Mocha.
24
+ def real_logger.warn(*); end
25
+
26
+ real_logger.expects(:fatal).with("message at fatal")
27
+ real_logger.expects(:error).with("message at error")
28
+ real_logger.expects(:warn).with("message at warn")
29
+ real_logger.expects(:info).with("message at info")
30
+ real_logger.expects(:debug).with("message at debug")
31
+
32
+ @logger.dump(real_logger)
33
+ end
34
+
35
+ def test_proxies_multiple_messages_with_a_single_call
36
+ @logger.info('a', 'b', 'c')
37
+
38
+ real_logger = stub
39
+ real_logger.expects(:info).with('a', 'b', 'c')
40
+
41
+ @logger.dump(real_logger)
42
+ end
43
+
44
+ def test_proxies_through_calls_to_log_exception
45
+ e = Exception.new
46
+ @logger.log_exception(:fatal, e, :error)
47
+
48
+ real_logger = stub
49
+ real_logger.expects(:log_exception).with(:fatal, e, :error)
50
+
51
+ @logger.dump(real_logger)
52
+ end
53
+ end
@@ -3,7 +3,7 @@
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 'new_relic/agent/commands/thread_profiler'
6
+ require 'new_relic/agent/commands/thread_profiler_session'
7
7
 
8
8
  # Tests of HTTP Keep Alive implementation that require a different setup and
9
9
  # set of mocks.
@@ -14,6 +14,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
14
14
  NewRelic::Agent.config.apply_config(@test_config)
15
15
  NewRelic::Agent::PipeChannelManager.listener.close_all_pipes
16
16
  NewRelic::Agent.manual_start
17
+ NewRelic::Agent::TransactionState.clear
17
18
  end
18
19
 
19
20
  def teardown
@@ -57,7 +58,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
57
58
  def test_listener_merges_transaction_traces
58
59
  sampler = NewRelic::Agent.agent.transaction_sampler
59
60
  run_sample_trace_on(sampler)
60
- NewRelic::Agent.agent.merge_data_from([nil, [sampler.samples], nil])
61
+ NewRelic::Agent.agent.merge_data_from([nil, [[sampler.last_sample]], nil])
61
62
 
62
63
  assert_equal(1, NewRelic::Agent.agent.unsent_traces_size)
63
64
 
@@ -65,11 +66,9 @@ class NewRelic::Agent::PipeChannelManagerTest < Test::Unit::TestCase
65
66
 
66
67
  pid = Process.fork do
67
68
  NewRelic::Agent.after_fork
68
- new_sampler = NewRelic::Agent::TransactionSampler.new
69
- sample = run_sample_trace_on(new_sampler)
70
- new_sampler.store_force_persist(sample)
71
69
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
72
- listener.pipes[667].write(:transaction_traces => new_sampler.harvest([]))
70
+ sample = run_sample_trace_on(sampler)
71
+ listener.pipes[667].write(:transaction_traces => sampler.harvest([]))
73
72
  end
74
73
  end
75
74
  Process.wait(pid)
@@ -16,43 +16,79 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
16
16
 
17
17
  def test_samples_on_transaction_finished_event
18
18
  with_sampler_config do
19
- advance_time( 0.60 )
20
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.095 )
21
-
19
+ generate_request
22
20
  assert_equal 1, @sampler.samples.length
23
21
  end
24
22
  end
25
23
 
26
- def test_samples_on_transaction_finished_event_include_options
24
+ def test_samples_on_transaction_finished_event_includes_overview_metrics
27
25
  with_sampler_config do
28
- advance_time( 0.60 )
29
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.095, :foo => :bar )
30
-
26
+ generate_request('name', :overview_metrics => {:foo => :bar})
31
27
  assert_equal :bar, @sampler.samples.first[:foo]
32
28
  end
33
29
  end
34
30
 
35
- def test_can_disable_sampling
36
- with_sampler_config( :'request_sampler.enabled' => false ) do
37
- @event_listener.notify( :transaction_finished, 'Controller/foo/bar', Time.now.to_f, 0.200 )
31
+ def test_can_disable_sampling_for_analytics
32
+ with_sampler_config( :'analytics_events.enabled' => false ) do
33
+ generate_request
38
34
  assert @sampler.samples.empty?
39
35
  end
40
36
  end
41
37
 
42
- def test_limits_total_number_of_samples_to_max_samples
43
- with_sampler_config( :'request_sampler.max_samples' => 100 ) do
38
+ def test_can_disable_sampling_for_analytics_transactions
39
+ with_sampler_config( :'analytics_events.transactions.enabled' => false ) do
40
+ generate_request
41
+ assert @sampler.samples.empty?
42
+ end
43
+ end
44
+
45
+ def test_harvest_returns_previous_sample_list
46
+ with_sampler_config do
47
+ 5.times { generate_request }
48
+
49
+ old_samples = @sampler.harvest
50
+
51
+ assert_equal 5, old_samples.size
52
+ assert_equal 0, @sampler.samples.size
53
+ end
54
+ end
55
+
56
+ def test_merge_merges_samples_back_into_buffer
57
+ with_sampler_config do
58
+ 5.times { generate_request }
59
+ old_samples = @sampler.harvest
60
+ 5.times { generate_request }
61
+
62
+ @sampler.merge(old_samples)
63
+ assert_equal(10, @sampler.samples.size)
64
+ end
65
+ end
66
+
67
+ def test_merge_abides_by_max_samples_limit
68
+ with_sampler_config(:'analytics_events.max_samples_stored' => 5) do
69
+ 4.times { generate_request }
70
+ old_samples = @sampler.harvest
71
+ 4.times { generate_request }
72
+
73
+ @sampler.merge(old_samples)
74
+ assert_equal(5, @sampler.samples.size)
75
+ end
76
+ end
77
+
78
+ def test_limits_total_number_of_samples_to_max_samples_stored
79
+ with_sampler_config( :'analytics_events.max_samples_stored' => 100 ) do
44
80
  150.times { generate_request }
45
81
  assert_equal 100, @sampler.samples.size
46
82
  end
47
83
  end
48
84
 
49
- def test_resets_limits_on_reset
50
- with_sampler_config( :'request_sampler.max_samples' => 100 ) do
85
+ def test_resets_limits_on_harvest
86
+ with_sampler_config( :'request_sampler.max_samples_stored' => 100 ) do
51
87
  50.times { generate_request('before') }
52
88
  samples_before = @sampler.samples
53
89
  assert_equal 50, samples_before.size
54
90
 
55
- @sampler.reset
91
+ @sampler.harvest
56
92
 
57
93
  150.times { generate_request('after') }
58
94
  samples_after = @sampler.samples
@@ -62,8 +98,16 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
62
98
  end
63
99
  end
64
100
 
101
+ def test_does_not_record_requests_from_background_tasks
102
+ with_sampler_config do
103
+ generate_request('a', :type => :controller)
104
+ generate_request('b', :type => :background)
105
+ assert_equal 1, @sampler.samples.size
106
+ end
107
+ end
108
+
65
109
  def test_does_not_drop_samples_when_used_from_multiple_threads
66
- with_sampler_config( :'request_sampler.max_samples' => 100 * 100 ) do
110
+ with_sampler_config( :'analytics_events.max_samples_stored' => 100 * 100 ) do
67
111
  threads = []
68
112
  25.times do
69
113
  threads << Thread.new do
@@ -80,15 +124,21 @@ class NewRelic::Agent::RequestSamplerTest < Test::Unit::TestCase
80
124
  # Helpers
81
125
  #
82
126
 
83
- def generate_request(name='whatever')
84
- @event_listener.notify( :transaction_finished, "Controller/#{name}", Time.now.to_f, 0.1)
127
+ def generate_request(name='whatever', options={})
128
+ payload = {
129
+ :name => "Controller/#{name}",
130
+ :type => :controller,
131
+ :start_timestamp => Time.now.to_f,
132
+ :duration => 0.1,
133
+ :overview_metrics => {}
134
+ }.merge(options)
135
+ @event_listener.notify(:transaction_finished, payload)
85
136
  end
86
137
 
87
138
  def with_sampler_config(options = {})
88
139
  defaults =
89
140
  {
90
- :'request_sampler.enabled' => true,
91
- :'request_sampler.max_samples' => 100
141
+ :'analytics_events.max_samples_stored' => 100
92
142
  }
93
143
 
94
144
  defaults.merge!(options)