Alerting: Restart rule routines if the type changes (#90867)

* Restart when types change

* Wire up test hooks correctly

* testing
This commit is contained in:
Alexander Weaver
2024-08-14 14:57:47 -05:00
committed by GitHub
parent f158d52ae4
commit 34ab5fe1f3
8 changed files with 160 additions and 14 deletions

View File

@@ -38,6 +38,8 @@ type Rule interface {
Eval(eval *Evaluation) (bool, *Evaluation)
// Update sends a singal to change the definition of the rule.
Update(lastVersion RuleVersionAndPauseStatus) bool
// Type gives the type of the rule.
Type() ngmodels.RuleType
}
type ruleFactoryFunc func(context.Context, *ngmodels.AlertRule) Rule
@@ -76,6 +78,8 @@ func newRuleFactory(
met,
tracer,
recordingWriter,
evalAppliedHook,
stopAppliedHook,
)
}
return newAlertRule(
@@ -172,6 +176,10 @@ func newAlertRule(
}
}
func (a *alertRule) Type() ngmodels.RuleType {
return ngmodels.RuleTypeAlerting
}
// eval signals the rule evaluation routine to perform the evaluation of the rule. Does nothing if the loop is stopped.
// Before sending a message into the channel, it does non-blocking read to make sure that there is no concurrent send operation.
// Returns a tuple where first element is