Files
easyai-ai-gateway/tests/release/production-acceptance-script-test.sh
T
wangbo 56a5176c92 perf(worker): 持久化准入快照提升队列吞吐
原因:线上 P24 验收显示 Worker 在每轮准入前逐条恢复媒体、重算候选和查询 attempts,跨地域查询导致 48 个执行槽长期只能使用约 8 至 16 个。\n\n影响:任务首次排队时保存鉴权后的 admission scope 快照,Worker 单次批量读取并只刷新动态总容量;显式重新选路保留完整慢路径。验收模拟器改到非数据库专用 Worker 节点,运行期 85% 作为立即中止硬门禁,80% 继续作为容量认证目标。\n\n验证:Go 全量测试、go vet、govulncheck、真实 PostgreSQL 迁移与跨 Store 集成测试、ShellCheck、发布及验收脚本、OpenAPI、前端 lint/test/build、pnpm audit high、Compose 与 Kubernetes 渲染均通过。
2026-08-01 21:25:54 +08:00

156 lines
5.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# shellcheck disable=SC2034,SC2329 # Symbols are consumed by dynamically sourced functions.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
script=$root/scripts/cluster/run-production-acceptance.sh
# shellcheck source=scripts/cluster/common.sh
source "$root/scripts/cluster/common.sh"
ssh() {
printf '%s\n' "$@" >"$tmp/ssh-arguments"
}
cluster_ssh_key=$tmp/test-key
cluster_ssh_control_dir=$tmp/ssh-control
cluster_ssh root@cluster.invalid true
grep -Fxq 'ConnectionAttempts=3' "$tmp/ssh-arguments"
grep -Fxq 'ControlMaster=auto' "$tmp/ssh-arguments"
grep -Fxq 'ControlPersist=120' "$tmp/ssh-arguments"
grep -Fxq "ControlPath=$cluster_ssh_control_dir/%C" "$tmp/ssh-arguments"
[[ $(stat -f '%Lp' "$cluster_ssh_control_dir") == 700 ]]
awk '
/^is_release_ancestor\(\)/ { capture = 1 }
capture && /^create_and_activate_run\(\)/ { exit }
capture { print }
' "$script" >"$tmp/is-release-ancestor.sh"
# shellcheck source=/dev/null
source "$tmp/is-release-ancestor.sh"
awk '
/^workload_metrics_for_site\(\)/ { capture = 1 }
capture && /^current_max_pod_memory_mib\(\)/ { exit }
capture { print }
' "$script" >"$tmp/pressure-monitor.sh"
# shellcheck source=/dev/null
source "$tmp/pressure-monitor.sh"
cluster_root=$tmp/repository
git init -q "$cluster_root"
git -C "$cluster_root" config user.name 'Acceptance Script Test'
git -C "$cluster_root" config user.email 'acceptance-script-test@example.invalid'
git -C "$cluster_root" commit --allow-empty -qm first
first=$(git -C "$cluster_root" rev-parse HEAD)
git -C "$cluster_root" commit --allow-empty -qm second
git -C "$cluster_root" commit --allow-empty -qm third
third=$(git -C "$cluster_root" rev-parse HEAD)
is_release_ancestor "$first" "$third"
if is_release_ancestor "$third" "$first"; then
echo 'descendant release was accepted as an ancestor' >&2
exit 1
fi
if is_release_ancestor invalid "$third"; then
echo 'invalid release identifier was accepted as an ancestor' >&2
exit 1
fi
remote_kubectl() {
if [[ $* == *'get pods'* ]]; then
printf '{"items":[]}'
else
printf 0
fi
}
cluster_ssh() {
echo 'zero-replica Worker attempted to collect metrics' >&2
return 1
}
namespace=easyai
if workload_metrics_for_site worker ningbo; then
echo 'zero-replica Worker site returned metrics success' >&2
exit 1
else
metrics_status=$?
fi
[[ $metrics_status == 2 ]]
remote_kubectl() {
printf '%s\n' '{"items":[
{"metadata":{},"spec":{"nodeName":"easyai-hongkong"},"status":{"podIP":"10.42.3.10","conditions":[{"type":"Ready","status":"True"}]}},
{"metadata":{},"spec":{"nodeName":"easyai-hongkong-worker-2"},"status":{"podIP":"10.42.5.10","conditions":[{"type":"Ready","status":"True"}]}}
]}'
}
cluster_ssh() {
while IFS= read -r _; do :; done
printf '# target_host %s\n' "$1"
printf 'test_metric 1\n'
}
CLUSTER_NINGBO_HOST=root@ningbo.invalid
CLUSTER_HONGKONG_HOST=root@hongkong.invalid
CLUSTER_LOS_ANGELES_HOST=root@losangeles.invalid
CLUSTER_WORKER_NODE_4_NAME=easyai-hongkong-worker-2
CLUSTER_WORKER_NODE_4_HOST=root@hongkong-worker-2.invalid
metrics=$(workload_metrics_for_site worker hongkong)
grep -Fq '# target_host root@hongkong.invalid' <<<"$metrics"
grep -Fq '# target_host root@hongkong-worker-2.invalid' <<<"$metrics"
[[ $(grep -c '^test_metric 1$' <<<"$metrics") == 2 ]]
[[ $(metric_min test_metric <<<"$metrics") == 1 ]]
[[ $(metric_max test_metric <<<"$metrics") == 1 ]]
[[ $(metric_sum test_metric <<<"$metrics") == 2 ]]
passing_pressure_row='2026-08-01T00:00:00Z,0,0,899,149,200,84,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100'
pressure_row_passes_live_gates "$passing_pressure_row"
[[ $(pressure_row_live_gate_reason '2026-08-01T00:00:00Z,0,0,900,149,200,79,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100') == \
'oldest_wait_seconds=900 limit=900' ]]
[[ $(pressure_row_live_gate_reason '2026-08-01T00:00:00Z,0,0,899,149,200,85,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100') == \
'node_memory_percent=85 hard_limit=85' ]]
for failed_pressure_row in \
'2026-08-01T00:00:00Z,0,0,901,149,200,79,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,150,200,79,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,80,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,79,1536,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,79,1535,0,32,32,0,0,1,0,2,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,79,1535,0,32,32,0,0,0,1,2,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,79,1535,0,32,32,0,0,0,0,0,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,79,1535,0,32,32,0,0,0,0,3,48,0,8,8,0,0,0,16,16,0,0,1535,100' \
'2026-08-01T00:00:00Z,0,0,900,149,200,79,1535,0,32,32,0,0,0,0,2,48,0,8,8,0,0,0,16,16,0,0,1536,100'; do
if pressure_row_passes_live_gates "$failed_pressure_row"; then
echo "unsafe pressure row passed live gates: $failed_pressure_row" >&2
exit 1
fi
done
long_running_load() {
while :; do
sleep 1
done
}
(sleep 1; exit 1) &
pressure_pid=$!
AI_GATEWAY_ACCEPTANCE_PROCESS_WATCH_SECONDS=1
active_load_pid=
if run_with_pressure_monitor "$pressure_pid" long_running_load; then
echo 'load continued after the pressure sampler failed' >&2
exit 1
fi
wait "$pressure_pid" >/dev/null 2>&1 || true
[[ -z $active_load_pid ]]
deploy_call_line=$(grep -n '^deploy_protocol_emulator$' "$script" | cut -d: -f1)
activate_call_line=$(grep -n '^create_and_activate_run$' "$script" | cut -d: -f1)
[[ -n $deploy_call_line && -n $activate_call_line && $deploy_call_line -lt $activate_call_line ]]
echo 'production_acceptance_script_tests=PASS'