Skip to content

Commit

Permalink
Add thread dump collection to report.sh
Browse files Browse the repository at this point in the history
This patch adds thread dump collection to the report.sh tool.
Unlike heap dumps, thread dumps are lightweight (~100ms), but still can help diagnose problems and better optimize application and JVM performance.

We simply run kill -SIGQUIT 1 just before collecting the pod logs.
Each output log will contain the thread dump at the end.
Tested with both ZK and KRaft based clusters.

Signed-off-by: Federico Valeri <[email protected]>
  • Loading branch information
fvaleri committed Dec 2, 2024
1 parent 03e3045 commit b68f595
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ for RES in "${CLUSTER_RESOURCES[@]}"; do
get_nonnamespaced_yamls "$RES"
done

# when kill command is available, each log file includes the thread dump at the end
get_pod_logs() {
local pod="$1"
local con="${2-}"
Expand All @@ -230,12 +231,14 @@ get_pod_logs() {
local logs
mkdir -p "$OUT_DIR"/reports/logs
if [[ "$count" -eq 1 ]]; then
$KUBE_CLIENT -n "$NAMESPACE" exec -i "$pod" -- sh -c "kill -3 1 ||true"
logs="$($KUBE_CLIENT -n "$NAMESPACE" logs "$pod" ||true)"
if [[ -n $logs ]]; then printf "%s" "$logs" > "$OUT_DIR"/reports/logs/"$pod".log; fi
logs="$($KUBE_CLIENT -n "$NAMESPACE" logs "$pod" -p 2>/dev/null ||true)"
if [[ -n $logs ]]; then printf "%s" "$logs" > "$OUT_DIR"/reports/logs/"$pod".log.0; fi
fi
if [[ "$count" -gt 1 && -n "$con" && "$names" == *"$con"* ]]; then
$KUBE_CLIENT -n "$NAMESPACE" exec -i "$pod" -c "$con" -- sh -c "kill -3 1 ||true"
logs="$($KUBE_CLIENT -n "$NAMESPACE" logs "$pod" -c "$con" ||true)"
if [[ -n $logs ]]; then printf "%s" "$logs" > "$OUT_DIR"/reports/logs/"$pod"-"$con".log; fi
logs="$($KUBE_CLIENT -n "$NAMESPACE" logs "$pod" -p -c "$con" 2>/dev/null ||true)"
Expand Down

0 comments on commit b68f595

Please sign in to comment.