alerting: fixed issue with included alerting error & no data reasons, fixes #8412

This commit is contained in:
Torkel Ödegaard
2017-05-18 14:10:12 +02:00
parent 43d5525aaa
commit 8918922179
5 changed files with 28 additions and 23 deletions

View File

@@ -131,6 +131,29 @@ function joinEvalMatches(matches, separator: string) {
}, []).join(separator);
}
function getAlertAnnotationInfo(ah) {
// backward compatability, can be removed in grafana 5.x
// old way stored evalMatches in data property directly,
// new way stores it in evalMatches property on new data object
if (_.isArray(ah.data)) {
return joinEvalMatches(ah.data, ', ');
} else if (_.isArray(ah.data.evalMatches)) {
return joinEvalMatches(ah.data.evalMatches, ', ');
}
if (ah.data.error) {
return "Error: " + ah.data.error;
}
if (ah.data.noData || ah.data.no_data) {
return "No Data";
}
return "";
}
export default {
alertQueryDef: alertQueryDef,
getStateDisplayModel: getStateDisplayModel,
@@ -141,6 +164,6 @@ export default {
executionErrorModes: executionErrorModes,
reducerTypes: reducerTypes,
createReducerPart: createReducerPart,
joinEvalMatches: joinEvalMatches,
getAlertAnnotationInfo: getAlertAnnotationInfo,
alertStateSortScore: alertStateSortScore,
};

View File

@@ -81,25 +81,7 @@ export class AlertTabCtrl {
this.alertHistory = _.map(res, ah => {
ah.time = moment(ah.time).format('MMM D, YYYY HH:mm:ss');
ah.stateModel = alertDef.getStateDisplayModel(ah.newState);
ah.reason = "";
if (_.isArray(ah.data)) {
ah.reason = "Conditions";
ah.metrics = alertDef.joinEvalMatches(ah.data, ', ');
} else if (_.isArray(ah.data.evalMatches)) {
ah.metrics = alertDef.joinEvalMatches(ah.data.evalMatches, ', ');
}
if (ah.data.error) {
ah.metrics = "" + ah.data.error;
ah.reason = "Error";
}
if (ah.data.noData || ah.data.no_data) {
ah.metrics = "";
ah.reason = "No Data";
}
ah.info = alertDef.getAlertAnnotationInfo(ah);
return ah;
});
});

View File

@@ -161,7 +161,7 @@
</span> {{ah.time}}
</div>
<div class="card-item-sub-name">
&nbsp;{{ah.metrics}}
{{ah.info}}
</div>
</div>
</div>

View File

@@ -40,7 +40,7 @@
<span class="alert-list-item-state {{al.stateModel.stateClass}}">
<i class="{{al.stateModel.iconClass}}"></i>
{{al.stateModel.text}}
</span> {{al.metrics}}
</span> {{al.info}}
</div>
</div>
</div>

View File

@@ -106,7 +106,7 @@ class AlertListPanel extends PanelCtrl {
this.alertHistory = _.map(res, al => {
al.time = moment(al.time).format('MMM D, YYYY HH:mm:ss');
al.stateModel = alertDef.getStateDisplayModel(al.newState);
al.metrics = alertDef.joinEvalMatches(al.data, ', ');
al.info = alertDef.getAlertAnnotationInfo(al);
return al;
});
});