From 99735f26b3a64c9b3e195e5af5374d3f6b682520 Mon Sep 17 00:00:00 2001 From: Clay Smith Date: Wed, 28 Feb 2024 22:00:08 +0000 Subject: [PATCH] Release v0.0.10 (#6) * update macOS automated installer * update docs * update msi release to include version number * remove sboms and apk packages * add unix autoinstaller script * add postrelease install check * allow token to be set during autoinstall * skip CI build + test on documentation updates * add markdown link check * fix broken link --- .github/workflows/build.yml | 4 +- .github/workflows/checks.yml | 12 +- .github/workflows/install.yml | 35 - .github/workflows/release-msi.yml | 8 +- .github/workflows/release.yml | 14 + .github/workflows/test.yml | 3 +- .goreleaser.yaml | 8 +- .../config/otelcol-linux-hostmetrics.yaml | 4 +- .../config/otelcol-macos-hostmetrics.yaml | 6 +- collector/otelcol-builder.yaml | 2 +- collector/scripts/install/install-macos.sh | 51 +- collector/scripts/install/install-unix.sh | 712 ++++++++++++++++++ .../service/com.servicenow.collector.plist | 2 + docs/monitor-kubernetes.md | 2 +- docs/monitor-linux.md | 31 +- docs/monitor-macos.md | 32 +- docs/monitor-windows.md | 8 +- readme.md | 6 +- 18 files changed, 833 insertions(+), 107 deletions(-) delete mode 100644 .github/workflows/install.yml create mode 100644 collector/scripts/install/install-unix.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c95e61..931afc6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,9 @@ name: Build on: pull_request: paths: - - collector/** + - '!docs/**' + - '!readme.md' + jobs: build_linux: runs-on: ubuntu-20.04 diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 540b953..cba4da0 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -4,7 +4,7 @@ on: jobs: yamllint: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - name: yaml-lint @@ -12,3 +12,13 @@ jobs: with: file_or_dir: collector/config/*.yaml collector/config-k8s/*.yaml config_file: .yamllint.yml + markdown-link-check: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@master + - uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + use-quiet-mode: 'yes' + use-verbose-mode: 'yes' + folder-path: 'docs/' + max-depth: 2 diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml deleted file mode 100644 index fdafb27..0000000 --- a/.github/workflows/install.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Test Install - -on: - release: - types: [published] - -jobs: - # Untar and validate collector and config from *.tar.gz - install_gzip: - runs-on: ubuntu-20.04 - steps: - - name: Untar latest release - uses: robinraju/release-downloader@v1.9 - with: - latest: true - extract: true - fileName: otelcol-servicenow_*_linux_amd64.tar.gz - - name: Validate otelcol-servicenow - run: ./otelcol-servicenow validate --config config/otelcol-linux-hostmetrics.yaml - - # Install and validate collector and config from *.deb - install_deb: - runs-on: ubuntu-20.04 - steps: - - name: Download latest *.deb release - uses: robinraju/release-downloader@v1.9 - with: - latest: true - extract: false - fileName: sn-collector_*_linux_amd64.deb - - run: ls -la - - name: Install otelcol-servicenow - run: sudo dpkg -i sn-collector_*_linux_amd64.deb - - name: Validate otelcol-servicenow - run: sudo /opt/sn-collector/otelcol-servicenow validate --config /opt/sn-collector/config.yaml diff --git a/.github/workflows/release-msi.yml b/.github/workflows/release-msi.yml index 6926cb7..e6e5f39 100644 --- a/.github/workflows/release-msi.yml +++ b/.github/workflows/release-msi.yml @@ -72,7 +72,7 @@ jobs: ls -la cd collector/windows ls -la - go-msi make --msi sn-collector.msi --version ${{ github.ref_name }} --src templates --out .\go-msi-tmp + go-msi make --msi sn-collector_${{ github.ref_name }}.msi --version ${{ github.ref_name }} --src templates --out .\go-msi-tmp shell: bash - name: Diagnostics @@ -84,8 +84,8 @@ jobs: - name: Upload MSI Artifact uses: actions/upload-artifact@v4 with: - name: sn-collector.msi - path: collector/windows/sn-collector.msi + name: sn-collector_${{ github.ref_name }}.msi + path: collector/windows/sn-collector_${{ github.ref_name }}.msi # Short lived because this is meant as an action for developers retention-days: 1 @@ -94,4 +94,4 @@ jobs: if: startsWith(github.ref, 'refs/tags/') with: files: | - collector/windows/sn-collector.msi \ No newline at end of file + collector/windows/sn-collector_${{ github.ref_name }}.msi \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af7453e..44d75b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,3 +70,17 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COSIGN_PWD: ${{ secrets.ORG_COSIGN_PWD }} + + postrelease: + runs-on: ubuntu-20.04 + needs: release + steps: + - name: Untar latest prerelease + uses: robinraju/release-downloader@v1.9 + with: + latest: true + extract: true + preRelease: true + fileName: otelcol-servicenow_*_linux_amd64.tar.gz + - name: Validate otelcol-servicenow + run: ./otelcol-servicenow validate --config config/otelcol-linux-hostmetrics.yaml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64a9f8e..828fe6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,8 @@ name: Tests on: pull_request: paths: - - collector/** + - '!docs/**' + - '!readme.md' jobs: unit-tests: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 472371b..a8fce57 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -100,7 +100,6 @@ nfpms: maintainer: ServiceNow Engineering description: SerivceNow distribution of the OpenTelemetry Collector. formats: - - apk - deb - rpm bindir: /opt/sn-collector @@ -138,9 +137,9 @@ signs: artifacts: all # https://goreleaser.com/customization/sbom/ -sboms: - - artifacts: archive - cmd: syft +# sboms: +# - artifacts: archive +# cmd: syft checksum: name_template: 'checksums.txt' @@ -149,4 +148,5 @@ release: draft: false prerelease: "true" extra_files: + - glob: "./collector/scripts/install/install-unix.sh" - glob: "./collector/scripts/install/install-macos.sh" diff --git a/collector/config/otelcol-linux-hostmetrics.yaml b/collector/config/otelcol-linux-hostmetrics.yaml index e5ba786..34c4665 100644 --- a/collector/config/otelcol-linux-hostmetrics.yaml +++ b/collector/config/otelcol-linux-hostmetrics.yaml @@ -36,7 +36,7 @@ exporters: otlp/lightstep: endpoint: ingest.lightstep.com:443 headers: - "lightstep-access-token": "${LS_TOKEN}" + "lightstep-access-token": "YOUR_TOKEN" sending_queue: enabled: true num_consumers: 4 @@ -78,4 +78,4 @@ service: metrics/host: receivers: [hostmetrics] processors: [batch, resourcedetection] - exporters: [debug] + exporters: [debug, otlp/lightstep] diff --git a/collector/config/otelcol-macos-hostmetrics.yaml b/collector/config/otelcol-macos-hostmetrics.yaml index 2591d70..471ddee 100644 --- a/collector/config/otelcol-macos-hostmetrics.yaml +++ b/collector/config/otelcol-macos-hostmetrics.yaml @@ -35,7 +35,7 @@ exporters: otlp/lightstep: endpoint: ingest.lightstep.com:443 headers: - "lightstep-access-token": "${LS_TOKEN}" + "lightstep-access-token": "YOUR_TOKEN" sending_queue: enabled: true num_consumers: 4 @@ -74,8 +74,8 @@ service: metrics/collector: receivers: [prometheus/self] processors: [batch, resourcedetection] - exporters: [debug] + exporters: [debug, otlp/lightstep] metrics/host: receivers: [hostmetrics] processors: [batch, resourcedetection] - exporters: [debug] + exporters: [debug, otlp/lightstep] diff --git a/collector/otelcol-builder.yaml b/collector/otelcol-builder.yaml index 817c895..19c7a4b 100644 --- a/collector/otelcol-builder.yaml +++ b/collector/otelcol-builder.yaml @@ -3,7 +3,7 @@ dist: description: ServiceNow-flavored OpenTelemetry Collector distro output_path: ./otelcol-servicenow otelcol_version: 0.95.0 - version: 0.0.9 + version: 0.0.10 exporters: - gomod: diff --git a/collector/scripts/install/install-macos.sh b/collector/scripts/install/install-macos.sh index 8706d74..73582bb 100755 --- a/collector/scripts/install/install-macos.sh +++ b/collector/scripts/install/install-macos.sh @@ -12,7 +12,6 @@ DOWNLOAD_BASE="https://github.com/lightstep/sn-collector/releases/download" PREREQS="printf sed uname tr find grep" TMP_DIR="${TMPDIR:-"/tmp/"}sn-collector" # Allow this to be overriden by cannonical TMPDIR env var INSTALL_DIR="/opt/sn-collector" -MANAGEMENT_YML_PATH="$INSTALL_DIR/manager.yaml" SCRIPT_NAME="$0" INDENT_WIDTH=' ' indent="" @@ -153,17 +152,11 @@ Usage: Example: '-b http://my.domain.org/servicenow-collector/binaries' will be used as the base of the download URL. $(fg_yellow '-e, --endpoint') - Defines the endpoint of an OpAMP compatible management server for this agent install. - This parameter may also be provided through the ENDPOINT environment variable. - - Specifying this will install the agent in a managed mode, as opposed to the - normal headless mode. + Defines the Cloud Observability ingest endpoint for telemetry $(fg_yellow '-i, --ingest-token') - Defines the secret key to be used when communicating with an OpAMP compatible server. - - This parameter may also be provided through the SECRET_KEY environment variable. - The '--endpoint' flag must be specified if this flag is specified. + Defines the token to be used when communicating with Cloud Observability + EOF ) info "$USAGE" @@ -348,7 +341,7 @@ set_download_urls() base_url=$DOWNLOAD_BASE fi - collector_download_url="$base_url/v$version/otelcol-servicenow_v${version}_darwin_${os_arch}.tar.gz" + collector_download_url="$base_url/v$version/otelcol-servicenow_${version}_darwin_${os_arch}.tar.gz" else collector_download_url="$url" fi @@ -370,20 +363,22 @@ set_ingest_token() fi INGEST_TOKEN="$ingest_token" - - if [ -n "$INGEST_TOKEN" ] && [ -z "$INGEST_ENDPOINT" ]; then - error_exit "$LINENO" "An endpoint must be specified when providing an ingest token" - fi } # latest_version gets the tag of the latest release, without the v prefix. latest_version() { - curl -sSL -H"Accept: application/vnd.github.v3+json" \ https://api.github.com/repos/lightstep/sn-collector/releases/latest | \ + curl -sSL -H"Accept: application/vnd.github.v3+json" "https://api.github.com/repos/lightstep/sn-collector/releases/latest" | \ grep "\"tag_name\"" | \ sed -E 's/ *"tag_name": "v([0-9]+\.[0-9]+\.[0-9+])",/\1/' } +# set the access token, if one was specified +set_access_token() +{ + sed -i "s/YOUR_TOKEN/$INGEST_TOKEN/g" /opt/sn-collector/config.yaml +} + # This will install the package by downloading & unpacking the tarball into the install directory install_package() { @@ -441,11 +436,6 @@ install_package() succeeded fi - # TODO: If an endpoint was specified, we need to update the config - #if [ -n "$OPAMP_ENDPOINT" ]; then - # create_manager_yml "$MANAGEMENT_YML_PATH" - #fi - if [ -f "/Library/LaunchDaemons/$SERVICE_NAME.plist" ]; then # Existing service file, we should stop & unload first. info "Uninstalling existing service file..." @@ -459,6 +449,11 @@ install_package() launchctl load -w "/Library/LaunchDaemons/$SERVICE_NAME.plist" > /dev/null 2>&1 || error_exit "$LINENO" "Failed to load service file /Library/LaunchDaemons/$SERVICE_NAME.plist" succeeded + if [ -n "$INGEST_TOKEN" ]; then + info "Setting access token..." + set_access_token + fi + info "Starting service..." launchctl start "$SERVICE_NAME" || error_exit "$LINENO" "Failed to start service file $SERVICE_NAME" succeeded @@ -471,20 +466,6 @@ install_package() decrease_indent } -# create_manager_yml creates the manager.yml at the specified path, containing opamp information. -create_manager_yml() -{ - manager_yml_path="$1" - if [ ! -f "$manager_yml_path" ]; then - info "Creating manager yaml..." - command printf 'endpoint: "%s"\n' "$OPAMP_ENDPOINT" > "$manager_yml_path" - [ -n "$OPAMP_LABELS" ] && command printf 'labels: "%s"\n' "$OPAMP_LABELS" >> "$manager_yml_path" - [ -n "$OPAMP_SECRET_KEY" ] && command printf 'secret_key: "%s"\n' "$OPAMP_SECRET_KEY" >> "$manager_yml_path" - succeeded - fi -} - - # This will display the results of an installation display_results() { diff --git a/collector/scripts/install/install-unix.sh b/collector/scripts/install/install-unix.sh new file mode 100644 index 0000000..8e686dd --- /dev/null +++ b/collector/scripts/install/install-unix.sh @@ -0,0 +1,712 @@ +#!/bin/sh + +set -e + +# Agent Constants +PACKAGE_NAME="sn-collector" +DOWNLOAD_BASE="https://github.com/lightstep/sn-collector/releases/download" + +# Script Constants +COLLECTOR_USER="sn-collector" +TMP_DIR=${TMPDIR:-"/tmp"} # Allow this to be overriden by cannonical TMPDIR env var +PREREQS="curl printf systemctl sed uname cut" +SCRIPT_NAME="$0" +INDENT_WIDTH=' ' +indent="" + +# out_file_path is the full path to the downloaded package (e.g. "/tmp/sn-collector_linux_amd64.deb") +out_file_path="unknown" + +# Colors +num_colors=$(tput colors 2>/dev/null) +if test -n "$num_colors" && test "$num_colors" -ge 8; then + bold="$(tput bold)" + underline="$(tput smul)" + # standout can be bold or reversed colors dependent on terminal + standout="$(tput smso)" + reset="$(tput sgr0)" + bg_black="$(tput setab 0)" + bg_blue="$(tput setab 4)" + bg_cyan="$(tput setab 6)" + bg_green="$(tput setab 2)" + bg_magenta="$(tput setab 5)" + bg_red="$(tput setab 1)" + bg_white="$(tput setab 7)" + bg_yellow="$(tput setab 3)" + fg_black="$(tput setaf 0)" + fg_blue="$(tput setaf 4)" + fg_cyan="$(tput setaf 6)" + fg_green="$(tput setaf 2)" + fg_magenta="$(tput setaf 5)" + fg_red="$(tput setaf 1)" + fg_white="$(tput setaf 7)" + fg_yellow="$(tput setaf 3)" +fi + +if [ -z "$reset" ]; then + sed_ignore='' +else + sed_ignore="/^[$reset]+$/!" +fi + +# Helper Functions +printf() { + if command -v sed >/dev/null; then + command printf -- "$@" | sed -E "$sed_ignore s/^/$indent/g" # Ignore sole reset characters if defined + else + # Ignore $* suggestion as this breaks the output + # shellcheck disable=SC2145 + command printf -- "$indent$@" + fi +} + +increase_indent() { indent="$INDENT_WIDTH$indent" ; } +decrease_indent() { indent="${indent#*"$INDENT_WIDTH"}" ; } + +# Color functions reset only when given an argument +bold() { command printf "$bold$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +underline() { command printf "$underline$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +standout() { command printf "$standout$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +# Ignore "parameters are never passed" +# shellcheck disable=SC2120 +reset() { command printf "$reset$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_black() { command printf "$bg_black$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_blue() { command printf "$bg_blue$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_cyan() { command printf "$bg_cyan$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_green() { command printf "$bg_green$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_magenta() { command printf "$bg_magenta$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_red() { command printf "$bg_red$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_white() { command printf "$bg_white$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +bg_yellow() { command printf "$bg_yellow$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_black() { command printf "$fg_black$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_blue() { command printf "$fg_blue$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_cyan() { command printf "$fg_cyan$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_green() { command printf "$fg_green$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_magenta() { command printf "$fg_magenta$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_red() { command printf "$fg_red$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_white() { command printf "$fg_white$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } +fg_yellow() { command printf "$fg_yellow$*$(if [ -n "$1" ]; then command printf "$reset"; fi)" ; } + +# Intentionally using variables in format string +# shellcheck disable=SC2059 +info() { printf "$*\\n" ; } +# Intentionally using variables in format string +# shellcheck disable=SC2059 +warn() { + increase_indent + printf "$fg_yellow$*$reset\\n" + decrease_indent +} +# Intentionally using variables in format string +# shellcheck disable=SC2059 +error() { + increase_indent + printf "$fg_red$*$reset\\n" + decrease_indent +} +# Intentionally using variables in format string +# shellcheck disable=SC2059 +success() { printf "$fg_green$*$reset\\n" ; } +# Ignore 'arguments are never passed' +# shellcheck disable=SC2120 +prompt() { + if [ "$1" = 'n' ]; then + command printf "y/$(fg_red '[n]'): " + else + command printf "$(fg_green '[y]')/n: " + fi +} + +separator() { printf "===================================================\\n" ; } + +banner() +{ + printf "\\n" + separator + printf "| %s\\n" "$*" ; + separator +} + +usage() +{ + increase_indent + USAGE=$(cat <&2 + if [ -n "$0" ]; then + increase_indent + error "$*" + decrease_indent + fi + force_exit +} + +print_prereq_line() +{ + if [ -n "$2" ]; then + command printf "\\n${indent} - " + command printf "[$1]: $2" + fi +} + +check_failure() +{ + if [ "$indent" != '' ]; then increase_indent; fi + command printf "${indent}${fg_red}ERROR: %s check failed!${reset}" "$1" + + print_prereq_line "Issue" "$2" + print_prereq_line "Resolution" "$3" + print_prereq_line "Help Link" "$4" + print_prereq_line "Rerun" "$5" + + command printf "\\n" + if [ "$indent" != '' ]; then decrease_indent; fi + force_exit +} + +succeeded() +{ + increase_indent + success "Succeeded!" + decrease_indent +} + +failed() +{ + error "Failed!" +} + +# This will set all installation variables +# at the beginning of the script. +setup_installation() +{ + banner "Configuring Installation Variables" + increase_indent + + # Installation variables + set_os_arch + set_package_type + + # if package_path is not set then download the package + if [ -z "$package_path" ]; then + set_download_urls + set_proxy + set_file_name + else + out_file_path="$package_path" + fi + + set_ingest_endpoint + set_ingest_token + + success "Configuration complete!" + decrease_indent +} + +set_file_name() { + if [ -z "$version" ] ; then + package_file_name="${PACKAGE_NAME}_linux_${arch}.${package_type}" + else + package_file_name="${PACKAGE_NAME}_v${version}_linux_${arch}.${package_type}" + fi + out_file_path="$TMP_DIR/$package_file_name" +} + +set_proxy() +{ + if [ -n "$proxy" ]; then + info "Using proxy from arguments: $proxy" + if [ -n "$proxy_user" ]; then + while [ -z "$proxy_password" ] ; do + increase_indent + command printf "${indent}$(fg_blue "$proxy_user@$proxy")'s password: " + stty -echo + read -r proxy_password + stty echo + info + if [ -z "$proxy_password" ]; then + warn "The password must be provided!" + fi + decrease_indent + done + protocol="$(echo "$proxy" | cut -d'/' -f1)" + host="$(echo "$proxy" | cut -d'/' -f3)" + full_proxy="$protocol//$proxy_user:$proxy_password@$host" + fi + fi + + if [ -z "$full_proxy" ]; then + full_proxy="$proxy" + fi +} + + +set_os_arch() +{ + os_arch=$(uname -m) + case "$os_arch" in + # arm64 strings. These are from https://stackoverflow.com/questions/45125516/possible-values-for-uname-m + aarch64|arm64|aarch64_be|armv8b|armv8l) + os_arch="arm64" + ;; + x86_64) + os_arch="amd64" + ;; + # experimental PowerPC arch support for collector + ppc64) + os_arch="ppc64" + ;; + ppc64le) + os_arch="ppc64le" + ;; + # armv6/32bit. These are what raspberry pi can return, which is the main reason we support 32-bit arm + arm|armv6l|armv7l) + os_arch="arm" + ;; + *) + error_exit "$LINENO" "Unsupported os arch: $os_arch" + ;; + esac +} + +# Set the package type before install +set_package_type() +{ + # if package_path is set get the file extension otherwise look at what's available on the system + if [ -n "$package_path" ]; then + case "$package_path" in + *.deb) + package_type="deb" + ;; + *.rpm) + package_type="rpm" + ;; + *) + error_exit "$LINENO" "Unsupported package type: $package_path" + ;; + esac + else + if command -v dpkg > /dev/null 2>&1; then + package_type="deb" + elif command -v rpm > /dev/null 2>&1; then + package_type="rpm" + else + error_exit "$LINENO" "Could not find dpkg or rpm on the system" + fi + fi + +} + +# This will set the urls to use when downloading the agent and its plugins. +# These urls are constructed based on the --version flag or COLLECTOR_VERSION env variable. +# If not specified, the version defaults to whatever the latest release on github is. +set_download_urls() +{ + if [ -z "$url" ] ; then + if [ -z "$version" ] ; then + # shellcheck disable=SC2153 + version=$COLLECTOR_VERSION + fi + + if [ -z "$version" ] ; then + version=$(latest_version) + fi + + if [ -z "$version" ] ; then + error_exit "$LINENO" "Could not determine version to install" + fi + + if [ -z "$base_url" ] ; then + base_url=$DOWNLOAD_BASE + fi + + collector_download_url="$base_url/v$version/${PACKAGE_NAME}_${version}_linux_${os_arch}.${package_type}" + else + collector_download_url="$url" + fi +} + +# This will check all prerequisites before running an installation. +check_prereqs() +{ + banner "Checking Prerequisites" + increase_indent + root_check + os_check + os_arch_check + package_type_check + dependencies_check + success "Prerequisite check complete!" + decrease_indent +} + +# This checks to see if the user who is running the script has root permissions. +root_check() +{ + system_user_name=$(id -un) + if [ "${system_user_name}" != 'root' ] + then + failed + error_exit "$LINENO" "Script needs to be run as root or with sudo" + fi +} + +# This will check if the operating system is supported. +os_check() +{ + info "Checking that the operating system is supported..." + os_type=$(uname -s) + case "$os_type" in + Linux) + succeeded + ;; + *) + failed + error_exit "$LINENO" "The operating system $(fg_yellow "$os_type") is not supported by this script." + ;; + esac +} + +# This will check if the system architecture is supported. +os_arch_check() +{ + info "Checking for valid operating system architecture..." + arch=$(uname -m) + case "$arch" in + x86_64|aarch64|ppc64|ppc64le|arm64|aarch64_be|armv8b|armv8l|arm|armv6l|armv7l) + succeeded + ;; + *) + failed + error_exit "$LINENO" "The operating system architecture $(fg_yellow "$arch") is not supported by this script." + ;; + esac +} + +# This will check if the current environment has +# all required shell dependencies to run the installation. +dependencies_check() +{ + info "Checking for script dependencies..." + FAILED_PREREQS='' + for prerequisite in $PREREQS; do + if command -v "$prerequisite" >/dev/null; then + continue + else + if [ -z "$FAILED_PREREQS" ]; then + FAILED_PREREQS="${fg_red}$prerequisite${reset}" + else + FAILED_PREREQS="$FAILED_PREREQS, ${fg_red}$prerequisite${reset}" + fi + fi + done + + if [ -n "$FAILED_PREREQS" ]; then + failed + error_exit "$LINENO" "The following dependencies are required by this script: [$FAILED_PREREQS]" + fi + succeeded +} + +# This will check to ensure either dpkg or rpm is installedon the system +package_type_check() +{ + info "Checking for package manager..." + if command -v dpkg > /dev/null 2>&1; then + succeeded + elif command -v rpm > /dev/null 2>&1; then + succeeded + else + failed + error_exit "$LINENO" "Could not find dpkg or rpm on the system" + fi +} + +set_ingest_endpoint() +{ + if [ -z "$ingest_endpoint" ] ; then + ingest_endpoint="$ENDPOINT" + fi + + INGEST_ENDPOINT="$ingest_endpoint" +} + +set_ingest_token() +{ + if [ -z "$ingest_token" ] ; then + ingest_token=$INGEST_TOKEN + fi + + INGEST_TOKEN="$ingest_token" +} + + +# latest_version gets the tag of the latest release, without the v prefix. +latest_version() +{ + curl -sSL -H"Accept: application/vnd.github.v3+json" https://api.github.com/repos/lightstep/sn-collector/releases/latest | \ + grep "\"tag_name\"" | \ + sed -E 's/ *"tag_name": "v([0-9]+\.[0-9]+\.[0-9+])",/\1/' +} + +# set the access token, if one was specified +set_access_token() +{ + sed -i "s/YOUR_TOKEN/$INGEST_TOKEN/g" /opt/sn-collector/config.yaml +} + +# This will install the package by downloading the archived agent, +# extracting the binaries, and then removing the archive. +install_package() +{ + banner "Installing ServiceNow OpenTelemetry Collector" + increase_indent + + # if the user didn't specify a local file then download the package + if [ -z "$package_path" ]; then + proxy_args="" + if [ -n "$proxy" ]; then + proxy_args="-x $proxy" + if [ -n "$proxy_user" ]; then + proxy_args="$proxy_args -U $proxy_user:$proxy_password" + fi + fi + + if [ -n "$proxy" ]; then + info "Downloading package using proxy..." + fi + + info "Downloading package..." + eval curl -L "$proxy_args" "$collector_download_url" -o "$out_file_path" --progress-bar --fail || error_exit "$LINENO" "Failed to download package" + succeeded + fi + + info "Installing package..." + # if target install directory doesn't exist and we're using dpkg ensure a clean state + # by checking for the package and running purge if it exists. + if [ ! -d "/opt/sn-collector" ] && [ "$package_type" = "deb" ]; then + dpkg -s "sn-collector" > /dev/null 2>&1 && dpkg --purge "sn-collector" > /dev/null 2>&1 + fi + + unpack_package || error_exit "$LINENO" "Failed to extract package" + succeeded + + if [ -n "$INGEST_TOKEN" ]; then + info "Setting access token..." + set_access_token + fi + + if [ "$(systemctl is-enabled sn-collector)" = "enabled" ]; then + # The unit is already enabled; It may be running, too, if this was an upgrade. + # We'll want to restart, which will start it if it wasn't running already, + # and restart in the case that this was an upgrade on a running agent. + info "Restarting service..." + systemctl restart sn-collector + succeeded + else + info "Enabling service..." + systemctl enable --now sn-collector > /dev/null 2>&1 || error_exit "$LINENO" "Failed to enable service" + succeeded + fi + + success "ServiceNow OpenTelemetry Collector installation complete!" + decrease_indent +} + +unpack_package() +{ + case "$package_type" in + deb) + dpkg --force-confold -i "$out_file_path" > /dev/null || error_exit "$LINENO" "Failed to unpack package" + ;; + rpm) + rpm -U "$out_file_path" > /dev/null || error_exit "$LINENO" "Failed to unpack package" + ;; + *) + error "Unrecognized package type" + return 1 + ;; + esac + return 0 +} + +# This will display the results of an installation +display_results() +{ + banner 'Information' + increase_indent + info "Collector Home: $(fg_cyan "/opt/sn-collector")$(reset)" + info "Collector Config: $(fg_cyan "/opt/sn-collector/config.yaml")$(reset)" + info "Start Command: $(fg_cyan "sudo systemctl start sn-collector")$(reset)" + info "Stop Command: $(fg_cyan "sudo systemctl stop sn-collector")$(reset)" + info "Logs Command: $(fg_cyan "sudo journalctl -u sn-collector -f")$(reset)" + decrease_indent + + banner 'Support' + increase_indent + info "For more information on configuring the agent, see the docs:" + increase_indent + info "$(fg_cyan "https://github.com/lightstep/sn-collector")$(reset)" + decrease_indent + info "If you have any other questions please open a case at support.servicenow.com$(reset)" + increase_indent + decrease_indent + decrease_indent + + banner "$(fg_green Installation Complete!)" + return 0 +} + +uninstall_package() +{ + case "$package_type" in + deb) + dpkg -r "sn-collector" > /dev/null 2>&1 + ;; + rpm) + rpm -e "sn-collector" > /dev/null 2>&1 + ;; + *) + error "Unrecognized package type" + return 1 + ;; + esac + return 0 +} + +uninstall() +{ + set_package_type + banner "Uninstalling ServiceNow OpenTelemetry Collector" + increase_indent + + info "Checking permissions..." + root_check + succeeded + + info "Stopping service..." + systemctl stop sn-collector > /dev/null || error_exit "$LINENO" "Failed to stop service" + succeeded + + info "Disabling service..." + systemctl disable sn-collector > /dev/null 2>&1 || error_exit "$LINENO" "Failed to disable service" + succeeded + + info "Removing package..." + uninstall_package || error_exit "$LINENO" "Failed to remove package" + succeeded + decrease_indent + + banner "$(fg_green Uninstallation Complete!)" +} + +main() +{ + # We do these checks before we process arguments, because + # some of these options bail early, and we'd like to be sure that those commands + # (e.g. uninstall) can run + + check_prereqs + + if [ $# -ge 1 ]; then + while [ -n "$1" ]; do + case "$1" in + -v|--version) + version=$2 ; shift 2 ;; + -l|--url) + url=$2 ; shift 2 ;; + -f|--file) + package_path=$2 ; shift 2 ;; + -x|--proxy) + proxy=$2 ; shift 2 ;; + -U|--proxy-user) + proxy_user=$2 ; shift 2 ;; + -P|--proxy-password) + proxy_password=$2 ; shift 2 ;; + -e|--endpoint) + ingest_endpoint=$2 ; shift 2 ;; + -i|--ingest-token) + ingest_token=$2 ; shift 2 ;; + -c|--check-bp-url) + check_bp_url="true" ; shift 1 ;; + -b|--base-url) + base_url=$2 ; shift 2 ;; + -r|--uninstall) + uninstall + exit 0 + ;; + -h|--help) + usage + exit 0 + ;; + --) + shift; break ;; + *) + error "Invalid argument: $1" + usage + force_exit + ;; + esac + done + fi + + setup_installation + install_package + display_results +} + +main "$@" diff --git a/collector/service/com.servicenow.collector.plist b/collector/service/com.servicenow.collector.plist index a4543c3..22e0cd7 100644 --- a/collector/service/com.servicenow.collector.plist +++ b/collector/service/com.servicenow.collector.plist @@ -25,6 +25,8 @@ [INSTALLDIR] ExitTimeOut 20 + StandardOutPath + /opt/sn-collector/collector.log StandardErrorPath /var/log/sn_collector.err diff --git a/docs/monitor-kubernetes.md b/docs/monitor-kubernetes.md index 100a3ce..8e0b90c 100644 --- a/docs/monitor-kubernetes.md +++ b/docs/monitor-kubernetes.md @@ -7,7 +7,7 @@ | AKS (Azure) | last three major versions | ARM, AMD | | Kubernetes | last three major versions | ARM, AMD | -* **Note:** We recommend Red Hat OpenShift customers use the [Red Hat OpenTelemetry Distribution](https://docs.openshift.com/container-platform/4.12/otel/otel-using.html). +* **Note:** We recommend Red Hat OpenShift customers use the [Red Hat OpenTelemetry Distribution](https://docs.openshift.com/container-platform/4.15/otel/otel-installing.html). ### Deploy for Kubernetes monitoring with The OpenTelemetry Operator and Helm diff --git a/docs/monitor-linux.md b/docs/monitor-linux.md index 8607aef..647c154 100644 --- a/docs/monitor-linux.md +++ b/docs/monitor-linux.md @@ -4,14 +4,30 @@ | ---------------------------------------------- | ------------------------- | ------------ | | Red Hat Enterprise Linux (RHEL), Amazon Linux | last three major versions | ARM, AMD | | Ubuntu | last three major versions | ARM, AMD | -| Alpine | last three major versions | ARM, AMD | | Debian | last three major versions | ARM, AMD | -### Install for for Linux server monitoring (no containers) +### Automated package install for Linux server monitoring + +This install approach automatically downloads dependencies and installs the collector as a service on Linux using a Debian or RPM package. Priviliged (root) access is needed. + +1. As `sudo`, run the following in your shell. If you do not specify an optional token, edit the configuration file after install complete. + - ```sh + export CLOUDOBS_TOKEN='your-cloudobs-access-token' + sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-unix.sh)" install_unix.sh --ingest-token $CLOUDOBS_TOKEN + ``` + +2. Review the collector configuration installed in `/opt/sn-collector/config.yaml`. The collector will automatically start running with the default configuration. + +3. To *uninstall*, run: + - ```sh + sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-unix.sh)" install_unix.sh --uninstall + ``` + +### Package install for Linux server monitoring Gather system metrics from a Linux system using an installed software package. Use this for servers and hosts that **do not** have Docker or a container runtime. -1. Download the appropriate package for your system and CPU architecture from the Releases page of this repository. +1. Download the appropriate package for your system and CPU architecture from the [Releases](https://github.com/lightstep/sn-collector/releases) page of this repository. - If you're not sure about what architecture your system is using, inspect the output of the `arch` command. ```sh arch @@ -26,13 +42,10 @@ Gather system metrics from a Linux system using an installed software package. U ```sh sudo apt-get install -y otelcol-servicenow_version_linux_arch.deb ``` - - APK (Alpine Linux) package with `apk`: - ```sh - sudo apk add --allow-untrusted otelcol-servicenow_version_linux_arch.apk - ``` + 3. Follow the post-install instructions on starting the collector service. -### Install for for Linux host monitoring with Docker +### Install for Linux host monitoring with Docker Gather host system metrics from a Linux using a Docker image. @@ -41,7 +54,7 @@ Gather host system metrics from a Linux using a Docker image. docker pull ghcr.io/lightstep/sn-collector/sn-collector-experimental:latest ``` -2. Run the collector as a container, but mount the host filesystem to gather host metrics. +2. Run the collector as a container, but mount the host filesystem to gather host metrics. Edit the configuration file as needed. - ```sh docker run --rm --name sn-collector-experimental \ -v ./collector/config/otelcol-docker-hostmetrics.yaml:/etc/otelcol/config.yaml \ diff --git a/docs/monitor-macos.md b/docs/monitor-macos.md index c49634f..6bbde20 100644 --- a/docs/monitor-macos.md +++ b/docs/monitor-macos.md @@ -1,13 +1,31 @@ ## Monitor macOS with the ServiceNow Collector -The last three macOS versions are supported on both Intel (AMD64) and Apple Silicon (ARM-based: M1, M2, etc) +The last three macOS versions are supported on both Intel (AMD64) and Apple Silicon (ARM-based: M1, M2, etc). -### Install for macOS Monitoring +### Automated install for macOS -To install using an automated script, run: +This install approach automatically downloads dependencies and installs the collector as a service on macOS. Priviliged (root) access is needed. -```sh -sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install_macos.sh)" install_macos.sh -``` +1. As `sudo`, run the following in your shell. If you do not specify an optional token, edit the configuration file after install complete. + - ```sh + export CLOUDOBS_TOKEN='your-cloudobs-access-token' + sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-macos.sh)" install_macos.sh --ingest-token $CLOUDOBS_TOKEN + ``` -By default, the configuration for the collector will be installed in `/opt/sn-collector/config.yaml`. +2. Review the collector configuration installed in `/opt/sn-collector/config.yaml`. The collector will automatically start running with the default configuration. + +3. To *uninstall*, run: + - ```sh + sudo sh -c "$(curl -fsSlL https://github.com/lightstep/sn-collector/releases/latest/download/install-macos.sh)" install_macos.sh --uninstall + ``` + +### Manual install for macOS + +1. On the [Releases](https://github.com/lightstep/sn-collector/releases) page, download the appropriate collector `*.tar.gz` for `darwin` and your processor type. Apple Silicon processors use the `amd` binary. + +2. Extract the `*.tar.gz` archive. + +3. Validate the collector runs and the bundled configuration is valid. + - ```sh + ./sn-collector validate config.yaml + ``` diff --git a/docs/monitor-windows.md b/docs/monitor-windows.md index 2ae487c..2e9ed1e 100644 --- a/docs/monitor-windows.md +++ b/docs/monitor-windows.md @@ -2,6 +2,12 @@ Windows 2022 64-bit (AMD) is supported. -Download the latest `*.msi` from the releases page and install. +### Install using an MSI + +Download the latest `*.msi` from the [Releases](https://github.com/lightstep/sn-collector/releases) page and install. By default, the collector will be installed in the `Program Files (x86)` directory. + +### Install from executable + +Instructions from installing from a collector executable are available on the ServiceNow Support site at [KB1634644](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1634644). diff --git a/readme.md b/readme.md index d2fb27a..3e499e1 100644 --- a/readme.md +++ b/readme.md @@ -62,6 +62,7 @@ The following tables represent the supported components of the ServiceNow Collec | otlp | [contrib][1] | | prometheus | [contrib][1] | | hostmetrics | [contrib][1] | +| kafka | [contrib][1] | | k8sevents | [contrib][1] | | k8sobjects | [contrib][1] | | k8scluster | [contrib][1] | @@ -82,7 +83,7 @@ The following tables represent the supported components of the ServiceNow Collec | resource | [contrib][2] | | resourcedetection | [contrib][2] | | transform | [contrib][2] | -| `concurrentbatch`* | pending contribution | +| `concurrentbatch`* | under development | [2]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor @@ -91,7 +92,8 @@ The following tables represent the supported components of the ServiceNow Collec | Exporter | Status | | ---------------------------------------------------------------- | -------------------- | | otlp | in core | -| `servicenow`* | pending contribution | +| `servicenow`* | under development | +| arrow | under development | | debug | in core | | kafka | [contrib][3] |