Alerting: remove State cache entries on Ruler Delete (#33638)

for https://github.com/grafana/alerting-squad/issues/133
This commit is contained in:
Kyle Brandt
2021-05-03 14:01:33 -04:00
committed by GitHub
parent 0609b80fdc
commit 48358efc13
5 changed files with 61 additions and 12 deletions

View File

@@ -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()