fix: 修復 3 個 P0 Bug
All checks were successful
E2E Health Check / e2e-health (push) Successful in 18s

1. E2E Health: Docker 容器無法訪問內網 IP,改用公網域名
2. metrics_repository: asyncpg 需要 datetime 物件,不能用字串
3. metrics_repository: PostgreSQL 用 date_trunc 而非 strftime

2026-03-31 ogt: 首席架構師審查發現並修復

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-31 11:27:51 +08:00
parent b2e41ebac6
commit 4c0f15d7b3
2 changed files with 8 additions and 7 deletions

View File

@@ -24,8 +24,8 @@ jobs:
id: health_check
run: |
sudo apt-get update && sudo apt-get install -y curl || (apt-get update && apt-get install -y curl)
# 使用 host.docker.internal 或直接 IP
API_URL="http://192.168.0.121:32334"
# 2026-03-31 ogt: Docker 容器無法訪問內網 IP改用公網域名
API_URL="https://awoooi.wooo.work"
echo "🔗 檢查 API 健康狀態..."
for i in 1 2 3; do

View File

@@ -56,8 +56,8 @@ class MetricsDBRepository(IMetricsRepository):
"""
try:
async with get_db_context() as session:
# 2026-03-31 ogt: asyncpg 需要 datetime 物件,不能用字串
cutoff = datetime.now(UTC) - timedelta(hours=hours)
cutoff_str = cutoff.isoformat()
# Query: 統計 executed vs total (approved + executed + execution_failed)
query = text("""
@@ -69,7 +69,7 @@ class MetricsDBRepository(IMetricsRepository):
AND status IN ('approved', 'executed', 'execution_failed')
""")
result = await session.execute(query, {"cutoff": cutoff_str})
result = await session.execute(query, {"cutoff": cutoff})
row = result.fetchone()
if row and row.total_count > 0:
@@ -119,13 +119,14 @@ class MetricsDBRepository(IMetricsRepository):
"""
try:
async with get_db_context() as session:
# 2026-03-31 ogt: asyncpg 需要 datetime 物件,不能用字串
cutoff = datetime.now(UTC) - timedelta(hours=hours)
cutoff_str = cutoff.isoformat()
# Trend: 過去 N 個時間點的成功率 (每小時一點)
# 2026-03-31 ogt: PostgreSQL 用 date_trunc 而非 strftime
trend_query = text("""
SELECT
strftime('%Y-%m-%d %H:00:00', created_at) as hour_bucket,
date_trunc('hour', created_at) as hour_bucket,
COUNT(CASE WHEN status = 'executed' THEN 1 END) * 100.0 /
NULLIF(COUNT(*), 0) as hourly_rate
FROM approval_records
@@ -138,7 +139,7 @@ class MetricsDBRepository(IMetricsRepository):
result = await session.execute(
trend_query,
{"cutoff": cutoff_str, "limit": points},
{"cutoff": cutoff, "limit": points},
)
rows = result.fetchall()