Don't return error from mem.Alerts.Put.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
This commit is contained in:
Peter Štibraný 2021-05-31 10:03:24 +02:00
parent cc0b08fd7c
commit 15ea220f45
3 changed files with 5 additions and 13 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}