From 39f7e38444e2254171bb7835ad43e4df9ede3919 Mon Sep 17 00:00:00 2001 From: blotus Date: Tue, 17 May 2022 22:57:15 +0800 Subject: [PATCH] retry to send alert to plugin channel if it fails (#1530) --- pkg/apiserver/controllers/v1/alerts.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/apiserver/controllers/v1/alerts.go b/pkg/apiserver/controllers/v1/alerts.go index 5522380db..9eb9c4b83 100644 --- a/pkg/apiserver/controllers/v1/alerts.go +++ b/pkg/apiserver/controllers/v1/alerts.go @@ -99,11 +99,16 @@ func FormatAlerts(result []*ent.Alert) models.AddAlertsRequest { func (c *Controller) sendAlertToPluginChannel(alert *models.Alert, profileID uint) { if c.PluginChannel != nil { - select { - case c.PluginChannel <- csplugin.ProfileAlert{ProfileID: uint(profileID), Alert: alert}: - log.Debugf("alert sent to Plugin channel") - default: - log.Warningf("Cannot send alert to Plugin channel") + RETRY: + for try := 0; try < 3; try++ { + select { + case c.PluginChannel <- csplugin.ProfileAlert{ProfileID: uint(profileID), Alert: alert}: + log.Debugf("alert sent to Plugin channel") + break RETRY + default: + log.Warningf("Cannot send alert to Plugin channel (try: %d)", try) + time.Sleep(time.Millisecond * 50) + } } } }