diff --git a/.github/config/file-filters.yml b/.github/config/file-filters.yml index cb9c770aa3..6ac042dbb2 100644 --- a/.github/config/file-filters.yml +++ b/.github/config/file-filters.yml @@ -11,6 +11,7 @@ changed: - 'go.sum' - '.patches/**' - 'vendor/**' + - '.github/scripts/test-collector-ctl.sh' all: - '**' version: diff --git a/.github/scripts/test-collector-ctl.sh b/.github/scripts/test-collector-ctl.sh index 958f5cfc3a..9d88dcd460 100755 --- a/.github/scripts/test-collector-ctl.sh +++ b/.github/scripts/test-collector-ctl.sh @@ -67,8 +67,29 @@ test_collector_ctl_with_sed_special_chars() { } +test_collector_ctl_with_samecfg() { + #ensure default cfg is cleared + rm /opt/aws/aws-otel-collector/etc/config.yaml + + $ADOT_CTL -a start -c "file:/opt/aws/aws-otel-collector/etc/config.yaml" + + echo "${FUNCNAME[0]} ... OK" +} + + +test_collector_ctl_with_samecfg_restart() { + #populate default conf by starting without -c + $ADOT_CTL -a start + + $ADOT_CTL -a start -c "file:/opt/aws/aws-otel-collector/etc/config.yaml" + + echo "${FUNCNAME[0]} ... OK" +} + setup ## Tests test_collector_ctl_does_not_overwrite_env test_collector_ctl_with_sed_special_chars +test_collector_ctl_with_samecfg +test_collector_ctl_with_samecfg_restart diff --git a/tools/ctl/linux/aws-otel-collector-ctl.sh b/tools/ctl/linux/aws-otel-collector-ctl.sh index 8846bb3cce..fb38780efe 100644 --- a/tools/ctl/linux/aws-otel-collector-ctl.sh +++ b/tools/ctl/linux/aws-otel-collector-ctl.sh @@ -69,7 +69,11 @@ aoc_config_local_uri() { if [ -n "$config" ] && [ -f "$config" ]; then - cp "$config" $CONFDIR/config.yaml + # do not copy if the default congif directory is provided for the -f flag. + # copying a file to the same location produces an error. + if [ ! "$config" = "$CONFDIR/config.yaml" ]; then + cp "$config" $CONFDIR/config.yaml + fi else echo "File $config does not exist" exit 1 @@ -77,6 +81,7 @@ aoc_config_local_uri() { } # Used in case the collector starts for the first time without a configuration parameter +# Safe to run as this will not overwrite a file if one exists in default location already. aoc_ensure_default_config() { if [ ! -f $CONFDIR/config.yaml ]; then cp $DFT_CONFDIR/.config.yaml $CONFDIR/config.yaml @@ -97,9 +102,8 @@ aoc_start() { config="${1:-}" # The previous configuration should be used if no configuration parameter is passed - if [ -z "$config" ]; then - aoc_ensure_default_config - else + aoc_ensure_default_config + if [ -n "$config" ]; then if is_remote_uri "$config"; then aoc_config_remote_uri "$config" else