Skip to content

Commit 0496484

Browse files
committed
fix: only copy last 1000 lines of mosquitto log file during diagnostic collection
Avoid copying the entire mosquitto.log file to prevent cases where the log file is large (e.g. when no log rotation is configured) Signed-off-by: reubenmiller <[email protected]>
1 parent 4b025b6 commit 0496484

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

configuration/contrib/diag-plugins/07_mosquitto.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ mosquitto_journal() {
3434

3535
mosquitto_log() {
3636
if [ -f /var/log/mosquitto/mosquitto.log ]; then
37-
cp /var/log/mosquitto/mosquitto.log "$OUTPUT_DIR"/
37+
# avoid copying the full file as it could be very large if logrotate is not installed and configured
38+
# but still log the details as it could be helpful to diagnose
39+
echo "mosquitto log file details:" >&2
40+
ls -l /var/log/mosquitto/mosquitto.log >&2 ||:
41+
tail -n 1000 /var/log/mosquitto/mosquitto.log > "$OUTPUT_DIR"/mosquitto.log ||:
3842
else
3943
echo "mosquitto.log not found" >&2
4044
fi

tests/RobotFramework/tests/tedge/diag/predefined_plugins.robot

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ Test Tags theme:troubleshooting theme:cli theme:plugins
7373
FOR ${log_name} IN @{log_names}
7474
File Size Is Not Zero ${log_name}
7575
END
76+
${log_line_count}= Execute Command
77+
... cmd=wc -l /results/test/07_mosquitto/mosquitto.log | awk '{print $1}'
78+
... strip=${True}
79+
Should Be True int(${log_line_count}) <= 1000
7680
Execute Command diff /var/log/mosquitto/mosquitto.log /results/test/07_mosquitto/mosquitto.log
77-
Log Should Contain mosquitto-journal.log Starting mosquitto.service
7881

7982

8083
*** Keywords ***

0 commit comments

Comments
 (0)