mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Update state history service to filter states transitions (#58863)
* rename the method to better reflect its behavior * make historian filter transition on itself * call historian with all changes
This commit is contained in:
@@ -181,7 +181,10 @@ func (st *Manager) ProcessEvalResults(ctx context.Context, evaluatedAt time.Time
|
||||
|
||||
st.saveAlertStates(ctx, logger, states...)
|
||||
|
||||
st.logStateTransitions(ctx, alertRule, states, staleStates)
|
||||
allChanges := append(states, staleStates...)
|
||||
if st.historian != nil {
|
||||
st.historian.RecordStatesAsync(ctx, alertRule, allChanges)
|
||||
}
|
||||
|
||||
nextStates := make([]*State, 0, len(states))
|
||||
for _, s := range states {
|
||||
@@ -316,26 +319,6 @@ func (st *Manager) saveAlertStates(ctx context.Context, logger log.Logger, state
|
||||
}
|
||||
}
|
||||
|
||||
func (st *Manager) logStateTransitions(ctx context.Context, alertRule *ngModels.AlertRule, newStates, staleStates []StateTransition) {
|
||||
if st.historian == nil {
|
||||
return
|
||||
}
|
||||
changedStates := make([]StateTransition, 0, len(staleStates))
|
||||
for _, s := range newStates {
|
||||
if s.changed() {
|
||||
changedStates = append(changedStates, s)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO refactor further. Let historian decide what to log. Current logic removes states `Normal (reason-X) -> Normal (reason-Y)`
|
||||
for _, t := range staleStates {
|
||||
if t.PreviousState == eval.Alerting {
|
||||
changedStates = append(changedStates, t)
|
||||
}
|
||||
}
|
||||
st.historian.RecordStates(ctx, alertRule, changedStates)
|
||||
}
|
||||
|
||||
func (st *Manager) deleteAlertStates(ctx context.Context, logger log.Logger, states []StateTransition) {
|
||||
if st.instanceStore == nil || len(states) == 0 {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user