mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Decouple rule routine from scheduler (#84018)
* create rule factory for more complicated dep injection into rules * Rules get direct access to metrics, logs, traces utilities, use factory in tests * Use clock internal to rule * Use sender, statemanager, evalfactory directly * evalApplied and stopApplied * use schedulableAlertRules behind interface * loaded metrics reader * 3 relevant config options * Drop unused scheduler parameter * Rename ruleRoutine to run * Update READMED * Handle long parameter lists * remove dead branch
This commit is contained in:
@@ -235,9 +235,24 @@ func (sch *schedule) processTick(ctx context.Context, dispatcherGroup *errgroup.
|
||||
readyToRun := make([]readyToRunItem, 0)
|
||||
updatedRules := make([]ngmodels.AlertRuleKeyWithVersion, 0, len(updated)) // this is needed for tests only
|
||||
missingFolder := make(map[string][]string)
|
||||
ruleFactory := newRuleFactory(
|
||||
sch.appURL,
|
||||
sch.disableGrafanaFolder,
|
||||
sch.maxAttempts,
|
||||
sch.alertsSender,
|
||||
sch.stateManager,
|
||||
sch.evaluatorFactory,
|
||||
&sch.schedulableAlertRules,
|
||||
sch.clock,
|
||||
sch.metrics,
|
||||
sch.log,
|
||||
sch.tracer,
|
||||
sch.evalAppliedFunc,
|
||||
sch.stopAppliedFunc,
|
||||
)
|
||||
for _, item := range alertRules {
|
||||
key := item.GetKey()
|
||||
ruleInfo, newRoutine := sch.registry.getOrCreateInfo(ctx, key)
|
||||
ruleInfo, newRoutine := sch.registry.getOrCreateInfo(ctx, key, ruleFactory)
|
||||
|
||||
// enforce minimum evaluation interval
|
||||
if item.IntervalSeconds < int64(sch.minRuleInterval.Seconds()) {
|
||||
@@ -249,7 +264,7 @@ func (sch *schedule) processTick(ctx context.Context, dispatcherGroup *errgroup.
|
||||
|
||||
if newRoutine && !invalidInterval {
|
||||
dispatcherGroup.Go(func() error {
|
||||
return ruleInfo.ruleRoutine(key, sch)
|
||||
return ruleInfo.run(key)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user