Fix race condition causing 1st alert to not be immediately delivered when group_wait is 0s

Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
Marco Pracucci 2021-04-30 10:11:10 +02:00
parent 1f3796c5cc
commit 72ef6e04e1
No known key found for this signature in database
GPG Key ID: 74C1BD403D2DF9B5
1 changed files with 26 additions and 20 deletions

View File

@ -290,13 +290,22 @@ func (d *Dispatcher) processAlert(alert *types.Alert, route *Route) {
d.aggrGroups[route] = group
}
// If the group does not exist, create it.
ag, ok := group[fp]
if !ok {
if ok {
ag.insert(alert)
return
}
// If the group does not exist, create it.
ag = newAggrGroup(d.ctx, groupLabels, route, d.timeout, d.logger)
group[fp] = ag
d.metrics.aggrGroups.Inc()
// Insert the 1st alert in the group before starting the group's run()
// function, to make sure that when the run() will be executed the 1st
// alert is already there.
ag.insert(alert)
go ag.run(func(ctx context.Context, alerts ...*types.Alert) bool {
_, _, err := d.stage.Exec(ctx, d.logger, alerts...)
if err != nil {
@ -311,9 +320,6 @@ func (d *Dispatcher) processAlert(alert *types.Alert, route *Route) {
}
return err == nil
})
}
ag.insert(alert)
}
func getGroupLabels(alert *types.Alert, route *Route) model.LabelSet {