instana 1.198.0 → 1.199.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/instana/backend/agent.rb +6 -0
- data/lib/instana/setup.rb +2 -0
- data/lib/instana/snapshot/google_cloud_run_instance.rb +69 -0
- data/lib/instana/snapshot/google_cloud_run_process.rb +58 -0
- data/lib/instana/version.rb +1 -1
- data/test/backend/agent_test.rb +13 -0
- data/test/snapshot/google_cloud_run_instance_test.rb +74 -0
- data/test/snapshot/google_cloud_run_process_test.rb +33 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86a3e023781d52d3b5efd25c9b5d304520dd3c88aecde954c326bd736abae787
|
4
|
+
data.tar.gz: b6c7bf11431925b9a48b827b5adbb52d93cb1f1f44bde1ebef98bd89f2188cb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2045faa632b6edc00e4dba26feb69d5249c755698a0dac2adeaa0e2b1cbe65f7f37682f7b59a1d3d000f8908dbee85c4f0356da333f02e874361b5861cfcc3f
|
7
|
+
data.tar.gz: e1b3983ace1be9653732b033902c7f59a74dce020ebfb585e02cf3dfdd1c2e7eb50df4cff9ff4eb8467df3a57b3208165efe659d97073bd6bc97f9e2bdd62fa0
|
@@ -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
|
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
|
data/lib/instana/version.rb
CHANGED
data/test/backend/agent_test.rb
CHANGED
@@ -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
|
@@ -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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.199.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Giacomo Lombardo
|
@@ -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
|
@@ -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
|