Skip to content

Commit f671458

Browse files
fix: ensure we build the agent registration plugin (#322)
* fix: ensure we build the agent registration plugin * test: add missing helper functions * fix: add git and other missing parts to UBI container image Signed-off-by: Patrick Stephens <pat@telemetryforge.io>
1 parent 9cb7317 commit f671458

13 files changed

Lines changed: 419 additions & 10 deletions

Dockerfile.ubi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
# syntax=docker/dockerfile:1
2+
13
FROM registry.access.redhat.com/ubi9:9.7 AS base-builder
24

35
# hadolint ignore=DL3041
46
RUN dnf update -y && \
5-
dnf install -y cmake3 diffutils gcc gcc-c++ git m4 make openssl-devel patch systemd-devel tar unzip libyaml-devel cyrus-sasl-devel zlib-devel pcre2-devel && \
7+
dnf install -y cmake3 diffutils gcc gcc-c++ git m4 make openssl-devel patch systemd-devel tar unzip \
8+
libyaml-devel cyrus-sasl-devel zlib-devel pcre2-devel libzstd-devel && \
69
dnf clean all && rm -rf /var/cache/dnf
710

811
# Provide the dependencies for record accessor built from source
@@ -28,6 +31,7 @@ RUN curl -LO https://www.libssh2.org/download/libssh2-${LIBSSH2_VER}.tar.gz && \
2831
WORKDIR /tmp/libssh2-${LIBSSH2_VER}
2932
RUN ./configure --with-openssl --prefix=/usr/local --disable-examples-build && \
3033
make -j "$(getconf _NPROCESSORS_ONLN)" && make install && \
34+
echo "/usr/local/lib" > /etc/ld.so.conf.d/libssh2.conf && \
3135
ldconfig
3236

3337
# Build libgit2 from source
@@ -57,7 +61,7 @@ ARG TELEMETRY_FORGE_AGENT_VERSION=26.4.8
5761
ENV TELEMETRY_FORGE_AGENT_VERSION=${TELEMETRY_FORGE_AGENT_VERSION}
5862

5963
# Build metadata
60-
ARG TELEMETRY_FORGE_AGENT_DISTRO=ubi/9.5
64+
ARG TELEMETRY_FORGE_AGENT_DISTRO=ubi/9.7
6165
ENV TELEMETRY_FORGE_AGENT_DISTRO=$TELEMETRY_FORGE_AGENT_DISTRO
6266

6367
ARG TELEMETRY_FORGE_AGENT_PACKAGE_TYPE=CONTAINER
@@ -95,6 +99,7 @@ RUN cmake -DCMAKE_BUILD_TYPE=Release \
9599
-DTELEMETRY_FORGE_AGENT_VERSION="$TELEMETRY_FORGE_AGENT_VERSION" \
96100
-DFLB_LOG_NO_CONTROL_CHARS=On \
97101
-DFLB_CORO_STACK_SIZE=131072 \
102+
-DFLB_PREFER_SYSTEM_LIB_ZSTD=On \
98103
${CMAKE_EXTRA_ARGS} \
99104
..
100105

@@ -111,7 +116,7 @@ RUN [ -n "$MAKE_EXTRA_ARGS" ] && make ${MAKE_EXTRA_ARGS} || make -j "$(getconf _
111116
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.7 AS production
112117

113118
# hadolint ignore=DL3041
114-
RUN microdnf update -y && microdnf install -y openssl libyaml cyrus-sasl && microdnf clean all
119+
RUN microdnf update -y && microdnf install -y openssl libyaml cyrus-sasl zstd && microdnf clean all
115120

116121
EXPOSE 2020
117122

@@ -127,7 +132,7 @@ COPY --from=builder /fluent-bit /fluent-bit
127132
# Copy libgit2 and libssh2 runtime libraries from builder
128133
COPY --from=builder /usr/local/lib64/libgit2.so.*.*.* /usr/local/lib64/
129134
COPY --from=builder /usr/local/lib/libssh2.so.*.*.* /usr/local/lib/
130-
# Set up ldconfig and symlinks for the copied libraries
135+
# Set up ldconfig and symlinks for the libraries
131136
RUN echo "/usr/local/lib64" > /etc/ld.so.conf.d/local-libs.conf && \
132137
echo "/usr/local/lib" >> /etc/ld.so.conf.d/local-libs.conf && \
133138
ldconfig
@@ -170,8 +175,9 @@ FROM production AS test
170175
USER root
171176

172177
# We need find and ps/pkill for BATS
178+
# We need git for the git_config plugin tests
173179
# hadolint ignore=DL3041
174-
RUN microdnf update -y && microdnf install -y findutils procps && microdnf clean all
180+
RUN microdnf update -y && microdnf install -y findutils procps git && microdnf clean all
175181

176182
COPY --from=bats /opt/bats /opt/bats
177183
RUN /opt/bats/install.sh /usr/local

source/cmake/plugins_options.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ option(FLB_MINIMAL "Enable minimal build configuration" No)
1111

1212
# Custom Plugins
1313
# ===============
14-
DEFINE_OPTION(FLB_CUSTOM_TELEMETRY_FORGE "Enable Telemetry Forge custom plugin" ON)
14+
DEFINE_OPTION(FLB_CUSTOM_TELEMETRYFORGE "Enable Telemetry Forge custom plugin" ON)
1515

1616
# Inputs (sources, data collectors)
1717
# =================================
18-
DEFINE_OPTION(FLB_IN_TELEMETRY_FORGE "Enable Telemetry Forge input plugin" ON)
18+
DEFINE_OPTION(FLB_IN_TELEMETRYFORGE "Enable Telemetry Forge input plugin" ON)
1919
# =================================
2020
DEFINE_OPTION(FLB_IN_BLOB "Enable Blob input plugin" ON)
2121
DEFINE_OPTION(FLB_IN_CALYPTIA_FLEET "Enable Calyptia Fleet input plugin" OFF)

testing/Dockerfile.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ FROM ${BASE_BUILDER} AS test
88
COPY --from=bats /opt/bats /opt/bats
99
RUN /opt/bats/install.sh /usr/local
1010

11+
# Install git for testing the git config plugin
12+
RUN if ! command -v git &>/dev/null; then \
13+
if command -v yum &>/dev/null; then \
14+
yum install -y git; \
15+
elif command -v microdnf &>/dev/null; then \
16+
microdnf install -y git; \
17+
elif command -v dnf &>/dev/null; then \
18+
dnf install -y git; \
19+
elif command -v apk &>/dev/null; then \
20+
apk add --no-cache git; \
21+
elif command -v zypper &>/dev/null; then \
22+
zypper install -y git; \
23+
elif command -v apt-get &>/dev/null; then \
24+
apt-get update && apt-get install -y git; \
25+
else \
26+
echo "ERROR: unable to install git"; \
27+
exit 1; \
28+
fi \
29+
fi
30+
1131
COPY testing/ /testing/
1232

1333
# Put packages to install here

testing/bats/helpers/test-helpers.bash

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,86 @@ function helmTeardown() {
228228
fi
229229
export DETIK_CLIENT_NAMESPACE=''
230230
}
231+
232+
# Starts fluent-bit in the background, redirecting output to a temp file
233+
# Sets FB_PID and FB_LOG as global variables
234+
function startFluentBit() {
235+
FB_LOG=$(mktemp)
236+
"$FLUENT_BIT_BINARY" "$@" > "$FB_LOG" 2>&1 &
237+
FB_PID=$!
238+
echo "Started $FLUENT_BIT_BINARY with PID $FB_PID and log file $FB_LOG: $*"
239+
}
240+
241+
# After a successful match, call this to record the current log position.
242+
# Future calls to waitForOutput can then only check for new output since this point
243+
function markLogPosition() {
244+
if [[ -z "${FB_LOG:-}" ]]; then
245+
fail "FB_LOG not set, cannot mark log position"
246+
fi
247+
FB_LOG_OFFSET=$(wc -c < "$FB_LOG")
248+
}
249+
250+
function resetLogPosition() {
251+
unset FB_LOG_OFFSET
252+
}
253+
254+
# Waits for a specific pattern to appear in the log
255+
# Usage: waitForOutput "pattern" [timeout_seconds]
256+
# Default timeout is 30 seconds
257+
function waitForOutputFromOffset() {
258+
local pattern="$1"
259+
local timeout="${2:-30}"
260+
local offset="${3:-0}"
261+
local elapsed=0
262+
local interval=1
263+
264+
if [[ -z "${FB_LOG:-}" ]]; then
265+
fail "FB_LOG not set, cannot wait for output"
266+
fi
267+
268+
if [[ -z "${FB_PID:-}" ]]; then
269+
fail "FB_PID not set, cannot wait for output"
270+
fi
271+
272+
while (( elapsed < timeout )); do
273+
if tail -c +"$((offset + 1))" "$FB_LOG" 2>/dev/null | grep -qE "$pattern"; then
274+
return 0
275+
fi
276+
277+
if ! kill -0 "$FB_PID" 2>/dev/null; then
278+
cat "$FB_LOG"
279+
fail "$FLUENT_BIT_BINARY exited unexpectedly."
280+
return 1
281+
fi
282+
283+
sleep "$interval"
284+
elapsed=$(( elapsed + interval ))
285+
done
286+
287+
echo "Log contents (from offset ${offset}):"
288+
tail -c +"$((offset + 1))" "$FB_LOG"
289+
fail "Timed out after ${timeout}s waiting for new pattern: $pattern"
290+
return 1
291+
}
292+
293+
# Wait for a specific pattern to appear in the log since the start of the log (i.e. not just new output since the last marked position)
294+
function waitForOutput() {
295+
waitForOutputFromOffset "$1" "$2" 0
296+
}
297+
298+
# Wait for a specific pattern to appear in the log since the last marked position
299+
function waitForNewOutput() {
300+
waitForOutputFromOffset "$1" "$2" "${FB_LOG_OFFSET:-0}"
301+
}
302+
303+
# Cleanup function to kill fluent-bit and remove temp files
304+
function stopFluentBit() {
305+
if [[ -n "${FB_PID:-}" ]] && kill -0 "$FB_PID" 2>/dev/null; then
306+
kill -9 "$FB_PID"
307+
wait "$FB_PID" 2>/dev/null || true
308+
fi
309+
if [[ -n "${FB_LOG:-}" ]]; then
310+
rm -f "$FB_LOG"
311+
fi
312+
resetLogPosition
313+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
service:
2+
flush: 1
3+
grace: 1
4+
log_level: info
5+
6+
pipeline:
7+
inputs:
8+
- name: dummy
9+
dummy: '{"message": "Dummy initial message"}'
10+
alias: input_dummy
11+
12+
outputs:
13+
- name: stdout
14+
match: '*'
15+
alias: output_stdout
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
service:
2+
flush: 1
3+
grace: 1
4+
log_level: info
5+
6+
pipeline:
7+
inputs:
8+
- name: dummy
9+
dummy: '{"message": "Switched to updated configuration", "sha": "${GIT_SHA}"}'
10+
alias: input_dummy
11+
12+
outputs:
13+
- name: stdout
14+
match: '*'
15+
alias: output_stdout
16+
- name: exit
17+
match: '*'
18+
# Exit after processing 2 records to ensure the test completes in a reasonable time frame
19+
record_count: 2
20+
alias: output_exit
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
service:
2+
flush: 1
3+
grace: 1
4+
log_level: debug
5+
6+
customs:
7+
- name: git_config
8+
# We use a local git repository for testing to keep things simple and consistent.
9+
repo: file://${GIT_REPO_PATH}
10+
# We may need to adjust this per-PR appropriately to ensure we are testing the correct branch/PR
11+
ref: ${GIT_SHA}
12+
path: fluent-bit-no-exit.yaml
13+
# Do not poll too fast as we still need to apply the commit between polls
14+
poll_interval: 10
15+
# Use a different config directory to prevent conflicts with other tests
16+
# See https://github.com/telemetryforge/agent/issues/274
17+
config_dir: ${BATS_TEST_TMPDIR}/tmp/fluent-bit
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
service:
2+
flush: 1
3+
grace: 1
4+
log_level: debug
5+
6+
customs:
7+
- name: git_config
8+
# We use a local git repository for testing to keep things simple and consistent.
9+
repo: file://${GIT_REPO_PATH}
10+
# We may need to adjust this per-PR appropriately to ensure we are testing the correct branch/PR
11+
ref: ${GIT_SHA}
12+
path: fluent-bit.yaml
13+
# Do not poll too fast as we still need to apply the commit between polls
14+
poll_interval: 10
15+
# Use a different config directory to prevent conflicts with other tests
16+
# See https://github.com/telemetryforge/agent/issues/274
17+
config_dir: ${BATS_TEST_TMPDIR}/tmp/fluent-bit
18+
19+
# Fall back to ensure we exit after 60 seconds in case the plugin doesn't work as expected to prevent hanging the test indefinitely
20+
# See https://github.com/telemetryforge/agent/issues/272 to remove this later once implemented.
21+
pipeline:
22+
inputs:
23+
- name: dummy
24+
dummy: '{"message": "Ignored"}'
25+
alias: input_dummy_ignored
26+
outputs:
27+
- name: exit
28+
match: '*'
29+
time_count: 60
30+
alias: output_exit_fallback

0 commit comments

Comments
 (0)