instana 1.198.0.pre1 → 1.199.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b2d93394311ee04b29279b946a5b2d6bf74e567aecbeccef6ffa13b07224002
4
- data.tar.gz: ba3febaf1f2089a0547ae9e30596de784bcc7636bb98906c287638233cfdc8a6
3
+ metadata.gz: 5f50b5331be370b903eef0f43c5565c82e6dc91776ee42f2a406820ab77a6281
4
+ data.tar.gz: b9f19763f4e27082ecb893706b016e181d9b03993b49e91dc0d106ced00c2689
5
5
  SHA512:
6
- metadata.gz: 74d25b236d861ec5eb144780a34e7b44b13f747ca843ee7bc25c3387eba63fbe0f3128a63bf19828a17e7bd02ebe51164f9f72c52070bd46a2d291e433ab4caa
7
- data.tar.gz: 2ce25e5cea1b1a38831a481e571603fe99b67143ee7653c38081e1df5c8989f13f02e6490dad28500c63fff99277937b9be7052d0f7cf679ce0c46ce36cb5c21
6
+ metadata.gz: 995d7c897b69f00439becf36790caebd57b7e39738ff480ea17e1b4a7c47487f6c28f322bd8b39149e6a182453672b285bc49245b904cbe9eba6cf316ea30582
7
+ data.tar.gz: 89c525c7d9ed2b4702b15e6fc8f74158973b5455007e5adbc9250cb504e8d82c5426e257a45690a3518f600eba2f4eb76b6df40eb2bebb2376987627918d0a66
@@ -16,11 +16,8 @@ module Instana
16
16
  ::Resque::Worker.prepend(::Instana::Instrumentation::ResqueWorker)
17
17
  ::Resque::Job.prepend(::Instana::Instrumentation::ResqueJob)
18
18
 
19
- ::Resque.before_fork do |_job|
20
- ::Instana.agent.before_resque_fork
21
- end
22
19
  ::Resque.after_fork do |_job|
23
- ::Instana.agent.after_resque_fork
20
+ ::Instana.agent.after_fork
24
21
  end
25
22
 
26
23
  # Set this so we assure that any remaining collected traces are reported at_exit
@@ -17,6 +17,12 @@ module Instana
17
17
  def setup
18
18
  @delegate = if ENV.key?('_HANDLER')
19
19
  ServerlessAgent.new([Snapshot::LambdaFunction.new])
20
+ elsif ENV.key?('K_REVISION') && ENV.key?('INSTANA_ENDPOINT_URL')
21
+ ServerlessAgent.new([
22
+ Snapshot::GoogleCloudRunProcess.new,
23
+ Snapshot::GoogleCloudRunInstance.new,
24
+ Snapshot::RubyProcess.new
25
+ ])
20
26
  elsif @fargate_metadata_uri && ENV.key?('INSTANA_ENDPOINT_URL')
21
27
  ServerlessAgent.new(fargate_snapshots)
22
28
  else
@@ -30,6 +30,9 @@ module Instana
30
30
  end
31
31
  end
32
32
 
33
+ alias start spawn_background_thread
34
+ alias after_fork spawn_background_thread
35
+
33
36
  # @return [Boolean] true if the agent able to send spans to the backend
34
37
  def ready?
35
38
  ENV.key?('INSTANA_TEST') || !@discovery.value.nil?
@@ -32,6 +32,9 @@ module Instana
32
32
  @timer.execute
33
33
  end
34
34
 
35
+ alias start spawn_background_thread
36
+ alias after_fork spawn_background_thread
37
+
35
38
  # @return [Boolean] true if the agent able to send spans to the backend
36
39
  def ready?
37
40
  true
@@ -13,21 +13,31 @@ module Instana
13
13
  def remove_from_query(str, secret_values = Instana.agent.secret_values)
14
14
  return str unless secret_values
15
15
 
16
- url = URI(str)
17
- params = url.scheme ? CGI.parse(url.query || '') : CGI.parse(url.to_s)
16
+ begin
17
+ url = URI(str)
18
+ params = url.scheme ? CGI.parse(url.query || '') : CGI.parse(url.to_s)
19
+
20
+ redacted = redact(params, secret_values)
21
+
22
+ url.query = URI.encode_www_form(redacted)
23
+ url.scheme ? CGI.unescape(url.to_s) : CGI.unescape(url.query)
24
+ rescue URI::InvalidURIError => _e
25
+ params = CGI.parse(str || '')
26
+ redacted = redact(params, secret_values)
27
+ CGI.unescape(URI.encode_www_form(redacted))
28
+ end
29
+ end
30
+
31
+ private
18
32
 
19
- redacted = params.map do |k, v|
33
+ def redact(params, secret_values)
34
+ params.map do |k, v|
20
35
  needs_redaction = secret_values['list']
21
36
  .any? { |t| matcher(secret_values['matcher']).(t,k) }
22
37
  [k, needs_redaction ? '<redacted>' : v]
23
38
  end
24
-
25
- url.query = URI.encode_www_form(redacted)
26
- url.scheme ? CGI.unescape(url.to_s) : CGI.unescape(url.query)
27
39
  end
28
40
 
29
- private
30
-
31
41
  def matcher(name)
32
42
  case name
33
43
  when 'equals-ignore-case'
@@ -4,7 +4,13 @@
4
4
  require 'base64'
5
5
  require 'zlib'
6
6
 
7
- require 'instana/instrumentation/instrumented_request'
7
+ # :nocov:
8
+ begin
9
+ require 'instana/instrumentation/instrumented_request'
10
+ rescue LoadError => _e
11
+ Instana.logger.warn("Unable to Instana::InstrumentedRequest. HTTP based triggers won't generate spans.")
12
+ end
13
+ # :nocov:
8
14
 
9
15
  module Instana
10
16
  # @since 1.198.0
@@ -49,10 +55,10 @@ module Instana
49
55
 
50
56
  def trigger_from_event(event) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
51
57
  case event
52
- when ->(e) { e.is_a?(Hash) && e.key?('requestContext') && e['requestContext'].key?('elb') }
58
+ when ->(e) { defined?(::Instana::InstrumentedRequest) && e.is_a?(Hash) && e.key?('requestContext') && e['requestContext'].key?('elb') }
53
59
  request = InstrumentedRequest.new(event_to_rack(event))
54
60
  ['aws:application.load.balancer', {http: request.request_tags}, request.incoming_context]
55
- when ->(e) { e.is_a?(Hash) && e.key?('httpMethod') && e.key?('path') && e.key?('headers') }
61
+ when ->(e) { defined?(::Instana::InstrumentedRequest) && e.is_a?(Hash) && e.key?('httpMethod') && e.key?('path') && e.key?('headers') }
56
62
  request = InstrumentedRequest.new(event_to_rack(event))
57
63
  ['aws:api.gateway', {http: request.request_tags}, request.incoming_context]
58
64
  when ->(e) { e.is_a?(Hash) && e['source'] == 'aws.events' && e['detail-type'] == 'Scheduled Event' }
data/lib/instana/setup.rb CHANGED
@@ -24,6 +24,8 @@ require 'instana/snapshot/fargate_task'
24
24
  require 'instana/snapshot/fargate_container'
25
25
  require 'instana/snapshot/docker_container'
26
26
  require 'instana/snapshot/lambda_function'
27
+ require 'instana/snapshot/google_cloud_run_instance'
28
+ require 'instana/snapshot/google_cloud_run_process'
27
29
 
28
30
  require 'instana/backend/host_agent_lookup'
29
31
  require 'instana/backend/host_agent_activation_observer'
@@ -0,0 +1,69 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Snapshot
6
+ # @since 1.199
7
+ class GoogleCloudRunInstance
8
+ ID = 'com.instana.plugin.gcp.run.revision.instance'.freeze
9
+
10
+ def initialize(metadata_uri: 'http://metadata.google.internal')
11
+ @metadata_uri = URI(metadata_uri)
12
+ @client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
13
+ end
14
+
15
+ def entity_id
16
+ lookup('/computeMetadata/v1/instance/id')
17
+ end
18
+
19
+ def data
20
+ {
21
+ runtime: 'ruby',
22
+ region: gcp_region,
23
+ service: ENV['K_SERVICE'],
24
+ configuration: ENV['K_CONFIGURATION'],
25
+ revision: ENV['K_REVISION'],
26
+ instanceId: entity_id,
27
+ port: ENV['PORT'],
28
+ numericProjectId: lookup('/computeMetadata/v1/project/numeric-project-id'),
29
+ projectId: lookup('/computeMetadata/v1/project/project-id')
30
+ }.compact
31
+ end
32
+
33
+ def snapshot
34
+ {
35
+ name: ID,
36
+ entityId: entity_id,
37
+ data: data
38
+ }
39
+ end
40
+
41
+ def source
42
+ {
43
+ hl: true,
44
+ cp: 'gcp',
45
+ e: entity_id
46
+ }
47
+ end
48
+
49
+ def host_name
50
+ "gcp:cloud-run:revision:#{ENV['K_REVISION']}"
51
+ end
52
+
53
+ private
54
+
55
+ def gcp_region
56
+ lookup('/computeMetadata/v1/instance/zone').split('/').last
57
+ end
58
+
59
+ def lookup(resource)
60
+ path = @metadata_uri.path + resource
61
+ response = @client.send_request('GET', path, nil, {'Metadata-Flavor' => 'Google'})
62
+
63
+ raise "Unable to get `#{path}`. Got `#{response.code}` `#{response['location']}`." unless response.ok?
64
+
65
+ response.body
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,58 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ module Instana
5
+ module Snapshot
6
+ # @since 1.199.0
7
+ class GoogleCloudRunProcess
8
+ ID = 'com.instana.plugin.process'.freeze
9
+
10
+ def initialize(metadata_uri: 'http://metadata.google.internal')
11
+ @metadata_uri = URI(metadata_uri)
12
+ @client = Backend::RequestClient.new(@metadata_uri.host, @metadata_uri.port, use_ssl: @metadata_uri.scheme == "https")
13
+ @start_time = Time.now
14
+ end
15
+
16
+ def entity_id
17
+ Process.pid.to_s
18
+ end
19
+
20
+ def data
21
+ proc_table = Sys::ProcTable.ps(pid: Process.pid)
22
+ process = Backend::ProcessInfo.new(proc_table)
23
+
24
+ {
25
+ pid: process.pid.to_i,
26
+ env: ENV.to_h,
27
+ exec: process.name,
28
+ args: process.arguments,
29
+ user: process.uid,
30
+ group: process.gid,
31
+ start: @start_time.to_i * 1000,
32
+ containerType: 'gcpCloudRunInstance',
33
+ container: lookup('/computeMetadata/v1/instance/id'),
34
+ "com.instana.plugin.host.name": "gcp:cloud-run:revision:#{ENV['K_REVISION']}"
35
+ }
36
+ end
37
+
38
+ def snapshot
39
+ {
40
+ name: ID,
41
+ entityId: entity_id,
42
+ data: data
43
+ }
44
+ end
45
+
46
+ private
47
+
48
+ def lookup(resource)
49
+ path = @metadata_uri.path + resource
50
+ response = @client.send_request('GET', path, nil, {'Metadata-Flavor' => 'Google'})
51
+
52
+ raise "Unable to get `#{path}`. Got `#{response.code}` `#{response['location']}`." unless response.ok?
53
+
54
+ response.body
55
+ end
56
+ end
57
+ end
58
+ end
@@ -2,6 +2,6 @@
2
2
  # (c) Copyright Instana Inc. 2016
3
3
 
4
4
  module Instana
5
- VERSION = "1.198.0.pre1"
5
+ VERSION = "1.199.3"
6
6
  VERSION_FULL = "instana-#{VERSION}"
7
7
  end
@@ -56,6 +56,19 @@ class AgentTest < Minitest::Test
56
56
  ENV['INSTANA_ENDPOINT_URL'] = nil
57
57
  end
58
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
+
59
72
  def test_delegate_super
60
73
  subject = Instana::Backend::Agent.new
61
74
  assert_raises NoMethodError do
@@ -44,4 +44,14 @@ class HostAgentTest < Minitest::Test
44
44
  subject = Instana::Backend::HostAgent.new(discovery: discovery)
45
45
  assert_equal 1, subject.source[:e]
46
46
  end
47
+
48
+ def test_start
49
+ subject = Instana::Backend::HostAgent.new
50
+ assert subject.respond_to? :start
51
+ end
52
+
53
+ def test_after_fork
54
+ subject = Instana::Backend::HostAgent.new
55
+ assert subject.respond_to? :after_fork
56
+ end
47
57
  end
@@ -70,4 +70,14 @@ class ServerlesAgentTest < Minitest::Test
70
70
 
71
71
  subject.timer.block.call
72
72
  end
73
+
74
+ def test_start
75
+ subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/', logger: Logger.new('/dev/null'))
76
+ assert subject.respond_to? :start
77
+ end
78
+
79
+ def test_after_fork
80
+ subject = Instana::Backend::ServerlessAgent.new([], timer_class: MockTimer, backend_uri: 'http://10.10.10.10:9292/', logger: Logger.new('/dev/null'))
81
+ assert subject.respond_to? :after_fork
82
+ end
73
83
  end
data/test/secrets_test.rb CHANGED
@@ -78,6 +78,16 @@ class SecretsTest < Minitest::Test
78
78
  assert_redacted @subject.remove_from_query(url, sample_config), %w(instantiate)
79
79
  end
80
80
 
81
+ def test_without_url
82
+ sample_config = {
83
+ "matcher"=>"contains",
84
+ "list"=>["stan"]
85
+ }
86
+
87
+ url = 'filter[instantiate]=true'
88
+ assert_redacted @subject.remove_from_query(url, sample_config), %w(filter[instantiate]), raw_str: true
89
+ end
90
+
81
91
  private
82
92
 
83
93
  def url_for(keys)
@@ -86,10 +96,8 @@ class SecretsTest < Minitest::Test
86
96
  url.to_s
87
97
  end
88
98
 
89
- def assert_redacted(str, keys)
90
- url = URI(str)
91
- params = CGI.parse(url.query)
92
-
99
+ def assert_redacted(str, keys, raw_str: false)
100
+ params = raw_str ? CGI.parse(str) : CGI.parse(URI(str).query)
93
101
  assert_equal keys, params.select { |_, v| v == %w(<redacted>) }.keys, 'to be redacted'
94
102
  end
95
103
  end
@@ -0,0 +1,74 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ require 'test_helper'
5
+
6
+ class GoogleCloudRunInstanceTest < Minitest::Test
7
+ def test_snapshot
8
+ ENV['K_SERVICE'] = 'test_service'
9
+ ENV['K_CONFIGURATION'] = 'test_config'
10
+ ENV['K_REVISION'] = 'test_revision'
11
+ ENV['PORT'] = 'test_port'
12
+
13
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/instance/id')
14
+ .to_return(status: 200, body: 'test_instance_id')
15
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/instance/zone')
16
+ .to_return(status: 200, body: 'region/number/test_region')
17
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/project/numeric-project-id')
18
+ .to_return(status: 200, body: 'numericProjectId')
19
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/project/project-id')
20
+ .to_return(status: 200, body: 'projectId')
21
+
22
+ subject = Instana::Snapshot::GoogleCloudRunInstance.new(metadata_uri: 'http://10.10.10.10/')
23
+ snapshot = subject.snapshot
24
+
25
+ assert_equal Instana::Snapshot::GoogleCloudRunInstance::ID, snapshot[:name]
26
+ assert_equal 'test_instance_id', snapshot[:entityId]
27
+
28
+ assert_equal "ruby", snapshot[:data][:runtime]
29
+ assert_equal "test_region", snapshot[:data][:region]
30
+ assert_equal "test_service", snapshot[:data][:service]
31
+ assert_equal "test_config", snapshot[:data][:configuration]
32
+ assert_equal "test_revision", snapshot[:data][:revision]
33
+ assert_equal "test_instance_id", snapshot[:data][:instanceId]
34
+ assert_equal "test_port", snapshot[:data][:port]
35
+ assert_equal "numericProjectId", snapshot[:data][:numericProjectId]
36
+ assert_equal "projectId", snapshot[:data][:projectId]
37
+ ensure
38
+ ENV['K_SERVICE'] = nil
39
+ ENV['K_CONFIGURATION'] = nil
40
+ ENV['K_REVISION'] = nil
41
+ ENV['PORT'] = nil
42
+ end
43
+
44
+ def test_snapshot_error
45
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/instance/id')
46
+ .to_return(status: 500)
47
+
48
+ subject = Instana::Snapshot::GoogleCloudRunInstance.new(metadata_uri: 'http://10.10.10.10/')
49
+
50
+ assert_raises do
51
+ subject.snapshot
52
+ end
53
+ end
54
+
55
+ def test_source
56
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/instance/id')
57
+ .to_return(status: 200, body: 'test_instance_id')
58
+ subject = Instana::Snapshot::GoogleCloudRunInstance.new(metadata_uri: 'http://10.10.10.10/')
59
+ source = subject.source
60
+
61
+ assert source[:hl]
62
+ assert_equal 'gcp', source[:cp]
63
+ assert_equal 'test_instance_id', source[:e]
64
+ end
65
+
66
+ def test_host_name
67
+ ENV['K_REVISION'] = 'test_revision'
68
+ subject = Instana::Snapshot::GoogleCloudRunInstance.new(metadata_uri: 'http://10.10.10.10/')
69
+
70
+ assert_equal 'gcp:cloud-run:revision:test_revision', subject.host_name
71
+ ensure
72
+ ENV['K_REVISION'] = nil
73
+ end
74
+ end
@@ -0,0 +1,33 @@
1
+ # (c) Copyright IBM Corp. 2021
2
+ # (c) Copyright Instana Inc. 2021
3
+
4
+ require 'test_helper'
5
+
6
+ class GoogleCloudRunProcessTest < Minitest::Test
7
+ def test_snapshot
8
+ ENV['K_REVISION'] = 'test'
9
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/instance/id')
10
+ .to_return(status: 200, body: 'test_instance_id')
11
+
12
+ subject = Instana::Snapshot::GoogleCloudRunProcess.new(metadata_uri: 'http://10.10.10.10/')
13
+ snapshot = subject.snapshot
14
+
15
+ assert_equal Instana::Snapshot::GoogleCloudRunProcess::ID, snapshot[:name]
16
+ assert_equal 'test_instance_id', snapshot[:data][:container]
17
+ assert_equal 'gcpCloudRunInstance', snapshot[:data][:containerType]
18
+ assert_equal 'gcp:cloud-run:revision:test', snapshot[:data][:'com.instana.plugin.host.name']
19
+ ensure
20
+ ENV['K_REVISION'] = nil
21
+ end
22
+
23
+ def test_snapshot_error
24
+ stub_request(:get, 'http://10.10.10.10//computeMetadata/v1/instance/id')
25
+ .to_return(status: 500)
26
+
27
+ subject = Instana::Snapshot::GoogleCloudRunProcess.new(metadata_uri: 'http://10.10.10.10/')
28
+
29
+ assert_raises do
30
+ subject.snapshot
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.198.0.pre1
4
+ version: 1.199.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Giacomo Lombardo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-08 00:00:00.000000000 Z
11
+ date: 2021-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -262,6 +262,8 @@ files:
262
262
  - lib/instana/snapshot/fargate_container.rb
263
263
  - lib/instana/snapshot/fargate_process.rb
264
264
  - lib/instana/snapshot/fargate_task.rb
265
+ - lib/instana/snapshot/google_cloud_run_instance.rb
266
+ - lib/instana/snapshot/google_cloud_run_process.rb
265
267
  - lib/instana/snapshot/lambda_function.rb
266
268
  - lib/instana/snapshot/ruby_process.rb
267
269
  - lib/instana/tracer.rb
@@ -314,6 +316,8 @@ files:
314
316
  - test/snapshot/fargate_container_test.rb
315
317
  - test/snapshot/fargate_process_test.rb
316
318
  - test/snapshot/fargate_task_test.rb
319
+ - test/snapshot/google_cloud_run_instance_test.rb
320
+ - test/snapshot/google_cloud_run_process_test.rb
317
321
  - test/snapshot/lambda_function_test.rb
318
322
  - test/snapshot/ruby_process_test.rb
319
323
  - test/support/apps/active_record/active_record.rb
@@ -361,9 +365,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
361
365
  version: '2.1'
362
366
  required_rubygems_version: !ruby/object:Gem::Requirement
363
367
  requirements:
364
- - - ">"
368
+ - - ">="
365
369
  - !ruby/object:Gem::Version
366
- version: 1.3.1
370
+ version: '0'
367
371
  requirements: []
368
372
  rubygems_version: 3.2.6
369
373
  signing_key:
@@ -386,8 +390,10 @@ test_files:
386
390
  - test/snapshot/deltable_test.rb
387
391
  - test/snapshot/fargate_task_test.rb
388
392
  - test/snapshot/ruby_process_test.rb
393
+ - test/snapshot/google_cloud_run_process_test.rb
389
394
  - test/snapshot/lambda_function_test.rb
390
395
  - test/snapshot/fargate_container_test.rb
396
+ - test/snapshot/google_cloud_run_instance_test.rb
391
397
  - test/backend/host_agent_activation_observer_test.rb
392
398
  - test/backend/host_agent_reporting_observer_test.rb
393
399
  - test/backend/gc_snapshot_test.rb