Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/getting-started/linux-installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ curl -sSL https://dl.signalfx.com/splunk-otel-collector.sh > /tmp/splunk-otel-co
sudo sh /tmp/splunk-otel-collector.sh --realm SPLUNK_REALM -- SPLUNK_ACCESS_TOKEN
```

Run the following command to check the `splunk-otel-collector` service status:
```sh
sudo systemctl status splunk-otel-collector
```

The `splunk-otel-collector` service logs and errors can be viewed in the
systemd journal:
```sh
sudo journalctl -u splunk-otel-collector
```

You can view the [source](../../internal/buildscripts/packaging/installer/install.sh)
for more details and available options.

Expand Down
20 changes: 17 additions & 3 deletions docs/getting-started/linux-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,30 @@ installed on x86_64/amd64 platforms.
2. A default configuration file will be installed to
`/etc/otel/collector/agent_config.yaml` if it does not already exist.
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
required to start the `splunk-otel-collector` systemd service (**Note**: The
service will automatically start if this file exists during
install/upgrade). 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-otel-collector.conf`.
4. Start/Restart the service with:
```sh
sudo systemctl restart splunk-otel-collector.service
sudo systemctl restart splunk-otel-collector
```
**Note:** The service must be restarted for any changes to the config file
or environment file to take effect.

Run the following command to check the `splunk-otel-collector` service status:
```sh
sudo systemctl status splunk-otel-collector
```

The `splunk-otel-collector` service logs and errors can be viewed in the
systemd journal:
```sh
sudo journalctl -u splunk-otel-collector
```

### Other

Expand Down
4 changes: 4 additions & 0 deletions internal/buildscripts/packaging/fpm/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ fi
if command -v systemctl >/dev/null 2>&1; then
systemctl daemon-reload
systemctl enable splunk-otel-collector.service
if [ -f /etc/otel/collector/splunk-otel-collector.conf ]; then
echo "Starting splunk-otel-collector service"
systemctl restart splunk-otel-collector.service
fi
fi
6 changes: 4 additions & 2 deletions internal/buildscripts/packaging/fpm/preuninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# limitations under the License.

if command -v systemctl >/dev/null 2>&1; then
echo "Stopping splunk-otel-collector service"
systemctl stop splunk-otel-collector.service
systemctl disable splunk-otel-collector.service
if systemctl status splunk-otel-collector.service >/dev/null 2>&1; then
echo "Stopping splunk-otel-collector service"
systemctl stop splunk-otel-collector.service
fi
fi
2 changes: 1 addition & 1 deletion internal/buildscripts/packaging/fpm/rpm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ sudo fpm -s dir -t rpm -n "$PKG_NAME" -v "$VERSION" -f -p "$OUTPUT_DIR" \
--rpm-summary "$PKG_DESCRIPTION" \
--rpm-use-file-permissions \
--before-install "$PREINSTALL_PATH" \
--after-install "$POSTINSTALL_PATH" \
--rpm-posttrans "$POSTINSTALL_PATH" \
--before-remove "$PREUNINSTALL_PATH" \
--config-files "$AGENT_CONFIG_INSTALL_PATH" \
--config-files "$GATEWAY_CONFIG_INSTALL_PATH" \
Expand Down
109 changes: 78 additions & 31 deletions internal/buildscripts/packaging/tests/package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
TESTS_DIR,
)

INSTALLER_PATH = REPO_DIR / "internal" / "buildscripts" / "packaging" / "installer" / "install.sh"
PKG_NAME = "splunk-otel-collector"
PKG_DIR = REPO_DIR / "dist"
SERVICE_NAME = "splunk-otel-collector"
SERVICE_OWNER = "splunk-otel-collector"
SERVICE_PROC = "otelcol"
ENV_PATH = "/etc/otel/collector/splunk-otel-collector.conf"
AGENT_CONFIG_PATH = "/etc/otel/collector/agent_config.yaml"
GATEWAY_CONFIG_PATH = "/etc/otel/collector/gateway_config.yaml"
BUNDLE_DIR = "/usr/lib/splunk-otel-collector/agent-bundle"


def get_package(distro, name, path):
if distro in DEB_DISTROS:
Expand Down Expand Up @@ -58,19 +69,8 @@ def get_libcap_command(container):
+ [pytest.param(distro, marks=pytest.mark.rpm) for distro in RPM_DISTROS],
)
def test_collector_package_install(distro):
pkg_name = "splunk-otel-collector"
pkg_dir = REPO_DIR / "dist"
service_name = "splunk-otel-collector"
service_owner = "splunk-otel-collector"
service_proc = "otelcol"
env_path = "/etc/otel/collector/splunk-otel-collector.conf"
agent_config_path = "/etc/otel/collector/agent_config.yaml"
gateway_config_path = "/etc/otel/collector/gateway_config.yaml"
bundle_dir = "/usr/lib/splunk-otel-collector/agent-bundle"

pkg_path = get_package(distro, pkg_name, pkg_dir)
assert pkg_path, f"{pkg_name} package not found in {pkg_dir}"

pkg_path = get_package(distro, PKG_NAME, PKG_DIR)
assert pkg_path, f"{PKG_NAME} package not found in {PKG_DIR}"
pkg_base = os.path.basename(pkg_path)

with run_distro_container(distro) as container:
Expand All @@ -90,46 +90,93 @@ def test_collector_package_install(distro):
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")
run_container_cmd(container, f"test -d {BUNDLE_DIR}")
run_container_cmd(container, f"test -d {BUNDLE_DIR}/run/collectd")

run_container_cmd(container, f"test -f {agent_config_path}")
run_container_cmd(container, f"test -f {gateway_config_path}")
run_container_cmd(container, f"test -f {AGENT_CONFIG_PATH}")
run_container_cmd(container, f"test -f {GATEWAY_CONFIG_PATH}")

# 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)
assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC)

# verify service starts with config file
run_container_cmd(container, f"cp -f {env_path}.example {env_path}")
run_container_cmd(container, f"systemctl start {service_name}")
run_container_cmd(container, f"cp -f {ENV_PATH}.example {ENV_PATH}")
run_container_cmd(container, f"systemctl start {SERVICE_NAME}")
time.sleep(5)
assert wait_for(lambda: service_is_running(container, service_name, service_owner, service_proc))
assert wait_for(lambda: service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC))

# verify service restart
run_container_cmd(container, f"systemctl restart {service_name}")
run_container_cmd(container, f"systemctl restart {SERVICE_NAME}")
time.sleep(5)
assert wait_for(lambda: service_is_running(container, service_name, service_owner, service_proc))
assert wait_for(lambda: service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC))

# verify service stop
run_container_cmd(container, f"systemctl stop {service_name}")
run_container_cmd(container, f"systemctl stop {SERVICE_NAME}")
time.sleep(5)
assert not service_is_running(container, service_name, service_owner, service_proc)
assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC)
finally:
run_container_cmd(container, f"journalctl -u {service_name} --no-pager")
run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")

# verify uninstall
run_container_cmd(container, f"systemctl start {service_name}")
run_container_cmd(container, f"systemctl start {SERVICE_NAME}")

time.sleep(5)

if distro in DEB_DISTROS:
run_container_cmd(container, f"dpkg -P {pkg_name}")
run_container_cmd(container, f"dpkg -P {PKG_NAME}")
else:
run_container_cmd(container, f"rpm -e {pkg_name}")
run_container_cmd(container, f"rpm -e {PKG_NAME}")

time.sleep(5)
assert not service_is_running(container, service_name, service_owner, service_proc)
assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC)

# verify config file is not removed
run_container_cmd(container, f"test -f {env_path}")
run_container_cmd(container, f"test -f {ENV_PATH}")


@pytest.mark.parametrize(
"distro",
[pytest.param(distro, marks=pytest.mark.deb) for distro in DEB_DISTROS]
+ [pytest.param(distro, marks=pytest.mark.rpm) for distro in RPM_DISTROS],
)
def test_collector_package_upgrade(distro):
install_cmd = f"sh /test/install.sh -- testing123 --realm test --without-fluentd --collector-version 0.35.0"

pkg_path = get_package(distro, PKG_NAME, PKG_DIR)
assert pkg_path, f"{PKG_NAME} package not found in {PKG_DIR}"
pkg_base = os.path.basename(pkg_path)

with run_distro_container(distro) as container:
copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh")

try:
# install an older version of the collector package
run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"})

time.sleep(5)

# verify collector service status
assert wait_for(lambda: service_is_running(container, service_owner=SERVICE_OWNER))

# change the config
run_container_cmd(container, f"sh -c 'echo \"# This line should be preserved\" >> {AGENT_CONFIG_PATH}'")

copy_file_into_container(container, pkg_path, f"/test/{pkg_base}")

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

time.sleep(5)

# verify collector service status
assert wait_for(lambda: service_is_running(container, service_owner=SERVICE_OWNER))

# verify changed config was preserved after upgrade
run_container_cmd(container, f"grep '# This line should be preserved' {AGENT_CONFIG_PATH}")

finally:
run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious if this for debugging purposes or a final check for service activity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for debugging.