From 2860a59eb1e74ca25dee8a95bc441c8e769c6bae Mon Sep 17 00:00:00 2001 From: Dakota Paasman <122491662+dpaasman00@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:09:06 -0500 Subject: [PATCH] chore: Don't require OpAMP endpoint when installing & starting (#1909) * use default opamp endpoint on mac & linux; testing for windows * msi creates supervisor.yaml even if enablemanagement not true * fix port in default opamp endpoint * include default supervisor cfg in release pkgs, check for known cfg file hash * fix shellchecks --- .goreleaser.yml | 6 +++ config/supervisor-default.yaml | 12 +++++ scripts/install/install_macos.sh | 50 +++++++++++------- scripts/install/install_unix.sh | 55 +++++++++++++------- windows/install/generate-supervisor-yaml.bat | 9 +--- windows/templates/product.wxs | 4 +- 6 files changed, 89 insertions(+), 47 deletions(-) create mode 100644 config/supervisor-default.yaml diff --git a/.goreleaser.yml b/.goreleaser.yml index f088bd628..4054205bf 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -188,6 +188,12 @@ nfpms: dst: /opt/observiq-otel-collector/plugins # Storage dir is used by stateful receivers, such as filelog receiver. It allows # receivers to track their progress and buffer data. + - src: config/supervisor-default.yaml + dst: /opt/observiq-otel-collector/supervisor.yaml + file_info: + mode: 0750 + owner: observiq-otel-collector + group: observiq-otel-collector - dst: /opt/observiq-otel-collector/storage type: dir file_info: diff --git a/config/supervisor-default.yaml b/config/supervisor-default.yaml new file mode 100644 index 000000000..7f801443e --- /dev/null +++ b/config/supervisor-default.yaml @@ -0,0 +1,12 @@ +server: + endpoint: ws://localhost:3001/v1/opamp + +capabilities: + accepts_remote_config: true + reports_remote_config: true + +agent: + executable: "./observiq-otel-collector" + +storage: + directory: "./supervisor_storage" diff --git a/scripts/install/install_macos.sh b/scripts/install/install_macos.sh index d1b3f8b70..843f8d878 100755 --- a/scripts/install/install_macos.sh +++ b/scripts/install/install_macos.sh @@ -30,6 +30,9 @@ indent="" non_interactive=false error_mode=false +# Default Supervisor Config Hash +DEFAULT_SUPERVISOR_CFG_HASH="ac4e6001f1b19d371bba6a2797ba0a55d7ca73151ba6908040598ca275c0efca" + # Colors if [ "$non_interactive" = "false" ]; then num_colors=$(tput colors 2>/dev/null) @@ -485,21 +488,28 @@ ask_clean_install() { fi if [ -f "$SUPERVISOR_YML_PATH" ]; then - command printf "${indent}An installation already exists. Would you like to do a clean install? $(prompt n)" - read -r clean_install_response - clean_install_response=$(echo "$clean_install_response" | tr '[:upper:]' '[:lower:]') - case $clean_install_response in - y | yes) - increase_indent - success "Doing clean install!" - decrease_indent + # Check for default config file hash + cfg_file_hash=$(sha256sum "$SUPERVISOR_YML_PATH" | awk '{print $1}') + if [ "$cfg_file_hash" = "$DEFAULT_SUPERVISOR_CFG_HASH" ]; then + # config matches default config, mark clean_install as true clean_install="true" - ;; - *) - warn "Doing upgrade instead of clean install" - clean_install="false" - ;; - esac + else + command printf "${indent}An installation already exists. Would you like to do a clean install? $(prompt n)" + read -r clean_install_response + clean_install_response=$(echo "$clean_install_response" | tr '[:upper:]' '[:lower:]') + case $clean_install_response in + y | yes) + increase_indent + success "Doing clean install!" + decrease_indent + clean_install="true" + ;; + *) + warn "Doing upgrade instead of clean install" + clean_install="false" + ;; + esac + fi else warn "Previous supervisor config not found, doing clean install" clean_install="true" @@ -569,10 +579,7 @@ install_package() { decrease_indent succeeded - # If an endpoint was specified, we need to write the supervisor.yaml - if [ -n "$OPAMP_ENDPOINT" ]; then - create_supervisor_config "$SUPERVISOR_YML_PATH" - fi + create_supervisor_config "$SUPERVISOR_YML_PATH" # Install jmx jar info "Moving opentelemetry-java-contrib-jmx-metrics.jar to /opt..." @@ -614,6 +621,13 @@ create_supervisor_config() { info "Creating supervisor config..." + if [ -z "$OPAMP_ENDPOINT" ]; then + OPAMP_ENDPOINT="ws://localhost:3001/v1/opamp" + increase_indent + info "No OpAMP endpoint specified, starting agent using 'ws://localhost:3001/v1/opamp' as endpoint." + decrease_indent + fi + # Note here: We create the file and change permissions of the file here BEFORE writing info to it. # We do this because the file contains the secret key. # We do not want the file readable by anyone other than root. diff --git a/scripts/install/install_unix.sh b/scripts/install/install_unix.sh index a10d93b85..b00ab0436 100755 --- a/scripts/install/install_unix.sh +++ b/scripts/install/install_unix.sh @@ -37,6 +37,9 @@ indent="" non_interactive=false error_mode=false +# Default Supervisor Config Hash +DEFAULT_SUPERVISOR_CFG_HASH="ac4e6001f1b19d371bba6a2797ba0a55d7ca73151ba6908040598ca275c0efca" + # out_file_path is the full path to the downloaded package (e.g. "/tmp/observiq-otel-collector_linux_amd64.deb") out_file_path="unknown" @@ -482,21 +485,28 @@ ask_clean_install() { fi if [ -f "$SUPERVISOR_YML_PATH" ]; then - command printf "${indent}An installation already exists. Would you like to do a clean install? $(prompt n)" - read -r clean_install_response - clean_install_response=$(echo "$clean_install_response" | tr '[:upper:]' '[:lower:]') - case $clean_install_response in - y | yes) - increase_indent - success "Doing clean install!" - decrease_indent + # Check for default config file hash + cfg_file_hash=$(sha256sum "$SUPERVISOR_YML_PATH" | awk '{print $1}') + if [ "$cfg_file_hash" = "$DEFAULT_SUPERVISOR_CFG_HASH" ]; then + # config matches default config, mark clean_install as true clean_install="true" - ;; - *) - warn "Doing upgrade instead of clean install" - clean_install="false" - ;; - esac + else + command printf "${indent}An installation already exists. Would you like to do a clean install? $(prompt n)" + read -r clean_install_response + clean_install_response=$(echo "$clean_install_response" | tr '[:upper:]' '[:lower:]') + case $clean_install_response in + y | yes) + increase_indent + success "Doing clean install!" + decrease_indent + clean_install="true" + ;; + *) + warn "Doing upgrade instead of clean install" + clean_install="false" + ;; + esac + fi else warn "Previous supervisor config not found, doing clean install" clean_install="true" @@ -677,12 +687,7 @@ install_package() { unpack_package || error_exit "$LINENO" "Failed to extract package" succeeded - # If an endpoint was specified, we need to write the manager.yaml - if [ -n "$OPAMP_ENDPOINT" ]; then - info "Creating supervisor config..." - create_supervisor_config "$SUPERVISOR_YML_PATH" - succeeded - fi + create_supervisor_config "$SUPERVISOR_YML_PATH" if [ "$SVC_PRE" = "systemctl" ]; then if [ "$(systemctl is-enabled observiq-otel-collector)" = "enabled" ]; then @@ -744,6 +749,15 @@ create_supervisor_config() { return fi + info "Creating supervisor config..." + + if [ -z "$OPAMP_ENDPOINT" ]; then + OPAMP_ENDPOINT="ws://localhost:3001/v1/opamp" + increase_indent + info "No OpAMP endpoint specified, starting agent using 'ws://localhost:3001/v1/opamp' as endpoint." + decrease_indent + fi + # Note here: We create the file and change permissions of the file here BEFORE writing info to it. # We do this because the file contains the secret key. # We do not want the file readable by anyone other than root/obseriq-otel-collector. @@ -772,6 +786,7 @@ create_supervisor_config() { command printf ' logs:\n' >>"$supervisor_yml_path" command printf ' level: 0\n' >>"$supervisor_yml_path" command printf ' output_paths: ["%s"]' "$INSTALL_DIR/supervisor_storage/supervisor.log" >>"$supervisor_yml_path" + succeeded } # This will display the results of an installation diff --git a/windows/install/generate-supervisor-yaml.bat b/windows/install/generate-supervisor-yaml.bat index f5c5613f1..fa3fda825 100644 --- a/windows/install/generate-supervisor-yaml.bat +++ b/windows/install/generate-supervisor-yaml.bat @@ -12,13 +12,8 @@ echo %secret_key% echo %labels% if "%endpoint%"=="" ( - echo Endpoint not specified; Not writing output yaml - exit /b 0 -) - -if "%secret_key%"=="" ( - echo Secret Key not specified; Not writing output yaml - exit /b 0 + echo Endpoint not specified, using default value of 'ws://localhost:3001/v1/opamp' + set "endpoint=ws://localhost:3001/v1/opamp" ) set "supervisorFile=%install_dir%supervisor.yaml" diff --git a/windows/templates/product.wxs b/windows/templates/product.wxs index 39aed7d1f..694313dcf 100644 --- a/windows/templates/product.wxs +++ b/windows/templates/product.wxs @@ -234,10 +234,10 @@ - = 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND ENABLEMANAGEMENT AND NOT WIX_UPGRADE_DETECTED]]> + = 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND NOT WIX_UPGRADE_DETECTED]]> - = 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND ENABLEMANAGEMENT AND NOT WIX_UPGRADE_DETECTED]]> + = 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND NOT WIX_UPGRADE_DETECTED]]>