Skip to content

Commit

Permalink
refactor: change eval sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo committed Jan 8, 2025
1 parent 2ebd64d commit cb56037
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 1 addition & 0 deletions alert/eval/alert_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 1 addition & 5 deletions alert/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit cb56037

Please sign in to comment.