Commit e78da57e by bergquist

feat(alerting): shows when no_data triggered alerts

closes #7035
ref #7257
parent f29f83ca
...@@ -75,6 +75,7 @@ func GetAlerts(c *middleware.Context) Response { ...@@ -75,6 +75,7 @@ func GetAlerts(c *middleware.Context) Response {
State: alert.State, State: alert.State,
NewStateDate: alert.NewStateDate, NewStateDate: alert.NewStateDate,
ExecutionError: alert.ExecutionError, ExecutionError: alert.ExecutionError,
EvalData: alert.EvalData,
}) })
} }
......
...@@ -17,6 +17,7 @@ type AlertRule struct { ...@@ -17,6 +17,7 @@ type AlertRule struct {
State m.AlertStateType `json:"state"` State m.AlertStateType `json:"state"`
NewStateDate time.Time `json:"newStateDate"` NewStateDate time.Time `json:"newStateDate"`
EvalDate time.Time `json:"evalDate"` EvalDate time.Time `json:"evalDate"`
EvalData *simplejson.Json `json:"evalData"`
ExecutionError string `json:"executionError"` ExecutionError string `json:"executionError"`
DashbboardUri string `json:"dashboardUri"` DashbboardUri string `json:"dashboardUri"`
} }
......
...@@ -31,13 +31,17 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error { ...@@ -31,13 +31,17 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error {
executionError := "" executionError := ""
annotationData := simplejson.New() annotationData := simplejson.New()
if evalContext.Firing {
annotationData = simplejson.NewFromAny(evalContext.EvalMatches)
}
if evalContext.Error != nil { if evalContext.Error != nil {
executionError = evalContext.Error.Error() executionError = evalContext.Error.Error()
annotationData.Set("errorMessage", executionError) annotationData.Set("errorMessage", executionError)
} }
if evalContext.Firing { if evalContext.NoDataFound {
annotationData = simplejson.NewFromAny(evalContext.EvalMatches) annotationData.Set("no_data", true)
} }
countStateResult(evalContext.Rule.State) countStateResult(evalContext.Rule.State)
......
...@@ -113,6 +113,12 @@ func HandleAlertsQuery(query *m.GetAlertsQuery) error { ...@@ -113,6 +113,12 @@ func HandleAlertsQuery(query *m.GetAlertsQuery) error {
return err return err
} }
for i, _ := range alerts {
if alerts[i].ExecutionError == " " {
alerts[i].ExecutionError = ""
}
}
query.Result = alerts query.Result = alerts
return nil return nil
} }
......
...@@ -37,6 +37,9 @@ export class AlertListCtrl { ...@@ -37,6 +37,9 @@ export class AlertListCtrl {
this.alerts = _.map(result, alert => { this.alerts = _.map(result, alert => {
alert.stateModel = alertDef.getStateDisplayModel(alert.state); alert.stateModel = alertDef.getStateDisplayModel(alert.state);
alert.newStateDateAgo = moment(alert.newStateDate).fromNow().replace(" ago", ""); alert.newStateDateAgo = moment(alert.newStateDate).fromNow().replace(" ago", "");
if (alert.evalData && alert.evalData.no_data) {
alert.no_data = true;
}
return alert; return alert;
}); });
}); });
......
...@@ -82,6 +82,15 @@ export class AlertTabCtrl { ...@@ -82,6 +82,15 @@ export class AlertTabCtrl {
ah.time = moment(ah.time).format('MMM D, YYYY HH:mm:ss'); ah.time = moment(ah.time).format('MMM D, YYYY HH:mm:ss');
ah.stateModel = alertDef.getStateDisplayModel(ah.newState); ah.stateModel = alertDef.getStateDisplayModel(ah.newState);
ah.metrics = alertDef.joinEvalMatches(ah.data, ', '); ah.metrics = alertDef.joinEvalMatches(ah.data, ', ');
if (ah.data.errorMessage) {
ah.metrics = "Error: " + ah.data.errorMessage;
}
if (ah.data.no_data) {
ah.metrics = "(due to no data)";
}
return ah; return ah;
}); });
}); });
......
...@@ -52,11 +52,11 @@ ...@@ -52,11 +52,11 @@
<div class="card-item-sub-name"> <div class="card-item-sub-name">
<span class="alert-list-item-state {{alert.stateModel.stateClass}}"> <span class="alert-list-item-state {{alert.stateModel.stateClass}}">
<i class="{{alert.stateModel.iconClass}}"></i> <i class="{{alert.stateModel.iconClass}}"></i>
{{alert.stateModel.text}} {{alert.stateModel.text}} <span class="small muted" ng-show="alert.no_data">(due to no data)</span>
</span> for {{alert.newStateDateAgo}} </span> for {{alert.newStateDateAgo}}
</div> </div>
<div class="small muted" ng-show="alert.executionError"> <div class="small muted" ng-show="alert.executionError !== ''">
{{alert.executionError}} Error: "{{alert.executionError}}"
</div> </div>
</div> </div>
</div> </div>
...@@ -64,6 +64,4 @@ ...@@ -64,6 +64,4 @@
</li> </li>
</ol> </ol>
</section> </section>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment