Skip to content

Commit 0bb7407

Browse files
authored
fix: support otel collector logging with minimal storage (#1509)
This commit sets up a FIFO named pipe with the same name/path that the otel collector and supervisor are expecting. By starting to tail that pipe before starting the collector, we can send log files to stdio without the memory required by the `passthrough_logs` feature or and storage on the volume. --- Running locally in orbstack, we're still seeing logs on stdout <img width="2316" height="1452" alt="image" src="https://github.com/user-attachments/assets/f86961cf-6ea4-4faa-82f8-54f9596b5f16" /> but the file size for `agent.log` remains at 0 <img width="1606" height="838" alt="image" src="https://github.com/user-attachments/assets/6feb9470-e220-4d8a-b5b3-10a221926158" /> disk usage stats also remain stable <img width="1728" height="860" alt="image" src="https://github.com/user-attachments/assets/ff5fe593-4936-446e-9396-606fb495d60d" />
1 parent ee9f43b commit 0bb7407

File tree

4 files changed

+20
-71
lines changed

4 files changed

+20
-71
lines changed

docker/otel-collector/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ USER ${USER_UID}:${USER_GID}
2323
COPY --from=supervisor --chmod=755 /usr/local/bin/opampsupervisor /opampsupervisor
2424
COPY --from=col --chmod=755 /otelcol-contrib /otelcontribcol
2525

26-
# Copy entrypoint and log rotation scripts
26+
# Copy entrypoint and log tail wrapper scripts
2727
COPY --chmod=755 ./entrypoint.sh /entrypoint.sh
28-
COPY --chmod=755 ./log-rotator.sh /log-rotator.sh
2928
COPY --chmod=755 ./log-tailer.sh /log-tailer.sh
3029

3130
## dev ##############################################################################################

docker/otel-collector/entrypoint.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#!/bin/sh
22
set -e
33

4-
# Start log rotation script in background for agent.log
5-
# Arguments: log_file_path [max_size_mb] [max_archives] [check_interval_seconds]
6-
/log-rotator.sh /etc/otel/supervisor-data/agent.log 16 1 60 &
7-
8-
# Start log tailer script in background for agent.log
9-
# Arguments: log_file_path [check_interval_seconds]
104
if [ "$OTEL_SUPERVISOR_LOGS" = "true" ]; then
11-
/log-tailer.sh /etc/otel/supervisor-data/agent.log 1 &
5+
# Start log tailer process in background for agent.log
6+
# Arguments: log_file_path [check_interval_seconds]
7+
/log-tailer.sh /etc/otel/supervisor-data/agent.log 1 &
8+
9+
# Create a agent log file for the supervisor and collector child process. Normally
10+
# this file would be created as a standard file but we just want a FIFO pipe that
11+
# will pass data over to the tail process in the entrypoint script. This avoids
12+
# the need to the supervisor to store and forward the logs in its memory while also
13+
# eliminating the need for volume based storage.
14+
if [ ! -e /etc/otel/supervisor-data/agent.log ]; then
15+
mkfifo /etc/otel/supervisor-data/agent.log || echo "Failed to create FIFO" >&2
16+
fi
1217
fi
1318

1419
# Render the supervisor config template using gomplate

docker/otel-collector/log-rotator.sh

Lines changed: 0 additions & 49 deletions
This file was deleted.

docker/otel-collector/log-tailer.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ if [ -z "$LOG_FILE" ]; then
1414
exit 1
1515
fi
1616

17-
# Wait for file to exist if it doesn't yet
18-
while [ ! -f "$LOG_FILE" ]; do
19-
echo "Waiting for log file to be created: $LOG_FILE" >&2
20-
sleep "$SLEEP_INTERVAL"
17+
while true; do
18+
# Use tail -F to follow the file by name, not by descriptor
19+
# This handles rotation and truncation gracefully
20+
# -n 0: Start from the end (don't output existing content)
21+
# -F: Follow by name and retry if file is inaccessible
22+
# -s: Sleep interval between checks
23+
tail -n 0 -F -s "$SLEEP_INTERVAL" "$LOG_FILE" || true
2124
done
22-
23-
echo "Starting to tail: $LOG_FILE" >&2
24-
25-
# Use tail -F to follow the file by name, not by descriptor
26-
# This handles rotation and truncation gracefully
27-
# -n 0: Start from the end (don't output existing content)
28-
# -F: Follow by name and retry if file is inaccessible
29-
# -s: Sleep interval between checks
30-
tail -n 0 -F -s "$SLEEP_INTERVAL" "$LOG_FILE"

0 commit comments

Comments
 (0)