88
99 prometheusModel "github.com/prometheus/common/model"
1010
11- "github.com/grafana/grafana/pkg/bus"
12- "github.com/grafana/grafana/pkg/events"
1311 "github.com/grafana/grafana/pkg/infra/log"
1412 "github.com/grafana/grafana/pkg/models"
1513 "github.com/grafana/grafana/pkg/services/alerting"
@@ -27,23 +25,19 @@ import (
2725
2826// ScheduleService is an interface for a service that schedules the evaluation
2927// of alert rules.
30- //go:generate mockery --name ScheduleService --structname FakeScheduleService --inpackage --filename schedule_mock.go
28+ //go:generate mockery --name ScheduleService --structname FakeScheduleService --inpackage --filename schedule_mock.go --with-expecter
3129type ScheduleService interface {
3230 // Run the scheduler until the context is canceled or the scheduler returns
3331 // an error. The scheduler is terminated when this function returns.
3432 Run (context.Context ) error
3533 // UpdateAlertRule notifies scheduler that a rule has been changed
3634 UpdateAlertRule (key ngmodels.AlertRuleKey , lastVersion int64 )
37- // UpdateAlertRulesByNamespaceUID notifies scheduler that all rules in a namespace should be updated.
38- UpdateAlertRulesByNamespaceUID (ctx context.Context , orgID int64 , uid string ) error
3935 // DeleteAlertRule notifies scheduler that a rule has been changed
4036 DeleteAlertRule (key ngmodels.AlertRuleKey )
4137 // the following are used by tests only used for tests
4238 evalApplied (ngmodels.AlertRuleKey , time.Time )
4339 stopApplied (ngmodels.AlertRuleKey )
4440 overrideCfg (cfg SchedulerCfg )
45-
46- folderUpdateHandler (ctx context.Context , evt * events.FolderUpdated ) error
4741}
4842
4943//go:generate mockery --name AlertsSender --structname AlertsSenderMock --inpackage --filename alerts_sender_mock.go --with-expecter
@@ -97,9 +91,6 @@ type schedule struct {
9791 // current tick depends on its evaluation interval and when it was
9892 // last evaluated.
9993 schedulableAlertRules alertRulesRegistry
100-
101- // bus is used to hook into events that should cause rule updates.
102- bus bus.Bus
10394}
10495
10596// SchedulerCfg is the scheduler configuration.
@@ -117,7 +108,7 @@ type SchedulerCfg struct {
117108}
118109
119110// NewScheduler returns a new schedule.
120- func NewScheduler (cfg SchedulerCfg , appURL * url.URL , stateManager * state.Manager , bus bus. Bus ) * schedule {
111+ func NewScheduler (cfg SchedulerCfg , appURL * url.URL , stateManager * state.Manager ) * schedule {
121112 ticker := alerting .NewTicker (cfg .C , cfg .Cfg .BaseInterval , cfg .Metrics .Ticker )
122113
123114 sch := schedule {
@@ -138,12 +129,9 @@ func NewScheduler(cfg SchedulerCfg, appURL *url.URL, stateManager *state.Manager
138129 stateManager : stateManager ,
139130 minRuleInterval : cfg .Cfg .MinInterval ,
140131 schedulableAlertRules : alertRulesRegistry {rules : make (map [ngmodels.AlertRuleKey ]* ngmodels.AlertRule )},
141- bus : bus ,
142132 alertsSender : cfg .AlertSender ,
143133 }
144134
145- bus .AddEventListener (sch .folderUpdateHandler )
146-
147135 return & sch
148136}
149137
@@ -165,26 +153,6 @@ func (sch *schedule) UpdateAlertRule(key ngmodels.AlertRuleKey, lastVersion int6
165153 ruleInfo .update (ruleVersion (lastVersion ))
166154}
167155
168- // UpdateAlertRulesByNamespaceUID looks for the active rule evaluation for every rule in the given namespace and commands it to update the rule.
169- func (sch * schedule ) UpdateAlertRulesByNamespaceUID (ctx context.Context , orgID int64 , uid string ) error {
170- q := ngmodels.ListAlertRulesQuery {
171- OrgID : orgID ,
172- NamespaceUIDs : []string {uid },
173- }
174- if err := sch .ruleStore .ListAlertRules (ctx , & q ); err != nil {
175- return err
176- }
177-
178- for _ , r := range q .Result {
179- sch .UpdateAlertRule (ngmodels.AlertRuleKey {
180- OrgID : orgID ,
181- UID : r .UID ,
182- }, r .Version )
183- }
184-
185- return nil
186- }
187-
188156// DeleteAlertRule stops evaluation of the rule, deletes it from active rules, and cleans up state cache.
189157func (sch * schedule ) DeleteAlertRule (key ngmodels.AlertRuleKey ) {
190158 // It can happen that the scheduler has deleted the alert rule before the
@@ -465,14 +433,6 @@ func (sch *schedule) saveAlertStates(ctx context.Context, states []*state.State)
465433 }
466434}
467435
468- // folderUpdateHandler listens for folder update events and updates all rules in the given folder.
469- func (sch * schedule ) folderUpdateHandler (ctx context.Context , evt * events.FolderUpdated ) error {
470- if sch .disableGrafanaFolder {
471- return nil
472- }
473- return sch .UpdateAlertRulesByNamespaceUID (ctx , evt .OrgID , evt .UID )
474- }
475-
476436// overrideCfg is only used on tests.
477437func (sch * schedule ) overrideCfg (cfg SchedulerCfg ) {
478438 sch .clock = cfg .C
0 commit comments