From 1eecb324d06eefe76262dbd71445febbc0a895a3 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Sun, 15 Aug 2021 10:28:37 +0800 Subject: [PATCH] code refactor: exec pull_prom early --- judge/prome_pull.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/judge/prome_pull.go b/judge/prome_pull.go index 5232e0b8..9c57444d 100644 --- a/judge/prome_pull.go +++ b/judge/prome_pull.go @@ -47,13 +47,16 @@ func (re RuleEval) start() { if re.R.PullExpr.EvaluationInterval <= 0 { re.R.PullExpr.EvaluationInterval = DEFAULT_PULL_ALERT_INTERVAL } + + sleepDuration := time.Duration(re.R.PullExpr.EvaluationInterval) * time.Second + for { select { case <-re.ctx.Done(): return case <-re.quiteChan: return - case <-time.After(time.Duration(re.R.PullExpr.EvaluationInterval) * time.Second): + default: } // 获取backend的prometheus DataSource @@ -67,8 +70,9 @@ func (re RuleEval) start() { promVector := pb.QueryVector(re.R.PullExpr.PromQl) handlePromqlVector(promVector, re.R) - } + time.Sleep(sleepDuration) + } }(re) }