newrelic_rpm 3.9.6.257 → 3.9.7.266

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +45 -0
  3. data/lib/new_relic/agent.rb +0 -1
  4. data/lib/new_relic/agent/agent.rb +61 -22
  5. data/lib/new_relic/agent/agent_logger.rb +11 -9
  6. data/lib/new_relic/agent/configuration/default_source.rb +25 -2
  7. data/lib/new_relic/agent/cross_app_monitor.rb +15 -53
  8. data/lib/new_relic/agent/cross_app_tracing.rb +11 -3
  9. data/lib/new_relic/agent/custom_event_aggregator.rb +98 -0
  10. data/lib/new_relic/agent/event_buffer.rb +84 -0
  11. data/lib/new_relic/agent/harvester.rb +4 -15
  12. data/lib/new_relic/agent/hostname.rb +1 -9
  13. data/lib/new_relic/agent/inbound_request_monitor.rb +41 -0
  14. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -2
  15. data/lib/new_relic/agent/instrumentation/queue_time.rb +0 -5
  16. data/lib/new_relic/agent/instrumentation/resque.rb +4 -9
  17. data/lib/new_relic/agent/javascript_instrumentor.rb +0 -12
  18. data/lib/new_relic/agent/method_tracer_helpers.rb +3 -1
  19. data/lib/new_relic/agent/new_relic_service.rb +1 -1
  20. data/lib/new_relic/agent/sampled_buffer.rb +13 -41
  21. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +52 -24
  22. data/lib/new_relic/agent/sized_buffer.rb +23 -0
  23. data/lib/new_relic/agent/synthetics_monitor.rb +50 -0
  24. data/lib/new_relic/agent/system_info.rb +28 -0
  25. data/lib/new_relic/agent/transaction.rb +78 -9
  26. data/lib/new_relic/agent/transaction/synthetics_sample_buffer.rb +25 -0
  27. data/lib/new_relic/agent/{request_sampler.rb → transaction_event_aggregator.rb} +53 -19
  28. data/lib/new_relic/agent/transaction_sample_builder.rb +3 -1
  29. data/lib/new_relic/agent/transaction_sampler.rb +10 -0
  30. data/lib/new_relic/agent/transaction_state.rb +1 -9
  31. data/lib/new_relic/coerce.rb +8 -2
  32. data/lib/new_relic/control.rb +0 -1
  33. data/lib/new_relic/local_environment.rb +12 -8
  34. data/lib/new_relic/metric_spec.rb +11 -2
  35. data/lib/new_relic/rack/developer_mode.rb +9 -1
  36. data/lib/new_relic/transaction_sample.rb +4 -10
  37. data/lib/new_relic/version.rb +1 -1
  38. data/newrelic_rpm.gemspec +1 -0
  39. data/test/agent_helper.rb +15 -2
  40. data/test/environments/norails/Gemfile +1 -0
  41. data/test/environments/rails21/Gemfile +1 -0
  42. data/test/environments/rails22/Gemfile +1 -0
  43. data/test/environments/rails23/Gemfile +1 -0
  44. data/test/environments/rails30/Gemfile +1 -0
  45. data/test/environments/rails31/Gemfile +1 -0
  46. data/test/environments/rails32/Gemfile +2 -1
  47. data/test/environments/rails40/Gemfile +2 -1
  48. data/test/environments/rails41/Gemfile +3 -1
  49. data/test/environments/rails42/Gemfile +3 -1
  50. data/test/fixtures/cross_agent_tests/README.md +6 -2
  51. data/test/fixtures/cross_agent_tests/docker_container_id/README.md +6 -0
  52. data/test/fixtures/cross_agent_tests/docker_container_id/cases.json +22 -0
  53. data/test/fixtures/cross_agent_tests/docker_container_id/docker-0.9.1.txt +10 -0
  54. data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.0.0.txt +10 -0
  55. data/test/fixtures/cross_agent_tests/docker_container_id/docker-1.3.txt +9 -0
  56. data/test/fixtures/cross_agent_tests/docker_container_id/empty.txt +0 -0
  57. data/test/fixtures/cross_agent_tests/docker_container_id/lxc-containers-without-docker.txt +10 -0
  58. data/test/fixtures/cross_agent_tests/proc_meminfo/README.md +7 -0
  59. data/test/fixtures/cross_agent_tests/proc_meminfo/meminfo_4096MB.txt +47 -0
  60. data/test/fixtures/cross_agent_tests/rum_client_config.json +0 -80
  61. data/test/fixtures/cross_agent_tests/synthetics/synthetics.json +317 -0
  62. data/test/multiverse/lib/multiverse/runner.rb +1 -1
  63. data/test/multiverse/lib/multiverse/suite.rb +1 -0
  64. data/test/multiverse/suites/active_record/Envfile +42 -8
  65. data/test/multiverse/suites/active_record/ar_method_aliasing.rb +8 -4
  66. data/test/multiverse/suites/agent_only/audit_log_test.rb +0 -2
  67. data/test/multiverse/suites/agent_only/collector_exception_handling_test.rb +1 -2
  68. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +5 -5
  69. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +2 -0
  70. data/test/multiverse/suites/agent_only/harvest_timestamps_test.rb +8 -0
  71. data/test/multiverse/suites/agent_only/synthetics_test.rb +139 -0
  72. data/test/multiverse/suites/delayed_job/Envfile +79 -0
  73. data/test/multiverse/suites/delayed_job/before_suite.rb +33 -0
  74. data/test/multiverse/suites/delayed_job/config/newrelic.yml +18 -0
  75. data/test/multiverse/suites/delayed_job/delayed_job_sampler_test.rb +131 -0
  76. data/test/multiverse/suites/delayed_job/unsupported_backend_test.rb +24 -0
  77. data/test/multiverse/suites/high_security/high_security_test.rb +3 -10
  78. data/test/multiverse/suites/rails/Envfile +4 -4
  79. data/test/multiverse/suites/rails/request_statistics_test.rb +4 -4
  80. data/test/new_relic/agent/agent_test.rb +32 -4
  81. data/test/new_relic/agent/configuration/default_source_test.rb +6 -0
  82. data/test/new_relic/agent/cross_app_monitor_test.rb +23 -29
  83. data/test/new_relic/agent/custom_event_aggregator_test.rb +88 -0
  84. data/test/new_relic/agent/event_buffer_test_cases.rb +152 -0
  85. data/test/new_relic/agent/harvester_test.rb +5 -25
  86. data/test/new_relic/agent/hostname_test.rb +1 -1
  87. data/test/new_relic/agent/inbound_request_monitor_test.rb +49 -0
  88. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +9 -9
  89. data/test/new_relic/agent/instrumentation/queue_time_test.rb +0 -19
  90. data/test/new_relic/agent/javascript_instrumentor_test.rb +0 -45
  91. data/test/new_relic/agent/new_relic_service_test.rb +17 -12
  92. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -4
  93. data/test/new_relic/agent/sampled_buffer_test.rb +73 -145
  94. data/test/new_relic/agent/sized_buffer_test.rb +29 -0
  95. data/test/new_relic/agent/synthetics_monitor_test.rb +96 -0
  96. data/test/new_relic/agent/system_info_test.rb +19 -3
  97. data/test/new_relic/agent/transaction/developer_mode_sample_buffer_test.rb +14 -8
  98. data/test/new_relic/agent/transaction/synthetics_sample_buffer_test.rb +38 -0
  99. data/test/new_relic/agent/{request_sampler_test.rb → transaction_event_aggregator_test.rb} +55 -4
  100. data/test/new_relic/agent/transaction_sampler_test.rb +33 -11
  101. data/test/new_relic/agent/transaction_state_test.rb +0 -1
  102. data/test/new_relic/agent/transaction_test.rb +121 -19
  103. data/test/new_relic/coerce_test.rb +38 -3
  104. data/test/new_relic/control_test.rb +1 -0
  105. data/test/new_relic/fake_collector.rb +6 -2
  106. data/test/new_relic/fake_external_server.rb +2 -6
  107. data/test/new_relic/fake_server.rb +46 -29
  108. data/test/new_relic/http_client_test_cases.rb +71 -2
  109. data/test/new_relic/local_environment_test.rb +78 -0
  110. data/test/new_relic/metric_parser/metric_parser_test.rb +2 -0
  111. data/test/new_relic/metric_spec_test.rb +43 -0
  112. data/test/new_relic/multiverse_helpers.rb +11 -18
  113. data/test/new_relic/rack/browser_monitoring_test.rb +1 -18
  114. data/test/new_relic/rack/developer_mode_test.rb +1 -1
  115. data/test/new_relic/transaction_sample_test.rb +14 -4
  116. data/test/performance/suites/rack_middleware.rb +3 -1
  117. data/test/test_helper.rb +33 -0
  118. metadata +48 -7
  119. metadata.gz.sig +0 -0
  120. data/lib/new_relic/agent/browser_token.rb +0 -41
  121. data/test/multiverse/suites/agent_only/before_suite.rb +0 -7
  122. data/test/new_relic/agent/browser_token_test.rb +0 -56
@@ -10,7 +10,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
10
10
  include TransactionSampleTestHelper
11
11
 
12
12
  def setup
13
- @test_config = { :developer_mode => true }
13
+ @test_config = { :monitor_mode => true }
14
14
  NewRelic::Agent.agent.drop_buffered_data
15
15
  NewRelic::Agent.config.add_config_for_testing(@test_config)
16
16
 
@@ -102,13 +102,13 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
102
102
  end
103
103
 
104
104
  def test_listener_merges_analytics_events
105
- request_sampler = NewRelic::Agent.agent.instance_variable_get(:@request_sampler)
105
+ transaction_event_aggregator = NewRelic::Agent.agent.instance_variable_get(:@transaction_event_aggregator)
106
106
 
107
107
  start_listener_with_pipe(699)
108
108
  NewRelic::Agent.agent.stubs(:connected?).returns(true)
109
109
  run_child(699) do
110
110
  NewRelic::Agent.after_fork(:report_to_channel => 699)
111
- request_sampler.on_transaction_finished({
111
+ transaction_event_aggregator.on_transaction_finished({
112
112
  :start_timestamp => Time.now,
113
113
  :name => 'whatever',
114
114
  :duration => 10,
@@ -117,7 +117,7 @@ class NewRelic::Agent::PipeChannelManagerTest < Minitest::Test
117
117
  NewRelic::Agent.agent.send(:transmit_event_data)
118
118
  end
119
119
 
120
- assert_equal(1, request_sampler.samples.size)
120
+ assert_equal(1, transaction_event_aggregator.samples.size)
121
121
  end
122
122
 
123
123
  def test_listener_merges_sql_traces
@@ -3,176 +3,104 @@
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 'test/new_relic/agent/event_buffer_test_cases'
6
7
 
7
- class NewRelic::Agent::SampledBufferTest < Minitest::Test
8
- def test_should_keep_all_samples_up_to_capacity
9
- buffer = NewRelic::Agent::SampledBuffer.new(100)
10
- all = []
11
- 100.times do |i|
12
- buffer << i
13
- all << i
14
- end
15
-
16
- assert_equal(100, buffer.size)
17
- assert_equal(all, buffer.to_a)
18
- end
8
+ module NewRelic::Agent
9
+ class SampledBufferTest < Minitest::Test
10
+ include EventBufferTestCases
19
11
 
20
- def test_replaces_old_entries_when_necessary
21
- buffer = NewRelic::Agent::SampledBuffer.new(5)
12
+ def buffer_class
13
+ SampledBuffer
14
+ end
22
15
 
23
- buffer.expects(:rand).with(6).returns(0)
24
- buffer.expects(:rand).with(7).returns(1)
25
- buffer.expects(:rand).with(8).returns(2)
26
- buffer.expects(:rand).with(9).returns(3)
27
- buffer.expects(:rand).with(10).returns(4)
16
+ def test_replaces_old_entries_when_necessary
17
+ buffer = buffer_class.new(5)
28
18
 
29
- 10.times { |i| buffer << i }
19
+ buffer.expects(:rand).with(6).returns(0)
20
+ buffer.expects(:rand).with(7).returns(1)
21
+ buffer.expects(:rand).with(8).returns(2)
22
+ buffer.expects(:rand).with(9).returns(3)
23
+ buffer.expects(:rand).with(10).returns(4)
30
24
 
31
- assert_equal([5, 6, 7, 8, 9], buffer.to_a)
32
- end
33
-
34
- def test_discards_new_entries_when_necessary
35
- buffer = NewRelic::Agent::SampledBuffer.new(5)
25
+ 10.times { |i| buffer << i }
36
26
 
37
- buffer.expects(:rand).with(6).returns(5)
38
- buffer.expects(:rand).with(7).returns(6)
39
- buffer.expects(:rand).with(8).returns(7)
40
- buffer.expects(:rand).with(9).returns(8)
41
- buffer.expects(:rand).with(10).returns(9)
27
+ assert_equal([5, 6, 7, 8, 9], buffer.to_a)
28
+ end
42
29
 
43
- 10.times { |i| buffer << i }
30
+ def test_discards_new_entries_when_necessary
31
+ buffer = buffer_class.new(5)
44
32
 
45
- assert_equal([0, 1, 2, 3, 4], buffer.to_a)
46
- end
33
+ buffer.expects(:rand).with(6).returns(5)
34
+ buffer.expects(:rand).with(7).returns(6)
35
+ buffer.expects(:rand).with(8).returns(7)
36
+ buffer.expects(:rand).with(9).returns(8)
37
+ buffer.expects(:rand).with(10).returns(9)
47
38
 
48
- # This test is non-deterministic: there is some (low) probability that it will
49
- # fail. We repeatedly stream 10 items into a buffer of capacity 5, and verify
50
- # that each item is included ~50% of the time.
51
- #
52
- # Because of the non-determinism, it is possible that we'll want to disable
53
- # this test. That said, I've thus far been unsuccessful in making it fail, so
54
- # I'm leaving it here for now.
55
- def test_should_sample_evenly
56
- buffer = NewRelic::Agent::SampledBuffer.new(5)
57
- results = []
58
-
59
- 10000.times do
60
- buffer.reset
61
39
  10.times { |i| buffer << i }
62
- results << buffer.to_a
63
- end
64
40
 
65
- (0...10).each do |v|
66
- num_results_including_v = results.select { |r| r.include?(v) }.size
67
- assert_in_delta(0.5, num_results_including_v.to_f / results.size, 0.05)
41
+ assert_equal([0, 1, 2, 3, 4], buffer.to_a)
68
42
  end
69
- end
70
-
71
- def test_to_a_should_dup_the_returned_array
72
- buffer = NewRelic::Agent::SampledBuffer.new(10)
73
43
 
74
- 5.times { |i| buffer << i }
44
+ def test_append_returns_whether_item_was_stored
45
+ buffer = buffer_class.new(5)
75
46
 
76
- items = buffer.to_a
77
- items << 'noodles'
78
-
79
- assert_equal([0, 1, 2, 3, 4], buffer.to_a)
80
- end
47
+ buffer.expects(:rand).with(6).returns(5)
81
48
 
82
- def test_append_should_return_true_when_buffer_is_full
83
- buffer = NewRelic::Agent::SampledBuffer.new(5)
49
+ 5.times do |i|
50
+ result = buffer.append(i)
51
+ assert(result)
52
+ end
84
53
 
85
- 4.times do |i|
86
- assert_equal(false, buffer.append(i), "SampledBuffer#append should return false until buffer is full")
54
+ result = buffer.append('foo')
55
+ refute(result)
87
56
  end
88
57
 
89
- 4.times do |i|
90
- assert_equal(true, buffer.append('lava'), "SampledBuffer#append should return true once buffer is full")
58
+ # This test is non-deterministic: there is some (low) probability that it will
59
+ # fail. We repeatedly stream 10 items into a buffer of capacity 5, and verify
60
+ # that each item is included ~50% of the time.
61
+ #
62
+ # Because of the non-determinism, it is possible that we'll want to disable
63
+ # this test. That said, I've thus far been unsuccessful in making it fail, so
64
+ # I'm leaving it here for now.
65
+ def test_should_sample_evenly
66
+ buffer = buffer_class.new(5)
67
+ results = []
68
+
69
+ 10000.times do
70
+ buffer.reset!
71
+ 10.times { |i| buffer << i }
72
+ results << buffer.to_a
73
+ end
74
+
75
+ (0...10).each do |v|
76
+ num_results_including_v = results.select { |r| r.include?(v) }.size
77
+ assert_in_delta(0.5, num_results_including_v.to_f / results.size, 0.05)
78
+ end
91
79
  end
92
- end
93
80
 
94
- def test_should_discard_items_as_needed_when_capacity_is_reset
95
- buffer = NewRelic::Agent::SampledBuffer.new(10)
96
- 10.times { |i| buffer << i }
81
+ def test_seen_lifetime_should_persist_across_resets
82
+ buffer = buffer_class.new(10)
97
83
 
98
- buffer.capacity = 5
99
- assert_equal(5, buffer.size)
84
+ 100.times { |i| buffer << i }
85
+ buffer.reset!
86
+ assert_equal(100, buffer.seen_lifetime)
100
87
 
101
- # We should have 5 unique values that were all in our original set of 0-9
102
- assert_equal(5, buffer.to_a.uniq.size)
103
- allowed_values = (0..9).to_a
104
- buffer.to_a.each do |v|
105
- assert_includes(allowed_values, v)
88
+ 100.times { |i| buffer << i }
89
+ buffer.reset!
90
+ assert_equal(200, buffer.seen_lifetime)
106
91
  end
107
- end
108
-
109
- def test_should_not_discard_items_if_not_needed_when_capacity_is_reset
110
- buffer = NewRelic::Agent::SampledBuffer.new(10)
111
- 10.times { |i| buffer << i }
112
-
113
- buffer.capacity = 20
114
- assert_equal(10, buffer.size)
115
- assert_equal((0..9).to_a, buffer.to_a)
116
- end
117
-
118
- def test_should_not_exceed_capacity
119
- buffer = NewRelic::Agent::SampledBuffer.new(100)
120
- 200.times { |i| buffer << i }
121
- assert_equal(100, buffer.size)
122
- end
123
-
124
- def test_reset_should_reset
125
- buffer = NewRelic::Agent::SampledBuffer.new(10)
126
- 100.times { |i| buffer << i }
127
- buffer.reset
128
- assert_equal(0, buffer.size)
129
- assert_equal([], buffer.to_a)
130
- end
131
-
132
- def test_seen_counts_all_seen_samples_since_last_reset
133
- buffer = NewRelic::Agent::SampledBuffer.new(10)
134
- assert_equal(0, buffer.seen)
135
-
136
- 20.times { |i| buffer << i }
137
- assert_equal(20, buffer.seen)
138
-
139
- buffer.reset
140
- assert_equal(0, buffer.seen)
141
- end
142
92
 
143
- def test_seen_lifetime_should_persist_across_resets
144
- buffer = NewRelic::Agent::SampledBuffer.new(10)
93
+ def test_sample_rate_lifetime
94
+ buffer = buffer_class.new(10)
95
+ assert_equal(0, buffer.sample_rate_lifetime)
145
96
 
146
- 100.times { |i| buffer << i }
147
- buffer.reset
148
- assert_equal(100, buffer.seen_lifetime)
97
+ 10.times { buffer << 'x' }
98
+ buffer.reset!
99
+ assert_equal(1.0, buffer.sample_rate_lifetime)
149
100
 
150
- 100.times { |i| buffer << i }
151
- buffer.reset
152
- assert_equal(200, buffer.seen_lifetime)
153
- end
154
-
155
- def test_sample_rate
156
- buffer = NewRelic::Agent::SampledBuffer.new(10)
157
- assert_equal(0, buffer.sample_rate)
158
-
159
- 10.times { buffer << 'x' }
160
- assert_equal(1.0, buffer.sample_rate)
161
-
162
- 10.times { buffer << 'x' }
163
- assert_equal(0.5, buffer.sample_rate)
164
- end
165
-
166
- def test_sample_rate_lifetime
167
- buffer = NewRelic::Agent::SampledBuffer.new(10)
168
- assert_equal(0, buffer.sample_rate_lifetime)
169
-
170
- 10.times { buffer << 'x' }
171
- buffer.reset
172
- assert_equal(1.0, buffer.sample_rate_lifetime)
173
-
174
- 30.times { buffer << 'x' }
175
- buffer.reset
176
- assert_equal(0.5, buffer.sample_rate_lifetime)
101
+ 30.times { buffer << 'x' }
102
+ buffer.reset!
103
+ assert_equal(0.5, buffer.sample_rate_lifetime)
104
+ end
177
105
  end
178
106
  end
@@ -0,0 +1,29 @@
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 'test/new_relic/agent/event_buffer_test_cases'
7
+ require 'new_relic/agent/sized_buffer'
8
+
9
+ module NewRelic::Agent
10
+ class SizedBufferTest < Minitest::Test
11
+ include EventBufferTestCases
12
+
13
+ def buffer_class
14
+ SizedBuffer
15
+ end
16
+
17
+ def test_append_returns_whether_item_was_stored
18
+ buffer = buffer_class.new(5)
19
+
20
+ 5.times do |i|
21
+ result = buffer.append(i)
22
+ assert(result)
23
+ end
24
+
25
+ result = buffer.append('foo')
26
+ refute(result)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,96 @@
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/synthetics_monitor'
7
+
8
+ module NewRelic::Agent
9
+ class SyntheticsMonitorTest < Minitest::Test
10
+ ENCODING_KEY_NOOP = "\0"
11
+ TRUSTED_ACCOUNT_IDS = [42,13]
12
+
13
+ VERSION_ID = 1
14
+ ACCOUNT_ID = 42
15
+ RESOURCE_ID = 100
16
+ JOB_ID = 200
17
+ MONITOR_ID = 300
18
+
19
+ BAD_ACCOUNT_ID = 7
20
+ BAD_VERSION_ID = 2
21
+
22
+ STANDARD_DATA = [ACCOUNT_ID, RESOURCE_ID, JOB_ID, MONITOR_ID]
23
+
24
+ def setup
25
+ @events = EventListener.new
26
+ @monitor = SyntheticsMonitor.new(@events)
27
+
28
+ NewRelic::Agent.reset_config
29
+ @config = {
30
+ :encoding_key => ENCODING_KEY_NOOP,
31
+ :trusted_account_ids => TRUSTED_ACCOUNT_IDS
32
+ }
33
+ NewRelic::Agent.config.add_config_for_testing(@config)
34
+
35
+ @events.notify(:finished_configuring)
36
+ end
37
+
38
+ def test_doesnt_record_synthetics_state_without_header
39
+ in_transaction do
40
+ # Make sure we're not just erroring in the event notification handler
41
+ expects_no_logging(:debug)
42
+
43
+ @events.notify(:before_call, {})
44
+ assert_no_synthetics_payload
45
+ end
46
+ end
47
+
48
+ def test_doesnt_record_synthetics_if_incoming_request_higher_version
49
+ synthetics_payload = [BAD_VERSION_ID] + STANDARD_DATA
50
+ with_synthetics_headers(synthetics_payload) do
51
+ assert_no_synthetics_payload
52
+ end
53
+ end
54
+
55
+ def test_doesnt_record_synthetics_if_not_trusted_account
56
+ synthetics_payload = [VERSION_ID, BAD_ACCOUNT_ID] + STANDARD_DATA[1..-1]
57
+ with_synthetics_headers(synthetics_payload) do
58
+ assert_no_synthetics_payload
59
+ end
60
+ end
61
+
62
+ def test_doesnt_record_synthetics_if_data_too_short
63
+ synthetics_payload = [VERSION_ID, ACCOUNT_ID]
64
+ with_synthetics_headers(synthetics_payload) do
65
+ assert_no_synthetics_payload
66
+ end
67
+ end
68
+
69
+ def test_records_synthetics_state_from_header
70
+ key = SyntheticsMonitor::SYNTHETICS_HEADER_KEY
71
+ synthetics_payload = [VERSION_ID] + STANDARD_DATA
72
+ with_synthetics_headers(synthetics_payload, key) do
73
+ state = NewRelic::Agent::TransactionState.tl_get
74
+ txn = state.current_transaction
75
+ assert_equal @last_encoded_header, txn.raw_synthetics_header
76
+ assert_equal synthetics_payload, txn.synthetics_payload
77
+ end
78
+ end
79
+
80
+ def synthetics_header(payload, header_key = SyntheticsMonitor::SYNTHETICS_HEADER_KEY)
81
+ @last_encoded_header = json_dump_and_encode(payload)
82
+ { header_key => @last_encoded_header }
83
+ end
84
+
85
+ def assert_no_synthetics_payload
86
+ assert_nil NewRelic::Agent::TransactionState.tl_get.current_transaction.synthetics_payload
87
+ end
88
+
89
+ def with_synthetics_headers(payload, header_key = SyntheticsMonitor::SYNTHETICS_HEADER_KEY)
90
+ in_transaction do
91
+ @events.notify(:before_call, synthetics_header(payload, header_key))
92
+ yield
93
+ end
94
+ end
95
+ end
96
+ end
@@ -11,13 +11,13 @@ class NewRelic::Agent::SystemInfoTest < Minitest::Test
11
11
  @sysinfo.clear_processor_info
12
12
  end
13
13
 
14
- test_dir = File.join(cross_agent_tests_dir, 'proc_cpuinfo')
14
+ cpuinfo_test_dir = File.join(cross_agent_tests_dir, 'proc_cpuinfo')
15
15
 
16
- Dir.chdir(test_dir) do
16
+ Dir.chdir(cpuinfo_test_dir) do
17
17
  Dir.glob("*.txt") do |file|
18
18
  if file =~ /^((\d+|X)pack_(\d+|X)core_(\d+|X)logical).txt$/
19
19
  test_name = "test_#{$1}"
20
- test_path = File.join(test_dir, file)
20
+ test_path = File.join(cpuinfo_test_dir, file)
21
21
 
22
22
  num_physical_packages = $2.to_i
23
23
  num_physical_cores = $3.to_i
@@ -41,5 +41,21 @@ class NewRelic::Agent::SystemInfoTest < Minitest::Test
41
41
  end
42
42
  end
43
43
 
44
+ docker_id_test_dir = File.join(cross_agent_tests_dir, 'docker_container_id')
45
+ docker_id_test_cases = load_cross_agent_test(File.join('docker_container_id', 'cases'))
46
+
47
+ docker_id_test_cases.each do |test_case|
48
+ filename = test_case['filename']
49
+ basename = File.basename(filename, '.txt')
50
+ test_name = "test_docker_container_id_#{basename}"
51
+
52
+ define_method(test_name) do
53
+ input = File.read(File.join(docker_id_test_dir, filename))
54
+ container_id = @sysinfo.parse_docker_container_id(input)
55
+
56
+ message = "Parsed incorrect Docker container ID from #{filename}"
57
+ assert_equal(test_case['dockerContainerId'], container_id, message)
58
+ end
59
+ end
44
60
  end
45
61
 
@@ -26,17 +26,21 @@ class NewRelic::Agent::Transaction
26
26
  end
27
27
 
28
28
  def test_stores_up_to_truncate_max
29
- sample = stub
30
- @buffer.capacity.times { @buffer.store(sample) }
29
+ with_config(:developer_mode => true) do
30
+ sample = stub
31
+ @buffer.capacity.times { @buffer.store(sample) }
31
32
 
32
- assert_equal(Array.new(@buffer.capacity, sample), @buffer.samples)
33
+ assert_equal(Array.new(@buffer.capacity, sample), @buffer.samples)
34
+ end
33
35
  end
34
36
 
35
37
  def test_stores_and_truncates
36
- sample = stub
37
- (@buffer.capacity * 2).times { @buffer.store(sample) }
38
+ with_config(:developer_mode => true) do
39
+ sample = stub
40
+ (@buffer.capacity * 2).times { @buffer.store(sample) }
38
41
 
39
- assert_equal(Array.new(@buffer.capacity, sample), @buffer.samples)
42
+ assert_equal(Array.new(@buffer.capacity, sample), @buffer.samples)
43
+ end
40
44
  end
41
45
 
42
46
  def test_visit_segment_takes_backtraces_in_dev_mode
@@ -62,8 +66,10 @@ class NewRelic::Agent::Transaction
62
66
  end
63
67
 
64
68
  def test_doesnt_store_previous
65
- @buffer.store_previous([stub])
66
- assert @buffer.samples.empty?
69
+ with_config(:developer_mode => true) do
70
+ @buffer.store_previous([stub])
71
+ assert @buffer.samples.empty?
72
+ end
67
73
  end
68
74
  end
69
75
  end