From d972d331e267568a47ca27da3cc84f0ca0cc115f Mon Sep 17 00:00:00 2001 From: naiba Date: Sun, 2 Mar 2025 16:57:24 +0800 Subject: [PATCH] fix: range data point --- model/alertrule.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/model/alertrule.go b/model/alertrule.go index 2bc7a65..fe73219 100644 --- a/model/alertrule.go +++ b/model/alertrule.go @@ -79,7 +79,7 @@ func (r *AlertRule) Check(points [][]bool) (int, bool) { durations := make([]int, len(r.Rules)) for ruleIndex, rule := range r.Rules { - fail, duration := 0, int(rule.Duration) + duration := int(rule.Duration) if rule.IsTransferDurationRule() { // 循环区间流量报警 if durations[ruleIndex] < 1 { @@ -97,9 +97,10 @@ func (r *AlertRule) Check(points [][]bool) (int, bool) { if hasPassedRule = boundCheck(len(points), duration, hasPassedRule); hasPassedRule { continue } - for timeTick := len(points); timeTick > len(points)-duration; timeTick-- { + var fail int + for _, point := range slices.Backward(points[len(points)-duration:]) { fail++ - if points[timeTick][ruleIndex] { + if point[ruleIndex] { hasPassedRule = true break }