Open linear[bot] opened 1 week ago
To implement cooldown logic for alert evaluation, modify the WatchLogAlerts
function in backend/jobs/log-alerts/log-alerts.go
as follows:
lastAlertTime
map to track the last alert time for each alert:lastAlertTime := make(map[int64]time.Time)
processLogAlert
function to include cooldown logic:func processLogAlert(ctx context.Context, DB *gorm.DB, MailClient *sendgrid.Client, alert *model.LogAlert, rh *resthooks.Resthook, redis *redis.Client, ccClient *clickhouse.Client, lambdaClient *lambda.Client, lastAlertTime map[int64]time.Time) error {
cooldownPeriod := time.Minute * 5 // Set cooldown period
if lastTime, exists := lastAlertTime[alert.ID]; exists && time.Since(lastTime) < cooldownPeriod {
log.WithContext(ctx).Infof("Alert %d is in cooldown period", alert.ID)
return nil
}
// Existing logic...
if alertCondition {
lastAlertTime[alert.ID] = time.Now()
// Existing alerting logic...
}
return nil
}
lastAlertTime
to processLogAlert
calls in WatchLogAlerts
:err := processLogAlert(ctx, DB, MailClient, alert, rh, redis, ccClient, lambdaClient, lastAlertTime)
/backend/jobs/log-alerts/log-alerts.go /backend/jobs/log-alerts
HIG-4777 Cooldown logic for alert evaluation