Skip to content

Commit

Permalink
Include smart agent bundle in amd64 deb/rpm
Browse files Browse the repository at this point in the history
  • Loading branch information
jchengsfx committed Mar 18, 2021
1 parent 89c8812 commit 92846af
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 42 deletions.
11 changes: 4 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,14 @@ jobs:
steps:
- attach_to_workspace
- run:
name: Install fpm and dependencies
command: |
sudo apt-get update
sudo apt-get install -y ruby ruby-dev rubygems build-essential rpm
sudo gem install --no-document fpm -v 1.11.0
name: Build fpm image
command: docker build -t otelcol-fpm internal/buildscripts/packaging/fpm
- run:
name: Build << parameters.package_type >> amd64 package
command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "amd64" "./dist/"
command: docker run --rm -v $(pwd):/repo -e PACKAGE="<< parameters.package_type >>" -e VERSION="${CIRCLE_TAG:-}" -e ARCH="amd64" otelcol-fpm
- run:
name: Build << parameters.package_type >> arm64 package
command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "arm64" "./dist/"
command: docker run --rm -v $(pwd):/repo -e PACKAGE="<< parameters.package_type >>" -e VERSION="${CIRCLE_TAG:-}" -e ARCH="arm64" otelcol-fpm
- install_pytest
- run:
name: Test << parameters.package_type >> package installation
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,4 @@ binaries-windows_amd64:
%-package:
$(MAKE) binaries-linux_$(ARCH)
docker build -t otelcol-fpm internal/buildscripts/packaging/fpm
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcol-fpm
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) -e SMART_AGENT_RELEASE=$(SMART_AGENT_RELEASE) otelcol-fpm
6 changes: 6 additions & 0 deletions cmd/otelcol/config/collector/agent_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# environment variables are required to be manually defined or configured below:
# - SPLUNK_ACCESS_TOKEN: The Splunk access token to authenticate requests
# - SPLUNK_API_URL: The Splunk API URL, e.g. https://api.us0.signalfx.com
# - SPLUNK_BUNDLE_DIR: The path to the Smart Agent bundle, e.g. /usr/lib/splunk-otel-collector
# - SPLUNK_COLLECTD_DIR: The path to the collectd config directory for the Smart Agent, e.g. /usr/lib/splunk-otel-collector/run/collectd
# - SPLUNK_HEC_TOKEN: The Splunk HEC authentication token
# - SPLUNK_HEC_URL: The Splunk HEC endpoint URL, e.g. https://ingest.us0.signalfx.com/v1/log
# - SPLUNK_INGEST_URL: The Splunk ingest URL, e.g. https://ingest.us0.signalfx.com
Expand All @@ -14,6 +16,10 @@ extensions:
http_forwarder:
egress:
endpoint: "${SPLUNK_API_URL}"
smartagent:
bundleDir: "${SPLUNK_BUNDLE_DIR}"
collectd:
configDir: "${SPLUNK_COLLECTD_DIR}"
zpages:

receivers:
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/linux-installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sudo sh /tmp/splunk-otel-collector.sh --realm SPLUNK_REALM --memory SPLUNK_MEMOR
### Collector Configuration

The Collector comes with a default configuration which can be found at
`/etc/otel/collector/splunk_otel_linux.yaml`. This configuration can be
`/etc/otel/collector/splunk_config_linux.yaml`. This configuration can be
modified as needed. Possible configuration options can be found in the
`receivers`, `processors`, `exporters`, and `extensions` folders of either:

Expand Down
11 changes: 6 additions & 5 deletions docs/getting-started/linux-standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ yum install -y splunk-otel-collector
```
2. A default configuration file will be installed to
`/etc/otel/collector/splunk_config_linux.yaml` if it does not already exist.
3. The `/etc/otel/collector/splunk_env` environment file is required to start
the `splunk-otel-collector` systemd service. A sample environment file will
be installed to `/etc/otel/collector/splunk_env.example` that includes the
3. The `/etc/otel/collector/splunk-otel-collector.conf` environment file is
required to start the `splunk-otel-collector` systemd service. A sample
environment file will be installed to
`/etc/otel/collector/splunk-otel-collector.conf.example` that includes the
required environment variables for the default config. To utilize this
sample file, set the variables as appropriate and save the file as
`/etc/otel/collector/splunk_env`.
`/etc/otel/collector/splunk-otel-collector.conf`.
4. Start/Restart the service with
`sudo systemctl restart splunk-otel-collector.service`.

Expand Down Expand Up @@ -164,5 +165,5 @@ configuration as shown above.
If the custom configuration includes a `memory_limiter` processor then the
`ballast_size_mib` parameter should be the same as the
`SPLUNK_BALLAST_SIZE_MIB` environment variable. See
[splunk_config_linux.yaml](cmd/otelcol/config/collector/splunk_config_linux.yaml)
[splunk_config_linux.yaml](../../cmd/otelcol/config/collector/splunk_config_linux.yaml)
as an example.
5 changes: 3 additions & 2 deletions internal/buildscripts/packaging/fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM debian:9

RUN apt-get update && \
apt-get install -y ruby ruby-dev rubygems build-essential git rpm sudo
apt-get install -y ruby ruby-dev rubygems build-essential git rpm sudo curl jq

RUN gem install --no-document fpm -v 1.11.0

Expand All @@ -12,5 +12,6 @@ ENV PACKAGE="deb"
ENV VERSION=""
ENV ARCH="amd64"
ENV OUTPUT_DIR="/repo/dist/"
ENV SMART_AGENT_RELEASE="latest"

CMD ./internal/buildscripts/packaging/fpm/$PACKAGE/build.sh "$VERSION" "$ARCH" "$OUTPUT_DIR"
CMD ./internal/buildscripts/packaging/fpm/$PACKAGE/build.sh "$VERSION" "$ARCH" "$OUTPUT_DIR" "$SMART_AGENT_RELEASE"
44 changes: 43 additions & 1 deletion internal/buildscripts/packaging/fpm/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ CONFIG_INSTALL_PATH="/etc/otel/collector/splunk_config_linux.yaml"
SERVICE_REPO_PATH="$FPM_DIR/$SERVICE_NAME.service"
SERVICE_INSTALL_PATH="/lib/systemd/system/$SERVICE_NAME.service"

FLUENTD_CONFIG_INSTALL_DIR="/etc/otel/collector/fluentd"

SMART_AGENT_RELEASE_URL="https://api.github.com/repos/signalfx/signalfx-agent/releases"
SMART_AGENT_INSTALL_PATH="/usr/lib/splunk-otel-collector"

PREINSTALL_PATH="$FPM_DIR/preinstall.sh"
POSTINSTALL_PATH="$FPM_DIR/postinstall.sh"
PREUNINSTALL_PATH="$FPM_DIR/preuninstall.sh"
Expand All @@ -43,6 +48,38 @@ create_user_group() {
sudo useradd --system --user-group --no-create-home --shell /sbin/nologin $SERVICE_USER
}

download_smart_agent() {
local tag="$1"
local buildroot="$2"
local api_url=""
local dl_url=""

if [ "$tag" = "latest" ]; then
tag=$( curl -sL "$SMART_AGENT_RELEASE_URL/latest" | jq -r '.tag_name' )
if [ -z "$tag" ]; then
echo "Failed to get tag_name for latest release from $SMART_AGENT_RELEASE_URL/latest" >&2
exit 1
fi
fi

api_url="$SMART_AGENT_RELEASE_URL/tags/$tag"
dl_url="$( curl -sL "$api_url" | jq -r '.assets[] .browser_download_url' | grep "signalfx-agent-${tag#v}\.tar\.gz" )"
if [ -z "$dl_url" ]; then
echo "Failed to get the agent download url from $api_url" >&2
exit 1
fi

echo "Downloading $dl_url ..."
curl -sL "$dl_url" -o "$buildroot/signalfx-agent.tar.gz"

mkdir -p "$buildroot/usr/lib"
tar -xzf "$buildroot/signalfx-agent.tar.gz" -C "$buildroot/usr/lib"
mv "$buildroot/usr/lib/signalfx-agent" "$buildroot/$SMART_AGENT_INSTALL_PATH"
rm -f "$buildroot/$SMART_AGENT_INSTALL_PATH/bin/signalfx-agent"
rm -f "$buildroot/$SMART_AGENT_INSTALL_PATH/bin/agent-status"
rm -f "$buildroot/signalfx-agent.tar.gz"
}

setup_files_and_permissions() {
local otelcol="$1"
local buildroot="$2"
Expand All @@ -58,10 +95,15 @@ setup_files_and_permissions() {
cp -f "$CONFIG_REPO_PATH" "$buildroot/$CONFIG_INSTALL_PATH"
sudo chown -R $SERVICE_USER:$SERVICE_GROUP "$buildroot/etc/otel"
sudo chmod -R 755 "$buildroot/etc/otel"
sudo chmod 600 "$buildroot/etc/otel/collector/splunk_env.example"
sudo chmod 600 "$buildroot/etc/otel/collector/$SERVICE_NAME.conf.example"

mkdir -p "$buildroot/$(dirname $SERVICE_INSTALL_PATH)"
cp -f "$SERVICE_REPO_PATH" "$buildroot/$SERVICE_INSTALL_PATH"
sudo chown root:root "$buildroot/$SERVICE_INSTALL_PATH"
sudo chmod 644 "$buildroot/$SERVICE_INSTALL_PATH"

if [ -d "$buildroot/$SMART_AGENT_INSTALL_PATH" ]; then
sudo chown -R $SERVICE_USER:$SERVICE_GROUP "$buildroot/$SMART_AGENT_INSTALL_PATH"
sudo chmod -R 755 "$buildroot/$SMART_AGENT_INSTALL_PATH"
fi
}
10 changes: 8 additions & 2 deletions internal/buildscripts/packaging/fpm/deb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
VERSION="${1:-}"
ARCH="${2:-amd64}"
OUTPUT_DIR="${3:-$REPO_DIR/dist}"
SMART_AGENT_RELEASE="${4:-latest}"

if [[ -z "$VERSION" ]]; then
VERSION="$( get_version )"
fi
VERSION="${VERSION#v}"

otelcol_path="$REPO_DIR/bin/otelcol_linux_${ARCH}"

buildroot="$(mktemp -d)"

if [ "$ARCH" = "amd64" ]; then
download_smart_agent "$SMART_AGENT_RELEASE" "$buildroot"
fi

setup_files_and_permissions "$otelcol_path" "$buildroot"

mkdir -p "$OUTPUT_DIR"
Expand All @@ -34,8 +40,8 @@ sudo fpm -s dir -t deb -n "$PKG_NAME" -v "$VERSION" -f -p "$OUTPUT_DIR" \
--after-install "$POSTINSTALL_PATH" \
--before-remove "$PREUNINSTALL_PATH" \
--deb-no-default-config-files \
--config-files /etc/otel/collector/splunk_config_linux.yaml \
--config-files /etc/otel/collector/fluentd \
--config-files "$CONFIG_INSTALL_PATH" \
--config-files "$FLUENTD_CONFIG_INSTALL_DIR" \
"$buildroot/"=/

dpkg -c "${OUTPUT_DIR}/${PKG_NAME}_${VERSION}_${ARCH}.deb"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See /etc/otel/collector/splunk_config_linux.yaml for how these variables will be consumed.

# To use this file, update the values below appropriately,
# and save the changes to "/etc/otel/collector/splunk_env".
# and save the changes to "/etc/otel/collector/splunk-otel-collector.conf".

# Then run the following commands to apply the changes and restart the service:
# sudo systemctl restart splunk-otel-collector.service
Expand Down Expand Up @@ -39,3 +39,10 @@ SPLUNK_MEMORY_TOTAL_MIB=1024

# How much memory to allocate to the ballast. This should be set to 1/3 to 1/2 of configured memory.
# SPLUNK_BALLAST_SIZE_MIB=683

# The path to the Smart Agent bundle.
SPLUNK_BUNDLE_DIR=/usr/lib/splunk-otel-collector

# The path to the collectd config directory for the Smart Agent.
# This directory must be read/writable by the collector process.
SPLUNK_COLLECTD_DIR=/usr/lib/splunk-otel-collector/run/collectd
4 changes: 4 additions & 0 deletions internal/buildscripts/packaging/fpm/postinstall.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

if [ -f /usr/lib/splunk-otel-collector/bin/patch-interpreter ]; then
/usr/lib/splunk-otel-collector/bin/patch-interpreter /usr/lib/splunk-otel-collector
fi

if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload
systemctl enable splunk-otel-collector.service
Expand Down
12 changes: 7 additions & 5 deletions internal/buildscripts/packaging/fpm/rpm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"

VERSION="${1:-}"
ARCH="${2:-amd64}"
OUTPUT_DIR="${3:-/output}"
OUTPUT_DIR="${3:-$REPO_DIR/dist}"
SMART_AGENT_RELEASE="${4:-latest}"

if [[ -z "$VERSION" ]]; then
VERSION="$( get_version )"
Expand All @@ -18,14 +19,15 @@ VERSION="${VERSION#v}"

otelcol_path="$REPO_DIR/bin/otelcol_linux_${ARCH}"

buildroot="$(mktemp -d)"

if [[ "$ARCH" = "arm64" ]]; then
ARCH="aarch64"
elif [[ "$ARCH" = "amd64" ]]; then
ARCH="x86_64"
download_smart_agent "$SMART_AGENT_RELEASE" "$buildroot"
fi

buildroot="$(mktemp -d)"

setup_files_and_permissions "$otelcol_path" "$buildroot"

mkdir -p "$OUTPUT_DIR"
Expand All @@ -42,8 +44,8 @@ sudo fpm -s dir -t rpm -n "$PKG_NAME" -v "$VERSION" -f -p "$OUTPUT_DIR" \
--before-install "$PREINSTALL_PATH" \
--after-install "$POSTINSTALL_PATH" \
--before-remove "$PREUNINSTALL_PATH" \
--config-files /etc/otel/collector/splunk_config_linux.yaml \
--config-files /etc/otel/collector/fluentd \
--config-files "$CONFIG_INSTALL_PATH" \
--config-files "$FLUENTD_CONFIG_INSTALL_DIR" \
"$buildroot/"=/

rpm -qpli "${OUTPUT_DIR}/${PKG_NAME}-${VERSION}*.${ARCH}.rpm"
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=Splunk OpenTelemetry Collector
After=network.target

[Service]
EnvironmentFile=/etc/otel/collector/splunk_env
EnvironmentFile=/etc/otel/collector/splunk-otel-collector.conf
ExecStart=/usr/bin/otelcol $OTELCOL_OPTIONS
KillMode=mixed
Restart=on-failure
Expand Down
18 changes: 17 additions & 1 deletion internal/buildscripts/packaging/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ get_distro_codename() {

collector_config_dir="/etc/otel/collector"
collector_config_path="${collector_config_dir}/splunk_config_linux.yaml"
collector_env_path="${collector_config_dir}/splunk_env"
collector_env_path="${collector_config_dir}/splunk-otel-collector.conf"
collector_env_old_path="${collector_config_dir}/splunk_env"
collector_bundle_dir="/usr/lib/splunk-otel-collector"
collectd_config_dir="${collector_bundle_dir}/run/collectd"
distro="$( get_distro )"
distro_codename="$( get_distro_codename )"
distro_version="$( get_distro_version )"
Expand Down Expand Up @@ -679,6 +682,9 @@ parse_args_and_install() {
create_user_group "$service_user" "$service_group"
configure_service_owner "$service_user" "$service_group"

if [ ! -f "${collector_env_path}.example" ]; then
collector_env_path=$collector_env_old_path
fi
configure_env_file "SPLUNK_ACCESS_TOKEN" "$access_token" "$collector_env_path"
configure_env_file "SPLUNK_REALM" "$realm" "$collector_env_path"
configure_env_file "SPLUNK_API_URL" "$api_url" "$collector_env_path"
Expand All @@ -691,6 +697,16 @@ parse_args_and_install() {
else
configure_env_file "SPLUNK_MEMORY_TOTAL_MIB" "$memory" "$collector_env_path"
fi
if [ -d "$collector_bundle_dir" ]; then
configure_env_file "SPLUNK_BUNDLE_DIR" "$collector_bundle_dir" "$collector_env_path"
# ensure the collector service owner has access to the bundle dir
chown -R $service_user:$service_group "$collector_bundle_dir"
fi
if [ -d "$collectd_config_dir" ]; then
configure_env_file "SPLUNK_COLLECTD_DIR" "$collectd_config_dir" "$collector_env_path"
# ensure the collector service owner has access to the collectd dir
chown -R $service_user:$service_group "$collectd_config_dir"
fi

# ensure the collector service owner has access to the config dir
chown -R $service_user:$service_group "$collector_config_dir"
Expand Down
23 changes: 15 additions & 8 deletions internal/buildscripts/packaging/tests/installer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
STAGE = os.environ.get("STAGE", "release")
VERSIONS = os.environ.get("VERSIONS", "latest").split(",")

SPLUNK_ENV_PATH = "/etc/otel/collector/splunk_env"
SPLUNK_ENV_PATH = "/etc/otel/collector/splunk-otel-collector.conf"
OLD_SPLUNK_ENV_PATH = "/etc/otel/collector/splunk_env"
TOTAL_MEMORY = "256"
BALLAST = "128"

Expand Down Expand Up @@ -60,12 +61,15 @@ def test_installer(distro, version, memory_option):
time.sleep(5)

# verify env file created with configured parameters
run_container_cmd(container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {SPLUNK_ENV_PATH}")
splunk_env_path = SPLUNK_ENV_PATH
if container.exec_run(f"test -f {OLD_SPLUNK_ENV_PATH}"):
splunk_env_path = OLD_SPLUNK_ENV_PATH
run_container_cmd(container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {splunk_env_path}")
run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {splunk_env_path}")
if memory_option == "memory":
run_container_cmd(container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {splunk_env_path}")
elif memory_option == "ballast":
run_container_cmd(container, f"grep '^SPLUNK_BALLAST_SIZE_MIB={BALLAST}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_BALLAST_SIZE_MIB={BALLAST}$' {splunk_env_path}")

# verify collector service status
assert wait_for(lambda: service_is_running(container, service_owner=SERVICE_OWNER))
Expand Down Expand Up @@ -112,9 +116,12 @@ def test_installer_service_owner(distro, version):

try:
# verify env file created with configured parameters
run_container_cmd(container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {SPLUNK_ENV_PATH}")
splunk_env_path = SPLUNK_ENV_PATH
if container.exec_run(f"test -f {OLD_SPLUNK_ENV_PATH}"):
splunk_env_path = OLD_SPLUNK_ENV_PATH
run_container_cmd(container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {splunk_env_path}")
run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {splunk_env_path}")
run_container_cmd(container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {splunk_env_path}")

# verify collector service status
assert wait_for(lambda: service_is_running(container, service_owner=service_owner))
Expand Down
18 changes: 11 additions & 7 deletions internal/buildscripts/packaging/tests/package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def test_collector_package_install(distro):
service_name = "splunk-otel-collector"
service_owner = "splunk-otel-collector"
service_proc = "otelcol"
config_path = "/etc/otel/collector/splunk_env"
config_path = "/etc/otel/collector/splunk-otel-collector.conf"
bundle_dir = "/usr/lib/splunk-otel-collector"

pkg_path = get_package(distro, pkg_name, pkg_dir)
assert pkg_path, f"{pkg_name} package not found in {pkg_dir}"
Expand All @@ -50,13 +51,16 @@ def test_collector_package_install(distro):
with run_distro_container(distro) as container:
copy_file_into_container(container, pkg_path, f"/test/{pkg_base}")

# install package
if distro in DEB_DISTROS:
run_container_cmd(container, f"dpkg -i /test/{pkg_base}")
else:
run_container_cmd(container, f"rpm -i /test/{pkg_base}")

try:
# install package
if distro in DEB_DISTROS:
run_container_cmd(container, f"dpkg -i /test/{pkg_base}")
else:
run_container_cmd(container, f"rpm -i /test/{pkg_base}")

run_container_cmd(container, f"test -d {bundle_dir}")
run_container_cmd(container, f"test -d {bundle_dir}/run/collectd")

# verify service is not running after install without config file
time.sleep(5)
assert not service_is_running(container, service_name, service_owner, service_proc)
Expand Down

0 comments on commit 92846af

Please sign in to comment.