Пофиксила тест === alert firing and resolved ===
This commit is contained in:
@@ -399,10 +399,19 @@ def _wait_alert(name: str, state: str, timeout: float = 240.0):
|
|||||||
deadline = time.monotonic() + timeout
|
deadline = time.monotonic() + timeout
|
||||||
while time.monotonic() < deadline:
|
while time.monotonic() < deadline:
|
||||||
alerts = _prom_alerts()
|
alerts = _prom_alerts()
|
||||||
for a in alerts:
|
# Prometheus /api/v1/alerts возвращает только pending/firing.
|
||||||
labels = a.get("labels", {})
|
# Состояние "inactive" == алерта с таким alertname нет в списке.
|
||||||
if labels.get("alertname") == name and a.get("state") == state:
|
active = [
|
||||||
|
a for a in alerts
|
||||||
|
if a.get("labels", {}).get("alertname") == name
|
||||||
|
]
|
||||||
|
if state == "inactive":
|
||||||
|
if not active:
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
for a in active:
|
||||||
|
if a.get("state") == state:
|
||||||
|
return
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
raise Failure("alert %s never reached %s" % (name, state))
|
raise Failure("alert %s never reached %s" % (name, state))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user