mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: remove State cache entries on Ruler Delete (#33638)
for https://github.com/grafana/alerting-squad/issues/133
This commit is contained in:
@@ -113,6 +113,17 @@ func (c *cache) getStatesByRuleUID() map[string][]*State {
|
||||
return ruleMap
|
||||
}
|
||||
|
||||
// removeByRuleUID deletes all entries in the state cache that match the given UID.
|
||||
func (c *cache) removeByRuleUID(orgID int64, uid string) {
|
||||
c.mtxStates.Lock()
|
||||
defer c.mtxStates.Unlock()
|
||||
for k, state := range c.states {
|
||||
if state.AlertRuleUID == uid && state.OrgID == orgID {
|
||||
delete(c.states, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cache) reset() {
|
||||
c.mtxStates.Lock()
|
||||
defer c.mtxStates.Unlock()
|
||||
|
@@ -45,11 +45,16 @@ func (st *Manager) Get(id string) (*State, error) {
|
||||
return st.cache.get(id)
|
||||
}
|
||||
|
||||
//Used to ensure a clean cache on startup
|
||||
// ResetCache is used to ensure a clean cache on startup.
|
||||
func (st *Manager) ResetCache() {
|
||||
st.cache.reset()
|
||||
}
|
||||
|
||||
// RemoveByRuleUID deletes all entries in the state manager that match the given rule UID.
|
||||
func (st *Manager) RemoveByRuleUID(orgID int64, ruleUID string) {
|
||||
st.cache.removeByRuleUID(orgID, ruleUID)
|
||||
}
|
||||
|
||||
func (st *Manager) ProcessEvalResults(alertRule *ngModels.AlertRule, results eval.Results) []*State {
|
||||
st.Log.Debug("state manager processing evaluation results", "uid", alertRule.UID, "resultCount", len(results))
|
||||
var states []*State
|
||||
|
Reference in New Issue
Block a user