Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly obtain machine-type info from gce metadata #395

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("")
}