Skip to content

Commit

Permalink
Fix ctl script error when providing default filepath (#2389)
Browse files Browse the repository at this point in the history
* Add new test

* Adjust file filters

* start collector first

* fix typo

* add file prefix

* add test for non restart

* Add test case for clean start

* Do not execute copy if default dir is provided

* remove extra whitespace

* Fix config equality check

* add test

---------

Co-authored-by: Vasi Vasireddy <[email protected]>
  • Loading branch information
bryan-aguilar and vasireddy99 authored Oct 13, 2023
1 parent 5ead52d commit 0775173
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/config/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ changed:
- 'go.sum'
- '.patches/**'
- 'vendor/**'
- '.github/scripts/test-collector-ctl.sh'
all:
- '**'
version:
Expand Down
21 changes: 21 additions & 0 deletions .github/scripts/test-collector-ctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 8 additions & 4 deletions tools/ctl/linux/aws-otel-collector-ctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ 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
fi
}

# 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
Expand All @@ -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
Expand Down

0 comments on commit 0775173

Please sign in to comment.