fix(ci): report provider degradation as warning
All checks were successful
CD Pipeline / tests (push) Successful in 5m55s
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / build-and-deploy (push) Successful in 3m59s
CD Pipeline / post-deploy-checks (push) Successful in 1m48s

This commit is contained in:
Your Name
2026-05-24 10:59:21 +08:00
parent f3b85cda4f
commit 22a4b44aef
3 changed files with 74 additions and 13 deletions

View File

@@ -17,6 +17,64 @@ SPEC.loader.exec_module(alert_chain_smoke_test)
class AlertChainSmokeMetricTest(unittest.TestCase):
def test_api_health_passes_when_only_provider_is_degraded(self):
def fake_get(url, *, params=None, timeout=None):
self.assertTrue(url.endswith("/api/v1/health"))
return alert_chain_smoke_test.HttpGetResult(
200,
json.dumps(
{
"status": "degraded",
"environment": "prod",
"components": {
"api": {"status": "up"},
"postgresql": {"status": "up"},
"redis": {"status": "up"},
"ollama": {"status": "down", "error": "timeout"},
"signoz": {"status": "up"},
},
}
),
)
original_get = alert_chain_smoke_test.http_get
try:
alert_chain_smoke_test.http_get = fake_get
result = alert_chain_smoke_test.check_api_health("http://api")
finally:
alert_chain_smoke_test.http_get = original_get
self.assertTrue(result.passed)
self.assertIn("非阻塞降級: ollama", result.message)
def test_api_health_fails_when_core_component_is_down(self):
def fake_get(url, *, params=None, timeout=None):
self.assertTrue(url.endswith("/api/v1/health"))
return alert_chain_smoke_test.HttpGetResult(
200,
json.dumps(
{
"status": "degraded",
"components": {
"api": {"status": "up"},
"postgresql": {"status": "down"},
"redis": {"status": "up"},
"ollama": {"status": "up"},
},
}
),
)
original_get = alert_chain_smoke_test.http_get
try:
alert_chain_smoke_test.http_get = fake_get
result = alert_chain_smoke_test.check_api_health("http://api")
finally:
alert_chain_smoke_test.http_get = original_get
self.assertFalse(result.passed)
self.assertIn("核心組件異常: postgresql", result.message)
def test_parse_app_alert_chain_metric_samples(self):
samples = alert_chain_smoke_test.parse_app_alert_chain_metric_samples(
"\n".join([