Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cfg/envconfig/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (

const (
//the following are the names of environment variables
HTTP_PROXY = "HTTP_PROXY" //nolint:revive
HTTPS_PROXY = "HTTPS_PROXY" //nolint:revive
NO_PROXY = "NO_PROXY" //nolint:revive
AWS_CA_BUNDLE = "AWS_CA_BUNDLE" //nolint:revive
AWS_SDK_LOG_LEVEL = "AWS_SDK_LOG_LEVEL" //nolint:revive
CWAGENT_USER_AGENT = "CWAGENT_USER_AGENT" //nolint:revive
CWAGENT_LOG_LEVEL = "CWAGENT_LOG_LEVEL" //nolint:revive
CWAGENT_ROLE = "CWAGENT_ROLE" //nolint:revive
CWAGENT_USAGE_DATA = "CWAGENT_USAGE_DATA" //nolint:revive
IMDS_NUMBER_RETRY = "IMDS_NUMBER_RETRY" //nolint:revive
HTTP_PROXY = "HTTP_PROXY" //nolint:revive
HTTPS_PROXY = "HTTPS_PROXY" //nolint:revive
NO_PROXY = "NO_PROXY" //nolint:revive
AWS_CA_BUNDLE = "AWS_CA_BUNDLE" //nolint:revive
AWS_SDK_LOG_LEVEL = "AWS_SDK_LOG_LEVEL" //nolint:revive
AWS_USE_DUALSTACK_ENDPOINT = "AWS_USE_DUALSTACK_ENDPOINT" //nolint:revive
CWAGENT_USER_AGENT = "CWAGENT_USER_AGENT" //nolint:revive
CWAGENT_LOG_LEVEL = "CWAGENT_LOG_LEVEL" //nolint:revive
CWAGENT_ROLE = "CWAGENT_ROLE" //nolint:revive
CWAGENT_USAGE_DATA = "CWAGENT_USAGE_DATA" //nolint:revive
IMDS_NUMBER_RETRY = "IMDS_NUMBER_RETRY" //nolint:revive
RunInContainer = "RUN_IN_CONTAINER"
RunAsHostProcessContainer = "RUN_AS_HOST_PROCESS_CONTAINER"
RunInAWS = "RUN_IN_AWS"
Expand Down
24 changes: 18 additions & 6 deletions packaging/darwin/amazon-cloudwatch-agent-ctl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ readonly ALL_CONFIG='all'
UsageString="


usage: amazon-cloudwatch-agent-ctl -a stop|start|status|fetch-config|append-config|remove-config [-m ec2|onPremise|onPrem|auto] [-c default|ssm:<parameter-store-name>|file:<file-path>] [-s]
usage: amazon-cloudwatch-agent-ctl -a stop|start|status|fetch-config|append-config|remove-config [-m ec2|onPremise|onPrem|auto] [-c default|ssm:<parameter-store-name>|file:<file-path>] [-s] [-d]

e.g.
1. apply a SSM parameter store config on EC2 instance and restart the agent afterwards:
Expand All @@ -46,6 +46,8 @@ UsageString="
amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s
3. query agent status:
amazon-cloudwatch-agent-ctl -a status
4. apply a SSM parameter store config with dual-stack endpoints:
amazon-cloudwatch-agent-ctl -d -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s

-a: action
stop: stop the agent process.
Expand All @@ -69,6 +71,9 @@ UsageString="
-s: optionally restart after configuring the agent configuration
this parameter is used for 'fetch-config', 'append-config', 'remove-config' action only.

-d: enable dual-stack endpoints for AWS API calls during config download
this parameter is used for 'fetch-config', 'append-config' actions only.

"

cwa_start() {
Expand All @@ -80,7 +85,7 @@ cwa_start() {

if [ ! -f "${TOML}" ]; then
echo "amazon-cloudwatch-agent is not configured. Applying default configuration before starting it."
cwa_config 'default' 'false' "${mode}" 'default'
cwa_config 'default' 'false' "${mode}" 'default' 'false'
fi

launchctl load $AGENT_LAUNCHD_CONFIG
Expand Down Expand Up @@ -165,6 +170,7 @@ cwa_config() {
restart="${2:-}"
mode="${3:-}"
multi_config="${4:-}"
use_dualstack="${5:-false}"

mkdir -p "${CONFDIR}"

Expand All @@ -176,7 +182,11 @@ cwa_config() {
if [ "${config_location}" = "${ALL_CONFIG}" ]; then
rm -rf "${JSON_DIR}"/*
else
runDownloaderCommand=$("${CMDDIR}/config-downloader" --output-dir "${JSON_DIR}" --download-source "${config_location}" --mode ${mode} --config "${COMMON_CONIG}" --multi-config ${multi_config})
downloader_cmd="${CMDDIR}/config-downloader --output-dir ${JSON_DIR} --download-source ${config_location} --mode ${mode} --config ${COMMON_CONIG} --multi-config ${multi_config}"
if [ "${use_dualstack}" = 'true' ]; then
downloader_cmd="${downloader_cmd} --dualstack"
fi
runDownloaderCommand=$(${downloader_cmd})
echo "${runDownloaderCommand}"
fi

Expand Down Expand Up @@ -243,9 +253,10 @@ main() {
config_location='default'
restart='false'
mode='auto'
use_dualstack='false'

OPTIND=1
while getopts ":hsa:r:c:m:" opt; do
while getopts ":hsa:r:c:m:d" opt; do
case "${opt}" in
h)
echo "${UsageString}"
Expand All @@ -255,6 +266,7 @@ main() {
a) action="${OPTARG}" ;;
c) config_location="${OPTARG}" ;;
m) mode="${OPTARG}" ;;
d) use_dualstack='true' ;;
\?)
echo "Invalid option: -${OPTARG} ${UsageString}" >&2
;;
Expand Down Expand Up @@ -286,8 +298,8 @@ main() {
case "${action}" in
stop) cwa_stop ;;
start) cwa_start "${mode}" ;;
fetch-config) cwa_config "${config_location}" "${restart}" "${mode}" 'default' ;;
append-config) cwa_config "${config_location}" "${restart}" "${mode}" 'append' ;;
fetch-config) cwa_config "${config_location}" "${restart}" "${mode}" 'default' "${use_dualstack}" ;;
append-config) cwa_config "${config_location}" "${restart}" "${mode}" 'append' "${use_dualstack}" ;;
remove-config) cwa_config "${config_location}" "${restart}" "${mode}" 'remove' ;;
status) cwa_status ;;
# helpers for ssm package scripts to workaround fact that it can't determine if invocation is due to
Expand Down
28 changes: 21 additions & 7 deletions packaging/dependencies/amazon-cloudwatch-agent-ctl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ UsageString="
[-m ec2|onPremise|onPrem|auto]
[-c default|all|ssm:<parameter-store-name>|file:<file-path>]
[-s]
[-d]
[-l INFO|DEBUG|WARN|ERROR|OFF]

e.g.
Expand All @@ -43,6 +44,8 @@ UsageString="
amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s
3. query agent status:
amazon-cloudwatch-agent-ctl -a status
4. apply a SSM parameter store config with dual-stack endpoints:
amazon-cloudwatch-agent-ctl -d -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s

-a: action
stop: stop the agent process.
Expand All @@ -67,6 +70,9 @@ UsageString="
-s: optionally restart after configuring the agent configuration
this parameter is used for 'fetch-config', 'append-config', 'remove-config' action only.

-d: enable dual-stack endpoints for AWS API calls during config download
Comment thread
Paramadon marked this conversation as resolved.
this parameter is used for 'fetch-config', 'append-config' actions only.

-l: log level to set the agent to INFO, DEBUG, WARN, ERROR, or OFF
this parameter is used for 'set-log-level' only.

Expand All @@ -91,7 +97,7 @@ agent_start() {

if [ "${agent_name}" = "${CWA_NAME}" ] && [ ! -f "${TOML}" ]; then
echo "${CWA_NAME} is not configured. Applying amazon-cloudwatch-agent default configuration."
cwa_config 'default' 'false' "${mode}" 'default'
cwa_config 'default' 'false' "${mode}" 'default' 'false'
fi

if [ "${SYSTEMD}" = 'true' ]; then
Expand Down Expand Up @@ -236,6 +242,7 @@ config_all() {
restart="${2:-}"
mode="${3:-}"
multi_config="${4:-}"
use_dualstack="${5:-}"

if [ -z "${cwa_config_location}" ]; then
cwa_config_location='default'
Expand All @@ -245,7 +252,7 @@ config_all() {

if [ -n "${cwa_config_location}" ]; then
echo "****** processing amazon-cloudwatch-agent ******"
cwa_config "${cwa_config_location}" "${restart}" "${mode}" "${multi_config}"
cwa_config "${cwa_config_location}" "${restart}" "${mode}" "${multi_config}" "${use_dualstack}"
fi
}

Expand All @@ -254,6 +261,7 @@ cwa_config() {
restart="${2:-}"
param_mode="${3:-}"
multi_config="${4:-}"
use_dualstack="${5:-}"

if [ "${cwa_config_location}" = "${ALL_CONFIG}" ] && [ "${multi_config}" != 'remove' ]; then
echo "ignore cwa configuration \"${ALL_CONFIG}\" as it is only supported by action \"remove-config\""
Expand All @@ -263,8 +271,12 @@ cwa_config() {
if [ "${cwa_config_location}" = "${ALL_CONFIG}" ]; then
rm -rf "${JSON_DIR}"/*
else
runDownloaderCommand=$("${CMDDIR}/config-downloader" --output-dir "${JSON_DIR}" --download-source "${cwa_config_location}" --mode ${param_mode} --config "${COMMON_CONIG}" --multi-config ${multi_config})
echo ${runDownloaderCommand} || return
downloader_cmd="${CMDDIR}/config-downloader --output-dir ${JSON_DIR} --download-source ${cwa_config_location} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config}"
if [ "${use_dualstack}" = 'true' ]; then
downloader_cmd="${downloader_cmd} --dualstack"
fi
runDownloaderCommand=$(${downloader_cmd})
echo "${runDownloaderCommand}" || return
fi

if [ ! "$(ls ${JSON_DIR})" ]; then
Expand Down Expand Up @@ -354,6 +366,7 @@ main() {
cwa_config_location=''
restart='false'
mode='ec2'
use_dualstack='false'
Comment thread
Paramadon marked this conversation as resolved.

# detect which init system is in use
if [ "$(/sbin/init --version 2>/dev/null | grep -c upstart)" = 1 ]; then
Expand All @@ -369,7 +382,7 @@ main() {
fi

OPTIND=1
while getopts ":hsa:c:m:l:" opt; do
while getopts ":hsa:c:m:l:d" opt; do
case "${opt}" in
h)
echo "${UsageString}"
Expand All @@ -380,6 +393,7 @@ main() {
c) cwa_config_location="${OPTARG}" ;;
m) mode="${OPTARG}" ;;
l) log_level="${OPTARG}" ;;
d) use_dualstack='true' ;;
\?)
echo "Invalid option: -${OPTARG} ${UsageString}" >&2
;;
Expand All @@ -405,8 +419,8 @@ main() {
case "${action}" in
stop) stop_all ;;
start) start_all "${mode}" ;;
fetch-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'default' ;;
append-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'append' ;;
fetch-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'default' "${use_dualstack}" ;;
append-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'append' "${use_dualstack}" ;;
remove-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'remove' ;;
status) status_all ;;
# helpers for ssm package scripts to workaround fact that it can't determine if invocation is due to
Expand Down
14 changes: 13 additions & 1 deletion packaging/windows/amazon-cloudwatch-agent-ctl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Param (
[string]$Mode = 'ec2',
[Parameter(Mandatory = $false)]
[string]$LogLevel = '',
[Parameter(Mandatory = $false)]
[switch]$d = $false,
Comment thread
Paramadon marked this conversation as resolved.
[parameter(ValueFromRemainingArguments=$true)]
$unsupportedVars
)
Expand All @@ -29,6 +31,7 @@ $UsageString = @"
[-m ec2|onPremise|onPrem|auto]
[-c default|all|ssm:<parameter-store-name>|file:<file-path>]
[-s]
[-d]
[-l INFO|DEBUG|WARN|ERROR|OFF]

e.g.
Expand All @@ -38,6 +41,8 @@ $UsageString = @"
amazon-cloudwatch-agent-ctl.ps1 -a append-config -m onPremise -c file:c:\config.json -s
3. query agent status:
amazon-cloudwatch-agent-ctl.ps1 -a status
4. apply a SSM parameter store config with dual-stack endpoints:
amazon-cloudwatch-agent-ctl.ps1 -d -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s

-a: action
stop: stop amazon-cloudwatch-agent if running.
Expand All @@ -62,6 +67,9 @@ $UsageString = @"
-s: optionally restart after configuring the agent configuration
this parameter is used for 'fetch-config', 'append-config', 'remove-config' action only.

-d: enable dual-stack endpoints for AWS API calls during config download
this parameter is used for 'fetch-config', 'append-config' actions only.

-l: log level to set the agent to INFO, DEBUG, WARN, ERROR, or OFF
this parameter is used for 'set-log-level' only.

Expand Down Expand Up @@ -301,7 +309,11 @@ Function CWAConfig() {
if ($ConfigLocation -eq $AllConfig) {
Remove-Item -Path "${JSON_DIR}\*" -Force -ErrorAction SilentlyContinue
} else {
& $CWAProgramFiles\config-downloader.exe --output-dir "${JSON_DIR}" --download-source "${ConfigLocation}" --mode "${param_mode}" --config "${COMMON_CONIG}" --multi-config "${multi_config}"
$downloader_cmd = "`"${CWAProgramFiles}\config-downloader.exe`" --output-dir `"${JSON_DIR}`" --download-source `"${ConfigLocation}`" --mode `"${param_mode}`" --config `"${COMMON_CONIG}`" --multi-config `"${multi_config}`""
if ($d -and $multi_config -ne 'remove') {
$downloader_cmd += " --dualstack"
}
& cmd /c $downloader_cmd
CheckCMDResult
}

Expand Down
8 changes: 7 additions & 1 deletion tool/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

configaws "github.com/aws/amazon-cloudwatch-agent/cfg/aws"
"github.com/aws/amazon-cloudwatch-agent/cfg/commonconfig"
"github.com/aws/amazon-cloudwatch-agent/cfg/envconfig"
"github.com/aws/amazon-cloudwatch-agent/internal/constants"
"github.com/aws/amazon-cloudwatch-agent/translator/config"
"github.com/aws/amazon-cloudwatch-agent/translator/util"
Expand All @@ -37,10 +38,11 @@ func RunDownloaderFromFlags(flags map[string]*string) error {
*flags["output-dir"],
*flags["config"],
*flags["multi-config"],
*flags["dualstack"] == "true",
)
}

func RunDownloader(mode, downloadLocation, outputDir, inputConfig, multiConfig string) (err error) {
func RunDownloader(mode, downloadLocation, outputDir, inputConfig, multiConfig string, useDualStack bool) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Fail to fetch the config")
Expand All @@ -64,6 +66,10 @@ func RunDownloader(mode, downloadLocation, outputDir, inputConfig, multiConfig s
util.SetProxyEnv(cc.ProxyMap())
util.SetSSLEnv(cc.SSLMap())

if useDualStack {
os.Setenv(envconfig.AWS_USE_DUALSTACK_ENDPOINT, "true")
}

// Validate required parameters
if downloadLocation == "" || outputDir == "" {
executable, err := os.Executable()
Expand Down
1 change: 1 addition & 0 deletions tool/downloader/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ var DownloaderFlags = map[string]cmdwrapper.Flag{
"output-dir": {DefaultValue: "", Description: "Path of output json config directory."},
"config": {DefaultValue: "", Description: "Please provide the common-config file"},
"multi-config": {DefaultValue: "default", Description: "valid values: default, append, remove"},
"dualstack": {DefaultValue: "false", Description: "Use dual-stack endpoints for AWS API calls for config-downloader", IsBool: true},
}
28 changes: 28 additions & 0 deletions translator/tocwconfig/sampleConfig/dualstack_config.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[agent]
collection_jitter = "0s"
debug = false
flush_interval = "1s"
flush_jitter = "0s"
hostname = ""
interval = "60s"
logfile = "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
logtarget = "lumberjack"
metric_batch_size = 1000
metric_buffer_limit = 10000
omit_hostname = false
precision = ""
quiet = false
round_interval = false
use_dualstack_endpoint = true

[inputs]

[[inputs.cpu]]
fieldpass = ["usage_active"]
percpu = false
report_active = true
totalcpu = true

[outputs]

[[outputs.cloudwatch]]
22 changes: 22 additions & 0 deletions translator/tocwconfig/sampleConfig/dualstack_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
Comment thread
Paramadon marked this conversation as resolved.
"agent": {
"region": "us-west-2",
"use_dualstack_endpoint": true
},
"metrics": {
"metrics_destinations": {
"amp": {
"workspace_id": "ws-12345"
},
"cloudwatch": {
}
},
"metrics_collected": {
"cpu": {
"measurement": [
"usage_active"
]
}
}
}
}
Loading
Loading