From 1b483d56ef17698d4f78a150f7fa06158601c79c Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 14 Sep 2023 17:27:46 -0700 Subject: [PATCH] Change 'cloud.project.id' for GCP metadata to be the 'project-id' Closes: #1509 --- internal/apmcloudutil/gcp.go | 11 +++-------- internal/apmcloudutil/gcp_test.go | 6 ++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/internal/apmcloudutil/gcp.go b/internal/apmcloudutil/gcp.go index fc2d291c1..f2034d299 100644 --- a/internal/apmcloudutil/gcp.go +++ b/internal/apmcloudutil/gcp.go @@ -24,7 +24,6 @@ import ( "fmt" "net/http" "path" - "strconv" "strings" "go.elastic.co/apm/v2/model" @@ -60,8 +59,7 @@ func getGCPCloudMetadata(ctx context.Context, client *http.Client, out *model.Cl Zone string `json:"zone"` } `json:"instance"` Project struct { - NumericProjectID *int `json:"numericProjectId"` - ProjectID string `json:"projectId"` + ProjectID string `json:"projectId"` } `json:"project"` } decoder := json.NewDecoder(resp.Body) @@ -82,11 +80,8 @@ func getGCPCloudMetadata(ctx context.Context, client *http.Client, out *model.Cl if gcpMetadata.Instance.MachineType != "" { out.Machine = &model.CloudMachine{Type: splitGCPMachineType(gcpMetadata.Instance.MachineType)} } - if gcpMetadata.Project.NumericProjectID != nil || gcpMetadata.Project.ProjectID != "" { - out.Project = &model.CloudProject{Name: gcpMetadata.Project.ProjectID} - if gcpMetadata.Project.NumericProjectID != nil { - out.Project.ID = strconv.Itoa(*gcpMetadata.Project.NumericProjectID) - } + if gcpMetadata.Project.ProjectID != "" { + out.Project = &model.CloudProject{ID: gcpMetadata.Project.ProjectID} } return nil } diff --git a/internal/apmcloudutil/gcp_test.go b/internal/apmcloudutil/gcp_test.go index ecfa82865..ea110ad60 100644 --- a/internal/apmcloudutil/gcp_test.go +++ b/internal/apmcloudutil/gcp_test.go @@ -50,8 +50,7 @@ func TestGCPCloudMetadata(t *testing.T) { Type: "n1-standard-1", }, Project: &model.CloudProject{ - ID: "513326162531", - Name: "elastic-apm", + ID: "elastic-apm", }, }, out) } @@ -73,8 +72,7 @@ func TestGCPCloudMetadata(t *testing.T) { ID: "00bf4bf02ddbda278fb9b4d70365018bd18a7d3ea42991e2cb03320b48a72b69b6d3765ff526347d7b8e0934dda4591cb1be3ead93086f0b390187fae88ee7cf8acdae7383", }, Project: &model.CloudProject{ - ID: "513326162531", - Name: "elastic-apm", + ID: "elastic-apm", }, }, out) })