Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Fix GCP metadata endpoint (#1350)
Browse files Browse the repository at this point in the history
* Fix GCP metadata endpoint

This was broken a few months ago:

- c295133#diff-e3a5b197b3f4e8bc25ffcc06c8e810caL27
- c295133#diff-6cfb951705f6c4b248a6d3c6faa23069R27

```
bash-4.3# curl -H "Metadata-Flavor: Google" http://metadata.google.pkg/computeMetadata/v1/instance/id
curl: (6) Could not resolve host: metadata.google.pkg

bash-4.3# curl "http://metadata.google.internal/computeMetadata/v1/instance/id" -H "Metadata-Flavor: Google"
3395187815902811713
```

Internal case: `00012827`

* Add debug log when GCP host id gathering fails

Co-authored-by: Ben Keith <[email protected]>
  • Loading branch information
pdecat and benkeith-splunk committed Jun 10, 2020
1 parent a2c0c82 commit b3bd676
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/core/hostid/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io/ioutil"
"net/http"
"time"

"github.com/sirupsen/logrus"
)

// GoogleComputeID generates a unique id for the compute instance that the
Expand All @@ -24,7 +26,7 @@ func GoogleComputeID() string {
}

func getMetadata(path string) string {
url := fmt.Sprintf("http://metadata.google.pkg/computeMetadata/v1/%s", path)
url := fmt.Sprintf("http://metadata.google.internal/computeMetadata/v1/%s", path)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
// This would only be due to a programming bug
Expand All @@ -39,6 +41,7 @@ func getMetadata(path string) string {

resp, err := c.Do(req)
if err != nil {
logrus.WithError(err).Debugf("Failed to query GCP Metadata endpoint at %s", url)
return ""
}
defer resp.Body.Close()
Expand Down

0 comments on commit b3bd676

Please sign in to comment.