From 843c4778990f559e9c3b82e89e5b86a57c68ea75 Mon Sep 17 00:00:00 2001 From: Alexander Weaver Date: Wed, 7 Feb 2024 09:31:22 -0600 Subject: [PATCH] Alerting: Add exported API to scheduler to access currently loaded rules (#82031) * Add exported API to fetch rule definitions from scheduler * Add comment --- pkg/services/ngalert/schedule/schedule.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/services/ngalert/schedule/schedule.go b/pkg/services/ngalert/schedule/schedule.go index c4e880ff616..08dcd88e08f 100644 --- a/pkg/services/ngalert/schedule/schedule.go +++ b/pkg/services/ngalert/schedule/schedule.go @@ -155,6 +155,13 @@ func (sch *schedule) Run(ctx context.Context) error { return nil } +// Rules fetches the entire set of rules considered for evaluation by the scheduler on the next tick. +// Such rules are not guaranteed to have been evaluated by the scheduler. +// Rules returns all supplementary metadata for the rules that is stored by the scheduler - namely, the set of folder titles. +func (sch *schedule) Rules() ([]*ngmodels.AlertRule, map[ngmodels.FolderKey]string) { + return sch.schedulableAlertRules.all() +} + // deleteAlertRule stops evaluation of the rule, deletes it from active rules, and cleans up state cache. func (sch *schedule) deleteAlertRule(keys ...ngmodels.AlertRuleKey) { for _, key := range keys {