Skip to content

Commit

Permalink
chore: Don't require OpAMP endpoint when installing & starting (#1909)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dpaasman00 committed Nov 14, 2024
1 parent 642a5f1 commit 2860a59
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 47 deletions.
6 changes: 6 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions config/supervisor-default.yaml
Original file line number Diff line number Diff line change
@@ -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"
50 changes: 32 additions & 18 deletions scripts/install/install_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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..."
Expand Down Expand Up @@ -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.
Expand Down
55 changes: 35 additions & 20 deletions scripts/install/install_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions windows/install/generate-supervisor-yaml.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions windows/templates/product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@

<!-- Schedule the action that creates the supervisor.yaml file on initial install -->
<Custom Action="CustomExecCreateSupervisorYaml_set" After="InstallInitialize" >
<![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND ENABLEMANAGEMENT AND NOT WIX_UPGRADE_DETECTED]]>
<![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND NOT WIX_UPGRADE_DETECTED]]>
</Custom>
<Custom Action="CustomExecCreateSupervisorYaml" After="InstallFiles" >
<![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND ENABLEMANAGEMENT AND NOT WIX_UPGRADE_DETECTED]]>
<![CDATA[(VersionNT >= 603 OR VersionNT64 >= 603) AND NOT Installed AND NOT REMOVE AND NOT WIX_UPGRADE_DETECTED]]>
</Custom>

<!-- Schedule the action that removes the supervisor.yaml file on final uninstall -->
Expand Down

0 comments on commit 2860a59

Please sign in to comment.