Skip to content

Commit

Permalink
chore(install-script): use otelcol-config abspath
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Kolberg <[email protected]>
  • Loading branch information
amdprophet committed Nov 8, 2024
1 parent 063db05 commit cbb77cd
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions install-script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ USER_ENV_DIRECTORY=""
UNINSTALL=""
UPGRADE=""
SUMO_BINARY_PATH=""
SUMO_CONFIG_BINARY_PATH=""
COMMON_CONFIG_PATH=""
PURGE=""
DOWNLOAD_ONLY=""
Expand Down Expand Up @@ -163,6 +164,7 @@ function set_defaults() {
DOWNLOAD_CACHE_DIR="/var/cache/otelcol-sumo" # this is in case we want to keep downloaded binaries
CONFIG_DIRECTORY="/etc/otelcol-sumo"
SUMO_BINARY_PATH="/usr/local/bin/otelcol-sumo"
SUMO_CONFIG_BINARY_PATH="/usr/local/bin/otelcol-config"
USER_ENV_DIRECTORY="${CONFIG_DIRECTORY}/env"
TOKEN_ENV_FILE="${USER_ENV_DIRECTORY}/token.env"

Expand Down Expand Up @@ -400,6 +402,9 @@ function verify_installation() {
echo "WARNING: ${SUMO_BINARY_PATH} is not in \$PATH"
otel_command="${SUMO_BINARY_PATH}"
fi
if ! command -v otelcol-config; then
echo "WARNING: ${SUMO_CONFIG_BINARY_PATH} is not in \$PATH"
fi
echo "Running ${otel_command} --version to verify installation"
OUTPUT="$(${otel_command} --version || true)"
readonly OUTPUT
Expand Down Expand Up @@ -473,7 +478,7 @@ function setup_config() {

if [[ "${INSTALL_HOSTMETRICS}" == "true" ]]; then
echo -e "Installing ${OS_TYPE} hostmetrics configuration"
otelcol-config --enable-hostmetrics
"${SUMO_CONFIG_BINARY_PATH}" --enable-hostmetrics
fi

## Check if there is anything to update in configuration
Expand Down Expand Up @@ -534,7 +539,7 @@ function setup_config_darwin() {

if [[ "${INSTALL_HOSTMETRICS}" == "true" ]]; then
echo -e "Installing ${OS_TYPE} hostmetrics configuration"
otelcol-config --enable-hostmetrics
"${SUMO_CONFIG_BINARY_PATH}" --enable-hostmetrics
fi
}

Expand Down Expand Up @@ -594,7 +599,7 @@ function uninstall_darwin() {
function uninstall_linux() {
case $(get_package_manager) in
yum | dnf)
yum remove --quiet -yes otelcol-sumo
yum remove --quiet -y otelcol-sumo
;;
apt-get)
if [[ "${PURGE}" == "true" ]]; then
Expand Down Expand Up @@ -648,17 +653,17 @@ function get_launchd_token() {
}

function get_user_api_url() {
if command -v otelcol-config &> /dev/null; then
KV=$(otelcol-config --read-kv .extensions.sumologic.api_base_url)
if command -v "${SUMO_CONFIG_BINARY_PATH}" &> /dev/null; then
KV=$("${SUMO_CONFIG_BINARY_PATH}" --read-kv .extensions.sumologic.api_base_url)
if [[ "${KV}" != "null" ]]; then
echo "${KV}"
fi
fi
}

function get_user_opamp_endpoint() {
if command -v otelcol-config &> /dev/null; then
KV=$(otelcol-config --read-kv .extensions.opamp.endpoint)
if command -v "${SUMO_CONFIG_BINARY_PATH}" &> /dev/null; then
KV=$("${SUMO_CONFIG_BINARY_PATH}" --read-kv .extensions.opamp.endpoint)
if [[ "${KV}" != "null" ]]; then
echo "${KV}"
fi
Expand All @@ -670,7 +675,7 @@ function write_installation_token() {
local token
readonly token="${1}"

otelcol-config --set-installation-token "$token"
"${SUMO_CONFIG_BINARY_PATH}" --set-installation-token "$token"
}

# write ${ENV_TOKEN} to launchd configuration file
Expand Down Expand Up @@ -707,37 +712,37 @@ function write_installation_token_launchd() {

# write sumologic ephemeral: true to user configuration file
function write_ephemeral_true() {
otelcol-config --enable-ephemeral
"${SUMO_CONFIG_BINARY_PATH}" --enable-ephemeral
}

# write api_url to user configuration file
function write_api_url() {
local api_url
readonly api_url="${1}"

otelcol-config --set-api-url "$api_url"
"${SUMO_CONFIG_BINARY_PATH}" --set-api-url "$api_url"
}

# write opamp endpoint to user configuration file
function write_opamp_endpoint() {
local opamp_endpoint
readonly opamp_endpoint="${1}"

otelcol-config --set-opamp-endpoint "$opamp_endpoint"
"${SUMO_CONFIG_BINARY_PATH}" --set-opamp-endpoint "$opamp_endpoint"
}

# write tags to user configuration file
function write_tags() {
arr=("$@")
for field in "${arr[@]}";
do
otelcol-config --add-tag "$field"
"${SUMO_CONFIG_BINARY_PATH}" --add-tag "$field"
done
}

# configure and enable the opamp extension for remote management
function write_opamp_extension() {
otelcol-config --enable-remote-control
"${SUMO_CONFIG_BINARY_PATH}" --enable-remote-control
}

# NB: this function is only for Darwin
Expand Down Expand Up @@ -1031,9 +1036,9 @@ function get_user_token() {

# Check yaml configuration for a token
if [[ -z "${token}" ]]; then
if command -v otelcol-config &> /dev/null; then
if command -v "${SUMO_CONFIG_BINARY_PATH}" &> /dev/null; then
local output=""
output=$(otelcol-config --read-kv .extensions.sumologic.installation_token)
output=$("${SUMO_CONFIG_BINARY_PATH}" --read-kv .extensions.sumologic.installation_token)
if [[ "${output}" != "null" ]]; then
token="${output}"
fi
Expand Down

0 comments on commit cbb77cd

Please sign in to comment.