feat(automation): 按成功率灰度扩缩自动重登
This commit is contained in:
@@ -344,3 +344,63 @@ def test_account_platform_status_builds_seven_day_trends(db):
|
||||
assert login_today["failed"] == 1
|
||||
assert login_today["success_rate"] == 50.0
|
||||
assert lifecycle_today["ck_invalid"] == 1
|
||||
|
||||
|
||||
def test_account_platform_status_alerts_on_persistently_low_trends(db):
|
||||
account = _account("platform-trend-alerts")
|
||||
db.add(account)
|
||||
db.flush()
|
||||
now = datetime.now(UTC)
|
||||
db.add_all(
|
||||
[
|
||||
AccountSyncRun(
|
||||
account_id=account.id,
|
||||
domain="storehome",
|
||||
started_at=now,
|
||||
finished_at=now,
|
||||
status="failed",
|
||||
duration_ms=100,
|
||||
)
|
||||
for _ in range(20)
|
||||
]
|
||||
)
|
||||
db.add_all(
|
||||
[
|
||||
LoginAttempt(
|
||||
account_id=account.id,
|
||||
category="relogin_ordinary",
|
||||
trigger_source="automation",
|
||||
started_at=now,
|
||||
finished_at=now,
|
||||
status="failed",
|
||||
failure_kind="network",
|
||||
quota_day=now.date(),
|
||||
)
|
||||
for _ in range(10)
|
||||
]
|
||||
)
|
||||
db.add_all(
|
||||
[
|
||||
AccountEvent(
|
||||
account_id=account.id,
|
||||
event_type="relogin_failed",
|
||||
category="auth",
|
||||
occurred_at=now,
|
||||
title="重登失败",
|
||||
source="pytest",
|
||||
actor_type="system",
|
||||
source_ref=f"pytest-relogin-alert:{account.id}:{index}",
|
||||
)
|
||||
for index in range(5)
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
status = account_platform_status(db, now=now)
|
||||
codes = {alert["code"] for alert in status["alerts"]}
|
||||
|
||||
assert {
|
||||
"query_success_rate_low",
|
||||
"login_success_rate_low",
|
||||
"relogin_failure_trend_high",
|
||||
} <= codes
|
||||
|
||||
Reference in New Issue
Block a user