Skip to content

Commit

Permalink
changes/fixes to metadata.cloud.* fields collected for GCP (#1415)
Browse files Browse the repository at this point in the history
* changes/fixes to metadata.cloud.* fields collected for GCP

- cloud.instance.id must be a string
- change cloud.project.id to be the 'projectId' (per spec change)
- drop cloud.project.name
- fix cloud.machine.type

Closes: #1414

* review feedback

Co-authored-by: Emily S <emily.s@elastic.co>

---------

Co-authored-by: Emily S <emily.s@elastic.co>
  • Loading branch information
trentm and estolfo committed Sep 18, 2023
1 parent 584fef4 commit c62fbc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
7 changes: 3 additions & 4 deletions lib/elastic_apm/metadata/cloud_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ def fetch_gcp
zone = metadata["instance"]["zone"]&.split("/")&.at(-1)

self.provider = "gcp"
self.instance_id = metadata["instance"]["id"]
self.instance_id = metadata["instance"]["id"].to_s
self.instance_name = metadata["instance"]["name"]
self.project_id = metadata["project"]["numericProjectId"]
self.project_name = metadata["project"]["projectId"]
self.project_id = metadata["project"]["projectId"]
self.availability_zone = zone
self.region = zone.split("-")[0..-2].join("-")
self.machine_type = metadata["instance"]["machineType"]
self.machine_type = metadata["instance"]["machineType"].split("/")[-1]
rescue HTTP::TimeoutError, HTTP::ConnectionError
nil
end
Expand Down
10 changes: 3 additions & 7 deletions spec/elastic_apm/metadata/cloud_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,12 @@ module CloudExamples
subject.fetch!

expect(subject.provider).to eq('gcp')
# rubocop:disable Style/NumericLiterals
expect(subject.instance_id).to eq(4306570268266786072)
expect(subject.instance_id).to eq("4306570268266786072")
expect(subject.instance_name).to eq("basepi-test")
expect(subject.project_id).to eq(513326162531)
# rubocop:enable Style/NumericLiterals
expect(subject.instance_name).to eq('basepi-test')
expect(subject.project_name).to eq('elastic-apm')
expect(subject.project_id).to eq('elastic-apm')
expect(subject.availability_zone).to eq('us-west3-a')
expect(subject.region).to eq('us-west3')
expect(subject.machine_type).to eq('projects/513326162531/machineTypes/n1-standard-1')
expect(subject.machine_type).to eq('n1-standard-1')

expect(@gcp_mock).to have_been_requested
end
Expand Down

0 comments on commit c62fbc5

Please sign in to comment.