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 { type AlertStoreCallback interface {
// PreStore is called before alert is stored into the store. If this method returns error, // 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. // 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. // 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 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. // Put adds the given alert to the set.
func (a *Alerts) Put(alerts ...*types.Alert) error { func (a *Alerts) Put(alerts ...*types.Alert) error {
errs := &types.MultiError{}
for _, alert := range alerts { for _, alert := range alerts {
fp := alert.Fingerprint() fp := alert.Fingerprint()
@ -190,12 +188,11 @@ func (a *Alerts) Put(alerts ...*types.Alert) error {
} }
if err := a.callback.PreStore(alert, existing); err != nil { 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 continue
} }
if err := a.alerts.Set(alert); err != nil { if err := a.alerts.Set(alert); err != nil {
errs.Add(err)
level.Error(a.logger).Log("msg", "error on set alert", "err", err) level.Error(a.logger).Log("msg", "error on set alert", "err", err)
continue continue
} }
@ -212,9 +209,6 @@ func (a *Alerts) Put(alerts ...*types.Alert) error {
a.mtx.Unlock() a.mtx.Unlock()
} }
if errs.Len() > 0 {
return errs
}
return nil return nil
} }

View File

@ -351,9 +351,9 @@ func TestAlertsStoreCallback(t *testing.T) {
} }
err = alerts.Put(&alert1Mod, alert4) err = alerts.Put(&alert1Mod, alert4)
// Verify that we failed to put new alert into store // Verify that we failed to put new alert into store (not reported via error, only checked using Load)
if err == nil || err.Error() != errTooManyAlerts.Error() { if err != nil {
t.Fatalf("expected %v, got %v", errTooManyAlerts, err) t.Fatalf("unexpected error %v", err)
} }
if num := cb.alerts.Load(); num != 3 { 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 returns the alert for a given fingerprint.
Get(model.Fingerprint) (*types.Alert, error) Get(model.Fingerprint) (*types.Alert, error)
// Put adds the given set of alerts to the set. // 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 Put(...*types.Alert) error
} }