mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-25 15:42:18 +00:00
delete resolved alerts during cleanup
This commit is contained in:
parent
dfdf8f452a
commit
6406631e81
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user