forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
347 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
exporter/awsemfexporter/internal/entity/entityattributes.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package entity | ||
|
||
const ( | ||
// Entity resource attributes in OTLP payload | ||
AWSEntityPrefix = "com.amazonaws.cloudwatch.entity.internal." | ||
AttributeEntityType = AWSEntityPrefix + "type" | ||
AttributeEntityServiceName = AWSEntityPrefix + "service.name" | ||
AttributeEntityDeploymentEnvironment = AWSEntityPrefix + "deployment.environment" | ||
AttributeEntityK8sClusterName = AWSEntityPrefix + "k8s.cluster.name" | ||
AttributeEntityK8sNamespaceName = AWSEntityPrefix + "k8s.namespace.name" | ||
AttributeEntityK8sWorkloadName = AWSEntityPrefix + "k8s.workload.name" | ||
AttributeEntityK8sNodeName = AWSEntityPrefix + "k8s.node.name" | ||
AttributeEntityServiceNameSource = AWSEntityPrefix + "service.name.source" | ||
AttributeEntityPlatformType = AWSEntityPrefix + "platform.type" | ||
AttributeEntityInstanceID = AWSEntityPrefix + "instance.id" | ||
|
||
// Entity fields in EMF log | ||
Name = "Name" | ||
Environment = "Environment" | ||
EntityType = "Entity.Type" | ||
EksCluster = "EKS.Cluster" | ||
K8sCluster = "K8s.Cluster" | ||
K8sNamespace = "K8s.Namespace" | ||
K8sWorkload = "K8s.Workload" | ||
K8sNode = "K8s.Node" | ||
AWSServiceNameSource = "AWS.ServiceNameSource" | ||
PlatformType = "PlatformType" | ||
InstanceID = "EC2.InstanceId" | ||
|
||
// Possible values for PlatformType | ||
AttributeEntityEKSPlatform = "AWS::EKS" | ||
AttributeEntityK8sPlatform = "K8s" | ||
) | ||
|
||
// attributeEntityToFieldMap maps attribute entity resource attributes to entity fields | ||
var attributeEntityToFieldMap = map[string]string{ | ||
AttributeEntityType: EntityType, | ||
AttributeEntityServiceName: Name, | ||
AttributeEntityDeploymentEnvironment: Environment, | ||
AttributeEntityK8sNamespaceName: K8sNamespace, | ||
AttributeEntityK8sWorkloadName: K8sWorkload, | ||
AttributeEntityK8sNodeName: K8sNode, | ||
AttributeEntityPlatformType: PlatformType, | ||
AttributeEntityInstanceID: InstanceID, | ||
AttributeEntityServiceNameSource: AWSServiceNameSource, | ||
} | ||
|
||
// GetEntityField returns entity field for provided attribute | ||
func GetEntityField(attribute string, value ...string) string { | ||
if attribute == AttributeEntityK8sClusterName && len(value) == 1 { | ||
switch value[0] { | ||
case AttributeEntityEKSPlatform: | ||
return EksCluster | ||
case AttributeEntityK8sPlatform: | ||
return K8sCluster | ||
} | ||
} | ||
|
||
if field, ok := attributeEntityToFieldMap[attribute]; ok { | ||
return field | ||
} | ||
|
||
return "" | ||
} |
110 changes: 110 additions & 0 deletions
110
exporter/awsemfexporter/internal/entity/entityattributes_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package entity | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetEntityField(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
attribute string | ||
values []string | ||
want string | ||
}{ | ||
{ | ||
name: "AttributeEntityType from map", | ||
attribute: AttributeEntityType, | ||
values: nil, | ||
want: EntityType, | ||
}, | ||
{ | ||
name: "AttributeEntityServiceName from map", | ||
attribute: AttributeEntityServiceName, | ||
values: nil, | ||
want: Name, | ||
}, | ||
{ | ||
name: "AttributeEntityDeploymentEnvironment from map", | ||
attribute: AttributeEntityDeploymentEnvironment, | ||
values: nil, | ||
want: Environment, | ||
}, | ||
{ | ||
name: "AttributeEntityK8sNamespaceName from map", | ||
attribute: AttributeEntityK8sNamespaceName, | ||
values: nil, | ||
want: K8sNamespace, | ||
}, | ||
{ | ||
name: "AttributeEntityK8sWorkloadName from map", | ||
attribute: AttributeEntityK8sWorkloadName, | ||
values: nil, | ||
want: K8sWorkload, | ||
}, | ||
{ | ||
name: "AttributeEntityK8sNodeName from map", | ||
attribute: AttributeEntityK8sNodeName, | ||
values: nil, | ||
want: K8sNode, | ||
}, | ||
{ | ||
name: "AttributeEntityPlatformType from map", | ||
attribute: AttributeEntityPlatformType, | ||
values: nil, | ||
want: PlatformType, | ||
}, | ||
{ | ||
name: "AttributeEntityInstanceID from map", | ||
attribute: AttributeEntityInstanceID, | ||
values: nil, | ||
want: InstanceID, | ||
}, | ||
{ | ||
name: "AttributeEntityServiceNameSource from map", | ||
attribute: AttributeEntityServiceNameSource, | ||
values: nil, | ||
want: AWSServiceNameSource, | ||
}, | ||
{ | ||
name: "K8sClusterName with EKSPlatform", | ||
attribute: AttributeEntityK8sClusterName, | ||
values: []string{AttributeEntityEKSPlatform}, | ||
want: EksCluster, | ||
}, | ||
{ | ||
name: "K8sClusterName with K8sPlatform", | ||
attribute: AttributeEntityK8sClusterName, | ||
values: []string{AttributeEntityK8sPlatform}, | ||
want: K8sCluster, | ||
}, | ||
{ | ||
name: "K8sClusterName with unknown platform", | ||
attribute: AttributeEntityK8sClusterName, | ||
values: []string{"unknown"}, | ||
want: "", | ||
}, | ||
{ | ||
name: "Unknown attribute", | ||
attribute: "unknown", | ||
values: nil, | ||
want: "", | ||
}, | ||
{ | ||
name: "K8sClusterName with no values provided", | ||
attribute: AttributeEntityK8sClusterName, | ||
values: nil, | ||
want: "", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := GetEntityField(tc.attribute, tc.values...) | ||
assert.Equalf(t, tc.want, got, | ||
"GetEntityField(%q, %v) = %q; want %q", | ||
tc.attribute, tc.values, got, tc.want) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.