Alerting: Move rule evaluation status logic out of prometheus API and into scheduler (#89141)
* Add health fields to rules and an aggregator method to the scheduler * Move health, last error, and last eval time in together to minimize state processing * Wire up a readonly scheduler to prom api * Extract to exported function * Use health in api_prometheus and fix up tests * Rename health struct to status * Fix tests one more time * Several new tests * Handle inactive rules * Push state mapping into state manager * rename to StatusReader * Rectify cyclo complexity rebase * Convert existing package local status implementation to models one * fix tests * undo RuleDefs rename
This commit is contained in:
@@ -166,3 +166,29 @@ func (f fakeRuleAccessControlService) AuthorizeDatasourceAccessForRule(ctx conte
|
||||
func (f fakeRuleAccessControlService) AuthorizeDatasourceAccessForRuleGroup(ctx context.Context, user identity.Requester, rules models.RulesGroup) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type statesReader interface {
|
||||
GetStatesForRuleUID(orgID int64, alertRuleUID string) []*state.State
|
||||
}
|
||||
|
||||
type fakeSchedulerReader struct {
|
||||
states statesReader
|
||||
}
|
||||
|
||||
func newFakeSchedulerReader(t *testing.T) *fakeSchedulerReader {
|
||||
return &fakeSchedulerReader{}
|
||||
}
|
||||
|
||||
// setupStates allows the fake scheduler to return data consistent with states defined elsewhere.
|
||||
// This can be combined with fakeAlertInstanceManager, for instance.
|
||||
func (f *fakeSchedulerReader) setupStates(reader statesReader) *fakeSchedulerReader {
|
||||
f.states = reader
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *fakeSchedulerReader) Status(key models.AlertRuleKey) (models.RuleStatus, bool) {
|
||||
if f.states == nil {
|
||||
return models.RuleStatus{}, false
|
||||
}
|
||||
return state.StatesToRuleStatus(f.states.GetStatesForRuleUID(key.OrgID, key.UID)), true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user