From cb56037ef86461a27184f4937b0f6eed2c31a268 Mon Sep 17 00:00:00 2001 From: ning <710leo@gmail.com> Date: Wed, 8 Jan 2025 19:40:04 +0800 Subject: [PATCH] refactor: change eval sleep --- alert/eval/alert_rule.go | 1 + alert/eval/eval.go | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/alert/eval/alert_rule.go b/alert/eval/alert_rule.go index b7317efb7..cc2e4b373 100644 --- a/alert/eval/alert_rule.go +++ b/alert/eval/alert_rule.go @@ -149,6 +149,7 @@ func (s *Scheduler) syncAlertRules() { for hash, rule := range alertRuleWorkers { if _, has := s.alertRules[hash]; !has { rule.Prepare() + time.Sleep(time.Duration(20) * time.Millisecond) rule.Start() s.alertRules[hash] = rule } diff --git a/alert/eval/eval.go b/alert/eval/eval.go index 70434c3d2..4564db548 100644 --- a/alert/eval/eval.go +++ b/alert/eval/eval.go @@ -25,7 +25,6 @@ import ( "github.com/ccfos/nightingale/v6/pkg/unit" "github.com/ccfos/nightingale/v6/prom" "github.com/prometheus/common/model" - "golang.org/x/exp/rand" "github.com/robfig/cron/v3" "github.com/toolkits/pkg/logger" @@ -137,14 +136,11 @@ func (arw *AlertRuleWorker) Prepare() { } func (arw *AlertRuleWorker) Start() { - randomWait := time.Duration(rand.Intn(60000)) * time.Millisecond - time.Sleep(randomWait) - - logger.Infof("eval:%s started after waiting %d ms", arw.Key(), randomWait) arw.Scheduler.Start() } func (arw *AlertRuleWorker) Eval() { + logger.Infof("eval:%s started", arw.Key()) if arw.Processor.PromEvalInterval == 0 { arw.Processor.PromEvalInterval = getPromEvalInterval(arw.Processor.ScheduleEntry.Schedule) }