Skip to content

Commit 13087eb

Browse files
authored
Update deb/rpm and installer script for fluentd (#52)
1 parent 4eb7232 commit 13087eb

File tree

17 files changed

+564
-129
lines changed

17 files changed

+564
-129
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ jobs:
380380
command: |
381381
sudo apt-get update
382382
sudo apt-get install -y ruby ruby-dev rubygems build-essential rpm
383-
gem install --no-document fpm -v 1.11.0
383+
sudo gem install --no-document fpm -v 1.11.0
384384
- run:
385385
name: Build << parameters.package_type >> amd64 package
386386
command: ./internal/buildscripts/packaging/fpm/<< parameters.package_type >>/build.sh "${CIRCLE_TAG:-}" "amd64" "./dist/"

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ For non-containerized Linux environments, a convenience script is available for
9090
installing the Collector package and [TD Agent
9191
(Fluentd)](https://www.fluentd.org/).
9292

93+
You can view the [source](internal/buildscripts/packaging/installer/install.sh)
94+
for more details and available options.
95+
9396
Run the following command on your host. Replace `SPLUNK_REALM`,
9497
`SPLUNK_BALLAST_SIZE`, and `SPLUNK_ACCESS_TOKEN` for your
9598
environment:
@@ -100,8 +103,22 @@ sudo sh /tmp/splunk-otel-collector.sh --realm SPLUNK_REALM --ballast SPLUNK_BALL
100103
-- SPLUNK_ACCESS_TOKEN
101104
```
102105

103-
You can view the [source](internal/buildscripts/packaging/installer/install.sh)
104-
for more details and other options.
106+
By default, the fluentd service will be installed and configured to forward
107+
log events with the `@SPLUNK` label to the collector (see the note below for
108+
how to add fluentd log sources), and the collector will send these events to
109+
the HEC ingest endpoint determined by the `--realm SPLUNK_REALM` option, e.g.
110+
`https://ingest.SPLUNK_REALM.signalfx.com/v1/log`. To configure the collector
111+
to send log events to a custom HEC endpoint URL, specify the `--hec-url URL`
112+
and `--hec-token TOKEN` options to the command above.
113+
114+
**Note**: The installer script does not include any fluentd log sources. Custom
115+
fluentd source config files can be added to the
116+
`/etc/otel/collector/fluentd/conf.d` directory after installation. Config files
117+
added to this directory should have a `.conf` extension, and the `td-agent`
118+
service will need to be restarted to include/enable the new files, i.e.
119+
`sudo systemctl restart td-agent`. A sample config and instructions for
120+
collecting journald log events is available at
121+
`/etc/otel/collector/fluentd/conf.d/journald.conf.example`.
105122

106123
Currently, only the following Linux distributions and versions are supported:
107124

internal/buildscripts/packaging/fpm/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM debian:9
22

33
RUN apt-get update && \
4-
apt-get install -y ruby ruby-dev rubygems build-essential git rpm
4+
apt-get install -y ruby ruby-dev rubygems build-essential git rpm sudo
55

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

internal/buildscripts/packaging/fpm/common.sh

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ SERVICE_NAME="splunk-otel-collector"
1414
SERVICE_USER="splunk-otel-collector"
1515
SERVICE_GROUP="splunk-otel-collector"
1616

17-
SERVICE_REPO_PATH="$FPM_DIR/$SERVICE_NAME.service"
18-
SERVICE_INSTALL_PATH="/usr/lib/systemd/system/$SERVICE_NAME.service"
19-
2017
OTELCOL_INSTALL_PATH="/usr/bin/otelcol"
21-
SPLUNK_CONFIG_REPO_PATH="$REPO_DIR/cmd/otelcol/config/collector/agent_config_linux.yaml"
22-
SPLUNK_CONFIG_INSTALL_PATH="/etc/otel/collector/splunk_config_linux.yaml"
23-
OTLP_CONFIG_REPO_PATH="$REPO_DIR/cmd/otelcol/config/collector/otlp_config_linux.yaml"
24-
OTLP_CONFIG_INSTALL_PATH="/etc/otel/collector/otlp_config_linux.yaml"
25-
SPLUNK_ENV_REPO_PATH="$FPM_DIR/splunk_env.example"
26-
SPLUNK_ENV_INSTALL_PATH="/etc/otel/collector/splunk_env.example"
18+
CONFIG_REPO_PATH="$FPM_DIR/etc/otel/collector/splunk_config_linux.yaml"
19+
CONFIG_INSTALL_PATH="/etc/otel/collector/splunk_config_linux.yaml"
20+
SERVICE_REPO_PATH="$FPM_DIR/$SERVICE_NAME.service"
21+
SERVICE_INSTALL_PATH="/lib/systemd/system/$SERVICE_NAME.service"
2722

2823
PREINSTALL_PATH="$FPM_DIR/preinstall.sh"
2924
POSTINSTALL_PATH="$FPM_DIR/postinstall.sh"
@@ -42,3 +37,31 @@ get_version() {
4237
echo "$commit_tag"
4338
fi
4439
}
40+
41+
create_user_group() {
42+
sudo getent passwd $SERVICE_USER >/dev/null || \
43+
sudo useradd --system --user-group --no-create-home --shell /sbin/nologin $SERVICE_USER
44+
}
45+
46+
setup_files_and_permissions() {
47+
local otelcol="$1"
48+
local buildroot="$2"
49+
50+
create_user_group
51+
52+
mkdir -p "$buildroot/$(dirname $OTELCOL_INSTALL_PATH)"
53+
cp -f "$otelcol" "$buildroot/$OTELCOL_INSTALL_PATH"
54+
sudo chown root:root "$buildroot/$OTELCOL_INSTALL_PATH"
55+
sudo chmod 755 "$buildroot/$OTELCOL_INSTALL_PATH"
56+
57+
cp -r "$FPM_DIR/etc" "$buildroot/etc"
58+
cp -f "$CONFIG_REPO_PATH" "$buildroot/$CONFIG_INSTALL_PATH"
59+
sudo chown -R $SERVICE_USER:$SERVICE_GROUP "$buildroot/etc/otel"
60+
sudo chmod -R 755 "$buildroot/etc/otel"
61+
sudo chmod 600 "$buildroot/etc/otel/collector/splunk_env.example"
62+
63+
mkdir -p "$buildroot/$(dirname $SERVICE_INSTALL_PATH)"
64+
cp -f "$SERVICE_REPO_PATH" "$buildroot/$SERVICE_INSTALL_PATH"
65+
sudo chown root:root "$buildroot/$SERVICE_INSTALL_PATH"
66+
sudo chmod 644 "$buildroot/$SERVICE_INSTALL_PATH"
67+
}

internal/buildscripts/packaging/fpm/deb/build.sh

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,36 @@ SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
66
. $SCRIPT_DIR/../common.sh
77

88
VERSION="${1:-}"
9-
ARCH="${2:-"amd64"}"
10-
OUTPUT_DIR="${3:-"$REPO_DIR/dist/"}"
11-
OTELCOL_REPO_PATH="$REPO_DIR/bin/otelcol_linux_${ARCH}"
12-
13-
14-
if [[ ! -f "$OTELCOL_REPO_PATH" ]]; then
15-
echo "$OTELCOL_REPO_PATH not found!"
16-
exit 1
17-
fi
9+
ARCH="${2:-amd64}"
10+
OUTPUT_DIR="${3:-$REPO_DIR/dist}"
1811

1912
if [[ -z "$VERSION" ]]; then
2013
VERSION="$( get_version )"
2114
fi
15+
VERSION="${VERSION#v}"
16+
17+
otelcol_path="$REPO_DIR/bin/otelcol_linux_${ARCH}"
18+
buildroot="$(mktemp -d)"
19+
20+
setup_files_and_permissions "$otelcol_path" "$buildroot"
2221

2322
mkdir -p "$OUTPUT_DIR"
2423

25-
fpm -s dir -t deb -n $PKG_NAME -v ${VERSION#v} -f -p "$OUTPUT_DIR" \
24+
sudo fpm -s dir -t deb -n "$PKG_NAME" -v "$VERSION" -f -p "$OUTPUT_DIR" \
2625
--vendor "$PKG_VENDOR" \
2726
--maintainer "$PKG_MAINTAINER" \
2827
--description "$PKG_DESCRIPTION" \
2928
--license "$PKG_LICENSE" \
3029
--url "$PKG_URL" \
3130
--architecture "$ARCH" \
3231
--deb-dist "stable" \
33-
--deb-user "$SERVICE_USER" \
34-
--deb-group "$SERVICE_GROUP" \
32+
--deb-use-file-permissions \
3533
--before-install "$PREINSTALL_PATH" \
3634
--after-install "$POSTINSTALL_PATH" \
3735
--before-remove "$PREUNINSTALL_PATH" \
38-
--config-files $SPLUNK_CONFIG_INSTALL_PATH \
39-
--config-files $OTLP_CONFIG_INSTALL_PATH \
40-
$SPLUNK_CONFIG_REPO_PATH=$SPLUNK_CONFIG_INSTALL_PATH \
41-
$OTLP_CONFIG_REPO_PATH=$OTLP_CONFIG_INSTALL_PATH \
42-
$SPLUNK_ENV_REPO_PATH=$SPLUNK_ENV_INSTALL_PATH \
43-
$SERVICE_REPO_PATH=$SERVICE_INSTALL_PATH \
44-
$OTELCOL_REPO_PATH=$OTELCOL_INSTALL_PATH
36+
--deb-no-default-config-files \
37+
--config-files /etc/otel/collector/splunk_config_linux.yaml \
38+
--config-files /etc/otel/collector/fluentd \
39+
"$buildroot/"=/
40+
41+
dpkg -c "${OUTPUT_DIR}/${PKG_NAME}_${VERSION}_${ARCH}.deb"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Custom TD Agent Fluentd Configuration for the Splunk OpenTelemetry Collector
2+
3+
This directory contains a custom fluentd configuration to forward log events
4+
to the Splunk OpenTelemetry Collector. By default, the collector will listen
5+
on 127.0.0.1:8006 for log events forwarded from fluentd. See the
6+
"fluentforward" receiver in the default collector config at
7+
/etc/otel/collector/splunk_config_linux.yaml for details or to make any changes
8+
to the collector.
9+
10+
Directory contents:
11+
12+
- splunk-otel-collector.conf: Drop-in file for the fluentd service. As an
13+
alternative to overwriting the default fluentd config file
14+
(/etc/td-agent/td-agent.conf), copy this file to
15+
/etc/systemd/system/td-agent.service.d/splunk-otel-collector.conf to
16+
override the default fluentd config path in favor of the custom
17+
fluentd config file in this directory (see fluent.conf below), and run the
18+
following commands to apply the changes:
19+
20+
systemctl daemon-reload
21+
systemctl restart td-agent
22+
23+
- fluent.conf: The main fluentd configuration file to forward events to the
24+
collector. By default, this file will configure fluentd to include custom
25+
fluentd sources from the conf.d sub-directory (see conf.d below) and forward
26+
all log events with the @SPLUNK label to the collector. If changes are made
27+
to this file, run the following command to apply the changes:
28+
29+
systemctl restart td-agent
30+
31+
- conf.d: Directory for custom fluentd configuration files. The main fluentd
32+
configuration (see fluent.conf above) will automatically include all files
33+
ending in .conf from the conf.d directory. New fluentd sources should
34+
include the @SPLUNK label for all log events intended to be forwarded to the
35+
collector (see the sample file in conf.d for details). After adding new
36+
config files to the conf.d directory, run the following command to apply the
37+
changes:
38+
39+
systemctl restart td-agent
40+
41+
*Important*: By default, the fluentd service runs as the "td-agent" user.
42+
When adding new fluentd source configurations, ensure that the "td-agent"
43+
user has permissions to access the paths defined in these sources.
44+
45+
See https://docs.fluentd.org/configuration for general fluentd configuration
46+
details.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Sample fluentd source config to read from journald and forward all log events
2+
# to the Splunk OpenTelemetry Collector.
3+
#
4+
# To enable this source, perform the following steps:
5+
#
6+
# 1. Ensure the systemd fluentd plugin is installed by running:
7+
#
8+
# td-agent-gem list fluent-plugin-systemd
9+
#
10+
# If necessary, install the plugin by running:
11+
#
12+
# td-agent-gem install fluent-plugin-systemd
13+
#
14+
# Note: Additional dependencies may be required to be installed/upgraded in
15+
# order to successfully install the plugin. See
16+
# https://github.com/fluent-plugin-systemd/fluent-plugin-systemd for
17+
# installation and configuration details.
18+
#
19+
# 2. Ensure that the fluentd service is configured to forward events to the
20+
# collector by checking if the drop-in file
21+
# "/etc/systemd/system/td-agent.service.d/splunk-otel-collector.conf"
22+
# exists. If not, copy "/etc/otel/collector/splunk-otel-collector.conf" to
23+
# "/etc/systemd/system/td-agent.service.d/splunk-otel-collector.conf" and
24+
# run:
25+
#
26+
# systemctl daemon-reload
27+
#
28+
# 3. Make any necessary changes to the configuration below and copy/rename this
29+
# file to "/etc/otel/collector/fluentd/conf.d/journald.conf". See
30+
# https://github.com/fluent-plugin-systemd/fluent-plugin-systemd for
31+
# details and other options.
32+
#
33+
# 4. Since the fluentd service runs as the "td-agent" user, ensure that this
34+
# user has permissions to access the path configured below. For example, if
35+
# the "/run/log/journal" path is only readable by the "systemd-journal"
36+
# group, it may be necessary to add the "td-agent" user to the group by
37+
# running the command:
38+
#
39+
# usermod -a -G systemd-journal td-agent
40+
#
41+
# 5. Restart the fluentd service to apply the changes by running:
42+
#
43+
# systemctl restart td-agent
44+
#
45+
46+
<source>
47+
@type systemd
48+
@label @SPLUNK
49+
tag "journald"
50+
path "/run/log/journal"
51+
<entry>
52+
fields_strip_underscores true
53+
fields_lowercase true
54+
</entry>
55+
</source>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@include conf.d/*.conf
2+
3+
<label @SPLUNK>
4+
<match **>
5+
@type forward
6+
heartbeat_type udp
7+
<server>
8+
host 127.0.0.1
9+
port 8006
10+
</server>
11+
<buffer>
12+
@type memory
13+
total_limit_size 600m
14+
chunk_limit_size 1m
15+
chunk_limit_records 100000
16+
flush_interval 5s
17+
flush_thread_count 1
18+
overflow_action block
19+
retry_max_times 3
20+
</buffer>
21+
</match>
22+
</label>
23+
24+
<system>
25+
log_level info
26+
</system>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Drop-in file for the fluentd service
2+
3+
# Copy this file to /etc/systemd/system/td-agent.service.d/ in order to override
4+
# the default fluentd config path in favor of the custom config defined below.
5+
6+
# Then run the following commands to apply the changes:
7+
# systemctl daemon-reload
8+
# systemctl restart td-agent
9+
10+
[Service]
11+
Environment=FLUENT_CONF=/etc/otel/collector/fluentd/fluent.conf

0 commit comments

Comments
 (0)