instana 1.217.1 → 2.1.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 (228) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/lib/instana/base.rb +4 -2
  4. data/lib/instana/instrumentation/action_cable.rb +8 -4
  5. data/lib/instana/instrumentation/action_controller.rb +2 -4
  6. data/lib/instana/instrumentation/action_mailer.rb +1 -1
  7. data/lib/instana/instrumentation/action_view.rb +4 -4
  8. data/lib/instana/instrumentation/active_job.rb +20 -5
  9. data/lib/instana/instrumentation/active_record.rb +1 -1
  10. data/lib/instana/instrumentation/aws_sdk_dynamodb.rb +1 -1
  11. data/lib/instana/instrumentation/aws_sdk_lambda.rb +1 -1
  12. data/lib/instana/instrumentation/aws_sdk_s3.rb +1 -1
  13. data/lib/instana/instrumentation/aws_sdk_sns.rb +1 -1
  14. data/lib/instana/instrumentation/aws_sdk_sqs.rb +1 -1
  15. data/lib/instana/instrumentation/dalli.rb +1 -1
  16. data/lib/instana/instrumentation/excon.rb +2 -2
  17. data/lib/instana/instrumentation/graphql.rb +3 -3
  18. data/lib/instana/instrumentation/grpc.rb +14 -13
  19. data/lib/instana/instrumentation/mongo.rb +3 -3
  20. data/lib/instana/instrumentation/net-http.rb +5 -4
  21. data/lib/instana/instrumentation/rack.rb +36 -4
  22. data/lib/instana/instrumentation/redis.rb +1 -1
  23. data/lib/instana/instrumentation/resque.rb +10 -8
  24. data/lib/instana/instrumentation/rest-client.rb +4 -4
  25. data/lib/instana/instrumentation/sequel.rb +3 -3
  26. data/lib/instana/instrumentation/shoryuken.rb +4 -1
  27. data/lib/instana/instrumentation/sidekiq-client.rb +21 -19
  28. data/lib/instana/instrumentation/sidekiq-worker.rb +22 -21
  29. data/lib/instana/instrumented_logger.rb +1 -1
  30. data/lib/instana/samplers/result.rb +32 -0
  31. data/lib/instana/samplers/samplers.rb +76 -0
  32. data/lib/instana/serverless.rb +4 -2
  33. data/lib/instana/setup.rb +5 -5
  34. data/lib/instana/span_filtering/condition.rb +134 -0
  35. data/lib/instana/span_filtering/configuration.rb +262 -0
  36. data/lib/instana/span_filtering/filter_rule.rb +31 -0
  37. data/lib/instana/span_filtering.rb +62 -0
  38. data/lib/instana/trace/export.rb +36 -0
  39. data/lib/instana/{tracing → trace}/processor.rb +19 -15
  40. data/lib/instana/trace/span.rb +534 -0
  41. data/lib/instana/{tracing → trace}/span_context.rb +17 -8
  42. data/lib/instana/trace/span_kind.rb +51 -0
  43. data/lib/instana/trace/span_limits.rb +63 -0
  44. data/lib/instana/{tracer.rb → trace/tracer.rb} +106 -54
  45. data/lib/instana/trace/tracer_provider.rb +198 -0
  46. data/lib/instana/trace.rb +74 -0
  47. data/lib/instana/util.rb +11 -0
  48. data/lib/instana/version.rb +1 -1
  49. metadata +89 -267
  50. data/.circleci/config.yml +0 -485
  51. data/.codeclimate.yml +0 -23
  52. data/.editorconfig +0 -10
  53. data/.fasterer.yml +0 -23
  54. data/.github/ISSUE_TEMPLATE/bug.yml +0 -39
  55. data/.github/ISSUE_TEMPLATE/config.yml +0 -8
  56. data/.github/workflows/pr_commits_signed_off.yml +0 -16
  57. data/.github/workflows/release-notification-on-slack.yml +0 -34
  58. data/.gitignore +0 -19
  59. data/.rubocop.yml +0 -34
  60. data/.rubocop_todo.yml +0 -1140
  61. data/.tekton/.currency/docs/report.md +0 -20
  62. data/.tekton/.currency/resources/requirements.txt +0 -4
  63. data/.tekton/.currency/resources/table.json +0 -100
  64. data/.tekton/.currency/scripts/generate_report.py +0 -136
  65. data/.tekton/README.md +0 -278
  66. data/.tekton/github-interceptor-secret.yaml +0 -8
  67. data/.tekton/github-pr-eventlistener.yaml +0 -104
  68. data/.tekton/github-pr-pipeline.yaml.part +0 -38
  69. data/.tekton/github-set-status-task.yaml +0 -43
  70. data/.tekton/github-webhook-ingress.yaml +0 -20
  71. data/.tekton/pipeline.yaml +0 -571
  72. data/.tekton/pipelinerun.yaml +0 -21
  73. data/.tekton/ruby-tracer-prepuller.yaml +0 -87
  74. data/.tekton/run_unittests.sh +0 -87
  75. data/.tekton/scheduled-eventlistener.yaml +0 -108
  76. data/.tekton/task.yaml +0 -449
  77. data/.tekton/tekton-triggers-eventlistener-serviceaccount.yaml +0 -29
  78. data/Appraisals +0 -124
  79. data/CONTRIBUTING.md +0 -86
  80. data/Gemfile +0 -17
  81. data/LICENSE +0 -22
  82. data/MAINTAINERS.md +0 -3
  83. data/Rakefile +0 -49
  84. data/bin/announce_release_on_slack.py +0 -103
  85. data/docker-compose.yml +0 -20
  86. data/download.sh +0 -85
  87. data/examples/opentracing.rb +0 -35
  88. data/examples/tracing.rb +0 -84
  89. data/extras/license_header.rb +0 -44
  90. data/gemfiles/.bundle/config +0 -2
  91. data/gemfiles/aws_30.gemfile +0 -21
  92. data/gemfiles/aws_60.gemfile +0 -16
  93. data/gemfiles/cuba_30.gemfile +0 -16
  94. data/gemfiles/cuba_40.gemfile +0 -13
  95. data/gemfiles/dalli_20.gemfile +0 -15
  96. data/gemfiles/dalli_30.gemfile +0 -12
  97. data/gemfiles/dalli_32.gemfile +0 -12
  98. data/gemfiles/excon_0100.gemfile +0 -14
  99. data/gemfiles/excon_021.gemfile +0 -17
  100. data/gemfiles/excon_079.gemfile +0 -17
  101. data/gemfiles/excon_100.gemfile +0 -14
  102. data/gemfiles/graphql_10.gemfile +0 -16
  103. data/gemfiles/graphql_20.gemfile +0 -15
  104. data/gemfiles/grpc_10.gemfile +0 -15
  105. data/gemfiles/mongo_216.gemfile +0 -15
  106. data/gemfiles/mongo_219.gemfile +0 -12
  107. data/gemfiles/net_http_01.gemfile +0 -17
  108. data/gemfiles/rack_16.gemfile +0 -15
  109. data/gemfiles/rack_20.gemfile +0 -15
  110. data/gemfiles/rack_30.gemfile +0 -13
  111. data/gemfiles/rails_42.gemfile +0 -18
  112. data/gemfiles/rails_50.gemfile +0 -19
  113. data/gemfiles/rails_52.gemfile +0 -19
  114. data/gemfiles/rails_60.gemfile +0 -19
  115. data/gemfiles/rails_61.gemfile +0 -20
  116. data/gemfiles/rails_70.gemfile +0 -17
  117. data/gemfiles/rails_71.gemfile +0 -17
  118. data/gemfiles/rails_80.gemfile +0 -17
  119. data/gemfiles/redis_40.gemfile +0 -15
  120. data/gemfiles/redis_50.gemfile +0 -13
  121. data/gemfiles/redis_51.gemfile +0 -13
  122. data/gemfiles/resque_122.gemfile +0 -16
  123. data/gemfiles/resque_1274_3scale.gemfile +0 -17
  124. data/gemfiles/resque_20.gemfile +0 -16
  125. data/gemfiles/rest_client_16.gemfile +0 -17
  126. data/gemfiles/rest_client_20.gemfile +0 -17
  127. data/gemfiles/roda_20.gemfile +0 -16
  128. data/gemfiles/roda_30.gemfile +0 -16
  129. data/gemfiles/rubocop_162.gemfile +0 -6
  130. data/gemfiles/sequel_56.gemfile +0 -16
  131. data/gemfiles/sequel_57.gemfile +0 -16
  132. data/gemfiles/sequel_58.gemfile +0 -16
  133. data/gemfiles/shoryuken_50.gemfile +0 -16
  134. data/gemfiles/shoryuken_60.gemfile +0 -13
  135. data/gemfiles/sidekiq_42.gemfile +0 -15
  136. data/gemfiles/sidekiq_50.gemfile +0 -15
  137. data/gemfiles/sidekiq_60.gemfile +0 -12
  138. data/gemfiles/sidekiq_65.gemfile +0 -12
  139. data/gemfiles/sidekiq_70.gemfile +0 -12
  140. data/gemfiles/sinatra_14.gemfile +0 -15
  141. data/gemfiles/sinatra_22.gemfile +0 -12
  142. data/gemfiles/sinatra_30.gemfile +0 -12
  143. data/gemfiles/sinatra_40.gemfile +0 -12
  144. data/instana.gemspec +0 -48
  145. data/lib/instana/open_tracing/carrier.rb +0 -7
  146. data/lib/instana/open_tracing/instana_tracer.rb +0 -99
  147. data/lib/instana/tracing/span.rb +0 -431
  148. data/lib/opentracing.rb +0 -32
  149. data/log/.keep +0 -0
  150. data/sonar-project.properties +0 -9
  151. data/test/activator_test.rb +0 -50
  152. data/test/backend/agent_test.rb +0 -80
  153. data/test/backend/gc_snapshot_test.rb +0 -11
  154. data/test/backend/host_agent_activation_observer_test.rb +0 -73
  155. data/test/backend/host_agent_lookup_test.rb +0 -78
  156. data/test/backend/host_agent_reporting_observer_test.rb +0 -276
  157. data/test/backend/host_agent_test.rb +0 -89
  158. data/test/backend/process_info_test.rb +0 -83
  159. data/test/backend/request_client_test.rb +0 -39
  160. data/test/backend/serverless_agent_test.rb +0 -83
  161. data/test/benchmarks/bench_id_generation.rb +0 -15
  162. data/test/benchmarks/bench_opentracing.rb +0 -16
  163. data/test/config_test.rb +0 -34
  164. data/test/frameworks/cuba_test.rb +0 -61
  165. data/test/frameworks/roda_test.rb +0 -60
  166. data/test/frameworks/sinatra_test.rb +0 -71
  167. data/test/instana_test.rb +0 -37
  168. data/test/instrumentation/aws_test.rb +0 -241
  169. data/test/instrumentation/dalli_test.rb +0 -325
  170. data/test/instrumentation/excon_test.rb +0 -204
  171. data/test/instrumentation/graphql_test.rb +0 -289
  172. data/test/instrumentation/grpc_test.rb +0 -420
  173. data/test/instrumentation/mongo_test.rb +0 -68
  174. data/test/instrumentation/net_http_test.rb +0 -220
  175. data/test/instrumentation/rack_instrumented_request_test.rb +0 -211
  176. data/test/instrumentation/rack_test.rb +0 -415
  177. data/test/instrumentation/rails_action_cable_test.rb +0 -135
  178. data/test/instrumentation/rails_action_controller_test.rb +0 -218
  179. data/test/instrumentation/rails_action_mailer_test.rb +0 -66
  180. data/test/instrumentation/rails_action_view_test.rb +0 -154
  181. data/test/instrumentation/rails_active_job_test.rb +0 -65
  182. data/test/instrumentation/rails_active_record_database_missing_test.rb +0 -45
  183. data/test/instrumentation/rails_active_record_test.rb +0 -115
  184. data/test/instrumentation/redis_test.rb +0 -152
  185. data/test/instrumentation/resque_test.rb +0 -188
  186. data/test/instrumentation/rest_client_test.rb +0 -107
  187. data/test/instrumentation/sequel_test.rb +0 -105
  188. data/test/instrumentation/shoryuken_test.rb +0 -47
  189. data/test/instrumentation/sidekiq-client_test.rb +0 -169
  190. data/test/instrumentation/sidekiq-worker_test.rb +0 -180
  191. data/test/secrets_test.rb +0 -112
  192. data/test/serverless_test.rb +0 -369
  193. data/test/snapshot/deltable_test.rb +0 -17
  194. data/test/snapshot/docker_container_test.rb +0 -82
  195. data/test/snapshot/fargate_container_test.rb +0 -82
  196. data/test/snapshot/fargate_process_test.rb +0 -35
  197. data/test/snapshot/fargate_task_test.rb +0 -49
  198. data/test/snapshot/google_cloud_run_instance_test.rb +0 -74
  199. data/test/snapshot/google_cloud_run_process_test.rb +0 -33
  200. data/test/snapshot/lambda_function_test.rb +0 -37
  201. data/test/snapshot/ruby_process_test.rb +0 -32
  202. data/test/support/apps/active_record/active_record.rb +0 -24
  203. data/test/support/apps/grpc/boot.rb +0 -23
  204. data/test/support/apps/grpc/grpc_server.rb +0 -84
  205. data/test/support/apps/http_endpoint/boot.rb +0 -28
  206. data/test/support/apps/rails/boot.rb +0 -219
  207. data/test/support/apps/rails/models/block.rb +0 -21
  208. data/test/support/apps/rails/models/block6.rb +0 -21
  209. data/test/support/apps/resque/boot.rb +0 -5
  210. data/test/support/apps/resque/jobs/resque_error_job.rb +0 -22
  211. data/test/support/apps/resque/jobs/resque_fast_job.rb +0 -23
  212. data/test/support/apps/sidekiq/boot.rb +0 -25
  213. data/test/support/apps/sidekiq/jobs/sidekiq_job_1.rb +0 -9
  214. data/test/support/apps/sidekiq/jobs/sidekiq_job_2.rb +0 -10
  215. data/test/support/apps/sidekiq/worker.rb +0 -37
  216. data/test/support/helpers.rb +0 -85
  217. data/test/support/mock_timer.rb +0 -20
  218. data/test/test_helper.rb +0 -69
  219. data/test/tracing/custom_test.rb +0 -226
  220. data/test/tracing/id_management_test.rb +0 -80
  221. data/test/tracing/instrumented_logger_test.rb +0 -39
  222. data/test/tracing/opentracing_test.rb +0 -382
  223. data/test/tracing/processor_test.rb +0 -58
  224. data/test/tracing/span_context_test.rb +0 -22
  225. data/test/tracing/span_test.rb +0 -179
  226. data/test/tracing/tracer_async_test.rb +0 -230
  227. data/test/tracing/tracer_test.rb +0 -352
  228. data/test/util_test.rb +0 -10
@@ -1,80 +0,0 @@
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_google_cloud
60
- ENV['K_REVISION'] = 'TEST'
61
- ENV['INSTANA_ENDPOINT_URL'] = 'http://example.com'
62
-
63
- subject = Instana::Backend::Agent.new
64
- assert_nil subject.delegate
65
- subject.setup
66
- assert subject.delegate.is_a?(Instana::Backend::ServerlessAgent)
67
- ensure
68
- ENV['K_REVISION'] = nil
69
- ENV['INSTANA_ENDPOINT_URL'] = nil
70
- end
71
-
72
- def test_delegate_super
73
- subject = Instana::Backend::Agent.new
74
- assert_raises NoMethodError do
75
- subject.invalid
76
- end
77
-
78
- refute subject.respond_to?(:invalid)
79
- end
80
- end
@@ -1,11 +0,0 @@
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
@@ -1,73 +0,0 @@
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
- .and_return(status: 200, body: '{"pid": 1234}')
17
-
18
- stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
19
- .and_return(status: 500, body: '{"ok": false}')
20
- .and_return(status: 200, body: '{"ok": true}')
21
-
22
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
23
- discovery = Concurrent::Atom.new(nil)
24
-
25
- subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), max_wait_tries: 1, socket_proc: @socket_proc)
26
-
27
- subject.update(nil, nil, nil)
28
- assert_equal({'pid' => 1234}, discovery.value)
29
- end
30
-
31
- def test_linux_discovery
32
- stub_request(:put, "http://10.10.10.10:9292/com.instana.plugin.ruby.discovery")
33
- .and_return(status: 200, body: '{"pid": 1234}')
34
-
35
- stub_request(:head, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
36
- .and_return(status: 200, body: '{"ok": true}')
37
-
38
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
39
- discovery = Concurrent::Atom.new(nil)
40
-
41
- subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), max_wait_tries: 1, socket_proc: @socket_proc)
42
-
43
- FakeFS.with_fresh do
44
- FakeFS::FileSystem.clone('test/support/proc', '/proc')
45
- FakeFS::FileSystem.clone('test/support/proc/0', "/proc/#{Process.pid}")
46
- Dir.mkdir('/proc/self/fd')
47
- File.symlink('/proc/self/sched', "/proc/self/fd/0")
48
-
49
- subject.update(nil, nil, nil)
50
- end
51
-
52
- assert_equal({'pid' => 1234}, discovery.value)
53
- end
54
-
55
- def test_discovery_standard_error
56
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
57
- discovery = Concurrent::Atom.new(nil)
58
-
59
- subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, wait_time: 0, logger: Logger.new('/dev/null'), proc_table: nil, socket_proc: @socket_proc)
60
-
61
- subject.update(nil, nil, nil)
62
- assert_nil discovery.value
63
- end
64
-
65
- def test_value_present
66
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
67
- discovery = Concurrent::Atom.new(nil)
68
-
69
- subject = Instana::Backend::HostAgentActivationObserver.new(client, discovery, socket_proc: @socket_proc)
70
- assert_nil subject.update(nil, nil, true)
71
- assert_nil discovery.value
72
- end
73
- end
@@ -1,78 +0,0 @@
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
@@ -1,276 +0,0 @@
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/tracermetrics")
27
- .to_return(status: 200)
28
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
29
- .to_return(status: 200)
30
-
31
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
32
- discovery = Concurrent::Atom.new({'pid' => 0})
33
-
34
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
35
-
36
- subject.report_timer.block.call
37
- end
38
-
39
- def test_report_fail
40
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
41
- .to_return(status: 200)
42
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
43
- .to_return(status: 500)
44
-
45
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
46
- discovery = Concurrent::Atom.new({'pid' => 0})
47
-
48
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
49
-
50
- subject.report_timer.block.call
51
- assert_nil discovery.value
52
- end
53
-
54
- def test_agent_action
55
- action = JSON.dump(
56
- {
57
- action: 'ruby.source',
58
- messageId: 'test',
59
- args: {file: 'test_helper.rb'}
60
- }
61
- )
62
-
63
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
64
- .to_return(status: 200)
65
-
66
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
67
- .to_return(status: 200, body: action)
68
-
69
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/response.0?messageId=test")
70
- .to_return(status: 200)
71
-
72
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
73
- discovery = Concurrent::Atom.new({'pid' => 0})
74
-
75
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
76
-
77
- subject.report_timer.block.call
78
- end
79
-
80
- def test_agent_actions
81
- action = JSON.dump([
82
- action: 'ruby.source',
83
- messageId: 'test',
84
- args: {file: 'test_helper.rb'}
85
- ])
86
-
87
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
88
- .to_return(status: 200)
89
-
90
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
91
- .to_return(status: 200, body: action)
92
-
93
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/response.0?messageId=test")
94
- .to_return(status: 200)
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_agent_action_error
105
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
106
- .to_return(status: 200)
107
-
108
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
109
- .to_return(status: 200, body: 'INVALID')
110
-
111
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
112
- discovery = Concurrent::Atom.new({'pid' => 0})
113
-
114
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
115
-
116
- subject.report_timer.block.call
117
- end
118
-
119
- def test_disable_metrics
120
- ::Instana.config[:metrics][:enabled] = false
121
-
122
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
123
- discovery = Concurrent::Atom.new(nil)
124
-
125
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
126
-
127
- subject.report_timer.block.call
128
- ensure
129
- ::Instana.config[:metrics][:enabled] = true
130
- end
131
-
132
- def test_disable_metrics_memory
133
- ::Instana.config[:metrics][:memory][:enabled] = false
134
-
135
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
136
- .to_return(status: 200)
137
-
138
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
139
- .with(body: ->(data) { (JSON.parse(data).keys & ['exec_args', 'memory']).length.eql?(0) })
140
- .to_return(status: 200)
141
-
142
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.0")
143
- .to_return(status: 200)
144
-
145
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
146
- discovery = Concurrent::Atom.new({'pid' => 0})
147
-
148
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
149
-
150
- subject.report_timer.block.call
151
- ensure
152
- ::Instana.config[:metrics][:memory][:enabled] = true
153
- end
154
-
155
- def test_disable_gc
156
- ::Instana.config[:metrics][:gc][:enabled] = false
157
-
158
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
159
- .to_return(status: 200)
160
-
161
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
162
- .with(body: ->(data) { (JSON.parse(data).keys & ['gc']).length.eql?(0) })
163
- .to_return(status: 200)
164
-
165
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.0")
166
- .to_return(status: 200)
167
-
168
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
169
- discovery = Concurrent::Atom.new({'pid' => 0})
170
-
171
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
172
-
173
- subject.report_timer.block.call
174
- ensure
175
- ::Instana.config[:metrics][:gc][:enabled] = true
176
- end
177
-
178
- def test_disable_thread
179
- ::Instana.config[:metrics][:thread][:enabled] = false
180
-
181
- stub_request(:post, "http://10.10.10.10:9292/tracermetrics")
182
- .to_return(status: 200)
183
-
184
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.0")
185
- .with(body: ->(data) { (JSON.parse(data).keys & ['thread']).length.eql?(0) })
186
- .to_return(status: 200)
187
-
188
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.0")
189
- .to_return(status: 200)
190
-
191
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
192
- discovery = Concurrent::Atom.new({'pid' => 0})
193
-
194
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
195
-
196
- subject.report_timer.block.call
197
- ensure
198
- ::Instana.config[:metrics][:thread][:enabled] = true
199
- end
200
-
201
- def test_disable_tracing
202
- ::Instana.config[:tracing][:enabled] = false
203
-
204
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
205
- discovery = Concurrent::Atom.new(nil)
206
-
207
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer)
208
-
209
- subject.report_timer.block.call
210
- ensure
211
- ::Instana.config[:tracing][:enabled] = true
212
- end
213
-
214
- def test_report_traces
215
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
216
- .to_return(status: 200)
217
-
218
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.1234")
219
- .to_return(status: 200)
220
-
221
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
222
- discovery = Concurrent::Atom.new({'pid' => 1234})
223
-
224
- processor = Class.new do
225
- def send
226
- yield([{n: 'test'}])
227
- end
228
- end.new
229
-
230
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer, processor: processor)
231
-
232
- subject.report_timer.block.call
233
- refute_nil discovery.value
234
- end
235
-
236
- def test_report_traces_error
237
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
238
- .to_return(status: 200)
239
-
240
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby/traces.1234")
241
- .to_return(status: 500)
242
-
243
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
244
- discovery = Concurrent::Atom.new({'pid' => 1234})
245
-
246
- processor = Class.new do
247
- def send
248
- yield([{n: 'test'}])
249
- end
250
- end.new
251
-
252
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer, processor: processor)
253
-
254
- subject.report_timer.block.call
255
- assert_nil discovery.value
256
- end
257
-
258
- def test_report_standard_error
259
- stub_request(:post, "http://10.10.10.10:9292/com.instana.plugin.ruby.1234")
260
- .to_return(status: 200)
261
-
262
- client = Instana::Backend::RequestClient.new('10.10.10.10', 9292)
263
- discovery = Concurrent::Atom.new({'pid' => 1234})
264
-
265
- processor = Class.new do
266
- def send
267
- raise 'Standard Error'
268
- end
269
- end.new
270
-
271
- subject = Instana::Backend::HostAgentReportingObserver.new(client, discovery, timer_class: MockTimer, processor: processor, logger: Logger.new('/dev/null'))
272
-
273
- subject.report_timer.block.call
274
- assert_equal({"pid" => 1234}, discovery.value)
275
- end
276
- end
@@ -1,89 +0,0 @@
1
- # (c) Copyright IBM Corp. 2021
2
- # (c) Copyright Instana Inc. 2021
3
-
4
- require 'test_helper'
5
-
6
- class HostAgentTest < Minitest::Test
7
- def test_spawn_background_thread
8
- ENV['INSTANA_TEST'] = nil
9
- agent_host = '10.10.10.10'
10
- ::Instana.config[:agent_host] = agent_host
11
-
12
- if File.exist?('/proc/net/route')
13
- default_gateway_hex = lambda {
14
- File.open('/proc/net/route', 'r') do |file|
15
- file.each_line do |line|
16
- columns = line.split("\t")
17
- if columns[1] == '00000000' && columns[1] == columns[7]
18
- return columns[2]
19
- end
20
- end
21
- end
22
- }.call
23
-
24
- addr = default_gateway_hex.scan(/.{2}/).map(&:hex).reverse.join('.')
25
- stub_request(:get, "http://#{addr}:42699/")
26
- .to_timeout
27
- end
28
-
29
- stub_request(:get, "http://#{agent_host}:42699/")
30
- .to_timeout.times(3).then
31
- .to_return(status: 200, body: "", headers: {})
32
-
33
- discovery = Minitest::Mock.new
34
- discovery.expect(:delete_observers, discovery, [])
35
- discovery.expect(:observers, discovery, [])
36
- discovery.expect(:notify_and_delete_observers, discovery, [Object, nil, nil])
37
- discovery.expect(:with_observer, discovery, [Instana::Backend::HostAgentActivationObserver])
38
- discovery.expect(:with_observer, discovery, [Instana::Backend::HostAgentReportingObserver])
39
- discovery.expect(:swap, discovery, [])
40
-
41
- subject = Instana::Backend::HostAgent.new(discovery: discovery)
42
-
43
- FakeFS.with_fresh do
44
- FakeFS::FileSystem.clone('test/support/ecs', '/proc')
45
- subject.spawn_background_thread
46
- end
47
-
48
- subject.future.value!
49
-
50
- discovery.verify
51
- ensure
52
- ::Instana.config[:agent_host] = '127.0.0.1'
53
- ENV['INSTANA_TEST'] = 'true'
54
- end
55
-
56
- def test_discovery_value
57
- discovery = Concurrent::Atom.new({'pid' => 1})
58
- subject = Instana::Backend::HostAgent.new(discovery: discovery)
59
- assert_equal 1, subject.source[:e]
60
- end
61
-
62
- def test_extra_headers_from_tracing_config
63
- discovery = Concurrent::Atom.new(
64
- {
65
- 'tracing' => {
66
- 'extra-http-headers' => ["X-Header-1", "X-Header-2"]
67
- }
68
- }
69
- )
70
- subject = Instana::Backend::HostAgent.new(discovery: discovery)
71
- assert_equal ["X-Header-1", "X-Header-2"], subject.extra_headers
72
- end
73
-
74
- def test_extra_headers_legacy
75
- discovery = Concurrent::Atom.new({'extraHeaders' => ["X-Header-3", "X-Header-4"]})
76
- subject = Instana::Backend::HostAgent.new(discovery: discovery)
77
- assert_equal ["X-Header-3", "X-Header-4"], subject.extra_headers
78
- end
79
-
80
- def test_start
81
- subject = Instana::Backend::HostAgent.new
82
- assert subject.respond_to? :start
83
- end
84
-
85
- def test_after_fork
86
- subject = Instana::Backend::HostAgent.new
87
- assert subject.respond_to? :after_fork
88
- end
89
- end
@@ -1,83 +0,0 @@
1
- # (c) Copyright IBM Corp. 2021
2
- # (c) Copyright Instana Inc. 2021
3
-
4
- require 'test_helper'
5
-
6
- class ProcessInfoTest < Minitest::Test
7
- def test_osx_argument_stripping
8
- host_os = RbConfig::CONFIG['host_os']
9
- RbConfig::CONFIG['host_os'] = 'darwin'
10
-
11
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(cmdline: 'test INSTANA_TEST=1 KV=2'))
12
- assert_equal ['KV=2'], subject.arguments
13
- ensure
14
- RbConfig::CONFIG['host_os'] = host_os
15
- end
16
-
17
- def test_linux_argument_stripping
18
- host_os = RbConfig::CONFIG['host_os']
19
- RbConfig::CONFIG['host_os'] = 'linux'
20
-
21
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(cmdline: 'test INSTANA_TEST=1 KV=2'))
22
- assert_equal ['INSTANA_TEST=1', 'KV=2'], subject.arguments
23
- ensure
24
- RbConfig::CONFIG['host_os'] = host_os
25
- end
26
-
27
- def test_no_proc
28
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 0))
29
-
30
- FakeFS.with_fresh do
31
- FakeFS::FileSystem.clone('test/support/ecs', '/proc')
32
-
33
- assert_equal 0, subject.parent_pid
34
- assert_nil subject.cpuset
35
- assert_nil subject.sched_pid
36
- refute subject.in_container?
37
- end
38
- end
39
-
40
- def test_cpuset_proc
41
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 0))
42
-
43
- FakeFS do
44
- FakeFS::FileSystem.clone('test/support/proc', '/proc')
45
- assert_equal '/', subject.cpuset
46
- refute subject.in_container?
47
- end
48
- end
49
-
50
- def test_sched_pid
51
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 1))
52
-
53
- FakeFS do
54
- FakeFS::FileSystem.clone('test/support/proc', '/proc')
55
- refute_equal '/', subject.cpuset
56
-
57
- assert subject.in_container?
58
- assert_equal 35, subject.sched_pid
59
- assert subject.from_parent_namespace
60
- assert_equal subject.sched_pid, subject.parent_pid
61
- end
62
- end
63
-
64
- def test_osx_memory_used
65
- host_os = RbConfig::CONFIG['host_os']
66
- RbConfig::CONFIG['host_os'] = 'darwin'
67
-
68
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(rss: 1))
69
- assert_equal 1, subject.memory_used
70
- ensure
71
- RbConfig::CONFIG['host_os'] = host_os
72
- end
73
-
74
- def test_linux_memory_used
75
- host_os = RbConfig::CONFIG['host_os']
76
- RbConfig::CONFIG['host_os'] = 'linux'
77
-
78
- subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(rss: 1))
79
- assert_equal 4096, subject.memory_used
80
- ensure
81
- RbConfig::CONFIG['host_os'] = host_os
82
- end
83
- end