Skip to content

Commit

Permalink
Merge pull request #1026 from brancz/marker-race
Browse files Browse the repository at this point in the history
Remove .WasInhibited and .WasSilenced fields of Alert type
  • Loading branch information
brancz authored Oct 10, 2017
2 parents 89200cc + 0ef6695 commit ff9e527
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
6 changes: 0 additions & 6 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,11 @@ func NewInhibitStage(m types.Muter, mk types.Marker) *InhibitStage {
func (n *InhibitStage) Exec(ctx context.Context, alerts ...*types.Alert) (context.Context, []*types.Alert, error) {
var filtered []*types.Alert
for _, a := range alerts {
_, ok := n.marker.Inhibited(a.Fingerprint())
// TODO(fabxc): increment total alerts counter.
// Do not send the alert if the silencer mutes it.
if !n.muter.Mutes(a.Labels) {
// TODO(fabxc): increment muted alerts counter.
filtered = append(filtered, a)
// Store whether a previously inhibited alert is firing again.
a.WasInhibited = ok
}
}

Expand All @@ -360,7 +357,6 @@ func NewSilenceStage(s *silence.Silences, mk types.Marker) *SilenceStage {
func (n *SilenceStage) Exec(ctx context.Context, alerts ...*types.Alert) (context.Context, []*types.Alert, error) {
var filtered []*types.Alert
for _, a := range alerts {
_, ok := n.marker.Silenced(a.Fingerprint())
// TODO(fabxc): increment total alerts counter.
// Do not send the alert if the silencer mutes it.
sils, err := n.silences.Query(
Expand All @@ -375,8 +371,6 @@ func (n *SilenceStage) Exec(ctx context.Context, alerts ...*types.Alert) (contex
// TODO(fabxc): increment muted alerts counter.
filtered = append(filtered, a)
n.marker.SetSilenced(a.Labels.Fingerprint())
// Store whether a previously silenced alert is firing again.
a.WasSilenced = ok
} else {
ids := make([]string, len(sils))
for i, s := range sils {
Expand Down
10 changes: 2 additions & 8 deletions notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,8 @@ func TestSilenceStage(t *testing.T) {
}

var got []model.LabelSet
for i, a := range alerts {
for _, a := range alerts {
got = append(got, a.Labels)
if a.WasSilenced != (i == 1) {
t.Errorf("Expected WasSilenced to be %v for %d, was %v", i == 1, i, a.WasSilenced)
}
}

if !reflect.DeepEqual(got, out) {
Expand Down Expand Up @@ -533,11 +530,8 @@ func TestInhibitStage(t *testing.T) {
}

var got []model.LabelSet
for i, a := range alerts {
for _, a := range alerts {
got = append(got, a.Labels)
if a.WasInhibited != (i == 1) {
t.Errorf("Expected WasInhibited to be %v for %d, was %v", i == 1, i, a.WasInhibited)
}
}

if !reflect.DeepEqual(got, out) {
Expand Down
6 changes: 2 additions & 4 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,8 @@ type Alert struct {
model.Alert

// The authoritative timestamp.
UpdatedAt time.Time
Timeout bool
WasSilenced bool `json:"-"`
WasInhibited bool `json:"-"`
UpdatedAt time.Time
Timeout bool
}

// AlertSlice is a sortable slice of Alerts.
Expand Down

0 comments on commit ff9e527

Please sign in to comment.