Skip to content

Commit

Permalink
Merge branch 'main' into container-insights-sll
Browse files Browse the repository at this point in the history
  • Loading branch information
bhanuba authored Oct 2, 2023
2 parents dac0a37 + 6977931 commit 5dcfd70
Show file tree
Hide file tree
Showing 105 changed files with 2,413 additions and 4,637 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/PR-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
if: needs.changes.outputs.lint == 'true'
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7
cache: false

- name: Check out code
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
if: needs.changes.outputs.build == 'true'
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7
cache: false

- name: Check out code
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7

- name: Generate matrix
id: set-matrix
Expand Down Expand Up @@ -327,7 +327,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7

- name: SetOutputs
id: set-outputs
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/otel-fork-replace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7
cache: false
- name: Update OTel fork components version
id: set-matrix
Expand Down Expand Up @@ -64,6 +64,8 @@ jobs:
go mod tidy
go mod edit -replace github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws=github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws@${{ steps.get-latest-commit.outputs.sha }}
go mod tidy
go mod edit -replace github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza=github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza@${{ steps.get-latest-commit.outputs.sha }}
go mod tidy
git commit -am "Update OTel fork components to https://github.com/amazon-contributing/opentelemetry-collector-contrib/commit/${{ steps.get-latest-commit.outputs.sha }}"
git push -u origin HEAD
git config --global --unset user.name
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7
cache: false

- name: Install rpm
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand Down Expand Up @@ -226,7 +226,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ~1.19.6
go-version: ~1.20.7

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
Expand Down
39 changes: 29 additions & 10 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
========================================================================
Amazon CloudWatch Agent 1.300026.3 (2022-08-22)
Amazon CloudWatch Agent 1.300028.1 (2023-09-18)
========================================================================

Bug fixes:
* Fix windows event logs to start only once

========================================================================
Amazon CloudWatch Agent 1.300028.0 (2023-09-11)
========================================================================

Bug fixes:
* Fix file pattern matching to support glob wildcard characters (!{})
* Use LogStreamName instead of ServiceName in token replacement for Prometheus
* Add fallback shared config files for credential ordering to maintain previous AWS SDK behavior
* Drop unsupported NaN, Inf, and out of range values

Enhancements:
* Try using IMDSv2 only first before using client with fallback
* Add support for configurable IMDS retries in the common-config.toml
* Add support for traces in agent configuration wizard
* Remove misleading metric filter warning

========================================================================
Amazon CloudWatch Agent 1.300026.3 (2023-08-22)
========================================================================

Bug fixes:
Expand All @@ -8,32 +31,28 @@ Bug fixes:
* Update config translation to respect common config profile and creds file (@e2ef915)
* Remove plugin key allowlist for metric decorator (@47a5e47)

Enhancements:
* Remove local trace test (@a96897f)

========================================================================
Amazon CloudWatch Agent 1.300026.2 (2022-08-10)
Amazon CloudWatch Agent 1.300026.2 (2023-08-10)
========================================================================

Bug fixes:
* Add expandconverter to config provider (@24592ba)
* Pin aws sdk to v1.44.106 since the defaults for root creds changed in future versions (@048809e)
* Update OTel fork components to 24607924fd49654505e942fe5768a1a288866b39 (@9a259d5)
* Pin AWS SDK to v1.44.106 since the defaults for root creds changed in future versions (@048809e)
* Add Endpoint Override To EMF And Only Publish EMF Logs (@db03fb6)
* Revert "Add Retry To IMDS Client" (@a367c86)

Enhancements:
* Removed warn log message for empty fields in telegraph metrics (@fd1b308)

========================================================================
Amazon CloudWatch Agent 1.300026.1 (2022-08-04)
Amazon CloudWatch Agent 1.300026.1 (2023-08-04)
========================================================================

Bug fixes:
* Macos script fix (@6792c77)

========================================================================
Amazon CloudWatch Agent 1.300026.0 (2022-07-28)
Amazon CloudWatch Agent 1.300026.0 (2023-07-28)
========================================================================

Bug fixes:
Expand All @@ -43,7 +62,7 @@ Enhancements:
* Remove telegraf agent start up (@3f60a57)

========================================================================
Amazon CloudWatch Agent 1.300025.0 (2022-07-19)
Amazon CloudWatch Agent 1.300025.0 (2023-07-19)
========================================================================

New features:
Expand Down
30 changes: 28 additions & 2 deletions cfg/aws/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ package aws
import (
"log"
"net/http"
"os"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"

"github.com/aws/amazon-cloudwatch-agent/handlers/agentinfo"
)

const (
Expand Down Expand Up @@ -76,11 +80,19 @@ func OverwriteCredentialsChain(providers ...RootCredentialsProvider) {
}

func getSession(config *aws.Config) *session.Session {
ses, err := session.NewSession(config)
cfgFiles := getFallbackSharedConfigFiles(backwardsCompatibleUserHomeDir)
log.Printf("D! Fallback shared config file(s): %v", cfgFiles)
ses, err := session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigFiles: cfgFiles,
})
if err != nil {
log.Printf("E! Failed to create credential sessions, retrying in 15s, error was '%s' \n", err)
time.Sleep(15 * time.Second)
ses, err = session.NewSession(config)
ses, err = session.NewSessionWithOptions(session.Options{
Config: *config,
SharedConfigFiles: cfgFiles,
})
if err != nil {
log.Printf("E! Retry failed for creating credential sessions, error was '%s' \n", err)
return ses
Expand All @@ -93,6 +105,20 @@ func getSession(config *aws.Config) *session.Session {
} else {
log.Printf("D! Using credential %s from %s", cred.AccessKeyID, cred.ProviderName)
}
if cred.ProviderName == ec2rolecreds.ProviderName {
var found []string
cfgFiles = getFallbackSharedConfigFiles(currentUserHomeDir)
for _, cfgFile := range cfgFiles {
if _, err = os.Stat(cfgFile); err == nil {
found = append(found, cfgFile)
}
}
if len(found) > 0 {
log.Printf("W! Unused shared config file(s) found: %v. If you would like to use them, "+
"please update your common-config.toml.", found)
agentinfo.RecordSharedConfigFallback()
}
}
return ses
}

Expand Down
83 changes: 83 additions & 0 deletions cfg/aws/shared_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package aws

import (
"os"
"os/user"
"path/filepath"
"strconv"
)

const (
envAwsSdkLoadConfig = "AWS_SDK_LOAD_CONFIG"
envAwsSharedCredentialsFile = "AWS_SHARED_CREDENTIALS_FILE"
envAwsSharedConfigFile = "AWS_CONFIG_FILE"
)

// getFallbackSharedConfigFiles follows the same logic as the AWS SDK but takes a getUserHomeDir
// function.
func getFallbackSharedConfigFiles(userHomeDirProvider func() string) []string {
var sharedCredentialsFile, sharedConfigFile string
setFromEnvVal(&sharedCredentialsFile, envAwsSharedCredentialsFile)
setFromEnvVal(&sharedConfigFile, envAwsSharedConfigFile)
if sharedCredentialsFile == "" {
sharedCredentialsFile = defaultSharedCredentialsFile(userHomeDirProvider())
}
if sharedConfigFile == "" {
sharedConfigFile = defaultSharedConfig(userHomeDirProvider())
}
var cfgFiles []string
enableSharedConfig, _ := strconv.ParseBool(os.Getenv(envAwsSdkLoadConfig))
if enableSharedConfig {
cfgFiles = append(cfgFiles, sharedConfigFile)
}
return append(cfgFiles, sharedCredentialsFile)
}

func setFromEnvVal(dst *string, keys ...string) {
for _, k := range keys {
if v := os.Getenv(k); len(v) != 0 {
*dst = v
break
}
}
}

func defaultSharedCredentialsFile(dir string) string {
return filepath.Join(dir, ".aws", "credentials")
}

func defaultSharedConfig(dir string) string {
return filepath.Join(dir, ".aws", "config")
}

// backwardsCompatibleUserHomeDir provides the home directory based on
// environment variables.
//
// Based on v1.44.106 of the AWS SDK.
func backwardsCompatibleUserHomeDir() string {
home, _ := os.UserHomeDir()
return home
}

// currentUserHomeDir attempts to use the environment variables before falling
// back on the current user's home directory.
//
// Based on v1.44.332 of the AWS SDK.
func currentUserHomeDir() string {
var home string

home = backwardsCompatibleUserHomeDir()
if len(home) > 0 {
return home
}

currUser, _ := user.Current()
if currUser != nil {
home = currUser.HomeDir
}

return home
}
31 changes: 31 additions & 0 deletions cfg/aws/shared_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package aws

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetFallbackSharedConfigFiles(t *testing.T) {
noOpGetUserHomeDir := func() string { return "home" }
t.Setenv(envAwsSdkLoadConfig, "true")
t.Setenv(envAwsSharedCredentialsFile, "credentials")
t.Setenv(envAwsSharedConfigFile, "config")

got := getFallbackSharedConfigFiles(noOpGetUserHomeDir)
assert.Equal(t, []string{"config", "credentials"}, got)

t.Setenv(envAwsSdkLoadConfig, "false")
got = getFallbackSharedConfigFiles(noOpGetUserHomeDir)
assert.Equal(t, []string{"credentials"}, got)

t.Setenv(envAwsSdkLoadConfig, "true")
t.Setenv(envAwsSharedCredentialsFile, "")
t.Setenv(envAwsSharedConfigFile, "")

got = getFallbackSharedConfigFiles(noOpGetUserHomeDir)
assert.Equal(t, []string{defaultSharedConfig("home"), defaultSharedCredentialsFile("home")}, got)
}
Loading

0 comments on commit 5dcfd70

Please sign in to comment.