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
@@ -16,23 +16,10 @@ module Instana
|
|
16
16
|
@batch_size = 3000
|
17
17
|
end
|
18
18
|
|
19
|
-
# Adds a Set of spans to the queue
|
20
|
-
#
|
21
|
-
# @param [spans] - the trace to be added to the queue
|
22
|
-
def add_spans(spans)
|
23
|
-
spans.each { |span| @queue.push(span)}
|
24
|
-
end
|
25
|
-
|
26
19
|
# Adds a span to the span queue
|
27
20
|
#
|
28
21
|
# @param [Trace] - the trace to be added to the queue
|
29
22
|
def add_span(span)
|
30
|
-
# Occasionally, do a checkup on our background thread.
|
31
|
-
if rand(10) > 8
|
32
|
-
if ::Instana.agent.collect_thread.nil? || !::Instana.agent.collect_thread.alive?
|
33
|
-
::Instana.agent.spawn_background_thread
|
34
|
-
end
|
35
|
-
end
|
36
23
|
@queue.push(span)
|
37
24
|
end
|
38
25
|
|
@@ -46,18 +33,14 @@ module Instana
|
|
46
33
|
# - Out of control/growing queue
|
47
34
|
# - Prevent another run of the timer while this is running
|
48
35
|
#
|
49
|
-
def send
|
36
|
+
def send(&block)
|
50
37
|
return if @queue.empty? || ENV.key?('INSTANA_TEST')
|
51
38
|
|
52
39
|
# Retrieve all spans for queued traces
|
53
40
|
spans = queued_spans
|
54
41
|
|
55
42
|
# Report spans in batches
|
56
|
-
|
57
|
-
while !batch.empty? do
|
58
|
-
::Instana.agent.report_spans(batch)
|
59
|
-
batch = spans.shift(@batch_size)
|
60
|
-
end
|
43
|
+
spans.each_slice(@batch_size, &block)
|
61
44
|
end
|
62
45
|
|
63
46
|
# Retrieves all of the traces in @queue and returns
|
@@ -75,10 +58,9 @@ module Instana
|
|
75
58
|
until @queue.empty? do
|
76
59
|
# Non-blocking pop; ignore exception
|
77
60
|
span = @queue.pop(true) rescue nil
|
78
|
-
if span
|
79
|
-
spans << span.raw
|
80
|
-
end
|
61
|
+
spans << span.raw if span.is_a?(Span) && span.context.level == 1
|
81
62
|
end
|
63
|
+
|
82
64
|
spans
|
83
65
|
end
|
84
66
|
|
data/lib/instana/tracing/span.rb
CHANGED
@@ -6,10 +6,10 @@ module Instana
|
|
6
6
|
REGISTERED_SPANS = [ :actioncontroller, :actionview, :activerecord, :excon,
|
7
7
|
:memcache, :'net-http', :rack, :render, :'rpc-client',
|
8
8
|
:'rpc-server', :'sidekiq-client', :'sidekiq-worker',
|
9
|
-
:redis, :'resque-client', :'resque-worker', :'graphql.server', :dynamodb ].freeze
|
10
|
-
ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker', :'graphql.server' ].freeze
|
9
|
+
:redis, :'resque-client', :'resque-worker', :'graphql.server', :dynamodb, :s3, :sns, :sqs ].freeze
|
10
|
+
ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker', :'graphql.server', :sqs ].freeze
|
11
11
|
EXIT_SPANS = [ :activerecord, :excon, :'net-http', :'resque-client',
|
12
|
-
:'rpc-client', :'sidekiq-client', :redis, :dynamodb ].freeze
|
12
|
+
:'rpc-client', :'sidekiq-client', :redis, :dynamodb, :s3, :sns, :sqs ].freeze
|
13
13
|
HTTP_SPANS = [ :rack, :excon, :'net-http' ].freeze
|
14
14
|
|
15
15
|
attr_accessor :parent
|
@@ -20,38 +20,34 @@ module Instana
|
|
20
20
|
def initialize(name, parent_ctx: nil, start_time: ::Instana::Util.now_in_ms)
|
21
21
|
@data = {}
|
22
22
|
|
23
|
-
if parent_ctx
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if parent_ctx.is_a?(::Instana::Span)
|
31
|
-
@parent = parent_ctx
|
32
|
-
parent_context = parent_ctx.context
|
33
|
-
elsif parent_ctx.is_a?(::Instana::SpanContext)
|
34
|
-
parent_context = parent_ctx
|
35
|
-
end
|
23
|
+
if parent_ctx.is_a?(::Instana::Span)
|
24
|
+
@parent = parent_ctx
|
25
|
+
parent_ctx = parent_ctx.context
|
26
|
+
end
|
27
|
+
|
28
|
+
if parent_ctx.is_a?(::Instana::SpanContext)
|
29
|
+
@is_root = false
|
36
30
|
|
37
|
-
@data[:t] =
|
31
|
+
@data[:t] = parent_ctx.trace_id # Trace ID
|
38
32
|
@data[:s] = ::Instana::Util.generate_id # Span ID
|
39
|
-
@data[:p] =
|
33
|
+
@data[:p] = parent_ctx.span_id # Parent ID
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
@baggage = parent_ctx.baggage.dup
|
36
|
+
@level = parent_ctx.level
|
37
|
+
else
|
38
|
+
# No parent specified so we're starting a new Trace - this will be the root span
|
39
|
+
@is_root = true
|
40
|
+
@level = 1
|
46
41
|
|
47
|
-
|
42
|
+
id = ::Instana::Util.generate_id
|
43
|
+
@data[:t] = id # Trace ID
|
44
|
+
@data[:s] = id # Span ID
|
48
45
|
end
|
49
46
|
|
50
47
|
@data[:data] = {}
|
51
48
|
|
52
49
|
# Entity Source
|
53
|
-
@data[:f] =
|
54
|
-
:h => ::Instana.agent.agent_uuid }
|
50
|
+
@data[:f] = ::Instana.agent.source
|
55
51
|
# Start time
|
56
52
|
if start_time.is_a?(Time)
|
57
53
|
@data[:ts] = ::Instana::Util.time_to_ms(start_time)
|
@@ -59,17 +55,15 @@ module Instana
|
|
59
55
|
@data[:ts] = start_time
|
60
56
|
end
|
61
57
|
|
62
|
-
if ::Instana.config[:collect_backtraces]
|
63
|
-
# Attach a backtrace to all exit spans
|
64
|
-
add_stack if EXIT_SPANS.include?(name)
|
65
|
-
end
|
66
|
-
|
67
58
|
# Check for custom tracing
|
68
59
|
if REGISTERED_SPANS.include?(name.to_sym)
|
69
60
|
@data[:n] = name.to_sym
|
70
61
|
else
|
71
62
|
configure_custom(name)
|
72
63
|
end
|
64
|
+
|
65
|
+
# Attach a backtrace to all exit spans
|
66
|
+
add_stack if ::Instana.config[:collect_backtraces] && exit_span?
|
73
67
|
end
|
74
68
|
|
75
69
|
# Adds a backtrace to this span
|
@@ -195,7 +189,7 @@ module Instana
|
|
195
189
|
# @return [Instana::SpanContext]
|
196
190
|
#
|
197
191
|
def context
|
198
|
-
@context ||= ::Instana::SpanContext.new(@data[:t], @data[:s],
|
192
|
+
@context ||= ::Instana::SpanContext.new(@data[:t], @data[:s], @level, @baggage)
|
199
193
|
end
|
200
194
|
|
201
195
|
# Retrieve the ID for this span
|
@@ -344,9 +338,7 @@ module Instana
|
|
344
338
|
end
|
345
339
|
end
|
346
340
|
else
|
347
|
-
if
|
348
|
-
@data[:data][key] = value
|
349
|
-
elsif value.is_a?(Hash) && self[:data][key].is_a?(Hash)
|
341
|
+
if value.is_a?(Hash) && @data[:data][key].is_a?(Hash)
|
350
342
|
@data[:data][key].merge!(value)
|
351
343
|
else
|
352
344
|
@data[:data][key] = value
|
@@ -381,7 +373,7 @@ module Instana
|
|
381
373
|
if @context
|
382
374
|
@context.baggage = @baggage
|
383
375
|
else
|
384
|
-
@context ||= ::Instana::SpanContext.new(@data[:t], @data[:s],
|
376
|
+
@context ||= ::Instana::SpanContext.new(@data[:t], @data[:s], @level, @baggage)
|
385
377
|
end
|
386
378
|
self
|
387
379
|
end
|
@@ -393,7 +385,6 @@ module Instana
|
|
393
385
|
# @return Value of the baggage item
|
394
386
|
#
|
395
387
|
def get_baggage_item(key)
|
396
|
-
return nil if @baggage.nil?
|
397
388
|
@baggage[key]
|
398
389
|
end
|
399
390
|
|
@@ -403,7 +394,7 @@ module Instana
|
|
403
394
|
if custom?
|
404
395
|
tags = @data[:data][:sdk][:custom][:tags]
|
405
396
|
else
|
406
|
-
tags = @data[:data]
|
397
|
+
tags = @data[:data]
|
407
398
|
end
|
408
399
|
key ? tags[key] : tags
|
409
400
|
end
|
@@ -6,6 +6,7 @@ module Instana
|
|
6
6
|
attr_accessor :trace_id
|
7
7
|
attr_accessor :span_id
|
8
8
|
attr_accessor :baggage
|
9
|
+
attr_reader :level
|
9
10
|
|
10
11
|
# Create a new SpanContext
|
11
12
|
#
|
@@ -17,7 +18,7 @@ module Instana
|
|
17
18
|
def initialize(tid, sid, level = 1, baggage = {})
|
18
19
|
@trace_id = tid
|
19
20
|
@span_id = sid
|
20
|
-
@level = level
|
21
|
+
@level = Integer(level || 1)
|
21
22
|
@baggage = baggage || {}
|
22
23
|
end
|
23
24
|
|
@@ -42,7 +43,7 @@ module Instana
|
|
42
43
|
def trace_state_header
|
43
44
|
return '' unless valid?
|
44
45
|
|
45
|
-
state = ["in=#{
|
46
|
+
state = ["in=#{trace_id_header};#{span_id_header}", @baggage[:external_state]]
|
46
47
|
state.compact.join(',')
|
47
48
|
end
|
48
49
|
|
data/lib/instana/util.rb
CHANGED
@@ -5,30 +5,6 @@ module Instana
|
|
5
5
|
module Util
|
6
6
|
class << self
|
7
7
|
ID_RANGE = -2**63..2**63-1
|
8
|
-
# Debugging helper method
|
9
|
-
#
|
10
|
-
def pry!
|
11
|
-
# Only valid for development or test environments
|
12
|
-
#env = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
13
|
-
#return unless %w(development, test).include? env
|
14
|
-
require 'pry-byebug'
|
15
|
-
|
16
|
-
if defined?(PryByebug)
|
17
|
-
Pry.commands.alias_command 'c', 'continue'
|
18
|
-
Pry.commands.alias_command 's', 'step'
|
19
|
-
Pry.commands.alias_command 'n', 'next'
|
20
|
-
Pry.commands.alias_command 'f', 'finish'
|
21
|
-
|
22
|
-
Pry::Commands.command(/^$/, 'repeat last command') do
|
23
|
-
_pry_.run_command Pry.history.to_a.last
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
binding.pry
|
28
|
-
rescue LoadError
|
29
|
-
::Instana.logger.warn("No debugger in bundle. Couldn't load pry-byebug.")
|
30
|
-
end
|
31
|
-
|
32
8
|
# Retrieves and returns the source code for any ruby
|
33
9
|
# files requested by the UI via the host agent
|
34
10
|
#
|
@@ -47,6 +23,7 @@ module Instana
|
|
47
23
|
# Method to collect up process info for snapshots. This
|
48
24
|
# is generally used once per process.
|
49
25
|
#
|
26
|
+
# :nocov:
|
50
27
|
def take_snapshot
|
51
28
|
data = {}
|
52
29
|
|
@@ -86,53 +63,12 @@ module Instana
|
|
86
63
|
::Instana.logger.debug { e.backtrace.join("\r\n") }
|
87
64
|
return data
|
88
65
|
end
|
89
|
-
|
90
|
-
# Used in class initialization and after a fork, this method
|
91
|
-
# collects up process information
|
92
|
-
#
|
93
|
-
def collect_process_info
|
94
|
-
process = {}
|
95
|
-
cmdline_file = "/proc/#{Process.pid}/cmdline"
|
96
|
-
|
97
|
-
# If there is a /proc filesystem, we read this manually so
|
98
|
-
# we can split on embedded null bytes. Otherwise (e.g. OSX, Windows)
|
99
|
-
# use ProcTable.
|
100
|
-
if File.exist?(cmdline_file)
|
101
|
-
cmdline = IO.read(cmdline_file).split(?\x00)
|
102
|
-
else
|
103
|
-
# Attempt to support older versions of sys-proctable and ffi.
|
104
|
-
#
|
105
|
-
# Alternatively we could use Sys::ProcTable::VERSION here but the
|
106
|
-
# consistency across historical versions is unknown. Alternative
|
107
|
-
# to the alternative, would be Ruby metaprogramming using the `arity`
|
108
|
-
# and `parameters` methods.
|
109
|
-
# e.g ProcTable.method(:ps).arity/parameters
|
110
|
-
if Gem.loaded_specs.key?("sys-proctable") &&
|
111
|
-
(Gem.loaded_specs["sys-proctable"].version >= Gem::Version.new("1.2.0"))
|
112
|
-
cmdline = ProcTable.ps(:pid => Process.pid).cmdline.split(' ')
|
113
|
-
else
|
114
|
-
cmdline = ProcTable.ps(Process.pid).cmdline.split(' ')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
if RUBY_PLATFORM =~ /darwin/i
|
119
|
-
cmdline.delete_if{ |e| e.include?('=') }
|
120
|
-
process[:name] = cmdline.join(' ')
|
121
|
-
else
|
122
|
-
process[:name] = cmdline.shift
|
123
|
-
process[:arguments] = cmdline
|
124
|
-
end
|
125
|
-
|
126
|
-
process[:pid] = Process.pid
|
127
|
-
# This is usually Process.pid but in the case of containers, the host agent
|
128
|
-
# will return to us the true host pid in which we use to report data.
|
129
|
-
process[:report_pid] = nil
|
130
|
-
process
|
131
|
-
end
|
66
|
+
# :nocov:
|
132
67
|
|
133
68
|
# Best effort to determine a name for the instrumented application
|
134
69
|
# on the dashboard.
|
135
70
|
#
|
71
|
+
# :nocov:
|
136
72
|
def get_app_name
|
137
73
|
if ENV.key?('INSTANA_SERVICE_NAME')
|
138
74
|
return ENV['INSTANA_SERVICE_NAME']
|
@@ -169,6 +105,7 @@ module Instana
|
|
169
105
|
Instana.logger.debug { e.backtrace.join("\r\n") }
|
170
106
|
return "Ruby"
|
171
107
|
end
|
108
|
+
# :nocov:
|
172
109
|
|
173
110
|
# Get the current time in milliseconds from the epoch
|
174
111
|
#
|
data/lib/instana/version.rb
CHANGED
data/lib/opentracing.rb
CHANGED
@@ -1,9 +1,32 @@
|
|
1
1
|
# (c) Copyright IBM Corp. 2021
|
2
2
|
# (c) Copyright Instana Inc. 2017
|
3
3
|
|
4
|
-
require "instana/
|
5
|
-
require "instana/
|
4
|
+
require "instana/open_tracing/carrier"
|
5
|
+
require "instana/open_tracing/instana_tracer"
|
6
|
+
|
7
|
+
module OpenTracing
|
8
|
+
class << self
|
9
|
+
# Text format for #inject and #extract
|
10
|
+
FORMAT_TEXT_MAP = 1
|
11
|
+
|
12
|
+
# Binary format for #inject and #extract
|
13
|
+
FORMAT_BINARY = 2
|
14
|
+
|
15
|
+
# Ruby Specific format to handle how Rack changes environment variables.
|
16
|
+
FORMAT_RACK = 3
|
17
|
+
|
18
|
+
attr_accessor :global_tracer
|
19
|
+
|
20
|
+
def method_missing(method_name, *args, &block)
|
21
|
+
@global_tracer.send(method_name, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def respond_to_missing?(name, all)
|
25
|
+
@global_tracer.respond_to?(name, all)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
6
29
|
|
7
30
|
# Set the global tracer to our OT tracer
|
8
31
|
# which supports the OT specification
|
9
|
-
OpenTracing.global_tracer = ::Instana.tracer
|
32
|
+
OpenTracing.global_tracer = OpenTracing::InstanaTracer.new(::Instana.tracer)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class AgentTest < Minitest::Test
|
7
|
+
def test_host
|
8
|
+
subject = Instana::Backend::Agent.new
|
9
|
+
assert_nil subject.delegate
|
10
|
+
subject.setup
|
11
|
+
assert subject.delegate.is_a?(Instana::Backend::HostAgent)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_fargate
|
15
|
+
ENV['ECS_CONTAINER_METADATA_URI'] = 'https://10.10.10.10:9292/v3'
|
16
|
+
ENV['INSTANA_ENDPOINT_URL'] = 'http://example.com'
|
17
|
+
|
18
|
+
stub_request(:get, 'https://10.10.10.10:9292/v3/task')
|
19
|
+
.to_return(status: 200, body: File.read('test/support/ecs/task.json'))
|
20
|
+
|
21
|
+
subject = Instana::Backend::Agent.new(fargate_metadata_uri: 'https://10.10.10.10:9292/v3')
|
22
|
+
assert_nil subject.delegate
|
23
|
+
subject.setup
|
24
|
+
assert subject.delegate.is_a?(Instana::Backend::ServerlessAgent)
|
25
|
+
ensure
|
26
|
+
ENV['INSTANA_ENDPOINT_URL'] = nil
|
27
|
+
ENV['ECS_CONTAINER_METADATA_URI'] = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_fargate_error
|
31
|
+
ENV['ECS_CONTAINER_METADATA_URI'] = 'https://10.10.10.10:9292/v3'
|
32
|
+
ENV['INSTANA_ENDPOINT_URL'] = 'http://example.com'
|
33
|
+
|
34
|
+
stub_request(:get, 'https://10.10.10.10:9292/v3/task')
|
35
|
+
.to_return(status: 500)
|
36
|
+
|
37
|
+
subject = Instana::Backend::Agent.new(logger: Logger.new('/dev/null'))
|
38
|
+
assert_nil subject.delegate
|
39
|
+
subject.setup
|
40
|
+
assert subject.delegate.is_a?(Instana::Backend::ServerlessAgent)
|
41
|
+
ensure
|
42
|
+
ENV['INSTANA_ENDPOINT_URL'] = nil
|
43
|
+
ENV['ECS_CONTAINER_METADATA_URI'] = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_delegate_super
|
47
|
+
subject = Instana::Backend::Agent.new
|
48
|
+
assert_raises NoMethodError do
|
49
|
+
subject.invalid
|
50
|
+
end
|
51
|
+
|
52
|
+
refute subject.respond_to?(:invalid)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# (c) Copyright IBM Corp. 2021
|
2
|
+
# (c) Copyright Instana Inc. 2021
|
3
|
+
|
4
|
+
require 'test_helper'
|
5
|
+
|
6
|
+
class HostAgentActivationObserverTest < Minitest::Test
|
7
|
+
def test_standard_discovery
|
8
|
+
stub_request(:put, "http://10.10.10.10:9292/com.instana.plugin.ruby.discovery")
|
9
|
+
.and_timeout
|
10
|
+
.and_return(status: 500, body: '{"ok": false}')
|
11
|
+
.and_return(status: 200, body: '{"pid": 1234}')
|
12
|
+
|
13
|
+
stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
|
14
|
+
.and_return(status: 500, body: '{"ok": false}')
|
15
|
+
.and_return(status: 200, body: '{"ok": true}')
|
16
|
+
|
17
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
18
|
+
discovery = Concurrent::Atom.new(nil)
|
19
|
+
|
20
|
+
subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), max_wait_tries: 1)
|
21
|
+
|
22
|
+
subject.update(nil, nil, nil)
|
23
|
+
assert_equal({'pid' => 1234}, discovery.value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_linux_discovery
|
27
|
+
stub_request(:put, "http://10.10.10.10:9292/com.instana.plugin.ruby.discovery")
|
28
|
+
.and_return(status: 200, body: '{"pid": 1234}')
|
29
|
+
|
30
|
+
stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
|
31
|
+
.and_return(status: 200, body: '{"ok": true}')
|
32
|
+
|
33
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
34
|
+
# This is the cleanest way to fake it so it works across all test environments
|
35
|
+
client.define_singleton_method(:fileno) { '0' }
|
36
|
+
client.define_singleton_method(:inode) { '0' }
|
37
|
+
|
38
|
+
discovery = Concurrent::Atom.new(nil)
|
39
|
+
|
40
|
+
subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), max_wait_tries: 1)
|
41
|
+
|
42
|
+
subject.update(nil, nil, nil)
|
43
|
+
|
44
|
+
assert_equal({'pid' => 1234}, discovery.value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_discovery_standard_error
|
48
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
49
|
+
discovery = Concurrent::Atom.new(nil)
|
50
|
+
|
51
|
+
subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), proc_table: nil)
|
52
|
+
|
53
|
+
subject.update(nil, nil, nil)
|
54
|
+
assert_nil discovery.value
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_value_present
|
58
|
+
client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
|
59
|
+
discovery = Concurrent::Atom.new(nil)
|
60
|
+
|
61
|
+
subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery)
|
62
|
+
assert_nil subject.update(nil, nil, true)
|
63
|
+
assert_nil discovery.value
|
64
|
+
end
|
65
|
+
end
|