forked from aws/amazon-cloudwatch-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AppSignals] EC2 Support: awsappsignals processor updates (aws#669)
- Added a number of variables analogous to the EKS, K8s, and generic use case ones to support the new schema for EC2 - Added specific logic to account for the different customer use cases regarding HostedIn.EC2.Environment, i.e. the use of customer input for this variable vs. the use of ASG value.
- Loading branch information
1 parent
bbea252
commit e009c44
Showing
9 changed files
with
221 additions
and
1 deletion.
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
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
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
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,58 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package resolver | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
|
||
attr "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/internal/attributes" | ||
) | ||
|
||
const AttributePlatformEC2 = "EC2" | ||
|
||
var EC2HostedInAttributes = map[string]string{ | ||
attr.AWSHostedInEnvironment: attr.HostedInEC2Environment, | ||
} | ||
|
||
type ec2HostedInAttributeResolver struct { | ||
name string | ||
attributeMap map[string]string | ||
} | ||
|
||
func newEC2HostedInAttributeResolver(name string) *ec2HostedInAttributeResolver { | ||
if name == "" { | ||
name = AttributePlatformEC2 | ||
} | ||
return &ec2HostedInAttributeResolver{ | ||
name: name, | ||
attributeMap: map[string]string{ | ||
attr.EC2AutoScalingGroupName: attr.HostedInEC2Environment, | ||
}, | ||
} | ||
} | ||
func (h *ec2HostedInAttributeResolver) Process(attributes, resourceAttributes pcommon.Map) error { | ||
for attrKey, mappingKey := range h.attributeMap { | ||
if val, ok := resourceAttributes.Get(attrKey); ok { | ||
attributes.PutStr(mappingKey, val.AsString()) | ||
} | ||
} | ||
|
||
// If aws.hostedin.environment is populated, override HostedIn.EC2.Environment value | ||
// Otherwise, keep ASG name if it exists | ||
if val, ok := resourceAttributes.Get(attr.AWSHostedInEnvironment); ok { | ||
attributes.PutStr(attr.HostedInEC2Environment, val.AsString()) | ||
} else if val, ok := resourceAttributes.Get(attr.EC2AutoScalingGroupName); ok { | ||
attributes.PutStr(attr.HostedInEC2Environment, val.AsString()) | ||
} else { | ||
attributes.PutStr(attr.HostedInEC2Environment, h.name) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (h *ec2HostedInAttributeResolver) Stop(ctx context.Context) error { | ||
return nil | ||
} |
125 changes: 125 additions & 0 deletions
125
plugins/processors/awsappsignals/internal/resolver/ec2_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,125 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package resolver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
|
||
attr "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/internal/attributes" | ||
) | ||
|
||
func TestEC2HostedInAttributeResolverWithNoConfiguredName_NoASG_NoEnv(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("") | ||
|
||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, AttributePlatformEC2, envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithNoConfiguredName_ASGExists_NoEnv(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("") | ||
|
||
asgName := "ASG" | ||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
resourceAttributes.PutStr(attr.EC2AutoScalingGroupName, asgName) | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, asgName, envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithConfiguredName_NoASG_NoEnv(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("test") | ||
|
||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, "test", envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithConfiguredName_ASGExists_NoEnv(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("test") | ||
|
||
asgName := "ASG" | ||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
resourceAttributes.PutStr(attr.EC2AutoScalingGroupName, asgName) | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, asgName, envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithNoConfiguredName_NoASG_EnvExists(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("") | ||
|
||
envName := "my-env" | ||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, envName) | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, envName, envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithConfiguredName_NoASG_EnvExists(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("test") | ||
|
||
envName := "my-env" | ||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, envName) | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, envName, envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithNoConfiguredName_ASGExists_EnvExists(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("") | ||
|
||
asgName := "ASG" | ||
envName := "my-env" | ||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
resourceAttributes.PutStr(attr.EC2AutoScalingGroupName, asgName) | ||
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, envName) | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, envName, envAttr.AsString()) | ||
} | ||
|
||
func TestEC2HostedInAttributeResolverWithConfiguredName_ASGExists_EnvExists(t *testing.T) { | ||
resolver := newEC2HostedInAttributeResolver("test") | ||
|
||
asgName := "ASG" | ||
envName := "my-env" | ||
attributes := pcommon.NewMap() | ||
resourceAttributes := pcommon.NewMap() | ||
resourceAttributes.PutStr(attr.EC2AutoScalingGroupName, asgName) | ||
resourceAttributes.PutStr(attr.AWSHostedInEnvironment, envName) | ||
|
||
resolver.Process(attributes, resourceAttributes) | ||
envAttr, ok := attributes.Get(attr.HostedInEC2Environment) | ||
assert.True(t, ok) | ||
assert.Equal(t, envName, envAttr.AsString()) | ||
} |
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