Skip to content

Commit

Permalink
Automated sync with upstream - last commit 8bbdba8 - run #12.1 (#71)
Browse files Browse the repository at this point in the history
* Fix DetectAgentMode so auto resolves to onPrem if not ec2. (#652)

* Add branch feature for ec2 test (#647)

* Add branch feature for ec2 test

* Add branch feature for everything

* Update RELEASE_NOTES for 1.247356 (#649)

Co-authored-by: Jeffrey Chien <[email protected]>
Co-authored-by: Chena Lee <[email protected]>
Co-authored-by: Adam <[email protected]>
Co-authored-by: Kaushik Surya <[email protected]>
  • Loading branch information
5 people authored Dec 20, 2022
1 parent 47d76c1 commit f7ea3f0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}}
ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -418,6 +419,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}}
ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -519,6 +521,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}}
ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down Expand Up @@ -660,6 +663,7 @@ jobs:
- uses: actions/checkout@v2
with:
repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}}
ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
Expand Down
16 changes: 16 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
========================================================================
Amazon CloudWatch Agent 1.247356.0 (2022-11-10)
========================================================================

Enhancements:
* Enhance Windows event log monitoring in preparation for Windows 11 support (#627)
* Remove Amazon Open Telemetry Collector that was bundled with CloudWatch Agent (#522)
* Integration tests moved to new repository (#622) (#625) (#630)
* Update default metric list scraped via Prometheus (#581)

Bug fixes:
* Fix corner case where "retention_in_days" was not actually getting set (#554)
* Fix ethtool name in input config (#585)
* Fix "amazon-cloudwatch-agent-ctl stop" to use systemd related commands (#542)

========================================================================
Amazon CloudWatch Agent 1.247355.0 (2022-08-10)
========================================================================
Expand Down Expand Up @@ -392,3 +407,4 @@ operating systems:
* RedHat Enterprise Linux (RHEL) version 7.4, 7.0, and 6.5
* Debian 8.0
* Windows Server 2016, Windows Server 2012, and Windows Server 2008

12 changes: 7 additions & 5 deletions translator/util/sdkutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (

var DetectRegion = detectRegion
var DetectCredentialsPath = detectCredentialsPath
var DefaultEC2Region = defaultEC2Region
var DefaultECSRegion = defaultECSRegion
var runInAws = os.Getenv(config.RUN_IN_AWS)

func DetectAgentMode(configuredMode string) string {
Expand All @@ -37,17 +39,17 @@ func DetectAgentMode(configuredMode string) string {
return config.ModeEC2
}

if defaultEC2Region() != "" {
if DefaultEC2Region() != "" {
fmt.Println("I! Detected the instance is EC2")
return config.ModeEC2
}

if defaultECSRegion() != "" {
if DefaultECSRegion() != "" {
fmt.Println("I! Detected the instance is ECS")
return config.ModeEC2
}
fmt.Println("I! Detected the instance is OnPremise")
return configuredMode
return config.ModeOnPrem
}

func SDKRegionWithCredsMap(mode string, credsConfig map[string]string) (region string) {
Expand Down Expand Up @@ -94,13 +96,13 @@ func detectRegion(mode string, credsConfig map[string]string) (region string) {
// For ec2, fallback to metadata when no region info found in credential profile.
if region == "" && mode == config.ModeEC2 {
fmt.Println("I! Trying to detect region from ec2")
region = defaultEC2Region()
region = DefaultEC2Region()
}

// try to get region from ecs metadata
if region == "" && mode == config.ModeEC2 {
fmt.Println("I! Trying to detect region from ecs")
region = defaultECSRegion()
region = DefaultECSRegion()
}

return
Expand Down
31 changes: 31 additions & 0 deletions translator/util/sdkutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package util

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/aws/amazon-cloudwatch-agent/translator/config"
)

func TestDetectAgentModeAuto(t *testing.T) {
testCases := map[string]struct {
runInAws string
ec2Region string
ecsRegion string
wantMode string
}{
"WithRunInAWS": {runInAws: config.RUN_IN_AWS_TRUE, wantMode: config.ModeEC2},
"WithEC2Region": {ec2Region: "us-east-1", wantMode: config.ModeEC2},
"WithECSRegion": {ecsRegion: "us-east-1", wantMode: config.ModeEC2},
"WithNone": {wantMode: config.ModeOnPrem},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
runInAws = testCase.runInAws
DefaultEC2Region = func() string { return testCase.ec2Region }
DefaultECSRegion = func() string { return testCase.ecsRegion }
require.Equal(t, testCase.wantMode, DetectAgentMode("auto"))
})
}
}

0 comments on commit f7ea3f0

Please sign in to comment.