8
8
9
9
prometheusModel "github.com/prometheus/common/model"
10
10
11
- "github.com/grafana/grafana/pkg/bus"
12
- "github.com/grafana/grafana/pkg/events"
13
11
"github.com/grafana/grafana/pkg/infra/log"
14
12
"github.com/grafana/grafana/pkg/models"
15
13
"github.com/grafana/grafana/pkg/services/alerting"
@@ -27,23 +25,19 @@ import (
27
25
28
26
// ScheduleService is an interface for a service that schedules the evaluation
29
27
// 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
31
29
type ScheduleService interface {
32
30
// Run the scheduler until the context is canceled or the scheduler returns
33
31
// an error. The scheduler is terminated when this function returns.
34
32
Run (context.Context ) error
35
33
// UpdateAlertRule notifies scheduler that a rule has been changed
36
34
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
39
35
// DeleteAlertRule notifies scheduler that a rule has been changed
40
36
DeleteAlertRule (key ngmodels.AlertRuleKey )
41
37
// the following are used by tests only used for tests
42
38
evalApplied (ngmodels.AlertRuleKey , time.Time )
43
39
stopApplied (ngmodels.AlertRuleKey )
44
40
overrideCfg (cfg SchedulerCfg )
45
-
46
- folderUpdateHandler (ctx context.Context , evt * events.FolderUpdated ) error
47
41
}
48
42
49
43
//go:generate mockery --name AlertsSender --structname AlertsSenderMock --inpackage --filename alerts_sender_mock.go --with-expecter
@@ -97,9 +91,6 @@ type schedule struct {
97
91
// current tick depends on its evaluation interval and when it was
98
92
// last evaluated.
99
93
schedulableAlertRules alertRulesRegistry
100
-
101
- // bus is used to hook into events that should cause rule updates.
102
- bus bus.Bus
103
94
}
104
95
105
96
// SchedulerCfg is the scheduler configuration.
@@ -117,7 +108,7 @@ type SchedulerCfg struct {
117
108
}
118
109
119
110
// 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 {
121
112
ticker := alerting .NewTicker (cfg .C , cfg .Cfg .BaseInterval , cfg .Metrics .Ticker )
122
113
123
114
sch := schedule {
@@ -138,12 +129,9 @@ func NewScheduler(cfg SchedulerCfg, appURL *url.URL, stateManager *state.Manager
138
129
stateManager : stateManager ,
139
130
minRuleInterval : cfg .Cfg .MinInterval ,
140
131
schedulableAlertRules : alertRulesRegistry {rules : make (map [ngmodels.AlertRuleKey ]* ngmodels.AlertRule )},
141
- bus : bus ,
142
132
alertsSender : cfg .AlertSender ,
143
133
}
144
134
145
- bus .AddEventListener (sch .folderUpdateHandler )
146
-
147
135
return & sch
148
136
}
149
137
@@ -165,26 +153,6 @@ func (sch *schedule) UpdateAlertRule(key ngmodels.AlertRuleKey, lastVersion int6
165
153
ruleInfo .update (ruleVersion (lastVersion ))
166
154
}
167
155
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
-
188
156
// DeleteAlertRule stops evaluation of the rule, deletes it from active rules, and cleans up state cache.
189
157
func (sch * schedule ) DeleteAlertRule (key ngmodels.AlertRuleKey ) {
190
158
// 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)
465
433
}
466
434
}
467
435
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
-
476
436
// overrideCfg is only used on tests.
477
437
func (sch * schedule ) overrideCfg (cfg SchedulerCfg ) {
478
438
sch .clock = cfg .C
0 commit comments