func (n *Manager) sendAll(alerts ...*Alert) bool {
	begin := time.Now()

	b, err := json.Marshal(alerts)
	if err != nil {
		level.Error(n.logger).Log("msg", "Encoding alerts failed", "err", err)
		return false
	}

	n.mtx.RLock()
	amSets := n.alertmanagers
	n.mtx.RUnlock()

	var (
		wg         sync.WaitGroup
		numSuccess uint64
	)
	for _, ams := range amSets {
		ams.mtx.RLock()

		for _, am := range ams.ams {
			wg.Add(1)

			ctx, cancel := context.WithTimeout(n.ctx, time.Duration(ams.cfg.Timeout))
			defer cancel()

			go func(ams *alertmanagerSet, am alertmanager) {
				u := am.url().String()

				if err := n.sendOne(ctx, ams.client, u, b); err != nil {
					level.Error(n.logger).Log("alertmanager", u, "count", len(alerts), "msg", "Error sending alert", "err", err)
					n.metrics.errors.WithLabelValues(u).Inc()
				} else {
					atomic.AddUint64(&numSuccess, 1)
				}
				n.metrics.latency.WithLabelValues(u).Observe(time.Since(begin).Seconds())
				n.metrics.sent.WithLabelValues(u).Add(float64(len(alerts)))

				wg.Done()
			}(ams, am)
		}
		ams.mtx.RUnlock()
	}
	wg.Wait()

	return numSuccess > 0
}
func (n *Manager) sendAll(alerts ...*Alert) bool {
	begin := time.Now()

	b, err := json.Marshal(alerts)
	if err != nil {
		level.Error(n.logger).Log("msg", "Encoding alerts failed", "err", err)
		return false
	}

	n.mtx.RLock()
	amSets := n.alertmanagers
	n.mtx.RUnlock()

	var (
		wg         sync.WaitGroup
		numSuccess uint64
	)
	for _, ams := range amSets {
		ams.mtx.RLock()

		for _, am := range ams.ams {
			wg.Add(1)

			ctx, cancel := context.WithTimeout(n.ctx, time.Duration(ams.cfg.Timeout))
			defer cancel()

			go func(ams *alertmanagerSet, am alertmanager) {
				u := am.url().String()

				if err := n.sendOne(ctx, ams.client, u, b); err != nil {
					level.Error(n.logger).Log("alertmanager", u, "count", len(alerts), "msg", "Error sending alert", "err", err)
					n.metrics.errors.WithLabelValues(u).Inc()
				} else {
					atomic.AddUint64(&numSuccess, 1)
				}
				n.metrics.latency.WithLabelValues(u).Observe(time.Since(begin).Seconds())
				n.metrics.sent.WithLabelValues(u).Add(float64(len(alerts)))

				wg.Done()
			}(ams, am)
		}
		ams.mtx.RUnlock()
	}
	wg.Wait()

	return numSuccess > 0
}
func ( n * Manager ) sendAll ( alerts ... * Alert ) bool { begin := time . Now ( ) b , err := json . Marshal ( alerts ) if err != nil { level . Error ( n . logger ) . Log ( " " , " " , " " , err ) return false } n . mtx . RLock ( ) amSets := n . alertmanagers n . mtx . RUnlock ( ) var ( wg sync . WaitGroup numSuccess uint64 ) for _ , ams := range amSets { ams . mtx . RLock ( ) for _ , am := range ams . ams { wg . Add ( 1 ) ctx , cancel := context . WithTimeout ( n . ctx , time . Duration ( ams . cfg . Timeout ) ) defer cancel ( ) go func ( ams * alertmanagerSet , am alertmanager ) { u := am . url ( ) . String ( ) if err := n . sendOne ( ctx , ams . client , u , b ) ; err != nil { level . Error ( n . logger ) . Log ( " " , u , " " , len ( alerts ) , " " , " " , " " , err ) n . metrics . errors . WithLabelValues ( u ) . Inc ( ) } else { atomic . AddUint64 ( & numSuccess , 1 ) } n . metrics . latency . WithLabelValues ( u ) . Observe ( time . Since ( begin ) . Seconds ( ) ) n . metrics . sent . WithLabelValues ( u ) . Add ( float64 ( len ( alerts ) ) ) wg . Done ( ) } ( ams , am ) } ams . mtx . RUnlock ( ) } wg . Wait ( ) return numSuccess > 0 }
// sendAll sends the alerts to all configured Alertmanagers concurrently.
// It returns true if the alerts could be sent successfully to at least one Alertmanager.
sendAll sends the alerts to all configured Alertmanagers concurrently . It returns true if the alerts could be sent successfully to at least one Alertmanager .