bugfix: for range goroutine

This commit is contained in:
Ulric Qin 2021-08-15 10:08:08 +08:00
parent a7cf8f9ec9
commit 60a964ae55
1 changed files with 8 additions and 8 deletions

View File

@ -41,9 +41,9 @@ type RuleEval struct {
ctx context.Context ctx context.Context
} }
func (re *RuleEval) start() { func (re RuleEval) start() {
go func(re RuleEval) {
logger.Debugf("[prome_pull_alert_start][RuleEval: %+v]", re) logger.Debugf("[prome_pull_alert_start][RuleEval: %+v]", re)
go func(re *RuleEval) {
if re.R.PullExpr.EvaluationInterval <= 0 { if re.R.PullExpr.EvaluationInterval <= 0 {
re.R.PullExpr.EvaluationInterval = DEFAULT_PULL_ALERT_INTERVAL re.R.PullExpr.EvaluationInterval = DEFAULT_PULL_ALERT_INTERVAL
} }
@ -72,7 +72,7 @@ func (re *RuleEval) start() {
}(re) }(re)
} }
func (r *RuleEval) stop() { func (r RuleEval) stop() {
logger.Debugf("[prome_pull_alert_stop][RuleEval: %+v]", r) logger.Debugf("[prome_pull_alert_stop][RuleEval: %+v]", r)
close(r.quiteChan) close(r.quiteChan)
} }
@ -103,17 +103,17 @@ func (rm *RuleManager) SyncRules(ctx context.Context, rules []models.AlertRule)
} }
// 停止旧的 // 停止旧的
for hash, t := range rm.activeRules { for hash := range rm.activeRules {
if _, loaded := thisAllRules[hash]; !loaded { if _, loaded := thisAllRules[hash]; !loaded {
t.stop() rm.activeRules[hash].stop()
delete(rm.activeRules, hash) delete(rm.activeRules, hash)
} }
} }
rm.targetMtx.Unlock() rm.targetMtx.Unlock()
// 开启新的 // 开启新的
for _, t := range thisNewRules { for hash := range thisNewRules {
t.start() thisNewRules[hash].start()
} }
} }