diff --git a/rules/group.go b/rules/group.go index a00801a01c..d31f6da75b 100644 --- a/rules/group.go +++ b/rules/group.go @@ -73,9 +73,9 @@ type Group struct { // Rule group evaluation iteration function, // defaults to DefaultEvalIterationFunc. evalIterationFunc GroupEvalIterationFunc + alertStore AlertStore - appOpts *storage.AppendOptions - alertStore AlertStore + appOpts *storage.AppendOptions } // GroupEvalIterationFunc is used to implement and extend rule group @@ -146,8 +146,8 @@ func NewGroup(o GroupOptions) *Group { logger: opts.Logger.With("file", o.File, "group", o.Name), metrics: metrics, evalIterationFunc: evalIterationFunc, - appOpts: &storage.AppendOptions{DiscardOutOfOrder: true}, alertStore: o.AlertStore, + appOpts: &storage.AppendOptions{DiscardOutOfOrder: true}, } } diff --git a/rules/store.go b/rules/store.go index e18401a48d..631f5e2799 100644 --- a/rules/store.go +++ b/rules/store.go @@ -115,12 +115,12 @@ func (s *FileStore) SetAlerts(key uint64, groupKey string, alerts []*Alert) erro s.stateMtx.Lock() defer s.stateMtx.Unlock() - // Update in memory - if alerts != nil { - s.alertsByRule[key] = alerts - } else { + if alerts == nil { return nil } + // Update in memory + s.alertsByRule[key] = alerts + // flush in memory state to file storage file, err := os.Create(s.path) if err != nil {