fix(alerts): group repeated alerts from second firing
This commit is contained in:
@@ -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:"
|
||||
|
||||
@@ -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 應長於視窗"""
|
||||
|
||||
Reference in New Issue
Block a user