instana 1.195.1 → 1.197.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +16 -2
  3. data/.rubocop.yml +6 -2
  4. data/Appraisals +13 -1
  5. data/Rakefile +1 -1
  6. data/docker-compose.yml +20 -0
  7. data/gemfiles/aws_30.gemfile +3 -0
  8. data/gemfiles/excon_021.gemfile +18 -0
  9. data/gemfiles/excon_079.gemfile +18 -0
  10. data/gemfiles/shoryuken_50.gemfile +19 -0
  11. data/instana.gemspec +3 -7
  12. data/lib/instana.rb +3 -0
  13. data/lib/instana/activator.rb +2 -0
  14. data/lib/instana/activators/aws_sdk_s3.rb +20 -0
  15. data/lib/instana/activators/aws_sdk_sns.rb +20 -0
  16. data/lib/instana/activators/aws_sdk_sqs.rb +20 -0
  17. data/lib/instana/activators/excon.rb +1 -1
  18. data/lib/instana/activators/shoryuken.rb +24 -0
  19. data/lib/instana/backend/agent.rb +60 -0
  20. data/lib/instana/backend/gc_snapshot.rb +41 -0
  21. data/lib/instana/backend/host_agent.rb +74 -0
  22. data/lib/instana/backend/host_agent_activation_observer.rb +97 -0
  23. data/lib/instana/backend/host_agent_lookup.rb +57 -0
  24. data/lib/instana/backend/host_agent_reporting_observer.rb +106 -0
  25. data/lib/instana/backend/process_info.rb +64 -0
  26. data/lib/instana/backend/request_client.rb +73 -0
  27. data/lib/instana/backend/serverless_agent.rb +118 -0
  28. data/lib/instana/base.rb +8 -27
  29. data/lib/instana/config.rb +8 -22
  30. data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +21 -2
  31. data/lib/instana/instrumentation/aws_sdk_s3.rb +55 -0
  32. data/lib/instana/instrumentation/aws_sdk_sns.rb +29 -0
  33. data/lib/instana/instrumentation/aws_sdk_sqs.rb +98 -0
  34. data/lib/instana/instrumentation/excon.rb +19 -9
  35. data/lib/instana/instrumentation/instrumented_request.rb +68 -8
  36. data/lib/instana/instrumentation/net-http.rb +11 -7
  37. data/lib/instana/instrumentation/rack.rb +12 -7
  38. data/lib/instana/instrumentation/shoryuken.rb +44 -0
  39. data/lib/instana/logger_delegator.rb +31 -0
  40. data/lib/instana/{opentracing → open_tracing}/carrier.rb +0 -0
  41. data/lib/instana/open_tracing/instana_tracer.rb +99 -0
  42. data/lib/instana/secrets.rb +8 -4
  43. data/lib/instana/setup.rb +20 -11
  44. data/lib/instana/snapshot/deltable.rb +25 -0
  45. data/lib/instana/snapshot/docker_container.rb +151 -0
  46. data/lib/instana/snapshot/fargate_container.rb +88 -0
  47. data/lib/instana/snapshot/fargate_process.rb +67 -0
  48. data/lib/instana/snapshot/fargate_task.rb +72 -0
  49. data/lib/instana/snapshot/ruby_process.rb +48 -0
  50. data/lib/instana/tracer.rb +29 -147
  51. data/lib/instana/tracing/processor.rb +14 -22
  52. data/lib/instana/tracing/span.rb +34 -37
  53. data/lib/instana/tracing/span_context.rb +16 -10
  54. data/lib/instana/util.rb +8 -69
  55. data/lib/instana/version.rb +1 -1
  56. data/lib/opentracing.rb +26 -3
  57. data/test/backend/agent_test.rb +54 -0
  58. data/test/backend/gc_snapshot_test.rb +11 -0
  59. data/test/backend/host_agent_activation_observer_test.rb +72 -0
  60. data/test/backend/host_agent_lookup_test.rb +78 -0
  61. data/test/backend/host_agent_reporting_observer_test.rb +192 -0
  62. data/test/backend/host_agent_test.rb +47 -0
  63. data/test/backend/process_info_test.rb +63 -0
  64. data/test/backend/request_client_test.rb +39 -0
  65. data/test/backend/serverless_agent_test.rb +73 -0
  66. data/test/config_test.rb +10 -0
  67. data/test/instana_test.rb +11 -4
  68. data/test/instrumentation/aws_test.rb +130 -2
  69. data/test/instrumentation/excon_test.rb +16 -1
  70. data/test/instrumentation/net_http_test.rb +18 -0
  71. data/test/instrumentation/rack_instrumented_request_test.rb +9 -4
  72. data/test/instrumentation/rack_test.rb +2 -14
  73. data/test/instrumentation/shoryuken_test.rb +47 -0
  74. data/test/secrets_test.rb +41 -22
  75. data/test/snapshot/deltable_test.rb +17 -0
  76. data/test/snapshot/docker_container_test.rb +82 -0
  77. data/test/snapshot/fargate_container_test.rb +82 -0
  78. data/test/snapshot/fargate_process_test.rb +35 -0
  79. data/test/snapshot/fargate_task_test.rb +49 -0
  80. data/test/snapshot/ruby_process_test.rb +14 -0
  81. data/test/support/mock_timer.rb +20 -0
  82. data/test/test_helper.rb +16 -4
  83. data/test/tracing/custom_test.rb +1 -3
  84. data/test/tracing/id_management_test.rb +4 -0
  85. data/test/tracing/opentracing_test.rb +15 -2
  86. data/test/tracing/processor_test.rb +58 -0
  87. data/test/tracing/span_context_test.rb +21 -0
  88. data/test/tracing/span_test.rb +136 -0
  89. data/test/tracing/tracer_async_test.rb +29 -0
  90. data/test/tracing/tracer_test.rb +82 -16
  91. data/test/util_test.rb +10 -0
  92. metadata +86 -46
  93. data/Dockerfile +0 -16
  94. data/lib/instana/agent.rb +0 -508
  95. data/lib/instana/agent/helpers.rb +0 -87
  96. data/lib/instana/agent/hooks.rb +0 -44
  97. data/lib/instana/agent/tasks.rb +0 -51
  98. data/lib/instana/collector.rb +0 -119
  99. data/lib/instana/collectors/gc.rb +0 -60
  100. data/lib/instana/collectors/memory.rb +0 -37
  101. data/lib/instana/collectors/thread.rb +0 -33
  102. data/lib/instana/eum/eum-test.js.erb +0 -17
  103. data/lib/instana/eum/eum.js.erb +0 -17
  104. data/lib/instana/helpers.rb +0 -47
  105. data/lib/instana/opentracing/tracer.rb +0 -21
  106. data/lib/instana/thread_local.rb +0 -18
  107. data/lib/oj_check.rb +0 -19
  108. data/test/agent/agent_test.rb +0 -151
@@ -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
 
@@ -30,19 +31,22 @@ module Instana
30
31
  end
31
32
 
32
33
  def trace_parent_header
33
- return '' unless valid?
34
-
35
- trace = (@baggage[:external_trace_id] || @trace_id).rjust(32, '0')
36
- parent = @span_id.rjust(16, '0')
34
+ trace = (@baggage[:external_trace_id] || trace_id_header).rjust(32, '0')
35
+ parent = span_id_header.rjust(16, '0')
37
36
  flags = @level == 1 ? "01" : "00"
38
37
 
39
38
  "00-#{trace}-#{parent}-#{flags}"
40
39
  end
41
40
 
42
41
  def trace_state_header
43
- return '' unless valid?
42
+ external_state = @baggage[:external_state] || ''
43
+ state = external_state.split(/,/)
44
+
45
+ if @level == 1
46
+ state = state.reject { |s| s.start_with?('in=') }
47
+ state.unshift("in=#{trace_id_header};#{span_id_header}")
48
+ end
44
49
 
45
- state = ["in=#{@trace_id};#{@span_id}", @baggage[:external_state]]
46
50
  state.compact.join(',')
47
51
  end
48
52
 
@@ -50,10 +54,12 @@ module Instana
50
54
  { :trace_id => @trace_id, :span_id => @span_id }
51
55
  end
52
56
 
53
- private
54
-
55
57
  def valid?
56
- @baggage && @trace_id && @span_id
58
+ @baggage && @trace_id && !@trace_id.emtpy?
59
+ end
60
+
61
+ def active?
62
+ @level == 1
57
63
  end
58
64
  end
59
65
  end
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.1"
5
+ VERSION = "1.197.0.pre2"
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,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