Alerting: Panic when rule being evaluated has unexpected key (#99002)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user