Alerting: Panic when rule being evaluated has unexpected key (#99002)

This commit is contained in:
Santiago
2025-01-15 14:59:50 +02:00
committed by GitHub
parent 5aeaccadff
commit ea6cb8f139
2 changed files with 5 additions and 3 deletions
+1 -2
View File
@@ -196,8 +196,7 @@ func (a *alertRule) Status() ngmodels.RuleStatus {
func (a *alertRule) Eval(eval *Evaluation) (bool, *Evaluation) {
if a.key.AlertRuleKey != eval.rule.GetKey() {
// Make sure that rule has the same key. This should not happen
a.logger.Error("Invalid rule sent for evaluating. Skipping", "ruleKeyToEvaluate", eval.rule.GetKey().String())
return false, eval
panic(fmt.Sprintf("Invalid rule sent for evaluating. Expected rule key %s, got %s", a.key.AlertRuleKey, eval.rule.GetKey()))
}
// read the channel in unblocking manner to make sure that there is no concurrent send operation.
var droppedMsg *Evaluation
@@ -220,6 +220,9 @@ func TestAlertRule(t *testing.T) {
}
}()
rule := gen.GenerateRef()
rule.UID = r.key.UID
rule.OrgID = r.key.OrgID
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
@@ -234,7 +237,7 @@ func TestAlertRule(t *testing.T) {
case 2:
r.Eval(&Evaluation{
scheduledAt: time.Now(),
rule: gen.GenerateRef(),
rule: rule,
folderTitle: util.GenerateShortUID(),
})
case 3: