Skip to content

Commit

Permalink
[ECS detector] Use conventions package constants (#3171)
Browse files Browse the repository at this point in the history
* Use conventions package constants

* Retrigger CI
  • Loading branch information
mx-psi authored Apr 19, 2021
1 parent ed6facc commit d3bf73b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions processor/resourcedetectionprocessor/internal/aws/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func (d *Detector) Detect(context.Context) (pdata.Resource, error) {
attr := res.Attributes()
attr.InsertString(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAWS)
attr.InsertString(conventions.AttributeCloudPlatform, conventions.AttributeCloudPlatformAWSECS)
attr.InsertString("aws.ecs.task.arn", tmdeResp.TaskARN)
attr.InsertString("aws.ecs.task.family", tmdeResp.Family)
attr.InsertString("aws.ecs.task.revision", tmdeResp.Revision)
attr.InsertString(conventions.AttributeAWSECSTaskARN, tmdeResp.TaskARN)
attr.InsertString(conventions.AttributeAWSECSTaskFamily, tmdeResp.Family)
attr.InsertString(conventions.AttributeAWSECSTaskRevision, tmdeResp.Revision)

region, account := parseRegionAndAccount(tmdeResp.TaskARN)
if account != "" {
Expand All @@ -81,7 +81,7 @@ func (d *Detector) Detect(context.Context) (pdata.Resource, error) {
}

// TMDE returns the the cluster short name or ARN, so we need to construct the ARN if necessary
attr.InsertString("aws.ecs.cluster.arn", constructClusterArn(tmdeResp.Cluster, region, account))
attr.InsertString(conventions.AttributeAWSECSClusterARN, constructClusterArn(tmdeResp.Cluster, region, account))

// The Availability Zone is not available in all Fargate runtimes
if tmdeResp.AvailabilityZone != "" {
Expand All @@ -91,10 +91,10 @@ func (d *Detector) Detect(context.Context) (pdata.Resource, error) {
// The launch type and log data attributes are only available in TMDE v4
switch lt := strings.ToLower(tmdeResp.LaunchType); lt {
case "ec2":
attr.InsertString("aws.ecs.launchtype", "ec2")
attr.InsertString(conventions.AttributeAWSECSLaunchType, "ec2")

case "fargate":
attr.InsertString("aws.ecs.launchtype", "fargate")
attr.InsertString(conventions.AttributeAWSECSLaunchType, "fargate")
}

selfMetaData, err := d.provider.fetchContainerMetaData(tmde)
Expand All @@ -103,7 +103,12 @@ func (d *Detector) Detect(context.Context) (pdata.Resource, error) {
return res, err
}

logAttributes := [4]string{"aws.log.group.names", "aws.log.group.arns", "aws.log.stream.names", "aws.log.stream.arns"}
logAttributes := [4]string{
conventions.AttributeAWSLogGroupNames,
conventions.AttributeAWSLogGroupARNs,
conventions.AttributeAWSLogStreamNames,
conventions.AttributeAWSLogStreamARNs,
}

for i, attribVal := range getValidLogData(tmdeResp.Containers, selfMetaData, account) {
if attribVal.ArrayVal().Len() > 0 {
Expand Down

0 comments on commit d3bf73b

Please sign in to comment.