#!/usr/bin/env bash # T96 — GSLB flip(A→B) 순간 "진행 중(in-flight) 요청"의 운명: STRICT_DNS vs LOGICAL_DNS # # T92(Mode 1)는 1ms 요청이라 drain이 항상 요청 사이에 떨어져 in-flight 절단이 관측 불가였다 # (destroy_with_active_rq = 0). 이 실측은 30초짜리 응답(300KB @ 10KB/s)을 wire에 걸쳐 두고 # flip을 넣어 두 가설을 가른다: # (A) 즉시 절단 → curl rc!=0 / bytes<307200, upstream_cx_destroy_with_active_rq +1 # (B) graceful → curl rc=0 / bytes=307200 완주, destroy는 완주 후(with_active_rq 0) # # 전제: setup.sh 완료 + t96-backends-slow.yaml 적용 완료 상태. set -uo pipefail CTX="${CTX:-homelab}"; NS="${NS:-dns-lab}" DIR="$(cd "$(dirname "$0")" && pwd)" LAB="${LAB:-$DIR}" K="kubectl --context=$CTX -n $NS" CL="outbound|443||gslb.lab.internal" SIZE=307200 # 300KB IP_A="$($K get svc backend-a -o jsonpath='{.spec.clusterIP}')" IP_B="$($K get svc backend-b -o jsonpath='{.spec.clusterIP}')" echo "== T96 == backend-a=$IP_A backend-b=$IP_B (기대 응답 크기 $SIZE bytes ≈ 30s)" flip(){ $K exec deploy/lab-dns -c writer -- sh -c "printf '%s gslb.lab.internal\n' '$1' > /hosts/addn"; } digq(){ $K exec deploy/netshoot -- dig +short gslb.lab.internal 2>/dev/null | tr '\n' ' '; } eps(){ istioctl --context="$CTX" proxy-config endpoints "deploy/netshoot.$NS" --cluster "$CL" 2>/dev/null | tail -n +1; } cstat(){ $K 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|membership_change|upstream_rq_total)' \ | sed 's#cluster.outbound|443||gslb.lab.internal.##' || echo "(none)" } snap(){ echo "--- snap[$1] @ $(date +%H:%M:%S) dig=$(digq)" echo "[endpoints]"; eps echo "[cluster|443 cx]"; cstat } run_variant(){ local V=$1 echo; echo "================ VARIANT=$V ================" $K delete serviceentry gslb-strict gslb-logical --ignore-not-found >/dev/null 2>&1 case $V in strict) $K apply -f "$LAB/40-serviceentry-strict.yaml" >/dev/null ;; logical) $K apply -f "$LAB/41-serviceentry-logical.yaml" >/dev/null ;; esac $K apply -f "$LAB/42-virtualservice-80to443.yaml" >/dev/null $K apply -f "$LAB/43-destinationrule-tls.yaml" >/dev/null flip "$IP_A"; sleep 8 snap "S0 pre-request (gslb->A)" echo; echo ">> slow GET 시작 @ $(date +%H:%M:%S) (완주 시 ~30s)" $K exec deploy/netshoot -- sh -c ' curl -sS -o /dev/null -D /tmp/t96h -m 90 \ -w "code=%{http_code} bytes=%{size_download} time=%{time_total}s" \ http://gslb.lab.internal/slow/slow.bin; echo " rc=$?" grep -i "x-backend" /tmp/t96h' > "$DIR/curl-$V.txt" 2>&1 & CPID=$! sleep 8 snap "S1 mid-flight, pre-flip (+8s)" echo ">> FLIP A->B @ $(date +%H:%M:%S)" flip "$IP_B" sleep 12 snap "S2 post-flip (+12s; 절단이면 이미 죽음 / graceful이면 아직 전송 중)" wait $CPID 2>/dev/null echo; echo "[curl 결과 — $V] @ $(date +%H:%M:%S)" cat "$DIR/curl-$V.txt" sleep 2 snap "S3 after" } run_variant strict run_variant logical echo; echo "== 판정 가이드 ==" echo " 절단(가설 A): curl rc!=0(18=partial/56=reset), bytes<$SIZE, destroy_with_active_rq 델타 +1" echo " graceful(가설 B): curl rc=0, bytes=$SIZE, time≈30s, destroy는 완주 후 with_active_rq 0"