Skip to content

Commit

Permalink
🚧 Fix goroutine panic of the rule eval
Browse files Browse the repository at this point in the history
  • Loading branch information
Cairry committed Nov 28, 2024
1 parent 612c2bb commit 557c764
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion alert/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ func (t *AlertRule) Stop(ruleId string) {

func (t *AlertRule) Eval(ctx context.Context, rule models.AlertRule) {
timer := time.NewTicker(time.Second * time.Duration(rule.EvalInterval))
defer timer.Stop()
defer func() {
timer.Stop()
if r := recover(); r != nil {
logc.Error(t.ctx.Ctx, fmt.Sprintf("Recovered from rule eval goroutine panic: %s", r))
}
}()

for {
select {
case <-timer.C:
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package provider

import (
"fmt"
"strconv"
"watchAlert/pkg/tools"
)
Expand Down Expand Up @@ -31,7 +32,7 @@ func (m Metrics) GetFingerprint() string {
for labelName, labelValue := range m.Metric {
sum := tools.HashNew()
sum = tools.HashAdd(sum, labelName)
sum = tools.HashAdd(sum, labelValue.(string))
sum = tools.HashAdd(sum, fmt.Sprintf("%v", labelValue))
result ^= sum
}

Expand Down

0 comments on commit 557c764

Please sign in to comment.