mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 09:57:47 +08:00
feat(stats,rules): api_key 用量统计(total_tokens 字段 + 回填)与 body rules 新增 append/insert/regex_replace/name_style 操作
- 新增迁移 20260422120000_add_api_key_usage_stats.sql,为 api_keys 表添加 total_tokens 列 - 新增回填 20260422120000_backfill_api_key_usage_stats.sql,按历史 usage 重建 api_key 维度汇总 - 在 UsageWriteRepository trait 中添加 rebuild_api_key_usage_stats,补齐 SQL/内存实现及上层调用链 - 内存实现中新增 apply_usage_stats_delta,支持增量更新 api_key 统计快照 - dev.sh:改进临时日志目录管理,并在网关异常退出时输出错误提示 - frontend EndpointFormDialog:将 append 操作从 insert 分支拆分,提供独立 path/value 输入 UI - rules.rs:扩展 body rules 支持,新增 append/insert/regex_replace/name_style 操作及 WildcardSlice 路径段
This commit is contained in:
@@ -152,6 +152,7 @@ export HTTP_MAX_CONNECTIONS=${HTTP_MAX_CONNECTIONS:-20}
|
||||
export HTTP_KEEPALIVE_CONNECTIONS=${HTTP_KEEPALIVE_CONNECTIONS:-5}
|
||||
|
||||
GATEWAY_PID=""
|
||||
GATEWAY_LOG_DIR=""
|
||||
GATEWAY_LOG_FILE=""
|
||||
STARTUP_WAIT_EARLY_EXIT=false
|
||||
|
||||
@@ -165,10 +166,22 @@ cleanup() {
|
||||
if [ -n "${GATEWAY_LOG_FILE}" ] && [ -f "${GATEWAY_LOG_FILE}" ]; then
|
||||
rm -f "${GATEWAY_LOG_FILE}"
|
||||
fi
|
||||
if [ -n "${GATEWAY_LOG_DIR}" ] && [ -d "${GATEWAY_LOG_DIR}" ]; then
|
||||
rmdir "${GATEWAY_LOG_DIR}" >/dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
create_gateway_log_file() {
|
||||
local tmp_root="${TMPDIR:-/tmp}"
|
||||
tmp_root="${tmp_root%/}"
|
||||
|
||||
GATEWAY_LOG_DIR="$(mktemp -d "${tmp_root}/aether-dev-startup.XXXXXX")"
|
||||
GATEWAY_LOG_FILE="${GATEWAY_LOG_DIR}/gateway.log"
|
||||
: > "${GATEWAY_LOG_FILE}"
|
||||
}
|
||||
|
||||
print_startup_failure_hint() {
|
||||
local log_file="$1"
|
||||
|
||||
@@ -283,7 +296,7 @@ if ! preflight_dev_infra; then
|
||||
fi
|
||||
|
||||
GATEWAY_ARGS=(--app-port "${APP_PORT}")
|
||||
GATEWAY_LOG_FILE="$(mktemp "${TMPDIR:-/tmp}/aether-dev-startup.XXXXXX.log")"
|
||||
create_gateway_log_file
|
||||
echo "=> 启动 aether-gateway (Rust frontdoor: 0.0.0.0:${APP_PORT})..."
|
||||
echo "=> 日志过滤: ${RUST_LOG} (需要更详细日志可用: RUST_LOG=aether_gateway=debug ./dev.sh)"
|
||||
if command -v script >/dev/null 2>&1; then
|
||||
@@ -304,4 +317,14 @@ if ! wait_for_startup "${GATEWAY_PID}" "${GATEWAY_STARTUP_TIMEOUT_SECONDS}" "aet
|
||||
exit 1
|
||||
fi
|
||||
|
||||
wait "${GATEWAY_PID}"
|
||||
if wait "${GATEWAY_PID}"; then
|
||||
exit 0
|
||||
else
|
||||
gateway_exit_code=$?
|
||||
fi
|
||||
|
||||
if [ "${gateway_exit_code}" -ne 130 ] && [ "${gateway_exit_code}" -ne 143 ]; then
|
||||
echo "=> aether-gateway 运行失败并已退出,请检查上面的日志。"
|
||||
print_startup_failure_hint "${GATEWAY_LOG_FILE}"
|
||||
fi
|
||||
exit "${gateway_exit_code}"
|
||||
|
||||
Reference in New Issue
Block a user