forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 27
Add service entity support for EMF exporter #291
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68e55f7
Add service entity support for EMF exporter (#275)
musa-asad 5c0c14a
Merge branch 'aws-cwa-dev' into feature-custom-metrics-entity
musa-asad 7b50088
Merge branch 'aws-cwa-dev' into feature-custom-metrics-entity
musa-asad 1b920e1
Merge branch 'aws-cwa-dev' into feature-custom-metrics-entity
musa-asad d2a9399
Merge branch 'aws-cwa-dev' into feature-custom-metrics-entity
musa-asad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package entity // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter/internal/entity" | ||
|
||
const ( | ||
// Entity resource attributes in OTLP payload | ||
AWSEntityPrefix = "com.amazonaws.cloudwatch.entity.internal." | ||
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 | ||
Service = "Service" | ||
Environment = "Environment" | ||
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{ | ||
AttributeEntityServiceName: Service, | ||
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, platform string) string { | ||
if attribute == AttributeEntityK8sClusterName { | ||
switch platform { | ||
case AttributeEntityEKSPlatform: | ||
return EksCluster | ||
case AttributeEntityK8sPlatform: | ||
return K8sCluster | ||
} | ||
} | ||
|
||
if field, ok := attributeEntityToFieldMap[attribute]; ok { | ||
return field | ||
} | ||
|
||
return "" | ||
} |
107 changes: 107 additions & 0 deletions
107
exporter/awsemfexporter/internal/entity/entityattributes_test.go
This file contains hidden or 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,107 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package entity | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetEntityField(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
attribute string | ||
value string | ||
want string | ||
}{ | ||
{ | ||
name: "AttributeEntityServiceName from map", | ||
attribute: AttributeEntityServiceName, | ||
value: "", | ||
want: Service, | ||
}, | ||
{ | ||
name: "AttributeEntityDeploymentEnvironment from map", | ||
attribute: AttributeEntityDeploymentEnvironment, | ||
value: "", | ||
want: Environment, | ||
}, | ||
{ | ||
name: "AttributeEntityK8sNamespaceName from map", | ||
attribute: AttributeEntityK8sNamespaceName, | ||
value: "", | ||
want: K8sNamespace, | ||
}, | ||
{ | ||
name: "AttributeEntityK8sWorkloadName from map", | ||
attribute: AttributeEntityK8sWorkloadName, | ||
value: "", | ||
want: K8sWorkload, | ||
}, | ||
{ | ||
name: "AttributeEntityK8sNodeName from map", | ||
attribute: AttributeEntityK8sNodeName, | ||
value: "", | ||
want: K8sNode, | ||
}, | ||
{ | ||
name: "AttributeEntityPlatformType from map", | ||
attribute: AttributeEntityPlatformType, | ||
value: "", | ||
want: PlatformType, | ||
}, | ||
{ | ||
name: "AttributeEntityInstanceID from map", | ||
attribute: AttributeEntityInstanceID, | ||
value: "", | ||
want: InstanceID, | ||
}, | ||
{ | ||
name: "AttributeEntityServiceNameSource from map", | ||
attribute: AttributeEntityServiceNameSource, | ||
value: "", | ||
want: AWSServiceNameSource, | ||
}, | ||
{ | ||
name: "K8sClusterName with EKSPlatform", | ||
attribute: AttributeEntityK8sClusterName, | ||
value: AttributeEntityEKSPlatform, | ||
want: EksCluster, | ||
}, | ||
{ | ||
name: "K8sClusterName with K8sPlatform", | ||
attribute: AttributeEntityK8sClusterName, | ||
value: AttributeEntityK8sPlatform, | ||
want: K8sCluster, | ||
}, | ||
{ | ||
name: "K8sClusterName with unknown platform", | ||
attribute: AttributeEntityK8sClusterName, | ||
value: "unknown", | ||
want: "", | ||
}, | ||
{ | ||
name: "Unknown attribute", | ||
attribute: "unknown", | ||
value: "", | ||
want: "", | ||
}, | ||
{ | ||
name: "K8sClusterName with no values provided", | ||
attribute: AttributeEntityK8sClusterName, | ||
value: "", | ||
want: "", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := GetEntityField(tc.attribute, tc.value) | ||
assert.Equalf(t, tc.want, got, | ||
"GetEntityField(%q, %v) = %q; want %q", | ||
tc.attribute, tc.value, got, tc.want) | ||
}) | ||
} | ||
} |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.