instana 1.195.4 → 1.197.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) 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 +60 -0
  8. data/lib/instana/backend/gc_snapshot.rb +41 -0
  9. data/lib/instana/backend/host_agent.rb +57 -0
  10. data/lib/instana/backend/host_agent_activation_observer.rb +87 -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 +84 -0
  15. data/lib/instana/backend/serverless_agent.rb +118 -0
  16. data/lib/instana/base.rb +8 -27
  17. data/lib/instana/config.rb +7 -21
  18. data/lib/instana/logger_delegator.rb +31 -0
  19. data/lib/instana/{opentracing → open_tracing}/carrier.rb +0 -0
  20. data/lib/instana/open_tracing/instana_tracer.rb +99 -0
  21. data/lib/instana/secrets.rb +6 -2
  22. data/lib/instana/setup.rb +20 -11
  23. data/lib/instana/snapshot/deltable.rb +25 -0
  24. data/lib/instana/snapshot/docker_container.rb +151 -0
  25. data/lib/instana/snapshot/fargate_container.rb +88 -0
  26. data/lib/instana/snapshot/fargate_process.rb +67 -0
  27. data/lib/instana/snapshot/fargate_task.rb +72 -0
  28. data/lib/instana/snapshot/ruby_process.rb +48 -0
  29. data/lib/instana/tracer.rb +25 -143
  30. data/lib/instana/tracing/processor.rb +4 -22
  31. data/lib/instana/tracing/span.rb +26 -35
  32. data/lib/instana/tracing/span_context.rb +1 -1
  33. data/lib/instana/util.rb +4 -67
  34. data/lib/instana/version.rb +1 -1
  35. data/lib/opentracing.rb +26 -3
  36. data/test/backend/agent_test.rb +54 -0
  37. data/test/backend/gc_snapshot_test.rb +11 -0
  38. data/test/backend/host_agent_activation_observer_test.rb +65 -0
  39. data/test/backend/host_agent_lookup_test.rb +78 -0
  40. data/test/backend/host_agent_reporting_observer_test.rb +192 -0
  41. data/test/backend/host_agent_test.rb +32 -0
  42. data/test/backend/process_info_test.rb +63 -0
  43. data/test/backend/request_client_test.rb +61 -0
  44. data/test/backend/serverless_agent_test.rb +73 -0
  45. data/test/config_test.rb +10 -0
  46. data/test/instana_test.rb +11 -4
  47. data/test/instrumentation/rack_instrumented_request_test.rb +3 -2
  48. data/test/instrumentation/rack_test.rb +2 -14
  49. data/test/secrets_test.rb +41 -22
  50. data/test/snapshot/deltable_test.rb +17 -0
  51. data/test/snapshot/docker_container_test.rb +82 -0
  52. data/test/snapshot/fargate_container_test.rb +82 -0
  53. data/test/snapshot/fargate_process_test.rb +35 -0
  54. data/test/snapshot/fargate_task_test.rb +49 -0
  55. data/test/snapshot/ruby_process_test.rb +14 -0
  56. data/test/support/mock_timer.rb +20 -0
  57. data/test/test_helper.rb +15 -3
  58. data/test/tracing/custom_test.rb +1 -3
  59. data/test/tracing/id_management_test.rb +4 -0
  60. data/test/tracing/opentracing_test.rb +15 -2
  61. data/test/tracing/processor_test.rb +58 -0
  62. data/test/tracing/span_context_test.rb +22 -0
  63. data/test/tracing/span_test.rb +127 -0
  64. data/test/tracing/tracer_async_test.rb +29 -0
  65. data/test/tracing/tracer_test.rb +82 -16
  66. data/test/util_test.rb +10 -0
  67. metadata +72 -45
  68. data/lib/instana/agent.rb +0 -508
  69. data/lib/instana/agent/helpers.rb +0 -87
  70. data/lib/instana/agent/hooks.rb +0 -44
  71. data/lib/instana/agent/tasks.rb +0 -51
  72. data/lib/instana/collector.rb +0 -119
  73. data/lib/instana/collectors/gc.rb +0 -60
  74. data/lib/instana/collectors/memory.rb +0 -37
  75. data/lib/instana/collectors/thread.rb +0 -33
  76. data/lib/instana/eum/eum-test.js.erb +0 -17
  77. data/lib/instana/eum/eum.js.erb +0 -17
  78. data/lib/instana/helpers.rb +0 -47
  79. data/lib/instana/opentracing/tracer.rb +0 -21
  80. data/lib/instana/thread_local.rb +0 -18
  81. data/lib/oj_check.rb +0 -19
  82. data/test/agent/agent_test.rb +0 -151
@@ -18,7 +18,7 @@ module Instana
18
18
  def initialize(tid, sid, level = 1, baggage = {})
19
19
  @trace_id = tid
20
20
  @span_id = sid
21
- @level = level
21
+ @level = Integer(level || 1)
22
22
  @baggage = baggage || {}
23
23
  end
24
24
 
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
  #
@@ -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.197.0.pre1"
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,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,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,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
@@ -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