Skip to content

Commit 3b72570

Browse files
committed
adding more change to downloader
1 parent 7591cf0 commit 3b72570

8 files changed

Lines changed: 109 additions & 335 deletions

File tree

amazon-cloudwatch-agent.yaml

Lines changed: 0 additions & 66 deletions
This file was deleted.

packaging/dependencies/amazon-cloudwatch-agent-ctl

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ UsageString="
3535
[-c default|all|ssm:<parameter-store-name>|file:<file-path>]
3636
[-s]
3737
[-l INFO|DEBUG|WARN|ERROR|OFF]
38+
[--use-dualstack]
3839
3940
e.g.
4041
1. apply a SSM parameter store config on EC2 instance and restart the agent afterwards:
@@ -43,6 +44,8 @@ UsageString="
4344
amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s
4445
3. query agent status:
4546
amazon-cloudwatch-agent-ctl -a status
47+
4. apply a SSM parameter store config with dual-stack endpoints:
48+
amazon-cloudwatch-agent-ctl --use-dualstack -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s
4649
4750
-a: action
4851
stop: stop the agent process.
@@ -70,6 +73,9 @@ UsageString="
7073
-l: log level to set the agent to INFO, DEBUG, WARN, ERROR, or OFF
7174
this parameter is used for 'set-log-level' only.
7275
76+
--use-dualstack: enable dual-stack endpoints for AWS API calls during config download
77+
this parameter is used for 'fetch-config', 'append-config', 'remove-config' actions only.
78+
7379
"
7480

7581
start_all() {
@@ -236,6 +242,7 @@ config_all() {
236242
restart="${2:-}"
237243
mode="${3:-}"
238244
multi_config="${4:-}"
245+
use_dualstack="${5:-}"
239246

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

246253
if [ -n "${cwa_config_location}" ]; then
247254
echo "****** processing amazon-cloudwatch-agent ******"
248-
cwa_config "${cwa_config_location}" "${restart}" "${mode}" "${multi_config}"
255+
cwa_config "${cwa_config_location}" "${restart}" "${mode}" "${multi_config}" "${use_dualstack}"
249256
fi
250257
}
251258

@@ -254,6 +261,7 @@ cwa_config() {
254261
restart="${2:-}"
255262
param_mode="${3:-}"
256263
multi_config="${4:-}"
264+
use_dualstack="${5:-}"
257265

258266
if [ "${cwa_config_location}" = "${ALL_CONFIG}" ] && [ "${multi_config}" != 'remove' ]; then
259267
echo "ignore cwa configuration \"${ALL_CONFIG}\" as it is only supported by action \"remove-config\""
@@ -263,7 +271,11 @@ cwa_config() {
263271
if [ "${cwa_config_location}" = "${ALL_CONFIG}" ]; then
264272
rm -rf "${JSON_DIR}"/*
265273
else
266-
runDownloaderCommand=$("${CMDDIR}/config-downloader" --output-dir "${JSON_DIR}" --download-source "${cwa_config_location}" --mode ${param_mode} --config "${COMMON_CONIG}" --multi-config ${multi_config})
274+
downloader_cmd="${CMDDIR}/config-downloader --output-dir ${JSON_DIR} --download-source ${cwa_config_location} --mode ${param_mode} --config ${COMMON_CONIG} --multi-config ${multi_config}"
275+
if [ "${use_dualstack}" = 'true' ]; then
276+
downloader_cmd="${downloader_cmd} --use-dualstack"
277+
fi
278+
runDownloaderCommand=$(${downloader_cmd})
267279
echo ${runDownloaderCommand} || return
268280
fi
269281

@@ -354,6 +366,7 @@ main() {
354366
cwa_config_location=''
355367
restart='false'
356368
mode='ec2'
369+
use_dualstack='false'
357370

358371
# detect which init system is in use
359372
if [ "$(/sbin/init --version 2>/dev/null | grep -c upstart)" = 1 ]; then
@@ -368,6 +381,26 @@ main() {
368381
exit 1
369382
fi
370383

384+
# Parse long options first
385+
while [ $# -gt 0 ]; do
386+
case "$1" in
387+
--use-dualstack)
388+
use_dualstack='true'
389+
shift
390+
;;
391+
--)
392+
shift
393+
break
394+
;;
395+
-*)
396+
break
397+
;;
398+
*)
399+
break
400+
;;
401+
esac
402+
done
403+
371404
OPTIND=1
372405
while getopts ":hsa:c:m:l:" opt; do
373406
case "${opt}" in
@@ -405,9 +438,9 @@ main() {
405438
case "${action}" in
406439
stop) stop_all ;;
407440
start) start_all "${mode}" ;;
408-
fetch-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'default' ;;
409-
append-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'append' ;;
410-
remove-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'remove' ;;
441+
fetch-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'default' "${use_dualstack}" ;;
442+
append-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'append' "${use_dualstack}" ;;
443+
remove-config) config_all "${cwa_config_location}" "${restart}" "${mode}" 'remove' "${use_dualstack}" ;;
411444
status) status_all ;;
412445
# helpers for ssm package scripts to workaround fact that it can't determine if invocation is due to
413446
# upgrade or install

tool/processors/tracesconfig/testdata/noArg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
"concurrency": 0,
1111
"buffer_size_mb": 0,
1212
"insecure": false
13-
}
13+
}

translator/tocwconfig/toenvconfig/toEnvConfig.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func ToEnvConfig(jsonConfigValue map[string]interface{}) []byte {
4343
envVars[envconfig.CWAGENT_USAGE_DATA] = "FALSE"
4444
}
4545

46-
// Set AWS_USE_DUALSTACK_ENDPOINT in env config based on agent section configuration
4746
if useDualStack, ok := agentMap[useDualStackEndpointKey].(bool); ok {
4847
if useDualStack {
4948
envVars["AWS_USE_DUALSTACK_ENDPOINT"] = "true"

0 commit comments

Comments
 (0)