instana 1.195.3 → 1.198.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/Rakefile +1 -1
- data/instana.gemspec +3 -7
- data/lib/instana.rb +3 -0
- data/lib/instana/activator.rb +2 -0
- data/lib/instana/backend/agent.rb +62 -0
- data/lib/instana/backend/gc_snapshot.rb +41 -0
- data/lib/instana/backend/host_agent.rb +74 -0
- data/lib/instana/backend/host_agent_activation_observer.rb +97 -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 +74 -0
- data/lib/instana/backend/serverless_agent.rb +113 -0
- data/lib/instana/base.rb +10 -27
- data/lib/instana/config.rb +8 -22
- data/lib/instana/instrumentation/excon.rb +17 -8
- data/lib/instana/instrumentation/instrumented_request.rb +62 -7
- data/lib/instana/instrumentation/net-http.rb +7 -5
- data/lib/instana/instrumentation/rack.rb +12 -7
- 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 +6 -2
- data/lib/instana/serverless.rb +133 -0
- data/lib/instana/setup.rb +23 -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/lambda_function.rb +39 -0
- data/lib/instana/snapshot/ruby_process.rb +48 -0
- data/lib/instana/tracer.rb +25 -143
- data/lib/instana/tracing/processor.rb +14 -22
- data/lib/instana/tracing/span.rb +33 -36
- data/lib/instana/tracing/span_context.rb +15 -10
- data/lib/instana/util.rb +8 -69
- data/lib/instana/version.rb +1 -1
- data/lib/opentracing.rb +26 -3
- data/test/backend/agent_test.rb +67 -0
- data/test/backend/gc_snapshot_test.rb +11 -0
- data/test/backend/host_agent_activation_observer_test.rb +72 -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 +47 -0
- data/test/backend/process_info_test.rb +63 -0
- data/test/backend/request_client_test.rb +39 -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/excon_test.rb +15 -1
- data/test/instrumentation/rack_instrumented_request_test.rb +5 -2
- data/test/instrumentation/rack_test.rb +2 -14
- data/test/secrets_test.rb +41 -22
- data/test/serverless_test.rb +323 -0
- 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/lambda_function_test.rb +37 -0
- data/test/snapshot/ruby_process_test.rb +14 -0
- data/test/support/mock_timer.rb +20 -0
- data/test/test_helper.rb +16 -4
- data/test/tracing/custom_test.rb +1 -3
- data/test/tracing/id_management_test.rb +8 -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 +136 -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 +78 -45
- 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,39 @@
|
|
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
|
+
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
|
data/test/config_test.rb
CHANGED
@@ -21,4 +21,14 @@ class ConfigTest < Minitest::Test
|
|
21
21
|
assert_equal true, ::Instana.config[:metrics][k].key?(:enabled)
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def test_custom_agent_host
|
26
|
+
subject = Instana::Config.new(logger: Logger.new('/dev/null'), agent_host: 'abc')
|
27
|
+
assert_equal 'abc', subject[:agent_host]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_custom_agent_port
|
31
|
+
subject = Instana::Config.new(logger: Logger.new('/dev/null'), agent_port: 'abc')
|
32
|
+
assert_equal 'abc', subject[:agent_port]
|
33
|
+
end
|
24
34
|
end
|
data/test/instana_test.rb
CHANGED
@@ -16,10 +16,6 @@ class InstanaTest < Minitest::Test
|
|
16
16
|
refute_nil ::Instana.agent
|
17
17
|
end
|
18
18
|
|
19
|
-
def test_that_it_has_a_collector
|
20
|
-
refute_nil ::Instana.collector
|
21
|
-
end
|
22
|
-
|
23
19
|
def test_that_it_has_a_tracer
|
24
20
|
refute_nil ::Instana.tracer
|
25
21
|
end
|
@@ -27,4 +23,15 @@ class InstanaTest < Minitest::Test
|
|
27
23
|
def test_that_it_has_a_config
|
28
24
|
refute_nil ::Instana.config
|
29
25
|
end
|
26
|
+
|
27
|
+
def test_assign_logger
|
28
|
+
mock = Minitest::Mock.new
|
29
|
+
mock.expect(:info, true, [String])
|
30
|
+
|
31
|
+
::Instana.logger = mock
|
32
|
+
::Instana.logger.info('test')
|
33
|
+
::Instana.logger = Logger.new('/dev/null')
|
34
|
+
|
35
|
+
mock.verify
|
36
|
+
end
|
30
37
|
end
|
@@ -22,7 +22,7 @@ class ExconTest < Minitest::Test
|
|
22
22
|
url = "http://127.0.0.1:6511"
|
23
23
|
|
24
24
|
connection = Excon.new(url)
|
25
|
-
Instana.tracer.start_or_continue_trace('excon-test') do
|
25
|
+
Instana.tracer.start_or_continue_trace(:'excon-test') do
|
26
26
|
connection.get(:path => '/?basic_get')
|
27
27
|
end
|
28
28
|
|
@@ -147,4 +147,18 @@ class ExconTest < Minitest::Test
|
|
147
147
|
assert_equal :sdk, grandparent_span[:n]
|
148
148
|
end
|
149
149
|
end
|
150
|
+
|
151
|
+
def test_basic_get_no_tracing
|
152
|
+
clear_all!
|
153
|
+
|
154
|
+
# A slight hack but webmock chokes with pipelined requests.
|
155
|
+
# Delete their excon middleware
|
156
|
+
Excon.defaults[:middlewares].delete ::WebMock::HttpLibAdapters::ExconAdapter
|
157
|
+
Excon.defaults[:middlewares].delete ::Excon::Middleware::Mock
|
158
|
+
|
159
|
+
url = "http://127.0.0.1:6511"
|
160
|
+
|
161
|
+
connection = Excon.new(url)
|
162
|
+
connection.get(:path => '/?basic_get')
|
163
|
+
end
|
150
164
|
end
|
@@ -29,6 +29,7 @@ class RackInstrumentedRequestTest < Minitest::Test
|
|
29
29
|
expected = {
|
30
30
|
trace_id: id,
|
31
31
|
span_id: id,
|
32
|
+
from_w3: false,
|
32
33
|
level: '1'
|
33
34
|
}
|
34
35
|
|
@@ -47,6 +48,7 @@ class RackInstrumentedRequestTest < Minitest::Test
|
|
47
48
|
external_state: nil,
|
48
49
|
trace_id: 'a3ce929d0e0e4736',
|
49
50
|
span_id: '00f067aa0ba902b7',
|
51
|
+
from_w3: true,
|
50
52
|
level: '1'
|
51
53
|
}
|
52
54
|
|
@@ -81,7 +83,8 @@ class RackInstrumentedRequestTest < Minitest::Test
|
|
81
83
|
end
|
82
84
|
|
83
85
|
def test_request_tags
|
84
|
-
::Instana.agent.extra_headers
|
86
|
+
::Instana.agent.define_singleton_method(:extra_headers) { %w[X-Capture-This] }
|
87
|
+
|
85
88
|
req = Instana::InstrumentedRequest.new(
|
86
89
|
'HTTP_HOST' => 'example.com',
|
87
90
|
'REQUEST_METHOD' => 'GET',
|
@@ -101,7 +104,7 @@ class RackInstrumentedRequestTest < Minitest::Test
|
|
101
104
|
}
|
102
105
|
|
103
106
|
assert_equal expected, req.request_tags
|
104
|
-
::Instana.agent.extra_headers
|
107
|
+
::Instana.agent.singleton_class.send(:remove_method, :extra_headers)
|
105
108
|
end
|
106
109
|
|
107
110
|
def test_correlation_data_valid
|
@@ -80,9 +80,6 @@ class RackTest < Minitest::Test
|
|
80
80
|
assert_equal 200, rack_span[:data][:http][:status]
|
81
81
|
assert_equal 'example.org', rack_span[:data][:http][:host]
|
82
82
|
assert rack_span.key?(:f)
|
83
|
-
assert rack_span[:f].key?(:e)
|
84
|
-
assert rack_span[:f].key?(:h)
|
85
|
-
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
86
83
|
assert !rack_span.key?(:stack)
|
87
84
|
|
88
85
|
# Restore to default
|
@@ -134,9 +131,6 @@ class RackTest < Minitest::Test
|
|
134
131
|
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
135
132
|
assert_equal 200, rack_span[:data][:http][:status]
|
136
133
|
assert rack_span.key?(:f)
|
137
|
-
assert rack_span[:f].key?(:e)
|
138
|
-
assert rack_span[:f].key?(:h)
|
139
|
-
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
140
134
|
end
|
141
135
|
|
142
136
|
def test_basic_put
|
@@ -166,9 +160,6 @@ class RackTest < Minitest::Test
|
|
166
160
|
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
167
161
|
assert_equal 200, rack_span[:data][:http][:status]
|
168
162
|
assert rack_span.key?(:f)
|
169
|
-
assert rack_span[:f].key?(:e)
|
170
|
-
assert rack_span[:f].key?(:h)
|
171
|
-
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
172
163
|
end
|
173
164
|
|
174
165
|
def test_context_continuation
|
@@ -202,9 +193,6 @@ class RackTest < Minitest::Test
|
|
202
193
|
assert_equal "/mrlobster", rack_span[:data][:http][:url]
|
203
194
|
assert_equal 200, rack_span[:data][:http][:status]
|
204
195
|
assert rack_span.key?(:f)
|
205
|
-
assert rack_span[:f].key?(:e)
|
206
|
-
assert rack_span[:f].key?(:h)
|
207
|
-
assert_equal ::Instana.agent.agent_uuid, rack_span[:f][:h]
|
208
196
|
|
209
197
|
# Context validation
|
210
198
|
# The first span should have the passed in trace ID
|
@@ -260,7 +248,7 @@ class RackTest < Minitest::Test
|
|
260
248
|
def test_custom_headers_capture
|
261
249
|
clear_all!
|
262
250
|
::Instana.config[:collect_backtraces] = true
|
263
|
-
::Instana.agent.extra_headers
|
251
|
+
::Instana.agent.define_singleton_method(:extra_headers) { %w(X-Capture-This X-Capture-That) }
|
264
252
|
|
265
253
|
get '/mrlobster', {}, { "HTTP_X_CAPTURE_THIS" => "ThereYouGo" }
|
266
254
|
assert last_response.ok?
|
@@ -280,7 +268,7 @@ class RackTest < Minitest::Test
|
|
280
268
|
|
281
269
|
# Restore to default
|
282
270
|
::Instana.config[:collect_backtraces] = false
|
283
|
-
::Instana.agent.extra_headers
|
271
|
+
::Instana.agent.singleton_class.send(:remove_method, :extra_headers)
|
284
272
|
end
|
285
273
|
|
286
274
|
def test_capture_http_path_template
|
data/test/secrets_test.rb
CHANGED
@@ -5,72 +5,91 @@ require 'test_helper'
|
|
5
5
|
|
6
6
|
class SecretsTest < Minitest::Test
|
7
7
|
def setup
|
8
|
-
@subject = Instana::Secrets.new
|
8
|
+
@subject = Instana::Secrets.new(logger: Logger.new('/dev/null'))
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def test_equals_ignore_case
|
12
12
|
sample_config = {
|
13
|
-
"matcher"=>"equals-ignore-case",
|
13
|
+
"matcher"=>"equals-ignore-case",
|
14
14
|
"list"=>["key"]
|
15
15
|
}
|
16
|
-
|
16
|
+
|
17
17
|
url = url_for(%w(key Str kEy KEY))
|
18
18
|
assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy KEY)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_equals
|
22
22
|
sample_config = {
|
23
|
-
"matcher"=>"equals",
|
23
|
+
"matcher"=>"equals",
|
24
24
|
"list"=>["key", "kEy"]
|
25
25
|
}
|
26
|
-
|
26
|
+
|
27
27
|
url = url_for(%w(key Str kEy KEY))
|
28
28
|
assert_redacted @subject.remove_from_query(url, sample_config), %w(key kEy)
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def test_contains_ignore_case
|
32
32
|
sample_config = {
|
33
|
-
"matcher"=>"contains-ignore-case",
|
33
|
+
"matcher"=>"contains-ignore-case",
|
34
34
|
"list"=>["stan"]
|
35
35
|
}
|
36
|
-
|
36
|
+
|
37
37
|
url = url_for(%w(instantiate conTESTant sample))
|
38
38
|
assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate conTESTant)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_contains
|
42
42
|
sample_config = {
|
43
|
-
"matcher"=>"contains",
|
43
|
+
"matcher"=>"contains",
|
44
44
|
"list"=>["stan"]
|
45
45
|
}
|
46
|
-
|
46
|
+
|
47
47
|
url = url_for(%w(instantiate conTESTant sample))
|
48
48
|
assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate)
|
49
|
-
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
def test_regexp
|
53
52
|
sample_config = {
|
54
|
-
"matcher"=>"regex",
|
53
|
+
"matcher"=>"regex",
|
55
54
|
"list"=>["l{2}"]
|
56
55
|
}
|
57
|
-
|
56
|
+
|
58
57
|
url = url_for(%w(ball foot move))
|
59
|
-
assert_redacted @subject.remove_from_query(url, sample_config), %w(ball)
|
58
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(ball)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_invalid
|
62
|
+
sample_config = {
|
63
|
+
"matcher"=>"test_invalid",
|
64
|
+
"list"=>["key"]
|
65
|
+
}
|
66
|
+
|
67
|
+
url = url_for(%w(key Str kEy KEY))
|
68
|
+
assert_redacted @subject.remove_from_query(url, sample_config), []
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_without_scheme
|
72
|
+
sample_config = {
|
73
|
+
"matcher"=>"contains",
|
74
|
+
"list"=>["stan"]
|
75
|
+
}
|
76
|
+
|
77
|
+
url = 'example.com?instantiate=true'
|
78
|
+
assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate)
|
60
79
|
end
|
61
|
-
|
80
|
+
|
62
81
|
private
|
63
|
-
|
82
|
+
|
64
83
|
def url_for(keys)
|
65
84
|
url = URI('http://example.com')
|
66
85
|
url.query = URI.encode_www_form(keys.map { |k| [k, rand(1..100)]})
|
67
86
|
url.to_s
|
68
87
|
end
|
69
|
-
|
88
|
+
|
70
89
|
def assert_redacted(str, keys)
|
71
90
|
url = URI(str)
|
72
91
|
params = CGI.parse(url.query)
|
73
|
-
|
92
|
+
|
74
93
|
assert_equal keys, params.select { |_, v| v == %w(<redacted>) }.keys, 'to be redacted'
|
75
94
|
end
|
76
95
|
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class ServerlessTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@mock_agent = Minitest::Mock.new
|
9
|
+
@mock_agent.expect(:send_bundle, true, [])
|
10
|
+
@subject = Instana::Serverless.new(agent: @mock_agent)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@mock_agent.verify
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_lambda_send_error
|
18
|
+
mock_logger = Minitest::Mock.new
|
19
|
+
mock_logger.expect(:error, true, [String])
|
20
|
+
|
21
|
+
@mock_agent.expect(:send_bundle, true) { |_args| raise StandardError, 'error' }
|
22
|
+
|
23
|
+
mock_context = OpenStruct.new(
|
24
|
+
invoked_function_arn: 'test_arn',
|
25
|
+
function_name: 'test_function',
|
26
|
+
function_version: '$TEST'
|
27
|
+
)
|
28
|
+
|
29
|
+
subject = Instana::Serverless.new(agent: @mock_agent, logger: mock_logger)
|
30
|
+
subject.wrap_aws(nil, mock_context) { 0 }
|
31
|
+
subject.wrap_aws(nil, mock_context) { 0 }
|
32
|
+
|
33
|
+
mock_logger.verify
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_lambda_data
|
37
|
+
clear_all!
|
38
|
+
|
39
|
+
mock_context = OpenStruct.new(
|
40
|
+
invoked_function_arn: 'test_arn',
|
41
|
+
function_name: 'test_function',
|
42
|
+
function_version: '$TEST'
|
43
|
+
)
|
44
|
+
|
45
|
+
@subject.wrap_aws(nil, mock_context) { 0 }
|
46
|
+
|
47
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
48
|
+
assert rest.empty?
|
49
|
+
|
50
|
+
data = lambda_span[:data][:lambda]
|
51
|
+
|
52
|
+
assert_equal 'aws:api.gateway.noproxy', lambda_span[:data][:lambda][:trigger]
|
53
|
+
|
54
|
+
assert_equal mock_context.invoked_function_arn, data[:arn]
|
55
|
+
assert_equal mock_context.function_name, data[:functionName]
|
56
|
+
assert_equal mock_context.function_version, data[:functionVersion]
|
57
|
+
assert_equal 'ruby', data[:runtime]
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_lambda_http
|
61
|
+
clear_all!
|
62
|
+
|
63
|
+
mock_id = Instana::Util.generate_id
|
64
|
+
mock_context = OpenStruct.new(
|
65
|
+
invoked_function_arn: 'test_arn',
|
66
|
+
function_name: 'test_function',
|
67
|
+
function_version: '$TEST'
|
68
|
+
)
|
69
|
+
mock_http = {
|
70
|
+
"headers" => {
|
71
|
+
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
72
|
+
"Accept-Encoding" => "gzip, deflate",
|
73
|
+
"Accept-Language" => "en-US,en;q=0.5",
|
74
|
+
"Connection" => "keep-alive",
|
75
|
+
"Host" => "127.0.0.1:3000",
|
76
|
+
"Upgrade-Insecure-Requests" => "1",
|
77
|
+
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:87.0) Gecko/20100101 Firefox/87.0",
|
78
|
+
"X-Forwarded-Port" => "3000",
|
79
|
+
"X-Forwarded-Proto" => "http",
|
80
|
+
'X-Instana-S' => mock_id,
|
81
|
+
'X-Instana-T' => mock_id,
|
82
|
+
'X-Instana-L' => '1'
|
83
|
+
},
|
84
|
+
"httpMethod" => "GET",
|
85
|
+
"path" => "/hello",
|
86
|
+
"queryStringParameters" => {"test" => "abcde"}
|
87
|
+
}
|
88
|
+
|
89
|
+
@subject.wrap_aws(mock_http, mock_context) { 0 }
|
90
|
+
|
91
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
92
|
+
assert rest.empty?
|
93
|
+
|
94
|
+
data = lambda_span[:data][:http]
|
95
|
+
|
96
|
+
assert_equal 'aws:api.gateway', lambda_span[:data][:lambda][:trigger]
|
97
|
+
assert_equal mock_id, lambda_span[:t]
|
98
|
+
assert_equal mock_id, lambda_span[:p]
|
99
|
+
|
100
|
+
assert_equal 'GET', data[:method]
|
101
|
+
assert_equal '/hello', data[:url]
|
102
|
+
assert_equal '127.0.0.1:3000', data[:host]
|
103
|
+
assert_equal 'test=abcde', data[:params]
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_lambda_alb
|
107
|
+
clear_all!
|
108
|
+
|
109
|
+
mock_id = Instana::Util.generate_id
|
110
|
+
mock_context = OpenStruct.new(
|
111
|
+
invoked_function_arn: 'test_arn',
|
112
|
+
function_name: 'test_function',
|
113
|
+
function_version: '$TEST'
|
114
|
+
)
|
115
|
+
mock_http = {
|
116
|
+
"headers" => {
|
117
|
+
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
118
|
+
"Accept-Encoding" => "gzip, deflate",
|
119
|
+
"Accept-Language" => "en-US,en;q=0.5",
|
120
|
+
"Connection" => "keep-alive",
|
121
|
+
"Host" => "127.0.0.1:3000",
|
122
|
+
"Upgrade-Insecure-Requests" => "1",
|
123
|
+
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:87.0) Gecko/20100101 Firefox/87.0",
|
124
|
+
"X-Forwarded-Port" => "3000",
|
125
|
+
"X-Forwarded-Proto" => "http",
|
126
|
+
'X-Instana-S' => mock_id,
|
127
|
+
'X-Instana-T' => mock_id,
|
128
|
+
'X-Instana-L' => '1'
|
129
|
+
},
|
130
|
+
"httpMethod" => "GET",
|
131
|
+
"path" => "/hello",
|
132
|
+
"requestContext" => { "elb" => {} }
|
133
|
+
}
|
134
|
+
|
135
|
+
@subject.wrap_aws(mock_http, mock_context) { 0 }
|
136
|
+
|
137
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
138
|
+
assert rest.empty?
|
139
|
+
|
140
|
+
data = lambda_span[:data][:http]
|
141
|
+
|
142
|
+
assert_equal 'aws:application.load.balancer', lambda_span[:data][:lambda][:trigger]
|
143
|
+
assert_equal mock_id, lambda_span[:t]
|
144
|
+
assert_equal mock_id, lambda_span[:p]
|
145
|
+
|
146
|
+
assert_equal 'GET', data[:method]
|
147
|
+
assert_equal '/hello', data[:url]
|
148
|
+
assert_equal '127.0.0.1:3000', data[:host]
|
149
|
+
assert_equal '', data[:params]
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_lambda_cw_event
|
153
|
+
clear_all!
|
154
|
+
|
155
|
+
mock_context = OpenStruct.new(
|
156
|
+
invoked_function_arn: 'test_arn',
|
157
|
+
function_name: 'test_function',
|
158
|
+
function_version: '$TEST'
|
159
|
+
)
|
160
|
+
mock_event = {
|
161
|
+
"detail-type" => "Scheduled Event",
|
162
|
+
"source" => "aws.events",
|
163
|
+
"id" => "test",
|
164
|
+
"resources" => ["test"]
|
165
|
+
}
|
166
|
+
|
167
|
+
@subject.wrap_aws(mock_event, mock_context) { 0 }
|
168
|
+
|
169
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
170
|
+
assert rest.empty?
|
171
|
+
|
172
|
+
data = lambda_span[:data][:lambda][:cw][:events]
|
173
|
+
|
174
|
+
assert_equal 'aws:cloudwatch.events', lambda_span[:data][:lambda][:trigger]
|
175
|
+
assert_equal 'test', data[:id]
|
176
|
+
assert_equal ["test"], data[:resources]
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_lambda_cw_logs
|
180
|
+
clear_all!
|
181
|
+
|
182
|
+
mock_context = OpenStruct.new(
|
183
|
+
invoked_function_arn: 'test_arn',
|
184
|
+
function_name: 'test_function',
|
185
|
+
function_version: '$TEST'
|
186
|
+
)
|
187
|
+
mock_event = {
|
188
|
+
"awslogs" => {"data" => File.read('test/support/serverless/cloudwatch_log.bin')}
|
189
|
+
}
|
190
|
+
|
191
|
+
@subject.wrap_aws(mock_event, mock_context) { 0 }
|
192
|
+
|
193
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
194
|
+
assert rest.empty?
|
195
|
+
|
196
|
+
data = lambda_span[:data][:lambda][:cw][:logs]
|
197
|
+
|
198
|
+
assert_equal 'aws:cloudwatch.logs', lambda_span[:data][:lambda][:trigger]
|
199
|
+
assert_equal '/aws/lambda/echo-nodejs', data[:group]
|
200
|
+
assert_equal '2019/03/13/[$LATEST]94fa867e5374431291a7fc14e2f56ae7', data[:stream]
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_lambda_cw_error
|
204
|
+
clear_all!
|
205
|
+
|
206
|
+
mock_context = OpenStruct.new(
|
207
|
+
invoked_function_arn: 'test_arn',
|
208
|
+
function_name: 'test_function',
|
209
|
+
function_version: '$TEST'
|
210
|
+
)
|
211
|
+
mock_event = {
|
212
|
+
"awslogs" => {"data" => "error"}
|
213
|
+
}
|
214
|
+
|
215
|
+
@subject.wrap_aws(mock_event, mock_context) { 0 }
|
216
|
+
|
217
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
218
|
+
assert rest.empty?
|
219
|
+
|
220
|
+
data = lambda_span[:data][:lambda][:cw][:logs]
|
221
|
+
|
222
|
+
assert_equal 'aws:cloudwatch.logs', lambda_span[:data][:lambda][:trigger]
|
223
|
+
assert_equal 'incorrect header check', data[:decodingError]
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_lambda_s3
|
227
|
+
clear_all!
|
228
|
+
|
229
|
+
mock_context = OpenStruct.new(
|
230
|
+
invoked_function_arn: 'test_arn',
|
231
|
+
function_name: 'test_function',
|
232
|
+
function_version: '$TEST'
|
233
|
+
)
|
234
|
+
mock_event = {
|
235
|
+
"Records" => [
|
236
|
+
{
|
237
|
+
"source" => "aws:s3",
|
238
|
+
"eventName" => "test",
|
239
|
+
"s3" => {
|
240
|
+
"bucket" => {"name" => "test_bucket"},
|
241
|
+
"object" => {"key" => "test_key"}
|
242
|
+
}
|
243
|
+
}
|
244
|
+
]
|
245
|
+
}
|
246
|
+
|
247
|
+
@subject.wrap_aws(mock_event, mock_context) { 0 }
|
248
|
+
|
249
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
250
|
+
assert rest.empty?
|
251
|
+
|
252
|
+
data = lambda_span[:data][:lambda][:s3]
|
253
|
+
|
254
|
+
assert_equal 'aws:s3', lambda_span[:data][:lambda][:trigger]
|
255
|
+
assert_equal 1, data[:events].length
|
256
|
+
|
257
|
+
assert_equal 'test', data[:events].first[:name]
|
258
|
+
assert_equal 'test_bucket', data[:events].first[:bucket]
|
259
|
+
assert_equal 'test_key', data[:events].first[:object]
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_lambda_s3_no_object
|
263
|
+
clear_all!
|
264
|
+
|
265
|
+
mock_context = OpenStruct.new(
|
266
|
+
invoked_function_arn: 'test_arn',
|
267
|
+
function_name: 'test_function',
|
268
|
+
function_version: '$TEST'
|
269
|
+
)
|
270
|
+
mock_event = {
|
271
|
+
"Records" => [
|
272
|
+
{
|
273
|
+
"source" => "aws:s3",
|
274
|
+
"eventName" => "test"
|
275
|
+
}
|
276
|
+
]
|
277
|
+
}
|
278
|
+
|
279
|
+
@subject.wrap_aws(mock_event, mock_context) { 0 }
|
280
|
+
|
281
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
282
|
+
assert rest.empty?
|
283
|
+
|
284
|
+
data = lambda_span[:data][:lambda][:s3]
|
285
|
+
|
286
|
+
assert_equal 'aws:s3', lambda_span[:data][:lambda][:trigger]
|
287
|
+
assert_equal 1, data[:events].length
|
288
|
+
|
289
|
+
assert_equal 'test', data[:events].first[:name]
|
290
|
+
assert_nil data[:events].first[:bucket]
|
291
|
+
assert_nil data[:events].first[:object]
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_lambda_sqs
|
295
|
+
clear_all!
|
296
|
+
|
297
|
+
mock_context = OpenStruct.new(
|
298
|
+
invoked_function_arn: 'test_arn',
|
299
|
+
function_name: 'test_function',
|
300
|
+
function_version: '$TEST'
|
301
|
+
)
|
302
|
+
mock_event = {
|
303
|
+
"Records" => [
|
304
|
+
{
|
305
|
+
"source" => "aws:sqs",
|
306
|
+
"eventSourceARN" => "test_arn"
|
307
|
+
}
|
308
|
+
]
|
309
|
+
}
|
310
|
+
|
311
|
+
@subject.wrap_aws(mock_event, mock_context) { 0 }
|
312
|
+
|
313
|
+
lambda_span, *rest = Instana.processor.queued_spans
|
314
|
+
assert rest.empty?
|
315
|
+
|
316
|
+
data = lambda_span[:data][:lambda][:sqs]
|
317
|
+
|
318
|
+
assert_equal 'aws:sqs', lambda_span[:data][:lambda][:trigger]
|
319
|
+
assert_equal 1, data[:messages].length
|
320
|
+
|
321
|
+
assert_equal 'test_arn', data[:messages].first[:queue]
|
322
|
+
end
|
323
|
+
end
|