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

Commit

Permalink
Make cloud provider metadata log more robust (#1620)
Browse files Browse the repository at this point in the history
Signed-off-by: Dani Louca <[email protected]>
  • Loading branch information
dloucasfx authored Mar 5, 2021
1 parent 27115e1 commit 8b4d34d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/core/hostid/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func AWSUniqueID(cloudMetadataTimeout timeutil.Duration) string {
resp, err := c.Get("http://169.254.169.254/2014-11-05/dynamic/instance-identity/document")
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Debug("Failed to get AWS instance-identity")
"detail": err,
}).Info("No AWS metadata server detected, assuming not on EC2")
return ""
}
defer resp.Body.Close()
Expand All @@ -30,7 +30,7 @@ func AWSUniqueID(cloudMetadataTimeout timeutil.Duration) string {
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Debug("Failed to read AWS instance-identity response")
}).Info("Failed to read AWS instance-identity response")
return ""
}

Expand All @@ -45,12 +45,12 @@ func AWSUniqueID(cloudMetadataTimeout timeutil.Duration) string {
log.WithFields(log.Fields{
"error": err,
"body": string(body),
}).Debug("Failed to unmarshal AWS instance-identity response")
}).Info("Failed to unmarshal AWS instance-identity response")
return ""
}

if doc.AccountID == "" || doc.InstanceID == "" || doc.Region == "" {
log.Debugf("One (or more) required field is empty. AccountID: %s ; InstanceID: %s ; Region: %s", doc.AccountID, doc.InstanceID, doc.Region)
log.Errorf("One (or more) required field is empty. AccountID: %s ; InstanceID: %s ; Region: %s", doc.AccountID, doc.InstanceID, doc.Region)
return ""
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/core/hostid/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/signalfx/signalfx-agent/pkg/utils/timeutil"
log "github.com/sirupsen/logrus"
)

// AzureUniqueID constructs the unique ID of the underlying Azure VM. If
Expand All @@ -26,6 +27,9 @@ func AzureUniqueID(cloudMetadataTimeout timeutil.Duration) string {
req.Header.Set("Metadata", "true")
resp, err := c.Do(req)
if err != nil {
log.WithFields(log.Fields{
"detail": err,
}).Infof("No Azure metadata server detected, assuming not on Azure")
return ""
}
defer resp.Body.Close()
Expand Down
6 changes: 4 additions & 2 deletions pkg/core/hostid/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"

"github.com/signalfx/signalfx-agent/pkg/utils/timeutil"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)

// GoogleComputeID generates a unique id for the compute instance that the
Expand Down Expand Up @@ -41,7 +41,9 @@ func getMetadata(path string, cloudMetadataTimeout timeutil.Duration) string {

resp, err := c.Do(req)
if err != nil {
logrus.WithError(err).Debugf("Failed to query GCP Metadata endpoint at %s", url)
log.WithFields(log.Fields{
"detail": err,
}).Infof("No GCP metadata server detected at %s , assuming not on GCP", url)
return ""
}
defer resp.Body.Close()
Expand Down

0 comments on commit 8b4d34d

Please sign in to comment.