Skip to content

Commit

Permalink
Change 'cloud.project.id' for GCP metadata to be the 'project-id'
Browse files Browse the repository at this point in the history
Closes: elastic#1509
  • Loading branch information
trentm committed Sep 15, 2023
1 parent 1782142 commit 1b483d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 3 additions & 8 deletions internal/apmcloudutil/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"fmt"
"net/http"
"path"
"strconv"
"strings"

"go.elastic.co/apm/v2/model"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions internal/apmcloudutil/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -73,8 +72,7 @@ func TestGCPCloudMetadata(t *testing.T) {
ID: "00bf4bf02ddbda278fb9b4d70365018bd18a7d3ea42991e2cb03320b48a72b69b6d3765ff526347d7b8e0934dda4591cb1be3ead93086f0b390187fae88ee7cf8acdae7383",
},
Project: &model.CloudProject{
ID: "513326162531",
Name: "elastic-apm",
ID: "elastic-apm",
},
}, out)
})
Expand Down

0 comments on commit 1b483d5

Please sign in to comment.