Install inotifytools for k8s sidecars log tailing#1364
Merged
Conversation
Contributor
|
Looks good.
Agreed. |
Member
Author
|
FYI, this is how I use that in Kubernetes in a sidecar container that only collects log messages: - name: log-forwarder
image: ocrd-core-image
command:
- /bin/sh
- -c
- |
# Tail already existing log files
find /logs -type f -name '*.log' | while read -r f; do
echo "[processor=$(OCRD_PROCESSOR_NAME)]: Tailing existing log: $f"
tail -n +1 -F "$f" &
done
# Tail newly created log files
inotifywait -m -r -e create /logs --format '%w%f' |
while read -r f; do
case "$f" in
*.log)
echo "Tailing new log: $f" >&2
job="${f##*/}"
job="${job%.log}"
tail -n +1 -F "$f" |
while IFS= read -r line; do
printf '[processor=%s job=%s] %s\n' "$(OCRD_PROCESSOR_NAME)" "$job" "$line"
done &
;;
esac
doneWhich gives me a complete log across all the log files, e.g. Still not ideal but it does allow me to debug individual jobs effectively and I don't need any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Does not add too many dependencies and allows a mechanism like
to get the logging of the workers into the STDOUT stream for log analysis.
It's still not a great solution but the least invasive change.
In the mid-term we should find a way to have the ocrd_network logging make fewer assumptions, perhaps carry the info from the filename (job UUID) as a logging metadata field or even just part of the log message.