From a89315214109145040bad3370646912d45d60d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 15 Jun 2016 10:41:21 +0200 Subject: [PATCH] feat(alerting): thesholds unification --- .../app/plugins/panel/graph/alert_tab_ctrl.ts | 25 ++++++++----------- public/app/plugins/panel/graph/graph.js | 7 +++--- .../panel/graph/partials/tab_alerting.html | 16 ++++++------ public/app/plugins/panel/graph/thresholds.ts | 10 +++----- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/public/app/plugins/panel/graph/alert_tab_ctrl.ts b/public/app/plugins/panel/graph/alert_tab_ctrl.ts index c47d58631b8..2578f17ffca 100644 --- a/public/app/plugins/panel/graph/alert_tab_ctrl.ts +++ b/public/app/plugins/panel/graph/alert_tab_ctrl.ts @@ -62,8 +62,8 @@ export class AlertTabCtrl { }); } - getThresholdWithDefaults(thresholds, type) { - var threshold = thresholds[type] || {}; + getThresholdWithDefaults(threshold) { + threshold = threshold || {}; threshold.op = threshold.op || '>'; threshold.value = threshold.value || undefined; return threshold; @@ -73,13 +73,8 @@ export class AlertTabCtrl { var alert = this.alert = this.panel.alert = this.panel.alert || {}; // set threshold defaults - alert.thresholds = alert.thresholds || {}; - alert.thresholds.warn = this.getThresholdWithDefaults(alert.thresholds, 'warn'); - alert.thresholds.crit = this.getThresholdWithDefaults(alert.thresholds, 'crit'); - - alert.frequency = alert.frequency || '60s'; - alert.handler = alert.handler || 1; - alert.notifications = alert.notifications || []; + alert.warn = this.getThresholdWithDefaults(alert.warn); + alert.crit = this.getThresholdWithDefaults(alert.crit); alert.query = alert.query || {}; alert.query.refId = alert.query.refId || 'A'; @@ -90,6 +85,10 @@ export class AlertTabCtrl { alert.transform.type = alert.transform.type || 'aggregation'; alert.transform.method = alert.transform.method || 'avg'; + alert.frequency = alert.frequency || '60s'; + alert.handler = alert.handler || 1; + alert.notifications = alert.notifications || []; + var defaultName = this.panel.title + ' alert'; alert.name = alert.name || defaultName; alert.description = alert.description || defaultName; @@ -133,13 +132,11 @@ export class AlertTabCtrl { } delete() { - // keep threshold object (instance used by graph handles) - var thresholds = this.alert.thresholds; - thresholds.warn.value = undefined; - thresholds.crit.value = undefined; + this.alert.enabled = false; + this.alert.warn.value = undefined; + this.alert.crit.value = undefined; // reset model but keep thresholds instance - this.alert = this.panel.alert = {thresholds: thresholds}; this.initModel(); } diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index b76956ff6e8..6c59bd63cea 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -333,13 +333,12 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) { } function addGridThresholds(options, panel) { - if (!panel.alert || !panel.alert.thresholds) { + if (!panel.alert) { return; } - var thresholds = panel.alert.thresholds; - var crit = thresholds.crit; - var warn = thresholds.warn; + var crit = panel.alert.crit; + var warn = panel.alert.warn; var critEdge = Infinity; var warnEdge = crit.value; diff --git a/public/app/plugins/panel/graph/partials/tab_alerting.html b/public/app/plugins/panel/graph/partials/tab_alerting.html index c07886aeddf..3cbc6042a88 100644 --- a/public/app/plugins/panel/graph/partials/tab_alerting.html +++ b/public/app/plugins/panel/graph/partials/tab_alerting.html @@ -8,16 +8,16 @@ Critcal if - - + +
Warn if - - + +
@@ -70,16 +70,16 @@ Critcal if - - + +
Warn if - - + +
diff --git a/public/app/plugins/panel/graph/thresholds.ts b/public/app/plugins/panel/graph/thresholds.ts index 1630b2a29d8..ee413fd990f 100644 --- a/public/app/plugins/panel/graph/thresholds.ts +++ b/public/app/plugins/panel/graph/thresholds.ts @@ -8,10 +8,10 @@ export class ThresholdControls { plot: any; placeholder: any; height: any; - thresholds: any; + alert: any; constructor(private panelCtrl) { - this.thresholds = this.panelCtrl.panel.alert.thresholds; + this.alert = this.panelCtrl.panel.alert; } getHandleInnerHtml(type, op, value) { @@ -120,10 +120,8 @@ export class ThresholdControls { this.placeholder = plot.getPlaceholder(); this.height = plot.height(); - this.renderHandle('crit', this.thresholds.crit, 10); - this.renderHandle('warn', this.thresholds.warn, this.height-30); + this.renderHandle('crit', this.alert.crit, 10); + this.renderHandle('warn', this.alert.warn, this.height-30); } - debugger; - }