mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-17 20:05:17 +00:00
Don't return error from mem.Alerts.Put.
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
This commit is contained in:
parent
cc0b08fd7c
commit
15ea220f45
@ -45,7 +45,7 @@ type Alerts struct {
|
||||
|
||||
type AlertStoreCallback interface {
|
||||
// PreStore is called before alert is stored into the store. If this method returns error,
|
||||
// this error is passed back to caller of Alerts.Put method.
|
||||
// alert is not stored.
|
||||
// Existing flag indicates whether alert has existed before (and is only updated) or not.
|
||||
// If alert has existed before, then alert passed to PreStore is result of merging existing alert with new alert.
|
||||
PreStore(alert *types.Alert, existing bool) error
|
||||
@ -170,8 +170,6 @@ func (a *Alerts) Get(fp model.Fingerprint) (*types.Alert, error) {
|
||||
|
||||
// Put adds the given alert to the set.
|
||||
func (a *Alerts) Put(alerts ...*types.Alert) error {
|
||||
errs := &types.MultiError{}
|
||||
|
||||
for _, alert := range alerts {
|
||||
fp := alert.Fingerprint()
|
||||
|
||||
@ -190,12 +188,11 @@ func (a *Alerts) Put(alerts ...*types.Alert) error {
|
||||
}
|
||||
|
||||
if err := a.callback.PreStore(alert, existing); err != nil {
|
||||
errs.Add(err)
|
||||
level.Error(a.logger).Log("msg", "pre-store callback returned error on set alert", "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := a.alerts.Set(alert); err != nil {
|
||||
errs.Add(err)
|
||||
level.Error(a.logger).Log("msg", "error on set alert", "err", err)
|
||||
continue
|
||||
}
|
||||
@ -212,9 +209,6 @@ func (a *Alerts) Put(alerts ...*types.Alert) error {
|
||||
a.mtx.Unlock()
|
||||
}
|
||||
|
||||
if errs.Len() > 0 {
|
||||
return errs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -351,9 +351,9 @@ func TestAlertsStoreCallback(t *testing.T) {
|
||||
}
|
||||
|
||||
err = alerts.Put(&alert1Mod, alert4)
|
||||
// Verify that we failed to put new alert into store
|
||||
if err == nil || err.Error() != errTooManyAlerts.Error() {
|
||||
t.Fatalf("expected %v, got %v", errTooManyAlerts, err)
|
||||
// Verify that we failed to put new alert into store (not reported via error, only checked using Load)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
if num := cb.alerts.Load(); num != 3 {
|
||||
|
@ -84,7 +84,5 @@ type Alerts interface {
|
||||
// Get returns the alert for a given fingerprint.
|
||||
Get(model.Fingerprint) (*types.Alert, error)
|
||||
// Put adds the given set of alerts to the set.
|
||||
// This operation is not atomic -- when error is returned, some alerts may have
|
||||
// be stored already.
|
||||
Put(...*types.Alert) error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user