Skip to content

Commit

Permalink
Add a getAlertState method that looks up the state
Browse files Browse the repository at this point in the history
  • Loading branch information
desa committed Mar 2, 2017
1 parent 55840df commit 8526f28
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,7 @@ func (a *AlertNode) runAlert([]byte) error {
return err
}
var currentLevel alert.Level
a.cardinalityMu.RLock()
state, ok := a.states[p.Group]
a.cardinalityMu.RUnlock()
state, ok := a.getAlertState(p.Group)
if ok {
currentLevel = state.currentLevel()
} else {
Expand Down Expand Up @@ -593,9 +591,7 @@ func (a *AlertNode) runAlert([]byte) error {
var highestPoint *models.BatchPoint

var currentLevel alert.Level
a.cardinalityMu.RLock()
state, ok := a.states[b.Group]
a.cardinalityMu.RUnlock()
state, ok := a.getAlertState(b.Group)
if ok {
currentLevel = state.currentLevel()
} else {
Expand Down Expand Up @@ -950,9 +946,7 @@ func (a *alertState) percentChange() float64 {
}

func (a *AlertNode) updateState(t time.Time, level alert.Level, group models.GroupID) *alertState {
a.cardinalityMu.RLock()
state, ok := a.states[group]
a.cardinalityMu.RUnlock()
state, ok := a.getAlertState(group)
if !ok {
state = &alertState{
history: make([]alert.Level, a.a.History),
Expand Down Expand Up @@ -1094,3 +1088,10 @@ func (a *AlertNode) renderMessageAndDetails(id, name string, t time.Time, group
details := tmpBuffer.String()
return msg, details, nil
}

func (a *AlertNode) getAlertState(id models.GroupID) (state *alertState, ok bool) {
a.cardinalityMu.RLock()
state, ok = a.states[id]
a.cardinalityMu.RUnlock()
return state, ok
}

0 comments on commit 8526f28

Please sign in to comment.