Skip to content

Commit

Permalink
Merge branch 'main' into opamp-endpoint-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
fguimond authored May 23, 2024
2 parents 3040939 + 6e2846d commit c2e7265
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 18 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/_reusable_build_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ on:
required: false
productbuild_identity_name:
required: false
microsoft_certificate:
required: false
microsoft_certificate_password:
required: false
microsoft_certhash:
required: false
microsoft_certname:
required: false
microsoft_description:
required: false

defaults:
run:
Expand Down Expand Up @@ -290,6 +300,15 @@ jobs:
echo "package_path=${PACKAGE_PATH}" >> $GITHUB_OUTPUT
echo "package_filename=$(basename ${PACKAGE_PATH})" >> $GITHUB_OUTPUT
- name: Sign MSI
uses: skymatic/code-sign-action@v3
with:
certificate: ${{ secrets.microsoft_certificate }}
password: ${{ secrets.microsoft_certificate_password }}
certificatesha1: ${{ secrets.microsoft_certhash }}
description: ${{ secrets.microsoft_description }}
folder: ./msi/wix/bin/${{ inputs.package_arch }}/en-US

- name: Store MSI as action artifact
uses: actions/upload-artifact@v4
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/build_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ jobs:
apple_developer_certificate_password: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
productbuild_identity_name: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_IDENTITY }}
gh_artifacts_token: ${{ secrets.GH_ARTIFACTS_TOKEN }}
microsoft_certificate: ${{ secrets.MICROSOFT_CERTIFICATE }}
microsoft_certificate_password: ${{ secrets.MICROSOFT_CERTIFICATE_PASSWORD }}
microsoft_certhash: ${{ secrets.MICROSOFT_CERTHASH }}
microsoft_certname: ${{ secrets.MICROSOFT_CERTNAME }}
microsoft_description: ${{ secrets.MICROSOFT_DESCRIPTION }}

strategy:
matrix:
include:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ UpgradeLog*.htm
wix/packages
msi/wix/packages
msi/SumoLogic.wixext/packages
install-script/test/sumologic_scripts_tests.test
2 changes: 2 additions & 0 deletions assets/conf.d/examples/oracle.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ receivers:
to: resource["_sourceName"]
include:
- /var/log/oracle/auditlogs/oracle*.log
multiline:
line_start_pattern: ^<AuditRecord>
processors:
resource/oracle_resource_attributes/localhost:
attributes:
Expand Down
89 changes: 73 additions & 16 deletions install-script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ARG_SHORT_HELP='h'
ARG_LONG_HELP='help'
ARG_SHORT_API='a'
ARG_LONG_API='api'
ARG_SHORT_OPAMP_API='o'
ARG_LONG_OPAMP_API='opamp-api'
ARG_SHORT_TAG='t'
ARG_LONG_TAG='tag'
ARG_SHORT_VERSION='v'
Expand Down Expand Up @@ -81,6 +83,7 @@ fi
set -u

API_BASE_URL=""
OPAMP_API_URL=""
FIELDS=""
VERSION=""
FIPS=false
Expand All @@ -107,6 +110,7 @@ LAUNCHD_ENV_KEY=""
LAUNCHD_TOKEN_KEY=""

USER_API_URL=""
USER_OPAMP_API_URL=""
USER_TOKEN=""
USER_FIELDS=""

Expand All @@ -132,7 +136,7 @@ SYSTEMD_DISABLED=false
function usage() {
cat << EOF
Usage: bash install.sh [--${ARG_LONG_TOKEN} <token>] [--${ARG_LONG_TAG} <key>=<value> [ --${ARG_LONG_TAG} ...]] [--${ARG_LONG_API} <url>] [--${ARG_LONG_VERSION} <version>] \\
Usage: bash install.sh [--${ARG_LONG_TOKEN} <token>] [--${ARG_LONG_TAG} <key>=<value> [ --${ARG_LONG_TAG} ...]] [--${ARG_LONG_API} <url>] [--${ARG_LONG_OPAMP_API} <url>] [--${ARG_LONG_VERSION} <version>] \\
[--${ARG_LONG_YES}] [--${ARG_LONG_VERSION} <version>] [--${ARG_LONG_HELP}]
Supported arguments:
Expand All @@ -148,7 +152,8 @@ Supported arguments:
-${ARG_SHORT_PURGE}, --${ARG_LONG_PURGE} It has to be used with '--${ARG_LONG_UNINSTALL}'.
It removes all Sumo Logic Distribution for OpenTelemetry Collector related configuration and data.
-${ARG_SHORT_API}, --${ARG_LONG_API} <url> Api URL
-${ARG_SHORT_API}, --${ARG_LONG_API} <url> API URL, forces the collector to use non-default API
-${ARG_SHORT_OPAMP_API}, --${ARG_LONG_OPAMP_API} <url> OpAmp API URL, forces the collector to use non-default OpAmp API
-${ARG_SHORT_SKIP_SYSTEMD}, --${ARG_LONG_SKIP_SYSTEMD} Do not install systemd unit.
-${ARG_SHORT_SKIP_CONFIG}, --${ARG_LONG_SKIP_CONFIG} Do not create default configuration.
-${ARG_SHORT_VERSION}, --${ARG_LONG_VERSION} <version> Version of Sumo Logic Distribution for OpenTelemetry Collector to install, e.g. 0.57.2-sumo-1.
Expand Down Expand Up @@ -209,6 +214,9 @@ function parse_options() {
echo "--${DEPRECATED_ARG_LONG_TOKEN}" is deprecated. Please use "--${ARG_LONG_TOKEN}" instead.
set -- "$@" "-${ARG_SHORT_TOKEN}"
;;
"--${ARG_LONG_OPAMP_API}")
set -- "$@" "-${ARG_SHORT_OPAMP_API}"
;;
"--${ARG_LONG_API}")
set -- "$@" "-${ARG_SHORT_API}"
;;
Expand Down Expand Up @@ -261,7 +269,7 @@ function parse_options() {
"--${ARG_LONG_TIMEOUT}")
set -- "$@" "-${ARG_SHORT_TIMEOUT}"
;;
"-${ARG_SHORT_TOKEN}"|"-${ARG_SHORT_HELP}"|"-${ARG_SHORT_API}"|"-${ARG_SHORT_TAG}"|"-${ARG_SHORT_SKIP_CONFIG}"|"-${ARG_SHORT_VERSION}"|"-${ARG_SHORT_FIPS}"|"-${ARG_SHORT_YES}"|"-${ARG_SHORT_SKIP_SYSTEMD}"|"-${ARG_SHORT_UNINSTALL}"|"-${ARG_SHORT_PURGE}"|"-${ARG_SHORT_SKIP_TOKEN}"|"-${ARG_SHORT_DOWNLOAD}"|"-${ARG_SHORT_CONFIG_BRANCH}"|"-${ARG_SHORT_BINARY_BRANCH}"|"-${ARG_SHORT_BRANCH}"|"-${ARG_SHORT_KEEP_DOWNLOADS}"|"-${ARG_SHORT_TIMEOUT}"|"-${ARG_SHORT_INSTALL_HOSTMETRICS}"|"-${ARG_SHORT_REMOTELY_MANAGED}"|"-${ARG_SHORT_EPHEMERAL}")
"-${ARG_SHORT_TOKEN}"|"-${ARG_SHORT_HELP}"|"-${ARG_SHORT_API}"|"-${ARG_SHORT_OPAMP_API}"|"-${ARG_SHORT_TAG}"|"-${ARG_SHORT_SKIP_CONFIG}"|"-${ARG_SHORT_VERSION}"|"-${ARG_SHORT_FIPS}"|"-${ARG_SHORT_YES}"|"-${ARG_SHORT_SKIP_SYSTEMD}"|"-${ARG_SHORT_UNINSTALL}"|"-${ARG_SHORT_PURGE}"|"-${ARG_SHORT_SKIP_TOKEN}"|"-${ARG_SHORT_DOWNLOAD}"|"-${ARG_SHORT_CONFIG_BRANCH}"|"-${ARG_SHORT_BINARY_BRANCH}"|"-${ARG_SHORT_BRANCH}"|"-${ARG_SHORT_KEEP_DOWNLOADS}"|"-${ARG_SHORT_TIMEOUT}"|"-${ARG_SHORT_INSTALL_HOSTMETRICS}"|"-${ARG_SHORT_REMOTELY_MANAGED}"|"-${ARG_SHORT_EPHEMERAL}")
set -- "$@" "${arg}"
;;
"--${ARG_LONG_INSTALL_HOSTMETRICS}")
Expand All @@ -285,7 +293,7 @@ function parse_options() {

while true; do
set +e
getopts "${ARG_SHORT_HELP}${ARG_SHORT_TOKEN}:${ARG_SHORT_API}:${ARG_SHORT_TAG}:${ARG_SHORT_VERSION}:${ARG_SHORT_FIPS}${ARG_SHORT_YES}${ARG_SHORT_SKIP_SYSTEMD}${ARG_SHORT_UNINSTALL}${ARG_SHORT_PURGE}${ARG_SHORT_SKIP_TOKEN}${ARG_SHORT_SKIP_CONFIG}${ARG_SHORT_DOWNLOAD}${ARG_SHORT_KEEP_DOWNLOADS}${ARG_SHORT_CONFIG_BRANCH}:${ARG_SHORT_BINARY_BRANCH}:${ARG_SHORT_BRANCH}:${ARG_SHORT_EPHEMERAL}${ARG_SHORT_REMOTELY_MANAGED}${ARG_SHORT_INSTALL_HOSTMETRICS}${ARG_SHORT_TIMEOUT}:" opt
getopts "${ARG_SHORT_HELP}${ARG_SHORT_TOKEN}:${ARG_SHORT_API}:${ARG_SHORT_OPAMP_API}:${ARG_SHORT_TAG}:${ARG_SHORT_VERSION}:${ARG_SHORT_FIPS}${ARG_SHORT_YES}${ARG_SHORT_SKIP_SYSTEMD}${ARG_SHORT_UNINSTALL}${ARG_SHORT_PURGE}${ARG_SHORT_SKIP_TOKEN}${ARG_SHORT_SKIP_CONFIG}${ARG_SHORT_DOWNLOAD}${ARG_SHORT_KEEP_DOWNLOADS}${ARG_SHORT_CONFIG_BRANCH}:${ARG_SHORT_BINARY_BRANCH}:${ARG_SHORT_BRANCH}:${ARG_SHORT_EPHEMERAL}${ARG_SHORT_REMOTELY_MANAGED}${ARG_SHORT_INSTALL_HOSTMETRICS}${ARG_SHORT_TIMEOUT}:" opt
set -e

# Invalid argument catched, print and exit
Expand All @@ -300,6 +308,7 @@ function parse_options() {
"${ARG_SHORT_HELP}") usage; exit 0 ;;
"${ARG_SHORT_TOKEN}") SUMOLOGIC_INSTALLATION_TOKEN="${OPTARG}" ;;
"${ARG_SHORT_API}") API_BASE_URL="${OPTARG}" ;;
"${ARG_SHORT_OPAMP_API}") OPAMP_API_URL="${OPTARG}" ;;
"${ARG_SHORT_SKIP_CONFIG}") SKIP_CONFIG=true ;;
"${ARG_SHORT_VERSION}") VERSION="${OPTARG}" ;;
"${ARG_SHORT_FIPS}") FIPS=true ;;
Expand Down Expand Up @@ -681,7 +690,7 @@ function setup_config() {
mkdir -p "${REMOTE_CONFIG_DIRECTORY}"

write_sumologic_extension "${CONFIG_PATH}" "${INDENTATION}"
write_opamp_extension "${CONFIG_PATH}" "${REMOTE_CONFIG_DIRECTORY}" "${INDENTATION}" "${EXT_INDENTATION}" "${API_BASE_URL}"
write_opamp_extension "${CONFIG_PATH}" "${REMOTE_CONFIG_DIRECTORY}" "${INDENTATION}" "${EXT_INDENTATION}" "${OPAMP_API_URL}"

if [[ -n "${SUMOLOGIC_INSTALLATION_TOKEN}" && "${SYSTEMD_DISABLED}" == "true" ]]; then
write_installation_token "${SUMOLOGIC_INSTALLATION_TOKEN}" "${CONFIG_PATH}" "${EXT_INDENTATION}"
Expand All @@ -695,6 +704,10 @@ function setup_config() {
write_api_url "${API_BASE_URL}" "${CONFIG_PATH}" "${EXT_INDENTATION}"
fi

if [[ -n "${OPAMP_API_URL}" ]]; then
write_opamp_endpoint "${OPAMP_API_URL}" "${CONFIG_PATH}" "${EXT_INDENTATION}"
fi

if [[ -n "${FIELDS}" ]]; then
write_tags "${FIELDS}" "${CONFIG_PATH}" "${INDENTATION}" "${EXT_INDENTATION}"
fi
Expand Down Expand Up @@ -751,6 +764,11 @@ function setup_config() {
write_api_url "${API_BASE_URL}" "${COMMON_CONFIG_PATH}" "${EXT_INDENTATION}"
fi

# fill in opamp url
if [[ -n "${OPAMP_API_URL}" && -z "${USER_OPAMP_API_URL}" ]]; then
write_opamp_extension "${CONFIG_PATH}" "${REMOTE_CONFIG_DIRECTORY}" "${INDENTATION}" "${EXT_INDENTATION}" "${OPAMP_API_URL}"
fi

if [[ -n "${FIELDS}" && -z "${USER_FIELDS}" ]]; then
write_tags "${FIELDS}" "${COMMON_CONFIG_PATH}" "${INDENTATION}" "${EXT_INDENTATION}"
fi
Expand Down Expand Up @@ -796,7 +814,7 @@ function setup_config_darwin() {
echo -e "Creating remote configurations directory (${REMOTE_CONFIG_DIRECTORY})"
mkdir -p "${REMOTE_CONFIG_DIRECTORY}"

write_opamp_extension "${config_path}" "${REMOTE_CONFIG_DIRECTORY}" "${INDENTATION}" "${EXT_INDENTATION}" "${API_BASE_URL}"
write_opamp_extension "${config_path}" "${REMOTE_CONFIG_DIRECTORY}" "${INDENTATION}" "${EXT_INDENTATION}" "${OPAMP_API_URL}"

write_remote_config_launchd "${LAUNCHD_CONFIG}"

Expand Down Expand Up @@ -1092,6 +1110,25 @@ function get_user_api_url() {
|| echo ""
}

function get_user_opamp_endpoint() {
local file
readonly file="${1}"

if [[ ! -f "${file}" ]]; then
return
fi

# extract endpoint and strip quotes
grep -m 1 endpoint "${file}" \
| sed 's/.*endpoint:[[:blank:]]*//' \
| sed 's/[[:blank:]]*$//' \
| sed 's/^"//' \
| sed "s/^'//" \
| sed 's/"$//' \
| sed "s/'\$//" \
|| echo ""
}

function get_user_tags() {
local file
readonly file="${1}"
Expand Down Expand Up @@ -1316,6 +1353,27 @@ function write_api_url() {
fi
}

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

local file
readonly file="${2}"

local ext_indentation
readonly ext_indentation="${3}"

# ToDo: ensure we override only sumologic `api_base_url`
if grep "endpoint" "${file}" > /dev/null; then
sed -i.bak -e "s/endpoint:.*$/endpoint: $(escape_sed "${opamp_endpoint}")/" "${file}"
else
# write endpoint on the top of sumologic: opamp: extension
sed -i.bak -e "1,/opamp:/ s/opamp:/opamp:\\
\\${ext_indentation}endpoint: $(escape_sed "${opamp_endpoint}")/" "${file}"
fi
}

# write tags to user configuration file
function write_tags() {
local fields
Expand Down Expand Up @@ -1380,18 +1438,11 @@ ${indentation}opamp:/" "${file}"

# if a different base url is specified, configure the corresponding opamp endpoint
if [[ -n "${api_url}" ]]; then
wss_url=${api_url/https:/"wss:"}
wss_url=${wss_url%/}
wss_url=${wss_url/open-events/"opamp-events"}
wss_url=${wss_url/open-collectors/"opamp-collectors"}
wss_url=${wss_url/\.net/".net/v1/opamp"}
wss_url=${wss_url/\.com/".com/v1/opamp"}

if grep "endpoint: wss:" "${file}" > /dev/null; then
sed -i.bak -e "s/endpoint: wss:.*$/endpoint: $(escape_sed "${wss_url}")/" "${file}"
sed -i.bak -e "s/endpoint: wss:.*$/endpoint: $(escape_sed "${api_url}")/" "${file}"
else
sed -i.bak -e "s/opamp:/opamp:\\
\\${ext_indentation}endpoint: $(escape_sed "${wss_url}")/" "${file}"
\\${ext_indentation}endpoint: $(escape_sed "${api_url}")/" "${file}"
fi
fi

Expand Down Expand Up @@ -1712,7 +1763,7 @@ set_tmpdir
install_missing_dependencies
check_dependencies

readonly SUMOLOGIC_INSTALLATION_TOKEN API_BASE_URL FIELDS CONTINUE FILE_STORAGE CONFIG_DIRECTORY SYSTEMD_CONFIG UNINSTALL
readonly SUMOLOGIC_INSTALLATION_TOKEN API_BASE_URL OPAMP_API_URL FIELDS CONTINUE FILE_STORAGE CONFIG_DIRECTORY SYSTEMD_CONFIG UNINSTALL
readonly USER_CONFIG_DIRECTORY USER_ENV_DIRECTORY CONFIG_DIRECTORY CONFIG_PATH COMMON_CONFIG_PATH
readonly ACL_LOG_FILE_PATHS
readonly INSTALL_HOSTMETRICS
Expand Down Expand Up @@ -1766,6 +1817,12 @@ if [[ -z "${DOWNLOAD_ONLY}" ]]; then
exit 1
fi

USER_OPAMP_API_URL="$(get_user_opamp_endpoint "${COMMON_CONFIG_PATH}")"
if [[ -n "${USER_OPAMP_API_URL}" && -n "${OPAMP_API_URL}" && "${USER_OPAMP_API_URL}" != "${OPAMP_API_URL}" ]]; then
echo "You are trying to install with different opamp endpoint than in your configuration file!"
exit 1
fi

USER_FIELDS="$(get_user_tags "${COMMON_CONFIG_PATH}" "${INDENTATION}" "${EXT_INDENTATION}")"
FIELDS_TO_COMPARE="$(get_fields_to_compare "${FIELDS}")"

Expand Down
7 changes: 7 additions & 0 deletions install-script/test/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ func checkNoBakFilesPresent(c check) {
}
}

func checkOpAmpEndpointSet(c check) {
conf, err := getConfig(configPath)
require.NoError(c.test, err, "error while reading configuration")

require.Equal(c.test, conf.Extensions.OpAmp.Endpoint, "wss://example.com")
}

func checkHostmetricsConfigCreated(c check) {
require.FileExists(c.test, hostmetricsConfigPath, "hostmetrics configuration has not been created properly")
}
Expand Down
5 changes: 5 additions & 0 deletions install-script/test/command_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type installOptions struct {
remotelyManaged bool
ephemeral bool
timeout float64
opampEndpoint string
}

func (io *installOptions) string() []string {
Expand Down Expand Up @@ -105,6 +106,10 @@ func (io *installOptions) string() []string {
opts = append(opts, "--download-timeout", fmt.Sprintf("%f", io.timeout))
}

if io.opampEndpoint != "" {
opts = append(opts, "--opamp-api", io.opampEndpoint)
}

return opts
}

Expand Down
5 changes: 5 additions & 0 deletions install-script/test/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type config struct {

type extensions struct {
Sumologic sumologicExtension `yaml:"sumologic"`
OpAmp opampExtension `yaml:"opamp"`
}

type sumologicExtension struct {
Expand All @@ -21,6 +22,10 @@ type sumologicExtension struct {
Ephemeral bool `yaml:"ephemeral"`
}

type opampExtension struct {
Endpoint string
}

func getConfig(path string) (config, error) {
var conf config

Expand Down
22 changes: 22 additions & 0 deletions install-script/test/install_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ func TestInstallScript(t *testing.T) {
checkUserNotExists,
},
},
{
name: "installation token, remotely-managed, and opamp-api",
options: installOptions{
skipSystemd: true,
installToken: installToken,
remotelyManaged: true,
opampEndpoint: "wss://example.com",
},
preChecks: []checkFunc{checkBinaryNotCreated, checkConfigNotCreated, checkUserConfigNotCreated, checkUserNotExists},
postChecks: []checkFunc{
checkBinaryCreated,
checkBinaryIsRunning,
checkConfigCreated,
checkRemoteConfigDirectoryCreated,
checkConfigFilesOwnershipAndPermissions(rootUser, rootGroup),
checkTokenInSumoConfig,
checkEphemeralNotInConfig(configPath),
checkSystemdConfigNotCreated,
checkUserNotExists,
checkOpAmpEndpointSet,
},
},
{
name: "installation token only, binary not in PATH",
options: installOptions{
Expand Down
3 changes: 1 addition & 2 deletions version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ endif()

set(OTC_SUMO_VERSION "$ENV{OTC_SUMO_VERSION}")

if(NOT "${OTC_SUMO_VERSION}" MATCHES "^[0-9]+$")
if(NOT ("${OTC_SUMO_VERSION}" MATCHES "^[0-9]+$" OR "${OTC_SUMO_VERSION}" MATCHES "^[0-9]+-rc.[0-9]+$"))
message(FATAL_ERROR
"OTC_SUMO_VERSION contains an invalid version: ${OTC_SUMO_VERSION}\n"
"Must be an unsigned integer"
)
endif()

Expand Down

0 comments on commit c2e7265

Please sign in to comment.