From b49a642ca5d6063a4b959d5d72ed61630d02e001 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 13 Sep 2016 13:46:29 +0200 Subject: [PATCH] feat(alerting): extract method for join eval matches --- public/app/features/alerting/alert_def.ts | 13 ++++++++++++- public/app/features/alerting/alert_tab_ctrl.ts | 6 +----- public/app/plugins/panel/alertlist/module.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/public/app/features/alerting/alert_def.ts b/public/app/features/alerting/alert_def.ts index 15f1f373bd5..8e9a86735ad 100644 --- a/public/app/features/alerting/alert_def.ts +++ b/public/app/features/alerting/alert_def.ts @@ -1,6 +1,6 @@ /// - +import _ from 'lodash'; import { QueryPartDef, 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 { alertQueryDef: alertQueryDef, getStateDisplayModel: getStateDisplayModel, @@ -97,4 +107,5 @@ export default { noDataModes: noDataModes, reducerTypes: reducerTypes, createReducerPart: createReducerPart, + joinEvalMatches: joinEvalMatches, }; diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index f5aa120fbeb..074d34eaea5 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -90,11 +90,7 @@ export class AlertTabCtrl { this.alertHistory = _.map(res, ah => { ah.time = moment(ah.timestamp).format('MMM D, YYYY HH:mm:ss'); ah.stateModel = alertDef.getStateDisplayModel(ah.newState); - - ah.metrics = _.map(ah.data, ev=> { - return ev.Metric + "=" + ev.Value; - }).join(', '); - + ah.metrics = alertDef.joinEvalMatches(ah.data, ', '); return ah; }); }); diff --git a/public/app/plugins/panel/alertlist/module.ts b/public/app/plugins/panel/alertlist/module.ts index 40c5af02133..e16ec7dd904 100644 --- a/public/app/plugins/panel/alertlist/module.ts +++ b/public/app/plugins/panel/alertlist/module.ts @@ -47,6 +47,7 @@ class AlertListPanel extends PanelCtrl { this.alertHistory = _.map(res, al => { al.time = moment(al.timestamp).format('MMM D, YYYY HH:mm:ss'); al.stateModel = alertDef.getStateDisplayModel(al.newState); + al.metrics = alertDef.joinEvalMatches(al.data, ', '); return al; }); }); @@ -58,7 +59,6 @@ class AlertListPanel extends PanelCtrl { this.currentAlerts = _.map(res, al => { al.stateModel = alertDef.getStateDisplayModel(al.state); al.newStateDateAgo = moment(al.newStateDate).fromNow().replace(" ago", ""); - return al; }); });