fix(ci): report provider degradation as warning
This commit is contained in:
@@ -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([
|
||||
|
||||
Reference in New Issue
Block a user