fix(awooop): record grouped alert events
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 1m6s
CD Pipeline / build-and-deploy (push) Successful in 3m48s
CD Pipeline / post-deploy-checks (push) Successful in 1m25s

This commit is contained in:
Your Name
2026-05-07 01:35:09 +08:00
parent 1a1dea00eb
commit 251554c044
8 changed files with 373 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
from __future__ import annotations
from src.services.channel_hub import (
build_grouped_alert_provider_event_id,
format_grouped_alert_event_content,
)
def test_build_grouped_alert_provider_event_id_is_deterministic() -> None:
event_id = build_grouped_alert_provider_event_id(
"INC-20260507-ABCD12",
"1234567890abcdef" * 4,
)
assert event_id == "alert-group:INC-20260507-ABCD12:1234567890abcdef1234567890abcdef"
assert len(event_id) < 256
def test_format_grouped_alert_event_content_keeps_operator_context() -> None:
content = format_grouped_alert_event_content(
alert_id="INC-20260507-ABCD12",
alertname="DockerContainerRestartSpike",
severity="critical",
namespace="default",
target_resource="sentry-self-hosted-events-consumer-1",
group_key="DockerContainerRestartSpike:default",
count=4,
parent_fingerprint="parent-fp",
fingerprint="child-fp",
)
assert "告警已收斂,不發 Telegram" in content
assert "Alert: DockerContainerRestartSpike" in content
assert "Target: sentry-self-hosted-events-consumer-1" in content
assert "Group Count: 4" in content
assert "Parent Fingerprint: parent-fp" in content

View File

@@ -13,3 +13,13 @@ def test_runs_list_route_is_registered_before_dynamic_run_id() -> None:
assert "/runs/list" in paths
assert "/runs/{run_id}" in paths
assert paths.index("/runs/list") < paths.index("/runs/{run_id}")
def test_recent_events_route_is_registered() -> None:
paths = [
route.path
for route in router.routes
if "GET" in getattr(route, "methods", set())
]
assert "/events/recent" in paths