Notifier: pass parameters to goroutine explicitly
Avoids possible false sharing between loops. Plausibly there is no problem in the current code, but it's easy enough to write it more safely. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
57c799132b
commit
8c4e4b72a8
|
@ -539,9 +539,9 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
|
||||||
ctx, cancel := context.WithTimeout(n.ctx, time.Duration(ams.cfg.Timeout))
|
ctx, cancel := context.WithTimeout(n.ctx, time.Duration(ams.cfg.Timeout))
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
go func(client *http.Client, url string) {
|
go func(ctx context.Context, client *http.Client, url string, payload []byte, count int) {
|
||||||
if err := n.sendOne(ctx, client, url, payload); err != nil {
|
if err := n.sendOne(ctx, client, url, payload); err != nil {
|
||||||
level.Error(n.logger).Log("alertmanager", url, "count", len(amAlerts), "msg", "Error sending alert", "err", err)
|
level.Error(n.logger).Log("alertmanager", url, "count", count, "msg", "Error sending alert", "err", err)
|
||||||
n.metrics.errors.WithLabelValues(url).Inc()
|
n.metrics.errors.WithLabelValues(url).Inc()
|
||||||
} else {
|
} else {
|
||||||
numSuccess.Inc()
|
numSuccess.Inc()
|
||||||
|
@ -550,7 +550,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
|
||||||
n.metrics.sent.WithLabelValues(url).Add(float64(len(amAlerts)))
|
n.metrics.sent.WithLabelValues(url).Add(float64(len(amAlerts)))
|
||||||
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(ams.client, am.url().String())
|
}(ctx, ams.client, am.url().String(), payload, len(amAlerts))
|
||||||
}
|
}
|
||||||
|
|
||||||
ams.mtx.RUnlock()
|
ams.mtx.RUnlock()
|
||||||
|
|
Loading…
Reference in New Issue