appoptics_apm 4.0.3 → 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile_test +6 -7
- data/README.md +3 -3
- data/Rakefile +3 -2
- data/appoptics_apm.gemspec +2 -2
- data/docker-compose.yml +0 -22
- data/ext/oboe_metal/extconf.rb +4 -0
- data/lib/appoptics_apm/config.rb +11 -6
- data/lib/appoptics_apm/version.rb +1 -1
- metadata +3 -202
- data/gemfiles/delayed_job.gemfile +0 -36
- data/gemfiles/frameworks.gemfile +0 -44
- data/gemfiles/instrumentation_mocked.gemfile +0 -29
- data/gemfiles/libraries.gemfile +0 -85
- data/gemfiles/noop.gemfile +0 -17
- data/gemfiles/rails23.gemfile +0 -39
- data/gemfiles/rails30.gemfile +0 -42
- data/gemfiles/rails31.gemfile +0 -44
- data/gemfiles/rails32.gemfile +0 -54
- data/gemfiles/rails40.gemfile +0 -27
- data/gemfiles/rails41.gemfile +0 -27
- data/gemfiles/rails42.gemfile +0 -35
- data/gemfiles/rails50.gemfile +0 -44
- data/gemfiles/rails51.gemfile +0 -44
- data/test/benchmark/README.md +0 -65
- data/test/benchmark/logging_bench.rb +0 -54
- data/test/benchmark/with_libraries_gemfile/bunny_bench.rb +0 -69
- data/test/benchmark/with_rails5x_gemfile/action_controller5x_bench.rb +0 -43
- data/test/frameworks/apps/grape_nested.rb +0 -33
- data/test/frameworks/apps/grape_simple.rb +0 -80
- data/test/frameworks/apps/padrino_simple.rb +0 -80
- data/test/frameworks/apps/sinatra_simple.rb +0 -55
- data/test/frameworks/grape_test.rb +0 -286
- data/test/frameworks/padrino_test.rb +0 -222
- data/test/frameworks/rails3x_test.rb +0 -554
- data/test/frameworks/rails4x_test.rb +0 -570
- data/test/frameworks/rails5x_api_test.rb +0 -210
- data/test/frameworks/rails5x_test.rb +0 -376
- data/test/frameworks/rails_shared_tests.rb +0 -172
- data/test/frameworks/sinatra_test.rb +0 -140
- data/test/instrumentation/bunny_client_test.rb +0 -276
- data/test/instrumentation/bunny_consumer_test.rb +0 -204
- data/test/instrumentation/curb_test.rb +0 -398
- data/test/instrumentation/dalli_test.rb +0 -177
- data/test/instrumentation/em_http_request_test.rb +0 -89
- data/test/instrumentation/excon_test.rb +0 -231
- data/test/instrumentation/faraday_test.rb +0 -228
- data/test/instrumentation/http_test.rb +0 -143
- data/test/instrumentation/httpclient_test.rb +0 -304
- data/test/instrumentation/memcache_test.rb +0 -260
- data/test/instrumentation/memcached_test.rb +0 -229
- data/test/instrumentation/mongo_v1_test.rb +0 -479
- data/test/instrumentation/mongo_v2_index_test.rb +0 -124
- data/test/instrumentation/mongo_v2_test.rb +0 -584
- data/test/instrumentation/mongo_v2_view_test.rb +0 -435
- data/test/instrumentation/moped_test.rb +0 -517
- data/test/instrumentation/rack_test.rb +0 -165
- data/test/instrumentation/redis_hashes_test.rb +0 -268
- data/test/instrumentation/redis_keys_test.rb +0 -321
- data/test/instrumentation/redis_lists_test.rb +0 -310
- data/test/instrumentation/redis_misc_test.rb +0 -163
- data/test/instrumentation/redis_sets_test.rb +0 -296
- data/test/instrumentation/redis_sortedsets_test.rb +0 -328
- data/test/instrumentation/redis_strings_test.rb +0 -349
- data/test/instrumentation/resque_test.rb +0 -185
- data/test/instrumentation/rest-client_test.rb +0 -288
- data/test/instrumentation/sequel_mysql2_test.rb +0 -353
- data/test/instrumentation/sequel_mysql_test.rb +0 -334
- data/test/instrumentation/sequel_pg_test.rb +0 -336
- data/test/instrumentation/sidekiq-client_test.rb +0 -159
- data/test/instrumentation/sidekiq-worker_test.rb +0 -180
- data/test/instrumentation/twitter-cassandra_test.rb +0 -424
- data/test/instrumentation/typhoeus_test.rb +0 -284
- data/test/jobs/delayed_job/db_worker_job.rb +0 -29
- data/test/jobs/delayed_job/error_worker_job.rb +0 -10
- data/test/jobs/delayed_job/remote_call_worker_job.rb +0 -20
- data/test/jobs/resque/db_worker_job.rb +0 -29
- data/test/jobs/resque/error_worker_job.rb +0 -10
- data/test/jobs/resque/remote_call_worker_job.rb +0 -20
- data/test/jobs/sidekiq/db_worker_job.rb +0 -29
- data/test/jobs/sidekiq/error_worker_job.rb +0 -10
- data/test/jobs/sidekiq/remote_call_worker_job.rb +0 -20
- data/test/minitest_helper.rb +0 -277
- data/test/mocked/curb_mocked_test.rb +0 -324
- data/test/mocked/excon_mocked_test.rb +0 -174
- data/test/mocked/faraday_mocked_test.rb +0 -97
- data/test/mocked/http_mocked_test.rb +0 -135
- data/test/mocked/httpclient_mocked_test.rb +0 -258
- data/test/mocked/rest_client_mocked_test.rb +0 -109
- data/test/mocked/typhoeus_mocked_test.rb +0 -207
- data/test/models/widget.rb +0 -36
- data/test/noop/noop_test.rb +0 -145
- data/test/profiling/legacy_method_profiling_test.rb +0 -201
- data/test/profiling/method_profiling_test.rb +0 -631
- data/test/queues/delayed_job-client_test.rb +0 -95
- data/test/queues/delayed_job-worker_test.rb +0 -91
- data/test/reporter/reporter_test.rb +0 -14
- data/test/servers/delayed_job.rb +0 -107
- data/test/servers/rackapp_8101.rb +0 -29
- data/test/servers/rails3x_8140.rb +0 -96
- data/test/servers/rails4x_8140.rb +0 -96
- data/test/servers/rails5x_8140.rb +0 -95
- data/test/servers/rails5x_api_8150.rb +0 -78
- data/test/servers/sidekiq.rb +0 -29
- data/test/servers/sidekiq.yml +0 -7
- data/test/servers/sidekiq_initializer.rb +0 -25
- data/test/settings +0 -0
- data/test/support/auto_tracing_test.rb +0 -50
- data/test/support/backcompat_test.rb +0 -276
- data/test/support/config_test.rb +0 -149
- data/test/support/dnt_test.rb +0 -98
- data/test/support/init_report_test.rb +0 -25
- data/test/support/liboboe_settings_test.rb +0 -110
- data/test/support/logging_test.rb +0 -130
- data/test/support/sql_sanitize_test.rb +0 -55
- data/test/support/tracing_mode_test.rb +0 -33
- data/test/support/tvalias_test.rb +0 -15
- data/test/support/xtrace_test.rb +0 -41
@@ -1,174 +0,0 @@
|
|
1
|
-
# Copyright (c) 2016 SolarWinds, LLC.
|
2
|
-
# All rights reserved.
|
3
|
-
|
4
|
-
if !defined?(JRUBY_VERSION)
|
5
|
-
|
6
|
-
require 'minitest_helper'
|
7
|
-
require 'webmock/minitest'
|
8
|
-
require 'mocha/mini_test'
|
9
|
-
|
10
|
-
class ExconTest < Minitest::Test
|
11
|
-
|
12
|
-
def setup
|
13
|
-
AppOpticsAPM::Context.clear
|
14
|
-
WebMock.enable!
|
15
|
-
WebMock.reset!
|
16
|
-
WebMock.disable_net_connect!
|
17
|
-
AppOpticsAPM.config_lock.synchronize {
|
18
|
-
@sample_rate = AppOpticsAPM::Config[:sample_rate]
|
19
|
-
@tracing_mode= AppOpticsAPM::Config[:tracing_mode]
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
AppOpticsAPM.config_lock.synchronize {
|
25
|
-
AppOpticsAPM::Config[:sample_rate] = @sample_rate
|
26
|
-
AppOpticsAPM::Config[:tracing_mode] = @tracing_mode
|
27
|
-
AppOpticsAPM::Config[:blacklist] = []
|
28
|
-
}
|
29
|
-
WebMock.reset!
|
30
|
-
WebMock.allow_net_connect!
|
31
|
-
WebMock.disable!
|
32
|
-
end
|
33
|
-
|
34
|
-
# ========== excon get =================================
|
35
|
-
|
36
|
-
def test_xtrace_no_trace
|
37
|
-
stub_request(:get, "http://127.0.0.6:8101/")
|
38
|
-
|
39
|
-
AppOpticsAPM.config_lock.synchronize do
|
40
|
-
::Excon.get("http://127.0.0.6:8101/")
|
41
|
-
end
|
42
|
-
|
43
|
-
assert_requested :get, "http://127.0.0.6:8101/", times: 1
|
44
|
-
assert_not_requested :get, "http://127.0.0.6:8101/", headers: {'X-Trace'=>/^.*$/}
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_xtrace_tracing
|
48
|
-
stub_request(:get, "http://127.0.0.7:8101/").to_return(status: 200, body: "", headers: {})
|
49
|
-
|
50
|
-
AppOpticsAPM::API.start_trace('excon_tests') do
|
51
|
-
::Excon.get("http://127.0.0.7:8101/")
|
52
|
-
end
|
53
|
-
|
54
|
-
assert_requested :get, "http://127.0.0.7:8101/", times: 1
|
55
|
-
assert_requested :get, "http://127.0.0.7:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]{56}01/}, times: 1
|
56
|
-
refute AppOpticsAPM::Context.isValid
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_xtrace_tracing_not_sampling
|
60
|
-
stub_request(:get, "http://127.0.0.4:8101/").to_return(status: 200, body: "", headers: {})
|
61
|
-
|
62
|
-
AppOpticsAPM.config_lock.synchronize do
|
63
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
64
|
-
AppOpticsAPM::API.start_trace('excon_test') do
|
65
|
-
::Excon.get("http://127.0.0.4:8101/")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
assert_requested :get, "http://127.0.0.4:8101/", times: 1
|
70
|
-
assert_requested :get, "http://127.0.0.4:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*00$/}, times: 1
|
71
|
-
assert_not_requested :get, "http://127.0.0.4:8101/", headers: {'X-Trace'=>/^2B0*$/}
|
72
|
-
refute AppOpticsAPM::Context.isValid
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_xtrace_tracing_blacklisted
|
76
|
-
stub_request(:get, "http://127.0.0.3:8101/").to_return(status: 200, body: "", headers: {})
|
77
|
-
|
78
|
-
AppOpticsAPM.config_lock.synchronize do
|
79
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.3'
|
80
|
-
AppOpticsAPM::API.start_trace('excon_tests') do
|
81
|
-
::Excon.get("http://127.0.0.3:8101/")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
assert_requested :get, "http://127.0.0.3:8101/", times: 1
|
86
|
-
assert_not_requested :get, "http://127.0.0.3:8101/", headers: {'X-Trace'=>/.*/}
|
87
|
-
refute AppOpticsAPM::Context.isValid
|
88
|
-
end
|
89
|
-
|
90
|
-
# ========== excon pipelined =================================
|
91
|
-
|
92
|
-
def test_xtrace_pipelined_tracing
|
93
|
-
stub_request(:get, "http://127.0.0.5:8101/").to_return(status: 200, body: "", headers: {})
|
94
|
-
stub_request(:put, "http://127.0.0.5:8101/").to_return(status: 200, body: "", headers: {})
|
95
|
-
|
96
|
-
AppOpticsAPM::API.start_trace('excon_tests') do
|
97
|
-
connection = ::Excon.new('http://127.0.0.5:8101/')
|
98
|
-
connection.requests([{:method => :get}, {:method => :put}])
|
99
|
-
end
|
100
|
-
|
101
|
-
assert_requested :get, "http://127.0.0.5:8101/", times: 1
|
102
|
-
assert_requested :put, "http://127.0.0.5:8101/", times: 1
|
103
|
-
assert_requested :get, "http://127.0.0.5:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*01$/}, times: 1
|
104
|
-
assert_requested :put, "http://127.0.0.5:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*01$/}, times: 1
|
105
|
-
refute AppOpticsAPM::Context.isValid
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_xtrace_pipelined_tracing_not_sampling
|
109
|
-
stub_request(:get, "http://127.0.0.2:8101/").to_return(status: 200, body: "", headers: {})
|
110
|
-
stub_request(:put, "http://127.0.0.2:8101/").to_return(status: 200, body: "", headers: {})
|
111
|
-
|
112
|
-
AppOpticsAPM.config_lock.synchronize do
|
113
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
114
|
-
AppOpticsAPM::API.start_trace('excon_tests') do
|
115
|
-
connection = ::Excon.new('http://127.0.0.2:8101/')
|
116
|
-
connection.requests([{:method => :get}, {:method => :put}])
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
assert_requested :get, "http://127.0.0.2:8101/", times: 1
|
121
|
-
assert_requested :put, "http://127.0.0.2:8101/", times: 1
|
122
|
-
assert_requested :get, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*00$/}, times: 1
|
123
|
-
assert_requested :put, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*00$/}, times: 1
|
124
|
-
assert_not_requested :get, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^2B0*$/}
|
125
|
-
assert_not_requested :put, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^2B0*$/}
|
126
|
-
refute AppOpticsAPM::Context.isValid
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_xtrace_pipelined_no_trace
|
130
|
-
stub_request(:get, "http://127.0.0.8:8101/").to_return(status: 200, body: "", headers: {})
|
131
|
-
stub_request(:put, "http://127.0.0.8:8101/").to_return(status: 200, body: "", headers: {})
|
132
|
-
|
133
|
-
connection = ::Excon.new('http://127.0.0.8:8101/')
|
134
|
-
connection.requests([{:method => :get}, {:method => :put}])
|
135
|
-
|
136
|
-
assert_requested :get, "http://127.0.0.8:8101/", times: 1
|
137
|
-
assert_requested :put, "http://127.0.0.8:8101/", times: 1
|
138
|
-
assert_not_requested :get, "http://127.0.0.8:8101/", headers: {'X-Trace'=>/^.*$/}
|
139
|
-
assert_not_requested :put, "http://127.0.0.8:8101/", headers: {'X-Trace'=>/^.*$/}
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_xtrace_pipelined_tracing_blacklisted
|
143
|
-
stub_request(:get, "http://127.0.0.9:8101/").to_return(status: 200, body: "", headers: {})
|
144
|
-
stub_request(:put, "http://127.0.0.9:8101/").to_return(status: 200, body: "", headers: {})
|
145
|
-
|
146
|
-
AppOpticsAPM.config_lock.synchronize do
|
147
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.9'
|
148
|
-
AppOpticsAPM::API.start_trace('excon_tests') do
|
149
|
-
connection = ::Excon.new('http://127.0.0.9:8101/')
|
150
|
-
connection.requests([{:method => :get}, {:method => :put}])
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
assert_requested :get, "http://127.0.0.9:8101/", times: 1
|
155
|
-
assert_requested :put, "http://127.0.0.9:8101/", times: 1
|
156
|
-
assert_not_requested :get, "http://127.9.0.8:8101/", headers: {'X-Trace'=>/^.*$/}
|
157
|
-
assert_not_requested :put, "http://127.9.0.8:8101/", headers: {'X-Trace'=>/^.*$/}
|
158
|
-
refute AppOpticsAPM::Context.isValid
|
159
|
-
end
|
160
|
-
|
161
|
-
# ========== excon make sure headers are preserved =============================
|
162
|
-
def test_preserves_custom_headers
|
163
|
-
stub_request(:get, "http://127.0.0.10:8101/").to_return(status: 200, body: "", headers: {})
|
164
|
-
|
165
|
-
AppOpticsAPM::API.start_trace('excon_tests') do
|
166
|
-
Excon.get('http://127.0.0.10:8101', headers: { 'Custom' => 'specialvalue' })
|
167
|
-
end
|
168
|
-
|
169
|
-
assert_requested :get, "http://127.0.0.10:8101/", headers: {'Custom'=>'specialvalue'}, times: 1
|
170
|
-
refute AppOpticsAPM::Context.isValid
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# Copyright (c) 2016 SolarWinds, LLC.
|
2
|
-
# All rights reserved.
|
3
|
-
|
4
|
-
if !defined?(JRUBY_VERSION)
|
5
|
-
|
6
|
-
require 'minitest_helper'
|
7
|
-
require 'webmock/minitest'
|
8
|
-
require 'mocha/mini_test'
|
9
|
-
|
10
|
-
class FaradayMockedTest < Minitest::Test
|
11
|
-
|
12
|
-
def setup
|
13
|
-
AppOpticsAPM::Context.clear
|
14
|
-
WebMock.enable!
|
15
|
-
WebMock.reset!
|
16
|
-
WebMock.disable_net_connect!
|
17
|
-
AppOpticsAPM.config_lock.synchronize {
|
18
|
-
@sample_rate = AppOpticsAPM::Config[:sample_rate]
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def teardown
|
23
|
-
AppOpticsAPM.config_lock.synchronize {
|
24
|
-
AppOpticsAPM::Config[:blacklist] = []
|
25
|
-
AppOpticsAPM::Config[:sample_rate] = @sample_rate
|
26
|
-
}
|
27
|
-
WebMock.reset!
|
28
|
-
WebMock.allow_net_connect!
|
29
|
-
WebMock.disable!
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_tracing_sampling
|
33
|
-
stub_request(:get, "http://127.0.0.1:8101/")
|
34
|
-
|
35
|
-
AppOpticsAPM::API.start_trace('faraday_test') do
|
36
|
-
conn = Faraday.new(:url => 'http://127.0.0.1:8101') do |faraday|
|
37
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
38
|
-
end
|
39
|
-
conn.get
|
40
|
-
end
|
41
|
-
|
42
|
-
assert_requested :get, "http://127.0.0.1:8101/", times: 1
|
43
|
-
assert_requested :get, "http://127.0.0.1:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*01$/}, times: 1
|
44
|
-
refute AppOpticsAPM::Context.isValid
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_tracing_not_sampling
|
48
|
-
stub_request(:get, "http://127.0.0.12:8101/")
|
49
|
-
|
50
|
-
AppOpticsAPM.config_lock.synchronize do
|
51
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
52
|
-
AppOpticsAPM::API.start_trace('faraday_test') do
|
53
|
-
conn = Faraday.new(:url => 'http://127.0.0.12:8101') do |faraday|
|
54
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
55
|
-
end
|
56
|
-
conn.get
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
assert_requested :get, "http://127.0.0.12:8101/", times: 1
|
61
|
-
assert_requested :get, "http://127.0.0.12:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*00$/}, times: 1
|
62
|
-
assert_not_requested :get, "http://127.0.0.12:8101/", headers: {'X-Trace'=>/^2B0*$/}
|
63
|
-
refute AppOpticsAPM::Context.isValid
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_no_xtrace
|
67
|
-
stub_request(:get, "http://127.0.0.3:8101/")
|
68
|
-
|
69
|
-
conn = Faraday.new(:url => 'http://127.0.0.3:8101') do |faraday|
|
70
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
71
|
-
end
|
72
|
-
conn.get
|
73
|
-
|
74
|
-
assert_requested :get, "http://127.0.0.3:8101/", times: 1
|
75
|
-
assert_not_requested :get, "http://127.0.0.3:8101/", headers: {'X-Trace'=>/^.*$/}
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_blacklisted
|
79
|
-
stub_request(:get, "http://127.0.0.4:8101/")
|
80
|
-
|
81
|
-
AppOpticsAPM.config_lock.synchronize do
|
82
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.4'
|
83
|
-
AppOpticsAPM::API.start_trace('faraday_test') do
|
84
|
-
conn = Faraday.new(:url => 'http://127.0.0.4:8101') do |faraday|
|
85
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
86
|
-
end
|
87
|
-
conn.get
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
assert_requested :get, "http://127.0.0.4:8101/", times: 1
|
92
|
-
assert_not_requested :get, "http://127.0.0.4:8101/", headers: {'X-Trace'=>/^.*$/}
|
93
|
-
refute AppOpticsAPM::Context.isValid
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
# Copyright (c) 2016 SolarWinds, LLC.
|
2
|
-
# All rights reserved.
|
3
|
-
|
4
|
-
unless defined?(JRUBY_VERSION)
|
5
|
-
require 'minitest_helper'
|
6
|
-
require 'mocha/mini_test'
|
7
|
-
require 'net/http'
|
8
|
-
|
9
|
-
class HTTPMockedTest < Minitest::Test
|
10
|
-
|
11
|
-
class MockResponse
|
12
|
-
def get_fields(x); nil; end
|
13
|
-
def code; 200; end
|
14
|
-
end
|
15
|
-
|
16
|
-
def setup
|
17
|
-
AppOpticsAPM::Context.clear
|
18
|
-
AppOpticsAPM.config_lock.synchronize do
|
19
|
-
@sample_rate = AppOpticsAPM::Config[:sample_rate]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def teardown
|
24
|
-
AppOpticsAPM.config_lock.synchronize do
|
25
|
-
AppOpticsAPM::Config[:sample_rate] = @sample_rate
|
26
|
-
AppOpticsAPM::Config[:blacklist] = []
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# webmock not working, interferes with instrumentation
|
31
|
-
|
32
|
-
def test_tracing_sampling
|
33
|
-
Net::HTTP.any_instance.expects(:request_without_appoptics).with do |req, _|
|
34
|
-
!req.to_hash['x-trace'].nil? &&
|
35
|
-
req.to_hash['x-trace'].first =~ /^2B[0-9,A-F]*01$/
|
36
|
-
end.returns(MockResponse.new)
|
37
|
-
|
38
|
-
AppOpticsAPM::API.start_trace('net_http_test') do
|
39
|
-
uri = URI('http://127.0.0.1:8101/?q=1')
|
40
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
41
|
-
request = Net::HTTP::Get.new(uri)
|
42
|
-
http.request(request)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
refute AppOpticsAPM::Context.isValid
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_tracing_not_sampling
|
49
|
-
Net::HTTP.any_instance.expects(:request_without_appoptics).with do |req, _, _|
|
50
|
-
!req.to_hash['x-trace'].nil? &&
|
51
|
-
req.to_hash['x-trace'].first =~ /^2B[0-9,A-F]*00$/ &&
|
52
|
-
req.to_hash['x-trace'].first !~ /^2B0*$/
|
53
|
-
end.returns(MockResponse.new)
|
54
|
-
|
55
|
-
AppOpticsAPM.config_lock.synchronize do
|
56
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
57
|
-
AppOpticsAPM::API.start_trace('Net::HTTP_test') do
|
58
|
-
uri = URI('http://127.0.0.1:8101/?q=1')
|
59
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
60
|
-
request = Net::HTTP::Get.new(uri)
|
61
|
-
http.request(request) # Net::HTTPResponse object
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
refute AppOpticsAPM::Context.isValid
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_no_xtrace
|
69
|
-
Net::HTTP.any_instance.expects(:request_without_appoptics).with do |req, _, _|
|
70
|
-
req.to_hash['x-trace'].nil?
|
71
|
-
end.returns(MockResponse.new)
|
72
|
-
|
73
|
-
uri = URI('http://127.0.0.1:8101/?q=1')
|
74
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
75
|
-
request = Net::HTTP::Get.new(uri)
|
76
|
-
http.request(request) # Net::HTTPResponse object
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_blacklisted
|
81
|
-
Net::HTTP.any_instance.expects(:request_without_appoptics).with do |req, _, _|
|
82
|
-
req.to_hash['x-trace'].nil?
|
83
|
-
end.returns(MockResponse.new)
|
84
|
-
|
85
|
-
AppOpticsAPM.config_lock.synchronize do
|
86
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.1'
|
87
|
-
AppOpticsAPM::API.start_trace('Net::HTTP_tests') do
|
88
|
-
uri = URI('http://127.0.0.1:8101/?q=1')
|
89
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
90
|
-
request = Net::HTTP::Get.new(uri)
|
91
|
-
http.request(request) # Net::HTTPResponse object
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
refute AppOpticsAPM::Context.isValid
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_not_sampling_blacklisted
|
99
|
-
Net::HTTP.any_instance.expects(:request_without_appoptics).with do |req, _, _|
|
100
|
-
req.to_hash['x-trace'].nil?
|
101
|
-
end.returns(MockResponse.new)
|
102
|
-
|
103
|
-
AppOpticsAPM.config_lock.synchronize do
|
104
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
105
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.1'
|
106
|
-
AppOpticsAPM::API.start_trace('Net::HTTP_tests') do
|
107
|
-
uri = URI('http://127.0.0.1:8101/?q=1')
|
108
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
109
|
-
request = Net::HTTP::Get.new(uri)
|
110
|
-
http.request(request) # Net::HTTPResponse object
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
refute AppOpticsAPM::Context.isValid
|
115
|
-
end
|
116
|
-
|
117
|
-
# ========== make sure headers are preserved =============================
|
118
|
-
def test_preserves_custom_headers
|
119
|
-
Net::HTTP.any_instance.expects(:request_without_appoptics).with do |req, _|
|
120
|
-
assert req.to_hash['custom'], "Custom header missing"
|
121
|
-
assert_match /specialvalue/, req.to_hash['custom'].first
|
122
|
-
end.returns(MockResponse.new)
|
123
|
-
|
124
|
-
AppOpticsAPM::API.start_trace('Net::HTTP_tests') do
|
125
|
-
uri = URI('http://127.0.0.1:8101/?q=1')
|
126
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
127
|
-
request = Net::HTTP::Get.new(uri)
|
128
|
-
request['Custom'] = 'specialvalue'
|
129
|
-
http.request(request) # Net::HTTPResponse object
|
130
|
-
end
|
131
|
-
end
|
132
|
-
refute AppOpticsAPM::Context.isValid
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,258 +0,0 @@
|
|
1
|
-
# Copyright (c) 2016 SolarWinds, LLC.
|
2
|
-
# All rights reserved.
|
3
|
-
|
4
|
-
unless defined?(JRUBY_VERSION)
|
5
|
-
require 'minitest_helper'
|
6
|
-
require 'webmock/minitest'
|
7
|
-
require 'mocha/mini_test'
|
8
|
-
|
9
|
-
class HTTPClientMockedTest < Minitest::Test
|
10
|
-
|
11
|
-
def setup
|
12
|
-
AppOpticsAPM::Context.clear
|
13
|
-
WebMock.enable!
|
14
|
-
WebMock.reset!
|
15
|
-
WebMock.disable_net_connect!
|
16
|
-
AppOpticsAPM.config_lock.synchronize do
|
17
|
-
@sample_rate = AppOpticsAPM::Config[:sample_rate]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
WebMock.reset!
|
23
|
-
WebMock.allow_net_connect!
|
24
|
-
WebMock.disable!
|
25
|
-
AppOpticsAPM.config_lock.synchronize do
|
26
|
-
AppOpticsAPM::Config[:sample_rate] = @sample_rate
|
27
|
-
AppOpticsAPM::Config[:blacklist] = []
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
#====== DO REQUEST ===================================================
|
32
|
-
|
33
|
-
def test_do_request_tracing_sampling_array_headers
|
34
|
-
stub_request(:get, "http://127.0.0.1:8101/")
|
35
|
-
AppOpticsAPM::API.start_trace('httpclient_test') do
|
36
|
-
clnt = HTTPClient.new
|
37
|
-
clnt.get('http://127.0.0.1:8101/', nil, [['some_header', 'some_value'], ['some_header2', 'some_value2']])
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_requested :get, "http://127.0.0.1:8101/", times: 1
|
41
|
-
assert_requested :get, "http://127.0.0.1:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*01$/}, times: 1
|
42
|
-
refute AppOpticsAPM::Context.isValid
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_do_request_tracing_sampling_hash_headers
|
46
|
-
stub_request(:get, "http://127.0.0.6:8101/")
|
47
|
-
AppOpticsAPM::API.start_trace('httpclient_test') do
|
48
|
-
clnt = HTTPClient.new
|
49
|
-
clnt.get('http://127.0.0.6:8101/', nil, { 'some_header' => 'some_value', 'some_header2' => 'some_value2' })
|
50
|
-
end
|
51
|
-
|
52
|
-
assert_requested :get, "http://127.0.0.6:8101/", times: 1
|
53
|
-
assert_requested :get, "http://127.0.0.6:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*01$/}, times: 1
|
54
|
-
refute AppOpticsAPM::Context.isValid
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_do_request_tracing_not_sampling
|
58
|
-
stub_request(:get, "http://127.0.0.2:8101/")
|
59
|
-
AppOpticsAPM.config_lock.synchronize do
|
60
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
61
|
-
AppOpticsAPM::API.start_trace('httpclient_test') do
|
62
|
-
clnt = HTTPClient.new
|
63
|
-
clnt.get('http://127.0.0.2:8101/')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
assert_requested :get, "http://127.0.0.2:8101/", times: 1
|
68
|
-
assert_requested :get, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*00$/}, times: 1
|
69
|
-
assert_not_requested :get, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^2B0*$/}
|
70
|
-
refute AppOpticsAPM::Context.isValid
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_do_request_no_xtrace
|
74
|
-
stub_request(:get, "http://127.0.0.3:8101/")
|
75
|
-
clnt = HTTPClient.new
|
76
|
-
clnt.get('http://127.0.0.3:8101/')
|
77
|
-
|
78
|
-
assert_requested :get, "http://127.0.0.3:8101/", times: 1
|
79
|
-
assert_not_requested :get, "http://127.0.0.3:8101/", headers: {'X-Trace'=>/^.*$/}
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_do_request_blacklisted
|
83
|
-
stub_request(:get, "http://127.0.0.4:8101/")
|
84
|
-
|
85
|
-
AppOpticsAPM.config_lock.synchronize do
|
86
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.4'
|
87
|
-
AppOpticsAPM::API.start_trace('httpclient_tests') do
|
88
|
-
clnt = HTTPClient.new
|
89
|
-
clnt.get('http://127.0.0.4:8101/')
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
assert_requested :get, "http://127.0.0.4:8101/"
|
94
|
-
assert_not_requested :get, "http://127.0.0.4:8101/", headers: {'X-Trace'=>/^.*$/}
|
95
|
-
refute AppOpticsAPM::Context.isValid
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_do_request_not_sampling_blacklisted
|
99
|
-
stub_request(:get, "http://127.0.0.5:8101/")
|
100
|
-
|
101
|
-
AppOpticsAPM.config_lock.synchronize do
|
102
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
103
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.5'
|
104
|
-
AppOpticsAPM::API.start_trace('httpclient_tests') do
|
105
|
-
clnt = HTTPClient.new
|
106
|
-
clnt.get('http://127.0.0.5:8101/')
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
assert_requested :get, "http://127.0.0.5:8101/"
|
111
|
-
assert_not_requested :get, "http://127.0.0.5:8101/", headers: {'X-Trace'=>/^.*$/}
|
112
|
-
refute AppOpticsAPM::Context.isValid
|
113
|
-
end
|
114
|
-
|
115
|
-
#====== ASYNC REQUEST ================================================
|
116
|
-
# using expectations in these tests because stubbing doesn't work with threads
|
117
|
-
|
118
|
-
def test_async_tracing_sampling_array_headers
|
119
|
-
WebMock.disable!
|
120
|
-
|
121
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
122
|
-
|
123
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
124
|
-
'http://127.0.0.11:8101/' == req.header.request_uri.to_s &&
|
125
|
-
req.header['X-Trace'].first =~ /^2B[0-9,A-F]*01$/
|
126
|
-
end
|
127
|
-
|
128
|
-
AppOpticsAPM::API.start_trace('httpclient_test') do
|
129
|
-
clnt = HTTPClient.new
|
130
|
-
clnt.get_async('http://127.0.0.11:8101/', nil, [['some_header', 'some_value'], ['some_header2', 'some_value2']])
|
131
|
-
end
|
132
|
-
refute AppOpticsAPM::Context.isValid
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_async_tracing_sampling_hash_headers
|
136
|
-
WebMock.disable!
|
137
|
-
|
138
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
139
|
-
|
140
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
141
|
-
'http://127.0.0.16:8101/' == req.header.request_uri.to_s &&
|
142
|
-
req.header['X-Trace'].first =~ /^2B[0-9,A-F]*01$/
|
143
|
-
end
|
144
|
-
|
145
|
-
AppOpticsAPM::API.start_trace('httpclient_test') do
|
146
|
-
clnt = HTTPClient.new
|
147
|
-
clnt.get_async('http://127.0.0.16:8101/', nil, { 'some_header' => 'some_value', 'some_header2' => 'some_value2' })
|
148
|
-
end
|
149
|
-
refute AppOpticsAPM::Context.isValid
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_async_tracing_not_sampling
|
153
|
-
WebMock.disable!
|
154
|
-
|
155
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
156
|
-
|
157
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
158
|
-
'http://127.0.0.12:8101/' == req.header.request_uri.to_s &&
|
159
|
-
req.header['X-Trace'].first =~ /^2B[0-9,A-F]*00$/ &&
|
160
|
-
req.header['X-Trace'].first !~ /^2B0*$/
|
161
|
-
end
|
162
|
-
|
163
|
-
AppOpticsAPM.config_lock.synchronize do
|
164
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
165
|
-
AppOpticsAPM::API.start_trace('httpclient_test') do
|
166
|
-
clnt = HTTPClient.new
|
167
|
-
clnt.get_async('http://127.0.0.12:8101/')
|
168
|
-
end
|
169
|
-
end
|
170
|
-
refute AppOpticsAPM::Context.isValid
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_async_no_xtrace
|
174
|
-
WebMock.disable!
|
175
|
-
|
176
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
177
|
-
|
178
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
179
|
-
'http://127.0.0.13:8101/' == req.header.request_uri.to_s &&
|
180
|
-
req.header['X-Trace'].empty?
|
181
|
-
end
|
182
|
-
|
183
|
-
clnt = HTTPClient.new
|
184
|
-
clnt.get_async('http://127.0.0.13:8101/')
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_async_blacklisted
|
188
|
-
WebMock.disable!
|
189
|
-
|
190
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
191
|
-
|
192
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
193
|
-
'http://127.0.0.14:8101/' == req.header.request_uri.to_s &&
|
194
|
-
req.header['X-Trace'].empty?
|
195
|
-
end
|
196
|
-
|
197
|
-
AppOpticsAPM.config_lock.synchronize do
|
198
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.14'
|
199
|
-
AppOpticsAPM::API.start_trace('httpclient_tests') do
|
200
|
-
clnt = HTTPClient.new
|
201
|
-
clnt.get_async('http://127.0.0.14:8101/')
|
202
|
-
end
|
203
|
-
end
|
204
|
-
refute AppOpticsAPM::Context.isValid
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_async_not_sampling_blacklisted
|
208
|
-
WebMock.disable!
|
209
|
-
|
210
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
211
|
-
|
212
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
213
|
-
'http://127.0.0.15:8101/' == req.header.request_uri.to_s &&
|
214
|
-
req.header['X-Trace'].empty?
|
215
|
-
end
|
216
|
-
|
217
|
-
AppOpticsAPM.config_lock.synchronize do
|
218
|
-
AppOpticsAPM::Config[:sample_rate] = 0
|
219
|
-
AppOpticsAPM::Config.blacklist << '127.0.0.15'
|
220
|
-
AppOpticsAPM::API.start_trace('httpclient_tests') do
|
221
|
-
clnt = HTTPClient.new
|
222
|
-
clnt.get_async('http://127.0.0.15:8101/')
|
223
|
-
end
|
224
|
-
end
|
225
|
-
refute AppOpticsAPM::Context.isValid
|
226
|
-
end
|
227
|
-
|
228
|
-
# ========== make sure headers are preserved =============================
|
229
|
-
def test_preserves_custom_headers
|
230
|
-
stub_request(:get, "http://127.0.0.6:8101/").to_return(status: 200, body: "", headers: {})
|
231
|
-
|
232
|
-
AppOpticsAPM::API.start_trace('httpclient_tests') do
|
233
|
-
clnt = HTTPClient.new
|
234
|
-
clnt.get('http://127.0.0.6:8101/', nil, [['Custom', 'specialvalue'], ['some_header2', 'some_value2']])
|
235
|
-
end
|
236
|
-
|
237
|
-
assert_requested :get, "http://127.0.0.6:8101/", headers: {'Custom'=>'specialvalue'}, times: 1
|
238
|
-
refute AppOpticsAPM::Context.isValid
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_async_preserves_custom_headers
|
242
|
-
WebMock.disable!
|
243
|
-
|
244
|
-
Thread.expects(:new).yields # continue without forking off a thread
|
245
|
-
|
246
|
-
HTTPClient.any_instance.expects(:do_get_stream_without_appoptics).with do |req, _, _|
|
247
|
-
assert req.headers['Custom'], "Custom header missing"
|
248
|
-
assert_match(/^specialvalue$/, req.headers['Custom'] )
|
249
|
-
end
|
250
|
-
|
251
|
-
AppOpticsAPM::API.start_trace('httpclient_tests') do
|
252
|
-
clnt = HTTPClient.new
|
253
|
-
clnt.get_async('http://127.0.0.6:8101/', nil, [['Custom', 'specialvalue'], ['some_header2', 'some_value2']])
|
254
|
-
end
|
255
|
-
refute AppOpticsAPM::Context.isValid
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|