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

Commit 60e8eb7

Browse files
committed
Make cloud provider metadata log more robust
Signed-off-by: Dani Louca <[email protected]>
1 parent 622d5d7 commit 60e8eb7

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

pkg/core/hostid/aws.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func AWSUniqueID(cloudMetadataTimeout timeutil.Duration) string {
2020
resp, err := c.Get("http://169.254.169.254/2014-11-05/dynamic/instance-identity/document")
2121
if err != nil {
2222
log.WithFields(log.Fields{
23-
"error": err,
24-
}).Debug("Failed to get AWS instance-identity")
23+
"detail": err,
24+
}).Info("No AWS metadata server detected, assuming not on EC2")
2525
return ""
2626
}
2727
defer resp.Body.Close()
@@ -30,7 +30,7 @@ func AWSUniqueID(cloudMetadataTimeout timeutil.Duration) string {
3030
if err != nil {
3131
log.WithFields(log.Fields{
3232
"error": err,
33-
}).Debug("Failed to read AWS instance-identity response")
33+
}).Info("Failed to read AWS instance-identity response")
3434
return ""
3535
}
3636

@@ -45,12 +45,12 @@ func AWSUniqueID(cloudMetadataTimeout timeutil.Duration) string {
4545
log.WithFields(log.Fields{
4646
"error": err,
4747
"body": string(body),
48-
}).Debug("Failed to unmarshal AWS instance-identity response")
48+
}).Info("Failed to unmarshal AWS instance-identity response")
4949
return ""
5050
}
5151

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

pkg/core/hostid/azure.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/signalfx/signalfx-agent/pkg/utils/timeutil"
11+
log "github.com/sirupsen/logrus"
1112
)
1213

1314
// AzureUniqueID constructs the unique ID of the underlying Azure VM. If
@@ -26,6 +27,9 @@ func AzureUniqueID(cloudMetadataTimeout timeutil.Duration) string {
2627
req.Header.Set("Metadata", "true")
2728
resp, err := c.Do(req)
2829
if err != nil {
30+
log.WithFields(log.Fields{
31+
"detail": err,
32+
}).Infof("No Azure metadata server detected, assuming not on Azure")
2933
return ""
3034
}
3135
defer resp.Body.Close()

pkg/core/hostid/gcp.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77

88
"github.com/signalfx/signalfx-agent/pkg/utils/timeutil"
9-
"github.com/sirupsen/logrus"
9+
log "github.com/sirupsen/logrus"
1010
)
1111

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

4242
resp, err := c.Do(req)
4343
if err != nil {
44-
logrus.WithError(err).Debugf("Failed to query GCP Metadata endpoint at %s", url)
44+
log.WithFields(log.Fields{
45+
"detail": err,
46+
}).Infof("No GCP metadata server detected at %s , assuming not on GCP", url)
4547
return ""
4648
}
4749
defer resp.Body.Close()

0 commit comments

Comments
 (0)