fix(telegram): 移除所有告警訊息欄位截斷限制,放寬至 Telegram 4096 字元硬限
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / build-and-deploy (push) Has been cancelled
問題:root_cause[:50/100]、suggested_action[:80]、suggestion[:50]、 note[:150]、fix_action[:100]、impact[:150]、hypothesis[:200] 以及 message[:900]/[:1000] 導致告警內容顯示不完整。 修復:移除欄位截斷,整體上限改為 4096(Telegram API 硬限制)。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -221,9 +221,9 @@ class TelegramMessage:
|
||||
signoz_block = f"━━━━━━━━━━━━━━━━━━━\n{self.signoz_metrics.format()}\n"
|
||||
|
||||
# HTML 轉義用戶輸入內容,防止 "Can't parse entities" 錯誤
|
||||
safe_resource = html.escape(self.resource_name[:35])
|
||||
safe_root_cause = html.escape(self.root_cause[:100])
|
||||
safe_action = html.escape(self.suggested_action[:80])
|
||||
safe_resource = html.escape(self.resource_name)
|
||||
safe_root_cause = html.escape(self.root_cause)
|
||||
safe_action = html.escape(self.suggested_action)
|
||||
safe_downtime = html.escape(self.estimated_downtime)
|
||||
|
||||
# 2026-03-29 ogt: AI Token/Cost 顯示
|
||||
@@ -315,7 +315,7 @@ class TelegramMessage:
|
||||
f"🔍 <a href='{signoz_url}'>SignOz Trace</a>"
|
||||
)
|
||||
|
||||
return message[:900] # 900 字元上限 (nemotron 版用 1000,因有額外 tool 區塊)
|
||||
return message[:4096] # Telegram 硬限制
|
||||
|
||||
def format_with_nemotron(self) -> str:
|
||||
"""
|
||||
@@ -372,9 +372,9 @@ class TelegramMessage:
|
||||
incident_id = f"INC-{self.approval_id[:8].upper()}"
|
||||
|
||||
# HTML 轉義
|
||||
safe_resource = html.escape(self.resource_name[:35])
|
||||
safe_root_cause = html.escape(self.root_cause[:100])
|
||||
safe_action = html.escape(self.suggested_action[:80])
|
||||
safe_resource = html.escape(self.resource_name)
|
||||
safe_root_cause = html.escape(self.root_cause)
|
||||
safe_action = html.escape(self.suggested_action)
|
||||
safe_downtime = html.escape(self.estimated_downtime)
|
||||
|
||||
# AI Provider 顯示
|
||||
@@ -451,7 +451,7 @@ class TelegramMessage:
|
||||
f"⏱️ 停機: {safe_downtime}"
|
||||
)
|
||||
|
||||
return message[:1000]
|
||||
return message[:4096] # Telegram 硬限制
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@@ -561,7 +561,7 @@ class ResourceWarnMessage:
|
||||
|
||||
suggestion_block = ""
|
||||
if self.suggestion:
|
||||
suggestion_block = f"💡 建議: {html.escape(self.suggestion[:50])}\n"
|
||||
suggestion_block = f"💡 建議: {html.escape(self.suggestion)}\n"
|
||||
|
||||
message = (
|
||||
f"═══════════════════════════\n"
|
||||
@@ -1072,17 +1072,17 @@ class InfraAlertMessage:
|
||||
"""格式化為 Telegram HTML"""
|
||||
# 有 note 表示「資訊性提示」,不顯示修復區塊
|
||||
if self.note:
|
||||
footer = f"━━━━━━━━━━━━━━━━━━━\n💡 {html.escape(self.note[:150])}\n"
|
||||
footer = f"━━━━━━━━━━━━━━━━━━━\n💡 {html.escape(self.note)}\n"
|
||||
elif self.auto_fixed:
|
||||
footer = f"━━━━━━━━━━━━━━━━━━━\n✅ <b>已自動修復</b>\n└ {html.escape(self.fix_action[:100])}\n"
|
||||
footer = f"━━━━━━━━━━━━━━━━━━━\n✅ <b>已自動修復</b>\n└ {html.escape(self.fix_action)}\n"
|
||||
else:
|
||||
footer = f"━━━━━━━━━━━━━━━━━━━\n⚠️ <b>需要關注</b>\n└ {html.escape(self.fix_action[:100] or '請確認元件狀態')}\n"
|
||||
footer = f"━━━━━━━━━━━━━━━━━━━\n⚠️ <b>需要關注</b>\n└ {html.escape(self.fix_action or '請確認元件狀態')}\n"
|
||||
|
||||
return (
|
||||
f"🚨 <b>基礎設施異常</b>\n"
|
||||
f"━━━━━━━━━━━━━━━━━━━\n"
|
||||
f"⚙️ <b>{html.escape(self.component)}</b>: {html.escape(self.status)}\n"
|
||||
f"📛 影響: {html.escape(self.impact[:150])}\n"
|
||||
f"📛 影響: {html.escape(self.impact)}\n"
|
||||
f"{footer}"
|
||||
)[:900]
|
||||
|
||||
@@ -2627,7 +2627,7 @@ class TelegramGateway:
|
||||
lines += [
|
||||
f"",
|
||||
f"🤖 <b>AI 分析</b> ({html.escape(dc.model_used)})",
|
||||
f"💡 {html.escape(dc.hypothesis[:200])}{'...' if len(dc.hypothesis) > 200 else ''}",
|
||||
f"💡 {html.escape(dc.hypothesis)}",
|
||||
f"📈 信心: [{confidence_bar}] {dc.confidence:.0%}",
|
||||
]
|
||||
if dc.probable_root_causes:
|
||||
|
||||
Reference in New Issue
Block a user