mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update handling of stale state (#58276)
* delete all stale states in one lock * do not use touched states to detect stale rely only on LastEvaluationTime maintained correctly * fix tests to use correct eval time * delete unused method
This commit is contained in:
@@ -156,6 +156,27 @@ func (rs *ruleStates) expandRuleLabelsAndAnnotations(ctx context.Context, log lo
|
||||
return expand(alertRule.Labels), expand(alertRule.Annotations)
|
||||
}
|
||||
|
||||
func (rs *ruleStates) deleteStates(predicate func(s *State) bool) []*State {
|
||||
deleted := make([]*State, 0)
|
||||
for id, state := range rs.states {
|
||||
if predicate(state) {
|
||||
delete(rs.states, id)
|
||||
deleted = append(deleted, state)
|
||||
}
|
||||
}
|
||||
return deleted
|
||||
}
|
||||
|
||||
func (c *cache) deleteRuleStates(ruleKey ngModels.AlertRuleKey, predicate func(s *State) bool) []*State {
|
||||
c.mtxStates.Lock()
|
||||
defer c.mtxStates.Unlock()
|
||||
ruleStates, ok := c.states[ruleKey.OrgID][ruleKey.UID]
|
||||
if ok {
|
||||
return ruleStates.deleteStates(predicate)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *cache) setAllStates(newStates map[int64]map[string]*ruleStates) {
|
||||
c.mtxStates.Lock()
|
||||
defer c.mtxStates.Unlock()
|
||||
@@ -283,13 +304,3 @@ func mergeLabels(a, b data.Labels) data.Labels {
|
||||
}
|
||||
return newLbs
|
||||
}
|
||||
|
||||
func (c *cache) deleteEntry(orgID int64, alertRuleUID, cacheID string) {
|
||||
c.mtxStates.Lock()
|
||||
defer c.mtxStates.Unlock()
|
||||
ruleStates, ok := c.states[orgID][alertRuleUID]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
delete(ruleStates.states, cacheID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user