Check expiry in alert

This commit is contained in:
Kishan Mohanbhai Sagathiya 2019-12-13 12:25:28 +05:30
parent d21860eee7
commit 618ebd23f4
2 changed files with 6 additions and 1 deletions

View File

@ -399,7 +399,11 @@ func (c *Cluster) Alerts() map[string]api.Alert {
c.alertsMux.Lock()
defer c.alertsMux.Unlock()
for i, alert := range c.alerts {
alerts[i] = alert
if time.Now().Before(time.Unix(0, alert.Expiry)) {
alerts[i] = alert
} else {
delete(c.alerts, i)
}
}
return alerts

View File

@ -132,6 +132,7 @@ func (mc *Checker) alert(pid peer.ID, metricName string) error {
alrt := &api.Alert{
Peer: pid,
MetricName: metricName,
Expiry: time.Now().Add(30 * time.Second).UnixNano(),
}
select {
case mc.alertCh <- alrt: