Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return no error when deleting expired silence #2817

3 changes: 2 additions & 1 deletion silence/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ func (s *Silences) expire(id string) error {

switch getState(sil, now) {
case types.SilenceStateExpired:
return errors.Errorf("silence %s already expired", id)
Copy link
Member

@gotjosh gotjosh Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for coming in late - I feel that this kind of comment about the semantics of the function is best put as part of the function description.

How do you feel about changing the top-level comment from:

// Expire the silence with the given ID immediately.

to

// Expire the silence with the given ID immediately. It is idempotent, nil is returned if the silence already expired before it is GC'd.
// If the silence is not found an error is returned.

and removing the comment on the body.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll make the change.

// Returning nil ensures idempotent behaviour, at least in the short term before the silence is gc'd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Returning nil ensures idempotent behaviour, at least in the short term before the silence is gc'd
// Returning nil ensures idempotent behaviour, at least in the short term before the silence is gc'd.

return nil
case types.SilenceStateActive:
sil.EndsAt = now
case types.SilenceStatePending:
Expand Down
8 changes: 2 additions & 6 deletions silence/silence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,7 @@ func TestSilenceExpire(t *testing.T) {
require.NoError(t, s.Expire("pending"))
require.NoError(t, s.Expire("active"))

err = s.Expire("expired")
require.Error(t, err)
require.Contains(t, err.Error(), "already expired")
require.NoError(t, s.Expire("expired"))

sil, err := s.QueryOne(QIDs("pending"))
require.NoError(t, err)
Expand Down Expand Up @@ -935,9 +933,7 @@ func TestSilenceExpireWithZeroRetention(t *testing.T) {
require.NoError(t, s.Expire("pending"))
require.NoError(t, s.Expire("active"))

err = s.Expire("expired")
require.Error(t, err)
require.Contains(t, err.Error(), "already expired")
require.NoError(t, s.Expire("expired"))

_, err = s.QueryOne(QIDs("pending"))
require.NoError(t, err)
Expand Down