From 469c92191f489f41b1a206f6a0ae3906e4ce5e44 Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Wed, 17 Jun 2026 00:44:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(scheduler):=20=E7=86=94=E6=96=AD=E5=99=A8/?= =?UTF-8?q?=E5=AE=B9=E9=87=8F=E7=9B=91=E6=8E=A7=E6=94=B9=E7=94=A8=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=20alert.Notify(Event)=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 容量水位(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 --- server/internal/scheduler/orchestrate/breaker.go | 5 ++++- server/internal/scheduler/orchestrate/capacity.go | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/internal/scheduler/orchestrate/breaker.go b/server/internal/scheduler/orchestrate/breaker.go index 1aba7b4..46c7a04 100644 --- a/server/internal/scheduler/orchestrate/breaker.go +++ b/server/internal/scheduler/orchestrate/breaker.go @@ -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) } diff --git a/server/internal/scheduler/orchestrate/capacity.go b/server/internal/scheduler/orchestrate/capacity.go index dbea5b0..95babc0 100644 --- a/server/internal/scheduler/orchestrate/capacity.go +++ b/server/internal/scheduler/orchestrate/capacity.go @@ -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) }