instana 1.195.4 → 1.198.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -2
  3. data/Rakefile +1 -1
  4. data/instana.gemspec +3 -7
  5. data/lib/instana.rb +3 -0
  6. data/lib/instana/activator.rb +2 -0
  7. data/lib/instana/backend/agent.rb +62 -0
  8. data/lib/instana/backend/gc_snapshot.rb +41 -0
  9. data/lib/instana/backend/host_agent.rb +74 -0
  10. data/lib/instana/backend/host_agent_activation_observer.rb +97 -0
  11. data/lib/instana/backend/host_agent_lookup.rb +57 -0
  12. data/lib/instana/backend/host_agent_reporting_observer.rb +106 -0
  13. data/lib/instana/backend/process_info.rb +64 -0
  14. data/lib/instana/backend/request_client.rb +74 -0
  15. data/lib/instana/backend/serverless_agent.rb +113 -0
  16. data/lib/instana/base.rb +10 -27
  17. data/lib/instana/config.rb +8 -22
  18. data/lib/instana/instrumentation/excon.rb +7 -5
  19. data/lib/instana/instrumentation/instrumented_request.rb +62 -7
  20. data/lib/instana/instrumentation/net-http.rb +7 -5
  21. data/lib/instana/instrumentation/rack.rb +12 -7
  22. data/lib/instana/logger_delegator.rb +31 -0
  23. data/lib/instana/{opentracing → open_tracing}/carrier.rb +0 -0
  24. data/lib/instana/open_tracing/instana_tracer.rb +99 -0
  25. data/lib/instana/secrets.rb +6 -2
  26. data/lib/instana/serverless.rb +139 -0
  27. data/lib/instana/setup.rb +23 -11
  28. data/lib/instana/snapshot/deltable.rb +25 -0
  29. data/lib/instana/snapshot/docker_container.rb +151 -0
  30. data/lib/instana/snapshot/fargate_container.rb +88 -0
  31. data/lib/instana/snapshot/fargate_process.rb +67 -0
  32. data/lib/instana/snapshot/fargate_task.rb +72 -0
  33. data/lib/instana/snapshot/lambda_function.rb +39 -0
  34. data/lib/instana/snapshot/ruby_process.rb +48 -0
  35. data/lib/instana/tracer.rb +25 -143
  36. data/lib/instana/tracing/processor.rb +14 -22
  37. data/lib/instana/tracing/span.rb +33 -36
  38. data/lib/instana/tracing/span_context.rb +15 -10
  39. data/lib/instana/util.rb +8 -69
  40. data/lib/instana/version.rb +1 -1
  41. data/lib/opentracing.rb +26 -3
  42. data/test/backend/agent_test.rb +67 -0
  43. data/test/backend/gc_snapshot_test.rb +11 -0
  44. data/test/backend/host_agent_activation_observer_test.rb +72 -0
  45. data/test/backend/host_agent_lookup_test.rb +78 -0
  46. data/test/backend/host_agent_reporting_observer_test.rb +192 -0
  47. data/test/backend/host_agent_test.rb +47 -0
  48. data/test/backend/process_info_test.rb +63 -0
  49. data/test/backend/request_client_test.rb +39 -0
  50. data/test/backend/serverless_agent_test.rb +73 -0
  51. data/test/config_test.rb +10 -0
  52. data/test/instana_test.rb +11 -4
  53. data/test/instrumentation/rack_instrumented_request_test.rb +5 -2
  54. data/test/instrumentation/rack_test.rb +2 -14
  55. data/test/secrets_test.rb +41 -22
  56. data/test/serverless_test.rb +323 -0
  57. data/test/snapshot/deltable_test.rb +17 -0
  58. data/test/snapshot/docker_container_test.rb +82 -0
  59. data/test/snapshot/fargate_container_test.rb +82 -0
  60. data/test/snapshot/fargate_process_test.rb +35 -0
  61. data/test/snapshot/fargate_task_test.rb +49 -0
  62. data/test/snapshot/lambda_function_test.rb +37 -0
  63. data/test/snapshot/ruby_process_test.rb +14 -0
  64. data/test/support/mock_timer.rb +20 -0
  65. data/test/test_helper.rb +16 -4
  66. data/test/tracing/custom_test.rb +1 -3
  67. data/test/tracing/id_management_test.rb +8 -0
  68. data/test/tracing/opentracing_test.rb +15 -2
  69. data/test/tracing/processor_test.rb +58 -0
  70. data/test/tracing/span_context_test.rb +22 -0
  71. data/test/tracing/span_test.rb +136 -0
  72. data/test/tracing/tracer_async_test.rb +29 -0
  73. data/test/tracing/tracer_test.rb +82 -16
  74. data/test/util_test.rb +10 -0
  75. metadata +76 -43
  76. data/lib/instana/agent.rb +0 -508
  77. data/lib/instana/agent/helpers.rb +0 -87
  78. data/lib/instana/agent/hooks.rb +0 -44
  79. data/lib/instana/agent/tasks.rb +0 -51
  80. data/lib/instana/collector.rb +0 -119
  81. data/lib/instana/collectors/gc.rb +0 -60
  82. data/lib/instana/collectors/memory.rb +0 -37
  83. data/lib/instana/collectors/thread.rb +0 -33
  84. data/lib/instana/eum/eum-test.js.erb +0 -17
  85. data/lib/instana/eum/eum.js.erb +0 -17
  86. data/lib/instana/helpers.rb +0 -47
  87. data/lib/instana/opentracing/tracer.rb +0 -21
  88. data/lib/instana/thread_local.rb +0 -18
  89. data/lib/oj_check.rb +0 -19
  90. data/test/agent/agent_test.rb +0 -151
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
  #
@@ -219,8 +156,10 @@ module Instana
219
156
  #
220
157
  # @return [String]
221
158
  #
222
- def header_to_id(header_id)
223
- header_id.is_a?(String) && header_id.match(/\A[a-z\d]{16,32}\z/i) ? header_id : ''
159
+ def header_to_id(given)
160
+ return '' unless given.is_a?(String)
161
+ return '' unless given.match(/\A[a-z\d]{16,32}\z/i)
162
+ given
224
163
  end
225
164
  end
226
165
  end
@@ -2,6 +2,6 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- VERSION = "1.195.4"
5
+ VERSION = "1.198.0"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
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/opentracing/tracer"
5
- require "instana/opentracing/carrier"
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,67 @@
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_lambda
47
+ ENV['_HANDLER'] = 'TEST_FUNCTION'
48
+ ENV['INSTANA_ENDPOINT_URL'] = 'http://example.com'
49
+
50
+ subject = Instana::Backend::Agent.new
51
+ assert_nil subject.delegate
52
+ subject.setup
53
+ assert subject.delegate.is_a?(Instana::Backend::ServerlessAgent)
54
+ ensure
55
+ ENV['_HANDLER'] = nil
56
+ ENV['INSTANA_ENDPOINT_URL'] = nil
57
+ end
58
+
59
+ def test_delegate_super
60
+ subject = Instana::Backend::Agent.new
61
+ assert_raises NoMethodError do
62
+ subject.invalid
63
+ end
64
+
65
+ refute subject.respond_to?(:invalid)
66
+ end
67
+ end
@@ -0,0 +1,11 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ require 'test_helper'
5
+
6
+ class GcSnapshotTest < Minitest::Test
7
+ def test_report
8
+ subject = Instana::Backend::GCSnapshot.instance
9
+ assert subject.report.is_a?(Hash)
10
+ end
11
+ end
@@ -0,0 +1,72 @@
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 setup
8
+ @socket_proc = ->(_c) { OpenStruct.new(fileno: 0) }
9
+ end
10
+
11
+ def test_standard_discovery
12
+ stub_request(:put, "http://10.10.10.10:9292/com.instana.plugin.ruby.discovery")
13
+ .and_timeout
14
+ .and_return(status: 500, body: '{"ok": false}')
15
+ .and_return(status: 200, body: '{"pid": 1234}')
16
+
17
+ stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
18
+ .and_return(status: 500, body: '{"ok": false}')
19
+ .and_return(status: 200, body: '{"ok": true}')
20
+
21
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
22
+ discovery = Concurrent::Atom.new(nil)
23
+
24
+ subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), max_wait_tries: 1, socket_proc: @socket_proc)
25
+
26
+ subject.update(nil, nil, nil)
27
+ assert_equal({'pid' => 1234}, discovery.value)
28
+ end
29
+
30
+ def test_linux_discovery
31
+ stub_request(:put, "http://10.10.10.10:9292/com.instana.plugin.ruby.discovery")
32
+ .and_return(status: 200, body: '{"pid": 1234}')
33
+
34
+ stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
35
+ .and_return(status: 200, body: '{"ok": true}')
36
+
37
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
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, socket_proc: @socket_proc)
41
+
42
+ FakeFS.with_fresh do
43
+ FakeFS::FileSystem.clone('test/support/proc', '/proc')
44
+ FakeFS::FileSystem.clone('test/support/proc/0', "/proc/#{Process.pid}")
45
+ Dir.mkdir('/proc/self/fd')
46
+ File.symlink('/proc/self/sched', "/proc/self/fd/0")
47
+
48
+ subject.update(nil, nil, nil)
49
+ end
50
+
51
+ assert_equal({'pid' => 1234}, discovery.value)
52
+ end
53
+
54
+ def test_discovery_standard_error
55
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
56
+ discovery = Concurrent::Atom.new(nil)
57
+
58
+ subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), proc_table: nil, socket_proc: @socket_proc)
59
+
60
+ subject.update(nil, nil, nil)
61
+ assert_nil discovery.value
62
+ end
63
+
64
+ def test_value_present
65
+ client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
66
+ discovery = Concurrent::Atom.new(nil)
67
+
68
+ subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, socket_proc: @socket_proc)
69
+ assert_nil subject.update(nil, nil, true)
70
+ assert_nil discovery.value
71
+ end
72
+ end
@@ -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