fix(scheduler): 熔断器/容量监控改用统一 alert.Notify(Event) 接口

容量水位(NPgPRxBGv0g9)与告警出口(9YMHMTfWJyNB)两条并行分支合并后接口
不兼容:前者调用旧的 NotifyFault(ctx,id,reason),后者把 alert.Notifier 统一
为 Notify(ctx, Event)。将熔断触发/水位过低/探针失联三处改用 alert.NewEvent +
Notify,对齐 alert 包的统一事件出口设计(EventTypeBreakerTripped/WatermarkLow/
ProbeAgentLost),mockNotifier 既有 count() 断言无需改动即通过。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-17 00:44:27 +08:00
parent 9f2f96d722
commit 469c92191f
2 changed files with 11 additions and 3 deletions
@@ -9,6 +9,7 @@ import (
"github.com/redis/go-redis/v9"
"github.com/wangjia/pangolin/server/internal/alert"
"github.com/wangjia/pangolin/server/internal/idgen"
)
@@ -299,7 +300,9 @@ func (b *RedisBreaker) emitTripAlert(ctx context.Context, tier, region string, c
"window_count", count, "threshold", threshold,
)
if b.notifier != nil {
if err := b.notifier.NotifyFault(ctx, poolID, reason); err != nil {
event := alert.NewEvent(alert.EventTypeBreakerTripped, poolID, map[string]string{"reason": reason})
event.Pool = poolID
if err := b.notifier.Notify(ctx, event); err != nil {
slog.Error("breaker: emit trip alert failed",
"pool", poolID, "error", err)
}
@@ -7,6 +7,8 @@ import (
"time"
"github.com/redis/go-redis/v9"
"github.com/wangjia/pangolin/server/internal/alert"
)
// ─────────────────────────────────────────────────────────────────────────────
@@ -176,7 +178,9 @@ func (m *CapacityMonitor) checkWatermarks(ctx context.Context, cfg *SchedConfig)
)
if m.notifier != nil {
if notifyErr := m.notifier.NotifyFault(ctx, poolID, reason); notifyErr != nil {
event := alert.NewEvent(alert.EventTypeWatermarkLow, "", map[string]string{"reason": reason})
event.Pool = poolID
if notifyErr := m.notifier.Notify(ctx, event); notifyErr != nil {
slog.Error("capacity: notify watermark alert",
"pool", poolID, "error", notifyErr)
}
@@ -232,7 +236,8 @@ func (m *CapacityMonitor) checkProbeHeartbeats(ctx context.Context, cfg *SchedCo
)
if m.notifier != nil {
if notifyErr := m.notifier.NotifyFault(ctx, probeNodeID, reason); notifyErr != nil {
event := alert.NewEvent(alert.EventTypeProbeAgentLost, probeNodeID, map[string]string{"reason": reason})
if notifyErr := m.notifier.Notify(ctx, event); notifyErr != nil {
slog.Error("capacity: notify probe lost contact",
"probe_id", pid, "error", notifyErr)
}