fix(alerts): group repeated alerts from second firing
All checks were successful
Code Review / ai-code-review (push) Successful in 10s
CD Pipeline / tests (push) Successful in 1m4s
CD Pipeline / build-and-deploy (push) Successful in 3m27s
CD Pipeline / post-deploy-checks (push) Successful in 1m20s

This commit is contained in:
Your Name
2026-05-07 01:20:18 +08:00
parent 67c70c071b
commit c49246b8c6
2 changed files with 9 additions and 8 deletions

View File

@@ -83,8 +83,9 @@ class AlertGroupingService:
# 5 分鐘滑動視窗
WINDOW_SECONDS: int = 300
# 觸發聚合的閾值(同一分組 5 分鐘內超過此數量才聚合)
GROUP_THRESHOLD: int = 3
# 觸發聚合的閾值:保留第一張主卡,第二個同組告警開始收斂。
# 2026-05-07 Codex — Telegram 群組噪音治理:舊值 3 會讓前兩張同類告警仍進 AI/Telegram。
GROUP_THRESHOLD: int = 2
# Redis Key 前綴
PREFIX_WINDOW = "alert_group:window:"

View File

@@ -91,16 +91,16 @@ class TestGroupingResultDataclass:
assert result.is_grouped is False
assert result.is_parent is True
def test_below_threshold_not_grouped(self):
"""未達閾值count=2, threshold=3 → is_grouped=False"""
def test_second_alert_is_now_grouped(self):
"""門檻為 2第一張保留主卡第二張同組告警開始收斂。"""
result = GroupingResult(
is_grouped=False,
is_grouped=True,
group_key="PodCrash:awoooi-prod",
count=2,
parent_fingerprint="fp-001",
is_parent=False,
)
assert result.is_grouped is False
assert result.is_grouped is True
def test_group_key_format(self):
"""group_key 格式應為 {alertname_prefix}:{namespace}"""
@@ -124,8 +124,8 @@ class TestAlertGroupingServiceConstants:
assert AlertGroupingService.WINDOW_SECONDS == 300
def test_group_threshold(self):
"""聚合閾值應為 3"""
assert AlertGroupingService.GROUP_THRESHOLD == 3
"""聚合閾值應為 2保留第一張主卡第二張同組告警開始收斂。"""
assert AlertGroupingService.GROUP_THRESHOLD == 2
def test_ttl_seconds(self):
"""TTL 應長於視窗"""