Annotations: Fix alerting annotation coloring (#37412)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Kyle Brandt
2021-08-12 12:37:54 -04:00
committed by GitHub
parent d18bd03a82
commit aef67994a1
3 changed files with 27 additions and 9 deletions

View File

@@ -181,7 +181,7 @@ func (st *Manager) setNextState(alertRule *ngModels.AlertRule, result eval.Resul
st.set(currentState)
if oldState != currentState.State {
go st.createAlertAnnotation(currentState.State, alertRule, result)
go st.createAlertAnnotation(currentState.State, alertRule, result, oldState)
}
return currentState
}
@@ -229,7 +229,7 @@ func translateInstanceState(state ngModels.InstanceStateType) eval.State {
}
}
func (st *Manager) createAlertAnnotation(new eval.State, alertRule *ngModels.AlertRule, result eval.Result) {
func (st *Manager) createAlertAnnotation(new eval.State, alertRule *ngModels.AlertRule, result eval.Result, oldState eval.State) {
st.log.Debug("alert state changed creating annotation", "alertRuleUID", alertRule.UID, "newState", new.String())
dashUid, ok := alertRule.Annotations["__dashboardUid__"]
if !ok {
@@ -255,12 +255,14 @@ func (st *Manager) createAlertAnnotation(new eval.State, alertRule *ngModels.Ale
return
}
annotationText := fmt.Sprintf("%s %s", result.Instance.String(), new.String())
annotationText := fmt.Sprintf("%s {%s} - %s", alertRule.Title, result.Instance.String(), new.String())
item := &annotations.Item{
OrgId: alertRule.OrgID,
DashboardId: query.Result.Id,
PanelId: panelId,
PrevState: oldState.String(),
NewState: new.String(),
Text: annotationText,
Epoch: result.EvaluatedAt.UnixNano() / int64(time.Millisecond),
}