#!/usr/bin/env bash # scripts/dns-inflight-4snap.sh — STRICT/LOGICAL flip 중 in-flight(장수명 40s) 요청 1회 + # flip(+5s) + 4점 스냅샷(BEFORE/MID1+12s/MID2+30s/AFTER end+3s)으로 "언제" 커넥션이 정리되는지 규명한다. # # 전제: scripts/dns-lab-setup.sh 로 랩이 떠 있고, scenarios/50-dns-resolution/20-backends.yaml 의 # `/slow`(10KB/s 제한, 409610B ≈ 40초 응답) 엔드포인트가 반영된 상태. SE(strict/logical)는 이 스크립트 # 실행 전 원하는 변형으로 미리 apply 해둘 것(예: 40-serviceentry-strict.yaml 또는 41-*-logical.yaml). # 스냅샷은 netshoot 사이드카(실제 트래픽 지점) 기준 — fortio 아님, 하네스 dns-flip-test.sh 의 # estat() 관례와 다르니 주의. # # 출처: docs/test-reports/2026-07-02_104250_dns-strict-inflight.md (2점 스냅샷, in-flight 절단 미재현) # docs/test-reports/2026-07-02_112113_dns-inflight-part2.md (이 4점 스냅샷으로 destroy_local 타이밍 확정) # # usage: bash scripts/dns-inflight-4snap.sh set -uo pipefail RUN="${1:?usage: dns-inflight-4snap.sh }" CTX="${CTX:-homelab}"; NS="${NS:-dns-lab}" DIR="$(cd "$(dirname "$0")/.." && pwd)" WORK="$DIR/tmp/dns-inflight"; mkdir -p "$WORK" snap(){ # $1 = snapshot name echo "=== ${RUN} ${1} snapshot @ $(date +%H:%M:%S) ===" echo "-- dig --" kubectl --context="$CTX" -n "$NS" exec deploy/netshoot -- dig +short gslb.lab.internal 2>/dev/null echo "-- endpoints (netshoot) --" istioctl --context="$CTX" proxy-config endpoints "deploy/netshoot.$NS" --cluster "outbound|443||gslb.lab.internal" 2>/dev/null echo "-- cluster stats (gslb, netshoot sidecar) --" kubectl --context="$CTX" -n "$NS" exec deploy/netshoot -c istio-proxy -- pilot-agent request GET "stats?filter=gslb" 2>/dev/null \ | grep -E 'cluster\.outbound\|443.*(upstream_cx_total|upstream_cx_destroy|upstream_cx_active|upstream_cx_connect_fail|upstream_rq_total|membership_change)' \ | sed 's#cluster.outbound|443||gslb.lab.internal.##' echo "-- endpoint cx (clusters, netshoot sidecar) --" kubectl --context="$CTX" -n "$NS" exec deploy/netshoot -c istio-proxy -- pilot-agent request GET clusters 2>/dev/null \ | grep -E 'outbound\|443\|\|gslb\.lab\.internal::[0-9]' \ | grep -E 'cx_active|cx_total|rq_total|rq_active|health_flags' \ | sed 's#outbound|443||gslb.lab.internal::##' echo } sleep_until(){ # $1 = target epoch local now; now=$(date +%s) local d=$(( $1 - now )) [ "$d" -gt 0 ] && sleep "$d" } { snap BEFORE T0=$(date +%s) echo "CURL_LAUNCH=$(date +%H:%M:%S) (T0=$T0)" kubectl --context="$CTX" -n "$NS" exec deploy/netshoot -- sh -c 'date +%H:%M:%S > /tmp/rX_podstart.txt; curl -s -m 90 -o /tmp/rX.bin -w "CURL_EXIT=%{exitcode} SIZE=%{size_download} TIME=%{time_total} CODE=%{http_code}" http://gslb.lab.internal/slow; rc=$?; echo; echo "RC=$rc"; date +%H:%M:%S > /tmp/rX_podend.txt' > "$WORK/${RUN}_curl_out.txt" 2>"$WORK/${RUN}_curl_stderr.txt" & CURLPID=$! sleep_until $((T0+5)) echo "FLIP_ISSUED=$(date +%H:%M:%S) (t=+$(( $(date +%s) - T0 ))s)" kubectl --context="$CTX" -n "$NS" exec deploy/lab-dns -c writer -- sh -c "printf '%s gslb.lab.internal\n' '10.250.27.55' > /hosts/addn" echo "FLIP_DONE=$(date +%H:%M:%S) (t=+$(( $(date +%s) - T0 ))s)" echo sleep_until $((T0+12)) echo "[t=+$(( $(date +%s) - T0 ))s]"; snap MID1 sleep_until $((T0+30)) echo "[t=+$(( $(date +%s) - T0 ))s]"; snap MID2 wait $CURLPID CURL_END=$(date +%s) echo "CURL_WAIT_DONE=$(date +%H:%M:%S) (t=+$(( CURL_END - T0 ))s)" echo "-- curl result --" cat "$WORK/${RUN}_curl_out.txt" echo sleep 3 echo "[t=+$(( $(date +%s) - T0 ))s]"; snap AFTER echo "-- received file check (netshoot) --" kubectl --context="$CTX" -n "$NS" exec deploy/netshoot -- sh -c 'wc -c /tmp/rX.bin; head -c 15 /tmp/rX.bin; echo' } | tee "$WORK/${RUN}_full.txt"