Skip to content

Commit

Permalink
collect missed logs + only collect from own ns
Browse files Browse the repository at this point in the history
  • Loading branch information
miampf committed Nov 7, 2024
1 parent 437d62a commit df0b8a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 13 additions & 1 deletion packages/log-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,29 @@ spec:
- mountPath: /logs
name: log-volume
readOnly: true
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
command:
- /usr/bin/bash
- -c
- |
mkdir /export
# TODO(miampf): Prepare an image that already has required tools installed
apt-get update && apt-get install -y inotify-tools
# collect all logs that may have been missed during startup
for file in $(find /logs -name *.log); do
if [[ -f "$file" && "$file" == *"$POD_NAMESPACE"* ]]; then
mkdir -p "/export$(dirname "$file")"
cp "$file" "/export$file"
fi
done
inotifywait -m /logs -r -e create -e moved_to |
while read path action file; do
filepath="$path$file"
if [[ -f "$filepath" ]]; then
if [[ -f "$filepath" && "$filepath" == *"$POD_NAMESPACE"* ]]; then
mkdir -p "/export$path"
tail --follow=name "$filepath" >"/export$filepath" &
fi
Expand Down
1 change: 0 additions & 1 deletion packages/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@
kubectl apply -f ./workspace/log-collector.yaml 1>/dev/null 2>/dev/null
pod="$(kubectl get pods -o name -n "$namespace" | grep log-collector | cut -c 5-)"
echo "$pod"
mkdir -p ./workspace/logs
kubectl wait --for=condition=Ready -n "$namespace" "pod/$pod" 1>/dev/null 2>/dev/null
# Download and extract the logs every 3 seconds
Expand Down

0 comments on commit df0b8a6

Please sign in to comment.