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

Marker: Rename SetSilenced to SetActiveOrSilenced #2950

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func TestMuteStageWithSilences(t *testing.T) {

// Set the second alert as previously silenced with an old version
// number. This is expected to get unsilenced by the stage.
marker.SetSilenced(inAlerts[1].Fingerprint(), 0, []string{"123"}, nil)
marker.SetActiveOrSilenced(inAlerts[1].Fingerprint(), 0, []string{"123"}, nil)

_, alerts, err := stage.Exec(context.Background(), log.NewNopLogger(), inAlerts...)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions provider/mem/mem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestAlertsGC(t *testing.T) {
}

for _, a := range insert {
marker.SetSilenced(a.Fingerprint(), 0, nil, nil)
marker.SetActiveOrSilenced(a.Fingerprint(), 0, nil, nil)
marker.SetInhibited(a.Fingerprint())
if !marker.Active(a.Fingerprint()) {
t.Errorf("error setting status: %v", a)
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestAlerts_Count(t *testing.T) {

// When insert an alert, and then silence it. It shows up with the correct filter.
alerts.Put(a2)
marker.SetSilenced(a2.Fingerprint(), 1, []string{"1"}, nil)
marker.SetActiveOrSilenced(a2.Fingerprint(), 1, []string{"1"}, nil)
require.Equal(t, 1, countByState(types.AlertStateSuppressed))
require.Equal(t, 1, countTotal())

Expand Down
4 changes: 2 additions & 2 deletions silence/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *Silencer) Mutes(lset model.LabelSet) bool {
}
if len(allSils) == 0 {
// Easy case, neither active nor pending silences anymore.
s.marker.SetSilenced(fp, newVersion, nil, nil)
s.marker.SetActiveOrSilenced(fp, newVersion, nil, nil)
return false
}
// It is still possible that nothing has changed, but finding out is not
Expand Down Expand Up @@ -183,7 +183,7 @@ func (s *Silencer) Mutes(lset model.LabelSet) bool {
sort.Strings(activeIDs)
sort.Strings(pendingIDs)

s.marker.SetSilenced(fp, newVersion, activeIDs, pendingIDs)
s.marker.SetActiveOrSilenced(fp, newVersion, activeIDs, pendingIDs)

return len(activeIDs) > 0
}
Expand Down
12 changes: 6 additions & 6 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ type AlertStatus struct {
// Marker helps to mark alerts as silenced and/or inhibited.
// All methods are goroutine-safe.
type Marker interface {
// SetSilenced replaces the previous SilencedBy by the provided IDs of
// SetActiveOrSilenced replaces the previous SilencedBy by the provided IDs of
// active and pending silences, including the version number of the
// silences state. The set of provided IDs is supposed to represent the
// complete set of relevant silences. If no active silence IDs are provided and
// InhibitedBy is already empty, it sets the provided alert to AlertStateActive.
// Otherwise, it sets the provided alert to AlertStateSuppressed.
SetSilenced(alert model.Fingerprint, version int, activeSilenceIDs, pendingSilenceIDs []string)
SetActiveOrSilenced(alert model.Fingerprint, version int, activeSilenceIDs, pendingSilenceIDs []string)
// SetInhibited replaces the previous InhibitedBy by the provided IDs of
// alerts. In contrast to SetSilenced, the set of provided IDs is not
// alerts. In contrast to SetActiveOrSilenced, the set of provided IDs is not
// expected to represent the complete set of inhibiting alerts. (In
// practice, this method is only called with one or zero IDs. However,
// this expectation might change in the future.) If no IDs are provided
// this expectation might change in the future. If no IDs are provided
// and InhibitedBy is already empty, it sets the provided alert to
// AlertStateActive. Otherwise, it sets the provided alert to
// AlertStateSuppressed.
Expand Down Expand Up @@ -150,8 +150,8 @@ func (m *memMarker) Count(states ...AlertState) int {
return count
}

// SetSilenced implements Marker.
func (m *memMarker) SetSilenced(alert model.Fingerprint, version int, activeIDs, pendingIDs []string) {
// SetActiveOrSilenced implements Marker.
func (m *memMarker) SetActiveOrSilenced(alert model.Fingerprint, version int, activeIDs, pendingIDs []string) {
m.mtx.Lock()
defer m.mtx.Unlock()

Expand Down
6 changes: 3 additions & 3 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ func TestMemMarker_Count(t *testing.T) {
}

// Insert an active alert.
marker.SetSilenced(a1.Fingerprint(), 1, nil, nil)
marker.SetActiveOrSilenced(a1.Fingerprint(), 1, nil, nil)
require.Equal(t, 1, countByState(AlertStateActive))
require.Equal(t, 1, countTotal())

// Insert a suppressed alert.
marker.SetSilenced(a2.Fingerprint(), 1, []string{"1"}, nil)
marker.SetActiveOrSilenced(a2.Fingerprint(), 1, []string{"1"}, nil)
require.Equal(t, 1, countByState(AlertStateSuppressed))
require.Equal(t, 2, countTotal())

// Insert a resolved alert - it'll count as active.
marker.SetSilenced(a3.Fingerprint(), 1, []string{"1"}, nil)
marker.SetActiveOrSilenced(a3.Fingerprint(), 1, []string{"1"}, nil)
require.Equal(t, 1, countByState(AlertStateActive))
require.Equal(t, 3, countTotal())
}
Expand Down