instana 1.195.0 → 1.197.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +16 -2
- data/.rubocop.yml +6 -2
- data/Appraisals +13 -1
- data/Rakefile +1 -1
- data/docker-compose.yml +20 -0
- data/gemfiles/aws_30.gemfile +3 -0
- data/gemfiles/excon_021.gemfile +18 -0
- data/gemfiles/excon_079.gemfile +18 -0
- data/gemfiles/shoryuken_50.gemfile +19 -0
- data/instana.gemspec +3 -7
- data/lib/instana.rb +3 -0
- data/lib/instana/activator.rb +2 -0
- data/lib/instana/activators/aws_sdk_s3.rb +20 -0
- data/lib/instana/activators/aws_sdk_sns.rb +20 -0
- data/lib/instana/activators/aws_sdk_sqs.rb +20 -0
- data/lib/instana/activators/excon.rb +1 -1
- data/lib/instana/activators/shoryuken.rb +24 -0
- data/lib/instana/backend/agent.rb +60 -0
- data/lib/instana/backend/gc_snapshot.rb +41 -0
- data/lib/instana/backend/host_agent.rb +57 -0
- data/lib/instana/backend/host_agent_activation_observer.rb +87 -0
- data/lib/instana/backend/host_agent_lookup.rb +57 -0
- data/lib/instana/backend/host_agent_reporting_observer.rb +106 -0
- data/lib/instana/backend/process_info.rb +64 -0
- data/lib/instana/backend/request_client.rb +84 -0
- data/lib/instana/backend/serverless_agent.rb +118 -0
- data/lib/instana/base.rb +8 -27
- data/lib/instana/config.rb +7 -21
- data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +21 -2
- data/lib/instana/instrumentation/aws_sdk_s3.rb +55 -0
- data/lib/instana/instrumentation/aws_sdk_sns.rb +29 -0
- data/lib/instana/instrumentation/aws_sdk_sqs.rb +98 -0
- data/lib/instana/instrumentation/excon.rb +12 -4
- data/lib/instana/instrumentation/instrumented_request.rb +7 -2
- data/lib/instana/instrumentation/net-http.rb +4 -2
- data/lib/instana/instrumentation/shoryuken.rb +44 -0
- data/lib/instana/logger_delegator.rb +31 -0
- data/lib/instana/{opentracing → open_tracing}/carrier.rb +0 -0
- data/lib/instana/open_tracing/instana_tracer.rb +99 -0
- data/lib/instana/secrets.rb +8 -4
- data/lib/instana/setup.rb +20 -11
- data/lib/instana/snapshot/deltable.rb +25 -0
- data/lib/instana/snapshot/docker_container.rb +151 -0
- data/lib/instana/snapshot/fargate_container.rb +88 -0
- data/lib/instana/snapshot/fargate_process.rb +67 -0
- data/lib/instana/snapshot/fargate_task.rb +72 -0
- data/lib/instana/snapshot/ruby_process.rb +48 -0
- data/lib/instana/tracer.rb +29 -147
- data/lib/instana/tracing/processor.rb +4 -22
- data/lib/instana/tracing/span.rb +29 -38
- data/lib/instana/tracing/span_context.rb +3 -2
- data/lib/instana/util.rb +4 -67
- data/lib/instana/version.rb +1 -1
- data/lib/opentracing.rb +26 -3
- data/test/backend/agent_test.rb +54 -0
- data/test/backend/gc_snapshot_test.rb +11 -0
- data/test/backend/host_agent_activation_observer_test.rb +65 -0
- data/test/backend/host_agent_lookup_test.rb +78 -0
- data/test/backend/host_agent_reporting_observer_test.rb +192 -0
- data/test/backend/host_agent_test.rb +32 -0
- data/test/backend/process_info_test.rb +63 -0
- data/test/backend/request_client_test.rb +61 -0
- data/test/backend/serverless_agent_test.rb +73 -0
- data/test/config_test.rb +10 -0
- data/test/instana_test.rb +11 -4
- data/test/instrumentation/aws_test.rb +130 -2
- data/test/instrumentation/excon_test.rb +16 -1
- data/test/instrumentation/net_http_test.rb +18 -0
- data/test/instrumentation/rack_instrumented_request_test.rb +7 -4
- data/test/instrumentation/rack_test.rb +2 -14
- data/test/instrumentation/shoryuken_test.rb +47 -0
- data/test/secrets_test.rb +41 -22
- data/test/snapshot/deltable_test.rb +17 -0
- data/test/snapshot/docker_container_test.rb +82 -0
- data/test/snapshot/fargate_container_test.rb +82 -0
- data/test/snapshot/fargate_process_test.rb +35 -0
- data/test/snapshot/fargate_task_test.rb +49 -0
- data/test/snapshot/ruby_process_test.rb +14 -0
- data/test/support/mock_timer.rb +20 -0
- data/test/test_helper.rb +15 -3
- data/test/tracing/custom_test.rb +1 -3
- data/test/tracing/id_management_test.rb +4 -0
- data/test/tracing/opentracing_test.rb +15 -2
- data/test/tracing/processor_test.rb +58 -0
- data/test/tracing/span_context_test.rb +22 -0
- data/test/tracing/span_test.rb +127 -0
- data/test/tracing/tracer_async_test.rb +29 -0
- data/test/tracing/tracer_test.rb +82 -16
- data/test/util_test.rb +10 -0
- metadata +86 -46
- data/Dockerfile +0 -16
- data/lib/instana/agent.rb +0 -508
- data/lib/instana/agent/helpers.rb +0 -87
- data/lib/instana/agent/hooks.rb +0 -44
- data/lib/instana/agent/tasks.rb +0 -51
- data/lib/instana/collector.rb +0 -119
- data/lib/instana/collectors/gc.rb +0 -60
- data/lib/instana/collectors/memory.rb +0 -37
- data/lib/instana/collectors/thread.rb +0 -33
- data/lib/instana/eum/eum-test.js.erb +0 -17
- data/lib/instana/eum/eum.js.erb +0 -17
- data/lib/instana/helpers.rb +0 -47
- data/lib/instana/opentracing/tracer.rb +0 -21
- data/lib/instana/thread_local.rb +0 -18
- data/lib/oj_check.rb +0 -19
- data/test/agent/agent_test.rb +0 -151
@@ -0,0 +1,78 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class HostAgentLookupTest < Minitest::Test
|
7
|
+
def test_lookup
|
8
|
+
stub_request(:get, "http://10.10.10.10:42699/")
|
9
|
+
.to_return(status: 200)
|
10
|
+
|
11
|
+
subject = Instana::Backend::HostAgentLookup.new('10.10.10.10', 42699)
|
12
|
+
client = subject.call
|
13
|
+
|
14
|
+
assert client
|
15
|
+
assert client.send_request('GET', '/').ok?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_lookup_no_agent
|
19
|
+
stub_request(:get, "http://10.10.10.10:42699/")
|
20
|
+
.to_timeout
|
21
|
+
|
22
|
+
subject = Instana::Backend::HostAgentLookup.new('10.10.10.10', 42699)
|
23
|
+
|
24
|
+
client = FakeFS.with_fresh do
|
25
|
+
FakeFS::FileSystem.clone('test/support/ecs', '/proc')
|
26
|
+
|
27
|
+
subject.call
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_nil client
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_lookup_agent_error
|
34
|
+
stub_request(:get, "http://10.10.10.10:42699/")
|
35
|
+
.to_return(status: 500)
|
36
|
+
|
37
|
+
subject = Instana::Backend::HostAgentLookup.new('10.10.10.10', 42699)
|
38
|
+
|
39
|
+
client = FakeFS.with_fresh do
|
40
|
+
FakeFS::FileSystem.clone('test/support/ecs', '/proc')
|
41
|
+
|
42
|
+
subject.call
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_nil client
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_lookup_with_gateway
|
49
|
+
stub_request(:get, "http://10.10.10.10:42699/")
|
50
|
+
.to_timeout
|
51
|
+
stub_request(:get, "http://172.18.0.1:42699/")
|
52
|
+
.to_return(status: 200)
|
53
|
+
|
54
|
+
subject = Instana::Backend::HostAgentLookup.new('10.10.10.10', 42699)
|
55
|
+
|
56
|
+
client = FakeFS do
|
57
|
+
FakeFS::FileSystem.clone('test/support/proc', '/proc')
|
58
|
+
subject.call
|
59
|
+
end
|
60
|
+
|
61
|
+
assert client
|
62
|
+
assert client.send_request('GET', '/').ok?
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_lookup_with_gateway_no_destination
|
66
|
+
stub_request(:get, "http://10.10.10.10:42699/")
|
67
|
+
.to_timeout
|
68
|
+
|
69
|
+
subject = Instana::Backend::HostAgentLookup.new('10.10.10.10', 42699, destination: '11111111')
|
70
|
+
|
71
|
+
client = FakeFS do
|
72
|
+
FakeFS::FileSystem.clone('test/support/proc', '/proc')
|
73
|
+
subject.call
|
74
|
+
end
|
75
|
+
|
76
|
+
assert_nil client
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class HostAgentReportingObserverTest < Minitest::Test
|
7
|
+
def test_start_stop
|
8
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
9
|
+
discovery = Concurrent::Atom.new(nil)
|
10
|
+
|
11
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
12
|
+
|
13
|
+
refute subject.report_timer.running
|
14
|
+
|
15
|
+
subject.update(Time.now, nil, true)
|
16
|
+
assert subject.report_timer.running
|
17
|
+
|
18
|
+
subject.update(Time.now, nil, nil)
|
19
|
+
refute subject.report_timer.running
|
20
|
+
|
21
|
+
subject.update(Time.now - 500, nil, true)
|
22
|
+
refute subject.report_timer.running
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_report
|
26
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
|
27
|
+
.to_return(status: 200)
|
28
|
+
|
29
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
30
|
+
discovery = Concurrent::Atom.new({'pid' => 0})
|
31
|
+
|
32
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
33
|
+
|
34
|
+
subject.report_timer.block.call
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_report_fail
|
38
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
|
39
|
+
.to_return(status: 500)
|
40
|
+
|
41
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
42
|
+
discovery = Concurrent::Atom.new({'pid' => 0})
|
43
|
+
|
44
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
45
|
+
|
46
|
+
subject.report_timer.block.call
|
47
|
+
assert_nil discovery.value
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_agent_action
|
51
|
+
action = JSON.dump(
|
52
|
+
action: 'ruby.source',
|
53
|
+
messageId: 'test',
|
54
|
+
args: {file: 'test_helper.rb'}
|
55
|
+
)
|
56
|
+
|
57
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
|
58
|
+
.to_return(status: 200, body: action)
|
59
|
+
|
60
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/response.0?messageId=test")
|
61
|
+
.to_return(status: 200)
|
62
|
+
|
63
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
64
|
+
discovery = Concurrent::Atom.new({'pid' => 0})
|
65
|
+
|
66
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
67
|
+
|
68
|
+
subject.report_timer.block.call
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_agent_actions
|
72
|
+
action = JSON.dump([
|
73
|
+
action: 'ruby.source',
|
74
|
+
messageId: 'test',
|
75
|
+
args: {file: 'test_helper.rb'}
|
76
|
+
])
|
77
|
+
|
78
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
|
79
|
+
.to_return(status: 200, body: action)
|
80
|
+
|
81
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/response.0?messageId=test")
|
82
|
+
.to_return(status: 200)
|
83
|
+
|
84
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
85
|
+
discovery = Concurrent::Atom.new({'pid' => 0})
|
86
|
+
|
87
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
88
|
+
|
89
|
+
subject.report_timer.block.call
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_agent_action_error
|
93
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
|
94
|
+
.to_return(status: 200, body: 'INVALID')
|
95
|
+
|
96
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
97
|
+
discovery = Concurrent::Atom.new({'pid' => 0})
|
98
|
+
|
99
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
100
|
+
|
101
|
+
subject.report_timer.block.call
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_disable_metrics
|
105
|
+
::Instana.config[:metrics][:enabled] = false
|
106
|
+
|
107
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
108
|
+
discovery = Concurrent::Atom.new(nil)
|
109
|
+
|
110
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
111
|
+
|
112
|
+
subject.report_timer.block.call
|
113
|
+
ensure
|
114
|
+
::Instana.config[:metrics][:enabled] = true
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_disable_tracing
|
118
|
+
::Instana.config[:tracing][:enabled] = false
|
119
|
+
|
120
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
121
|
+
discovery = Concurrent::Atom.new(nil)
|
122
|
+
|
123
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
|
124
|
+
|
125
|
+
subject.report_timer.block.call
|
126
|
+
ensure
|
127
|
+
::Instana.config[:tracing][:enabled] = true
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_report_traces
|
131
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
|
132
|
+
.to_return(status: 200)
|
133
|
+
|
134
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.1234")
|
135
|
+
.to_return(status: 200)
|
136
|
+
|
137
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
138
|
+
discovery = Concurrent::Atom.new({'pid' => 1234})
|
139
|
+
|
140
|
+
processor = Class.new do
|
141
|
+
def send
|
142
|
+
yield([{n: 'test'}])
|
143
|
+
end
|
144
|
+
end.new
|
145
|
+
|
146
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer, processor: processor)
|
147
|
+
|
148
|
+
subject.report_timer.block.call
|
149
|
+
refute_nil discovery.value
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_report_traces_error
|
153
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
|
154
|
+
.to_return(status: 200)
|
155
|
+
|
156
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.1234")
|
157
|
+
.to_return(status: 500)
|
158
|
+
|
159
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
160
|
+
discovery = Concurrent::Atom.new({'pid' => 1234})
|
161
|
+
|
162
|
+
processor = Class.new do
|
163
|
+
def send
|
164
|
+
yield([{n: 'test'}])
|
165
|
+
end
|
166
|
+
end.new
|
167
|
+
|
168
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer, processor: processor)
|
169
|
+
|
170
|
+
subject.report_timer.block.call
|
171
|
+
assert_nil discovery.value
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_report_standard_error
|
175
|
+
stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
|
176
|
+
.to_return(status: 200)
|
177
|
+
|
178
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
179
|
+
discovery = Concurrent::Atom.new({'pid' => 1234})
|
180
|
+
|
181
|
+
processor = Class.new do
|
182
|
+
def send
|
183
|
+
raise 'Standard Error'
|
184
|
+
end
|
185
|
+
end.new
|
186
|
+
|
187
|
+
subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer, processor: processor, logger: Logger.new('/dev/null'))
|
188
|
+
|
189
|
+
subject.report_timer.block.call
|
190
|
+
assert_equal({"pid" => 1234}, discovery.value)
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class HostAgentTest < Minitest::Test
|
7
|
+
def test_setup
|
8
|
+
ENV['INSTANA_TEST'] = nil
|
9
|
+
::Instana.config[:agent_host] = '10.10.10.10'
|
10
|
+
|
11
|
+
stub_request(:get, "http://10.10.10.10:42699/")
|
12
|
+
.to_return(status: 200, body: "", headers: {})
|
13
|
+
|
14
|
+
discovery = Minitest::Mock.new
|
15
|
+
discovery.expect(:with_observer, discovery, [Instana::Backend::HostAgentActivationObserver])
|
16
|
+
discovery.expect(:with_observer, discovery, [Instana::Backend::HostAgentReportingObserver])
|
17
|
+
|
18
|
+
subject = Instana::Backend::HostAgent.new(discovery: discovery)
|
19
|
+
subject.setup
|
20
|
+
|
21
|
+
discovery.verify
|
22
|
+
ensure
|
23
|
+
::Instana.config[:agent_host] = '127.0.0.1'
|
24
|
+
ENV['INSTANA_TEST'] = 'true'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_discovery_value
|
28
|
+
discovery = Concurrent::Atom.new({'pid' => 1})
|
29
|
+
subject = Instana::Backend::HostAgent.new(discovery: discovery)
|
30
|
+
assert_equal 1, subject.source[:e]
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class ProcessInfoTest < Minitest::Test
|
7
|
+
def test_osx_argument_stripping
|
8
|
+
host_os = RbConfig::CONFIG['host_os']
|
9
|
+
RbConfig::CONFIG['host_os'] = 'darwin'
|
10
|
+
|
11
|
+
subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(cmdline: 'test INSTANA_TEST=1 KV=2'))
|
12
|
+
assert_equal ['KV=2'], subject.arguments
|
13
|
+
ensure
|
14
|
+
RbConfig::CONFIG['host_os'] = host_os
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_linux_argument_stripping
|
18
|
+
host_os = RbConfig::CONFIG['host_os']
|
19
|
+
RbConfig::CONFIG['host_os'] = 'linux'
|
20
|
+
|
21
|
+
subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(cmdline: 'test INSTANA_TEST=1 KV=2'))
|
22
|
+
assert_equal ['INSTANA_TEST=1', 'KV=2'], subject.arguments
|
23
|
+
ensure
|
24
|
+
RbConfig::CONFIG['host_os'] = host_os
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_no_proc
|
28
|
+
subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 0))
|
29
|
+
|
30
|
+
FakeFS.with_fresh do
|
31
|
+
FakeFS::FileSystem.clone('test/support/ecs', '/proc')
|
32
|
+
|
33
|
+
assert_equal 0, subject.parent_pid
|
34
|
+
assert_nil subject.cpuset
|
35
|
+
assert_nil subject.sched_pid
|
36
|
+
refute subject.in_container?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_cpuset_proc
|
41
|
+
subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 0))
|
42
|
+
|
43
|
+
FakeFS do
|
44
|
+
FakeFS::FileSystem.clone('test/support/proc', '/proc')
|
45
|
+
assert_equal '/', subject.cpuset
|
46
|
+
refute subject.in_container?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_sched_pid
|
51
|
+
subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 1))
|
52
|
+
|
53
|
+
FakeFS do
|
54
|
+
FakeFS::FileSystem.clone('test/support/proc', '/proc')
|
55
|
+
refute_equal '/', subject.cpuset
|
56
|
+
|
57
|
+
assert subject.in_container?
|
58
|
+
assert_equal 35, subject.sched_pid
|
59
|
+
assert subject.from_parent_namespace
|
60
|
+
assert_equal subject.sched_pid, subject.parent_pid
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class RequestClientTest < Minitest::Test
|
7
|
+
def test_send_request_simple
|
8
|
+
stub_request(:get, 'http://example.com:9292/')
|
9
|
+
.to_return(body: 'ok', status: '200')
|
10
|
+
|
11
|
+
subject = Instana::Backend::RequestClient.new('example.com', 9292)
|
12
|
+
response = subject.send_request('GET', '/')
|
13
|
+
|
14
|
+
assert response.ok?
|
15
|
+
assert 'ok', response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_send_request_json
|
19
|
+
stub_request(:post, 'http://example.com:9292/')
|
20
|
+
.with(body: '{"key":"value"}')
|
21
|
+
.to_return(body: '{"ok": true}', status: '200')
|
22
|
+
|
23
|
+
subject = Instana::Backend::RequestClient.new('example.com', 9292)
|
24
|
+
response = subject.send_request('POST', '/', {key: 'value'})
|
25
|
+
|
26
|
+
assert response.ok?
|
27
|
+
assert_equal({"ok" => true}, response.json)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_send_request_failure
|
31
|
+
stub_request(:get, 'http://example.com:9292/')
|
32
|
+
.to_return(status: '500')
|
33
|
+
|
34
|
+
subject = Instana::Backend::RequestClient.new('example.com', 9292)
|
35
|
+
response = subject.send_request('GET', '/')
|
36
|
+
|
37
|
+
refute response.ok?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_fileno
|
41
|
+
subject = Instana::Backend::RequestClient.new('example.com', 9292)
|
42
|
+
assert_nil subject.fileno
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_inode
|
46
|
+
subject = Instana::Backend::RequestClient.new('example.com', 9292)
|
47
|
+
subject.define_singleton_method(:fileno) { '0' } # This is the cleanest way to fake it so it works across all test environments
|
48
|
+
FakeFS.with_fresh do
|
49
|
+
FakeFS::FileSystem.clone('test/support/proc', '/proc')
|
50
|
+
Dir.mkdir('/proc/self/fd')
|
51
|
+
File.symlink('/proc/self/sched', '/proc/self/fd/0')
|
52
|
+
|
53
|
+
assert_equal '/proc/self/sched', subject.inode
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_inode_no_proc
|
58
|
+
subject = Instana::Backend::RequestClient.new('example.com', 9292)
|
59
|
+
assert_nil subject.inode
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class ServerlesAgentTest < Minitest::Test
|
7
|
+
def test_report
|
8
|
+
stub_request(:post, "http://10.10.10.10:9292//bundle")
|
9
|
+
.to_return(status: 500)
|
10
|
+
.to_return(status: 200)
|
11
|
+
|
12
|
+
host_name = Class.new do
|
13
|
+
def host_name
|
14
|
+
'hello'
|
15
|
+
end
|
16
|
+
end.new
|
17
|
+
|
18
|
+
snapshots = [Instana::Snapshot::RubyProcess.new, host_name]
|
19
|
+
subject = Instana::Backend::ServerlessAgent.new(snapshots, timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/', logger: Logger.new('/dev/null'))
|
20
|
+
|
21
|
+
subject.timer.block.call
|
22
|
+
subject.timer.block.call
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_ready
|
26
|
+
subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/')
|
27
|
+
assert subject.ready?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_extra_headers
|
31
|
+
subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/')
|
32
|
+
assert_equal [], subject.extra_headers
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_secret_values
|
36
|
+
subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/')
|
37
|
+
assert_equal({"matcher" => "contains-ignore-case", "list" => %w[key password secret]}, subject.secret_values)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_spawn_background_thread
|
41
|
+
subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/')
|
42
|
+
subject.spawn_background_thread
|
43
|
+
|
44
|
+
assert subject.timer.running
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_source
|
48
|
+
snapshot = Class.new do
|
49
|
+
def source
|
50
|
+
{test: 1}
|
51
|
+
end
|
52
|
+
end.new
|
53
|
+
subject = Instana::Backend::ServerlessAgent.new([snapshot], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/')
|
54
|
+
|
55
|
+
assert_equal({test: 1}, subject.source)
|
56
|
+
assert_equal({test: 1}, subject.source)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_missing_source
|
60
|
+
subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/', logger: Logger.new('/dev/null'))
|
61
|
+
|
62
|
+
assert_equal({}, subject.source)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_report_error
|
66
|
+
stub_request(:post, "http://10.10.10.10:9292//bundle")
|
67
|
+
.to_return(status: 500)
|
68
|
+
|
69
|
+
subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/', logger: Logger.new('/dev/null'))
|
70
|
+
|
71
|
+
subject.timer.block.call
|
72
|
+
end
|
73
|
+
end
|