fix(ci): use internal metrics for provider freshness smoke
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 4m0s
CD Pipeline / build-and-deploy (push) Successful in 3m30s
CD Pipeline / post-deploy-checks (push) Successful in 2m9s

This commit is contained in:
Your Name
2026-05-20 19:51:15 +08:00
parent 6003fd03ec
commit 017d57c96a
3 changed files with 85 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
import importlib.util
import json
import sys
import time
import unittest
@@ -78,6 +79,50 @@ class AlertChainSmokeMetricTest(unittest.TestCase):
self.assertFalse(result.passed)
self.assertTrue(result.critical)
def test_alert_chain_metric_checks_app_metric_when_prometheus_is_stale(self):
fresh_ts = time.time() - 30
stale_ts = time.time() - alert_chain_smoke_test.MAX_ALERT_CHAIN_SILENCE_SECONDS - 60
def fake_get(url, *, params=None, timeout=None):
if url.endswith("/api/v1/query"):
return alert_chain_smoke_test.HttpGetResult(
200,
json.dumps(
{
"data": {
"result": [
{
"metric": {"source": "sentry"},
"value": [time.time(), str(stale_ts)],
}
]
}
}
),
)
if url.endswith("/metrics"):
return alert_chain_smoke_test.HttpGetResult(
200,
'awoooi_alert_chain_last_success_timestamp{source="sentry"} '
f"{fresh_ts}",
)
raise AssertionError(f"unexpected url {url}")
original_get = alert_chain_smoke_test.http_get
try:
alert_chain_smoke_test.http_get = fake_get
result = alert_chain_smoke_test.check_alert_chain_metric(
"http://prometheus",
"http://api",
source="sentry",
)
finally:
alert_chain_smoke_test.http_get = original_get
self.assertTrue(result.passed)
self.assertIn("app_metrics", result.message)
self.assertIn("Prometheus scrape 尚未看到", result.message)
def test_source_provider_heartbeat_requires_operator_key(self):
result = alert_chain_smoke_test.send_source_provider_heartbeat(
"https://awoooi.example",