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.
Merge branch 'main-compass' into compass-ga2-rebase
- Loading branch information
Showing
196 changed files
with
47,556 additions
and
2,410 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: MIT | ||
|
||
name: Compass Beta Release | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
BuildAndUpload: | ||
uses: ./.github/workflows/test-build.yml | ||
secrets: inherit | ||
permissions: | ||
id-token: write | ||
contents: read | ||
with: | ||
BucketKey: "compass-beta-release" | ||
PackageBucketKey: "compass-beta-release" | ||
TerraformAWSAssumeRole: ${{ vars.TERRAFORM_AWS_ASSUME_ROLE }} | ||
Bucket: "private-cloudwatch-agent-integration-test" | ||
|
||
BuildAndUploadContainer: | ||
uses: ./.github/workflows/test-build-docker.yml | ||
secrets: inherit | ||
permissions: | ||
id-token: write | ||
contents: read | ||
with: | ||
ContainerRepositoryNameAndTag: "cwagent-compass-beta-release:latest" | ||
BucketKey: "compass-beta-release" | ||
PackageBucketKey: "compass-beta-release" |
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,19 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package entitystore | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
type Config struct { | ||
Mode string `mapstructure:"mode"` | ||
KubernetesMode string `mapstructure:"kubernetes_mode,omitempty"` | ||
Region string `mapstructure:"region"` | ||
Profile string `mapstructure:"profile,omitempty"` | ||
RoleARN string `mapstructure:"role_arn,omitempty"` | ||
Filename string `mapstructure:"shared_credential_file,omitempty"` | ||
} | ||
|
||
var _ component.Config = (*Config)(nil) |
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,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package entitystore | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/confmap" | ||
) | ||
|
||
func TestUnmarshalDefaultConfig(t *testing.T) { | ||
factory := NewFactory() | ||
cfg := factory.CreateDefaultConfig() | ||
assert.NoError(t, confmap.New().Unmarshal(cfg)) | ||
assert.Equal(t, factory.CreateDefaultConfig(), cfg) | ||
} |
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,144 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package entitystore | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
"time" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent/internal/ec2metadataprovider" | ||
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/ec2tagger" | ||
) | ||
|
||
const ( | ||
// InstanceId character maximum length is 19. | ||
// See https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_Instance.html. | ||
instanceIdSizeMax = 19 | ||
|
||
// AutoScalingGroup character maximum length is 255. | ||
// See https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_AutoScalingGroup.html. | ||
autoScalingGroupSizeMax = 255 | ||
) | ||
|
||
type EC2Info struct { | ||
InstanceID string | ||
AccountID string | ||
AutoScalingGroup string | ||
|
||
// region is used while making call to describeTags Ec2 API for AutoScalingGroup | ||
Region string | ||
|
||
metadataProvider ec2metadataprovider.MetadataProvider | ||
logger *zap.Logger | ||
done chan struct{} | ||
} | ||
|
||
func (ei *EC2Info) initEc2Info() { | ||
ei.logger.Debug("Initializing EC2Info") | ||
if err := ei.setInstanceIDAccountID(); err != nil { | ||
return | ||
} | ||
if err := ei.setAutoScalingGroup(); err != nil { | ||
return | ||
} | ||
ei.logger.Debug("Finished initializing EC2Info") | ||
ei.ignoreInvalidFields() | ||
} | ||
|
||
func (ei *EC2Info) setInstanceIDAccountID() error { | ||
for { | ||
metadataDoc, err := ei.metadataProvider.Get(context.Background()) | ||
if err != nil { | ||
ei.logger.Warn("Failed to get Instance ID / Account ID through metadata provider", zap.Error(err)) | ||
wait := time.NewTimer(1 * time.Minute) | ||
select { | ||
case <-ei.done: | ||
wait.Stop() | ||
return errors.New("shutdown signal received") | ||
case <-wait.C: | ||
continue | ||
} | ||
} | ||
ei.logger.Debug("Successfully retrieved Instance ID and Account ID") | ||
ei.InstanceID = metadataDoc.InstanceID | ||
ei.AccountID = metadataDoc.AccountID | ||
return nil | ||
} | ||
} | ||
|
||
func (ei *EC2Info) setAutoScalingGroup() error { | ||
retry := 0 | ||
for { | ||
var waitDuration time.Duration | ||
if retry < len(ec2tagger.BackoffSleepArray) { | ||
waitDuration = ec2tagger.BackoffSleepArray[retry] | ||
} else { | ||
waitDuration = ec2tagger.BackoffSleepArray[len(ec2tagger.BackoffSleepArray)-1] | ||
} | ||
|
||
wait := time.NewTimer(waitDuration) | ||
select { | ||
case <-ei.done: | ||
wait.Stop() | ||
return errors.New("shutdown signal received") | ||
case <-wait.C: | ||
} | ||
|
||
if retry > 0 { | ||
ei.logger.Debug("Initial retrieval of tags and volumes", zap.Int("retry", retry)) | ||
} | ||
|
||
if err := ei.retrieveAsgName(); err != nil { | ||
ei.logger.Warn("Unable to fetch instance tags with imds", zap.Int("retry", retry), zap.Error(err)) | ||
} else { | ||
ei.logger.Debug("Retrieval of auto-scaling group tags succeeded") | ||
return nil | ||
} | ||
|
||
retry++ | ||
} | ||
|
||
} | ||
|
||
func (ei *EC2Info) retrieveAsgName() error { | ||
tags, err := ei.metadataProvider.InstanceTags(context.Background()) | ||
if err != nil { | ||
ei.logger.Debug("Failed to get tags through metadata provider", zap.Error(err)) | ||
return err | ||
} else if strings.Contains(tags, ec2tagger.Ec2InstanceTagKeyASG) { | ||
asg, err := ei.metadataProvider.InstanceTagValue(context.Background(), ec2tagger.Ec2InstanceTagKeyASG) | ||
if err != nil { | ||
ei.logger.Error("Failed to get AutoScalingGroup through metadata provider", zap.Error(err)) | ||
} else { | ||
ei.logger.Debug("AutoScalingGroup retrieved through IMDS") | ||
ei.AutoScalingGroup = asg | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func newEC2Info(metadataProvider ec2metadataprovider.MetadataProvider, done chan struct{}, region string, logger *zap.Logger) *EC2Info { | ||
return &EC2Info{ | ||
metadataProvider: metadataProvider, | ||
done: done, | ||
Region: region, | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (ei *EC2Info) ignoreInvalidFields() { | ||
if idLength := len(ei.InstanceID); idLength > instanceIdSizeMax { | ||
ei.logger.Warn("InstanceId length exceeds characters limit and will be ignored", zap.Int("length", idLength), zap.Int("character limit", instanceIdSizeMax)) | ||
ei.InstanceID = "" | ||
} | ||
|
||
if asgLength := len(ei.AutoScalingGroup); asgLength > autoScalingGroupSizeMax { | ||
ei.logger.Warn("AutoScalingGroup length exceeds characters limit and will be ignored", zap.Int("length", asgLength), zap.Int("character limit", autoScalingGroupSizeMax)) | ||
ei.AutoScalingGroup = "" | ||
} | ||
} |
Oops, something went wrong.