Skip to content

Commit

Permalink
Correctly obtain machine-type info from gce metadata (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington committed Jul 9, 2020
1 parent 52e6596 commit 00d9077
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (d *Detector) initializeHostAttributes(attr pdata.AttributeMap) []error {
attr.InsertString(conventions.AttributeHostName, name)
}

hostType, err := d.metadata.InstanceAttributeValue("instance/machine-type")
hostType, err := d.metadata.Get("instance/machine-type")
if err != nil {
errors = append(errors, err)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (m *mockMetadata) InstanceName() (string, error) {
return args.String(0), args.Error(1)
}

func (m *mockMetadata) InstanceAttributeValue(attr string) (string, error) {
args := m.MethodCalled("InstanceAttributeValue")
func (m *mockMetadata) Get(suffix string) (string, error) {
args := m.MethodCalled("Get")
return args.String(0), args.Error(1)
}

Expand All @@ -73,7 +73,7 @@ func TestDetectTrue(t *testing.T) {
md.On("Hostname").Return("hostname", nil)
md.On("InstanceID").Return("2", nil)
md.On("InstanceName").Return("name", nil)
md.On("InstanceAttributeValue").Return("machine-type", nil)
md.On("Get").Return("machine-type", nil)

detector := &Detector{metadata: md}
res, err := detector.Detect(context.Background())
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestDetectError(t *testing.T) {
md.On("Hostname").Return("", errors.New("err3"))
md.On("InstanceID").Return("", errors.New("err4"))
md.On("InstanceName").Return("", errors.New("err5"))
md.On("InstanceAttributeValue").Return("", errors.New("err6"))
md.On("Get").Return("", errors.New("err6"))

detector := &Detector{metadata: md}
res, err := detector.Detect(context.Background())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type gceMetadata interface {
Hostname() (string, error)
InstanceID() (string, error)
InstanceName() (string, error)
InstanceAttributeValue(attr string) (string, error)
Get(suffix string) (string, error)
}

type gceMetadataImpl struct{}
Expand Down Expand Up @@ -52,6 +52,6 @@ func (m *gceMetadataImpl) InstanceName() (string, error) {
return metadata.InstanceName()
}

func (m *gceMetadataImpl) InstanceAttributeValue(attr string) (string, error) {
return metadata.InstanceAttributeValue(attr)
func (m *gceMetadataImpl) Get(suffix string) (string, error) {
return metadata.Get(suffix)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ func TestGCEMetadata(t *testing.T) {
metadata.Hostname()
metadata.InstanceID()
metadata.InstanceName()
metadata.InstanceAttributeValue("")
metadata.Get("")
}

0 comments on commit 00d9077

Please sign in to comment.