Alerting: Fix persisting result fingerprint that is used by recovery threshold (#91224)

* fix persister to save result fingerprint

* revert change

* fmt
This commit is contained in:
Yuri Tseretyan
2024-07-30 18:07:13 -04:00
committed by GitHub
parent f96eed5abf
commit 537f1fb857
3 changed files with 85 additions and 2 deletions
+6 -2
View File
@@ -91,10 +91,10 @@ func (c *cache) getOrCreate(ctx context.Context, log log.Logger, alertRule *ngMo
states = &ruleStates{states: make(map[data.Fingerprint]*State)}
c.states[stateCandidate.OrgID][stateCandidate.AlertRuleUID] = states
}
return states.getOrAdd(stateCandidate)
return states.getOrAdd(stateCandidate, log)
}
func (rs *ruleStates) getOrAdd(stateCandidate State) *State {
func (rs *ruleStates) getOrAdd(stateCandidate State, log log.Logger) *State {
state, ok := rs.states[stateCandidate.CacheID]
// Check if the state with this ID already exists.
if !ok {
@@ -115,6 +115,10 @@ func (rs *ruleStates) getOrAdd(stateCandidate State) *State {
}
state.Annotations = stateCandidate.Annotations
state.Values = stateCandidate.Values
if state.ResultFingerprint != stateCandidate.ResultFingerprint {
log.Info("Result fingerprint has changed", "oldFingerprint", state.ResultFingerprint, "newFingerprint", stateCandidate.ResultFingerprint, "cacheID", state.CacheID, "stateLabels", state.Labels.String())
state.ResultFingerprint = stateCandidate.ResultFingerprint
}
rs.states[stateCandidate.CacheID] = state
return state
}