Alerting: Decouple schedule package from store (#55858)

* Separate out fake for scheduler tests

* Delete extracted methods from older fake
This commit is contained in:
Alexander Weaver
2022-09-27 13:48:12 -05:00
committed by GitHub
parent 664aa795c1
commit e6f99fc418
3 changed files with 53 additions and 56 deletions
-47
View File
@@ -222,53 +222,6 @@ func (f *FakeRuleStore) GetAlertRulesGroupByRuleUID(_ context.Context, q *models
}
return nil
}
func (f *FakeRuleStore) GetAlertRulesKeysForScheduling(_ context.Context) ([]models.AlertRuleKeyWithVersion, error) {
f.mtx.Lock()
defer f.mtx.Unlock()
f.RecordedOps = append(f.RecordedOps, GenericRecordedQuery{
Name: "GetAlertRulesKeysForScheduling",
Params: []interface{}{},
})
result := make([]models.AlertRuleKeyWithVersion, 0, len(f.Rules))
for _, rules := range f.Rules {
for _, rule := range rules {
result = append(result, models.AlertRuleKeyWithVersion{
Version: rule.Version,
AlertRuleKey: rule.GetKey(),
})
}
}
return result, nil
}
// For now, we're not implementing namespace filtering.
func (f *FakeRuleStore) GetAlertRulesForScheduling(_ context.Context, q *models.GetAlertRulesForSchedulingQuery) error {
f.mtx.Lock()
defer f.mtx.Unlock()
f.RecordedOps = append(f.RecordedOps, *q)
if err := f.Hook(*q); err != nil {
return err
}
q.ResultFoldersTitles = make(map[string]string)
for _, rules := range f.Rules {
for _, rule := range rules {
q.ResultRules = append(q.ResultRules, rule)
if !q.PopulateFolders {
continue
}
if _, ok := q.ResultFoldersTitles[rule.NamespaceUID]; !ok {
if folders, ok := f.Folders[rule.OrgID]; ok {
for _, folder := range folders {
if folder.Uid == rule.NamespaceUID {
q.ResultFoldersTitles[rule.NamespaceUID] = folder.Title
}
}
}
}
}
}
return nil
}
func (f *FakeRuleStore) ListAlertRules(_ context.Context, q *models.ListAlertRulesQuery) error {
f.mtx.Lock()