mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): extract method for join eval matches
This commit is contained in:
parent
d02f29fb02
commit
b49a642ca5
@ -1,6 +1,6 @@
|
|||||||
///<reference path="../../headers/common.d.ts" />
|
///<reference path="../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
import {
|
import {
|
||||||
QueryPartDef,
|
QueryPartDef,
|
||||||
QueryPart,
|
QueryPart,
|
||||||
@ -89,6 +89,16 @@ function getStateDisplayModel(state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function joinEvalMatches(matches, seperator: string) {
|
||||||
|
return _.reduce(matches, (res, ev)=> {
|
||||||
|
if (ev.Metric !== undefined && ev.Value !== undefined) {
|
||||||
|
res.push(ev.Metric + "=" + ev.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}, []).join(seperator);
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
alertQueryDef: alertQueryDef,
|
alertQueryDef: alertQueryDef,
|
||||||
getStateDisplayModel: getStateDisplayModel,
|
getStateDisplayModel: getStateDisplayModel,
|
||||||
@ -97,4 +107,5 @@ export default {
|
|||||||
noDataModes: noDataModes,
|
noDataModes: noDataModes,
|
||||||
reducerTypes: reducerTypes,
|
reducerTypes: reducerTypes,
|
||||||
createReducerPart: createReducerPart,
|
createReducerPart: createReducerPart,
|
||||||
|
joinEvalMatches: joinEvalMatches,
|
||||||
};
|
};
|
||||||
|
@ -90,11 +90,7 @@ export class AlertTabCtrl {
|
|||||||
this.alertHistory = _.map(res, ah => {
|
this.alertHistory = _.map(res, ah => {
|
||||||
ah.time = moment(ah.timestamp).format('MMM D, YYYY HH:mm:ss');
|
ah.time = moment(ah.timestamp).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 = _.map(ah.data, ev=> {
|
|
||||||
return ev.Metric + "=" + ev.Value;
|
|
||||||
}).join(', ');
|
|
||||||
|
|
||||||
return ah;
|
return ah;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -47,6 +47,7 @@ class AlertListPanel extends PanelCtrl {
|
|||||||
this.alertHistory = _.map(res, al => {
|
this.alertHistory = _.map(res, al => {
|
||||||
al.time = moment(al.timestamp).format('MMM D, YYYY HH:mm:ss');
|
al.time = moment(al.timestamp).format('MMM D, YYYY HH:mm:ss');
|
||||||
al.stateModel = alertDef.getStateDisplayModel(al.newState);
|
al.stateModel = alertDef.getStateDisplayModel(al.newState);
|
||||||
|
al.metrics = alertDef.joinEvalMatches(al.data, ', ');
|
||||||
return al;
|
return al;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -58,7 +59,6 @@ class AlertListPanel extends PanelCtrl {
|
|||||||
this.currentAlerts = _.map(res, al => {
|
this.currentAlerts = _.map(res, al => {
|
||||||
al.stateModel = alertDef.getStateDisplayModel(al.state);
|
al.stateModel = alertDef.getStateDisplayModel(al.state);
|
||||||
al.newStateDateAgo = moment(al.newStateDate).fromNow().replace(" ago", "");
|
al.newStateDateAgo = moment(al.newStateDate).fromNow().replace(" ago", "");
|
||||||
|
|
||||||
return al;
|
return al;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user