delete resolved alerts during cleanup

This commit is contained in:
Fabian Reinartz 2015-07-04 15:50:42 +02:00
parent dfdf8f452a
commit 6406631e81
2 changed files with 21 additions and 1 deletions

View File

@ -69,6 +69,16 @@ func (d *Dispatcher) Run() {
}
}
now := time.Now()
for _, a := range d.state.Alert().GetAll() {
if a.Resolved() && a.ResolvedAt.Before(now.Sub(ResolveTimeout)) {
if err := d.state.Alert().Del(a.Fingerprint()); err != nil {
log.Errorf("error cleaning resolved alerts: %s", err)
}
}
}
case alert := <-updates:
conf, err := d.state.Config().Get()

View File

@ -20,6 +20,7 @@ type State interface {
type AlertState interface {
Add(...*Alert) error
Del(model.Fingerprint) error
Get(model.Fingerprint) (*Alert, error)
GetAll() ([]*Alert, error)
@ -31,7 +32,8 @@ type ConfigState interface {
Get() (*Config, error)
}
type NotifyState interface{}
type NotifyState interface {
}
type SilenceState interface {
// Silences returns a list of all silences.
@ -169,6 +171,14 @@ func (s *memAlerts) Get(fp model.Fingerprint) (*Alert, error) {
return nil, fmt.Errorf("alert with fingerprint %s does not exist", fp)
}
func (s *memAlerts) Del(fp model.Fingerprint) error {
s.mtx.Lock()
defer s.mtx.Unlock()
delete(s.alerts, fp)
return nil
}
func (s *memAlerts) Iter() <-chan *Alert {
ch := make(chan *Alert, 100)