mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-30 15:50:07 +01:00
ef7f52e0e6
* vmalert: remove head of line blocking for sending alerts This change makes sending alerts to notifiers concurrent instead of sequential. This eliminates head of line blocking, where first faulty notifier address prevents the rest of notifiers from receiving notifications. Signed-off-by: hagen1778 <roman@victoriametrics.com> * vmalert: make default timeout for sending alerts 10s Previous value of 1m was too high and was inconsistent with default timeout defined for notifiers via configuration file. Signed-off-by: hagen1778 <roman@victoriametrics.com> * vmalert: linter checks fix Signed-off-by: hagen1778 <roman@victoriametrics.com>
57 lines
911 B
Go
57 lines
911 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// ErrGroup accumulates multiple errors
|
|
// and produces single error message.
|
|
type ErrGroup struct {
|
|
mu sync.Mutex
|
|
errs []error
|
|
}
|
|
|
|
// Add adds a new error to group.
|
|
// Is thread-safe.
|
|
func (eg *ErrGroup) Add(err error) {
|
|
eg.mu.Lock()
|
|
eg.errs = append(eg.errs, err)
|
|
eg.mu.Unlock()
|
|
}
|
|
|
|
// Err checks if group contains at least
|
|
// one error.
|
|
func (eg *ErrGroup) Err() error {
|
|
if eg == nil {
|
|
return nil
|
|
}
|
|
|
|
eg.mu.Lock()
|
|
defer eg.mu.Unlock()
|
|
if len(eg.errs) == 0 {
|
|
return nil
|
|
}
|
|
return eg
|
|
}
|
|
|
|
// Error satisfies Error interface
|
|
func (eg *ErrGroup) Error() string {
|
|
eg.mu.Lock()
|
|
defer eg.mu.Unlock()
|
|
|
|
if len(eg.errs) == 0 {
|
|
return ""
|
|
}
|
|
var b strings.Builder
|
|
fmt.Fprintf(&b, "errors(%d): ", len(eg.errs))
|
|
for i, err := range eg.errs {
|
|
b.WriteString(err.Error())
|
|
if i != len(eg.errs)-1 {
|
|
b.WriteString("\n")
|
|
}
|
|
}
|
|
return b.String()
|
|
}
|