Alerting: Update state manager to accept rule store as Warm method argument (#58244)

This commit is contained in:
Yuri Tseretyan
2022-11-04 14:23:08 -04:00
committed by GitHub
parent 8f6cdd4cda
commit dce8879145
5 changed files with 19 additions and 23 deletions

View File

@@ -32,22 +32,19 @@ type Manager struct {
quit chan struct{}
ResendDelay time.Duration
ruleStore RuleReader
instanceStore InstanceStore
imageService image.ImageService
historian Historian
externalURL *url.URL
}
func NewManager(metrics *metrics.State, externalURL *url.URL,
ruleStore RuleReader, instanceStore InstanceStore, imageService image.ImageService, clock clock.Clock, historian Historian) *Manager {
func NewManager(metrics *metrics.State, externalURL *url.URL, instanceStore InstanceStore, imageService image.ImageService, clock clock.Clock, historian Historian) *Manager {
manager := &Manager{
cache: newCache(),
quit: make(chan struct{}),
ResendDelay: ResendDelay, // TODO: make this configurable
log: log.New("ngalert.state.manager"),
metrics: metrics,
ruleStore: ruleStore,
instanceStore: instanceStore,
imageService: imageService,
historian: historian,
@@ -64,12 +61,10 @@ func (st *Manager) Close() {
st.quit <- struct{}{}
}
func (st *Manager) Warm(ctx context.Context) {
func (st *Manager) Warm(ctx context.Context, rulesReader RuleReader) {
if st.instanceStore == nil {
st.log.Info("Skip warming the state because instance store is not configured")
}
if st.ruleStore == nil {
st.log.Info("Skip warming the state because rule store is not configured")
return
}
startTime := time.Now()
st.log.Info("Warming state cache for startup")
@@ -86,7 +81,7 @@ func (st *Manager) Warm(ctx context.Context) {
ruleCmd := ngModels.ListAlertRulesQuery{
OrgID: orgId,
}
if err := st.ruleStore.ListAlertRules(ctx, &ruleCmd); err != nil {
if err := rulesReader.ListAlertRules(ctx, &ruleCmd); err != nil {
st.log.Error("Unable to fetch previous state", "error", err)
}