Skip to content

Commit

Permalink
Fix inconsistent Id returned for silences.Set
Browse files Browse the repository at this point in the history
This commit fixes inconsistent behavior of silences.Set where if
a silence was invalid or exceeds limits, sil.Id would contain the
silence UUID but the Id returned would be the empty string.
This bug was introduced in prometheus#3866.

Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Jun 6, 2024
1 parent b59669f commit a97f41d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions silence/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,7 @@ func (s *Silences) Set(sil *pb.Silence) (string, error) {
sil.StartsAt = now
}

if err = s.setSilence(sil, now, false); err != nil {
return "", err
}

return sil.Id, nil
return sil.Id, s.setSilence(sil, now, false)
}

// canUpdate returns true if silence a can be updated to b without
Expand Down
2 changes: 1 addition & 1 deletion silence/silence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func TestSilenceLimits(t *testing.T) {
// Do not check the exact size as it can change between consecutive runs
// due to padding.
require.Contains(t, err.Error(), "silence exceeded maximum size")
require.Equal(t, "", id3)
require.NotEqual(t, "", id3)
}

func TestSetActiveSilence(t *testing.T) {
Expand Down

0 comments on commit a97f41d

Please sign in to comment.