fix(ci): use internal metrics for provider freshness smoke
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user