From 5204d27fd5ab645060c5f07d746404b6b8ca54df Mon Sep 17 00:00:00 2001 From: bhautikpip Date: Tue, 9 Feb 2021 17:24:15 -0800 Subject: [PATCH] minor changes to address review comments --- detectors/aws/ecs/ecs.go | 22 +++++++++++----------- detectors/aws/ecs/ecs_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/detectors/aws/ecs/ecs.go b/detectors/aws/ecs/ecs.go index 57376e876e9..2e21bb080b0 100644 --- a/detectors/aws/ecs/ecs.go +++ b/detectors/aws/ecs/ecs.go @@ -43,28 +43,28 @@ var ( ) // Create interface for methods needing to be mocked -type detectorUtilsResources interface { +type detectorUtils interface { getContainerName() (string, error) getContainerID() (string, error) } -// struct implements detectorUtilsResources interface -type DetectorUtils struct{} +// struct implements detectorUtils interface +type ecsDetectorUtils struct{} // resource detector collects resource information from Elastic Container Service environment type resourceDetector struct { - utils detectorUtilsResources + utils detectorUtils } -// compile time assertion that ecsDetectorUtils implements detectorUtilsResources interface -var _ detectorUtilsResources = (*DetectorUtils)(nil) +// compile time assertion that ecsDetectorUtils implements detectorUtils interface +var _ detectorUtils = (*ecsDetectorUtils)(nil) // compile time assertion that resource detector implements the resource.Detector interface. var _ resource.Detector = (*resourceDetector)(nil) -// returns resource detector struct -func NewResourceDetector(detectorUtils detectorUtilsResources) resource.Detector { - return &resourceDetector{utils: detectorUtils} +// NewResourceDetector returns a resource detector that will detect AWS ECS resources. +func NewResourceDetector() resource.Detector { + return &resourceDetector{utils: ecsDetectorUtils{}} } // Detect finds associated resources when running on ECS environment. @@ -92,7 +92,7 @@ func (detector *resourceDetector) Detect(ctx context.Context) (*resource.Resourc } // returns docker container ID from default c group path -func (ecsUtils DetectorUtils) getContainerID() (string, error) { +func (ecsUtils ecsDetectorUtils) getContainerID() (string, error) { fileData, err := ioutil.ReadFile(defaultCgroupPath) if err != nil { return "", errCannotReadCGroupFile @@ -107,7 +107,7 @@ func (ecsUtils DetectorUtils) getContainerID() (string, error) { } // returns host name reported by the kernel -func (ecsUtils DetectorUtils) getContainerName() (string, error) { +func (ecsUtils ecsDetectorUtils) getContainerName() (string, error) { hostName, err := os.Hostname() if err != nil { return "", errCannotReadContainerName diff --git a/detectors/aws/ecs/ecs_test.go b/detectors/aws/ecs/ecs_test.go index fda1d4ba210..c7719102818 100644 --- a/detectors/aws/ecs/ecs_test.go +++ b/detectors/aws/ecs/ecs_test.go @@ -58,7 +58,7 @@ func TestDetect(t *testing.T) { semconv.ContainerIDKey.String("0123456789A"), } expectedResource := resource.NewWithAttributes(labels...) - detector := NewResourceDetector(detectorUtils) + detector := &resourceDetector{utils: detectorUtils} res, _ := detector.Detect(context.Background()) assert.Equal(t, res, expectedResource, "Resource returned is incorrect") @@ -74,7 +74,7 @@ func TestDetectCannotReadContainerID(t *testing.T) { detectorUtils.On("getContainerName").Return("container-Name", nil) detectorUtils.On("getContainerID").Return("", errCannotReadContainerID) - detector := NewResourceDetector(detectorUtils) + detector := &resourceDetector{utils: detectorUtils} res, err := detector.Detect(context.Background()) assert.Equal(t, errCannotReadContainerID, err) @@ -91,7 +91,7 @@ func TestDetectCannotReadContainerName(t *testing.T) { detectorUtils.On("getContainerName").Return("", errCannotReadContainerName) detectorUtils.On("getContainerID").Return("0123456789A", nil) - detector := NewResourceDetector(detectorUtils) + detector := &resourceDetector{utils: detectorUtils} res, err := detector.Detect(context.Background()) assert.Equal(t, errCannotReadContainerName, err) @@ -101,7 +101,7 @@ func TestDetectCannotReadContainerName(t *testing.T) { //returns empty resource when process is not running ECS func TestReturnsIfNoEnvVars(t *testing.T) { os.Clearenv() - detector := NewResourceDetector(nil) + detector := &resourceDetector{utils: nil} res, err := detector.Detect(context.Background()) assert.Equal(t, errNotOnECS, err)