Skip to content

Commit f03e829

Browse files
committed
feat(alerting): progress on threshold unification
1 parent ed7a539 commit f03e829

File tree

4 files changed

+24
-46
lines changed

4 files changed

+24
-46
lines changed

public/app/plugins/panel/graph/alert_tab_ctrl.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,20 @@ export class AlertTabCtrl {
6262
});
6363
}
6464

65-
getThresholdWithDefaults(thresholds, type, copyFrom) {
65+
getThresholdWithDefaults(thresholds, type) {
6666
var threshold = thresholds[type] || {};
67-
var defaultValue = (copyFrom[type] || {}).value || undefined;
68-
6967
threshold.op = threshold.op || '>';
70-
threshold.value = threshold.value || defaultValue;
68+
threshold.value = threshold.value || undefined;
7169
return threshold;
7270
}
7371

74-
initThresholdsOnlyMode() {
75-
if (!this.panel.thresholds) {
76-
return;
77-
}
78-
79-
this.thresholds = this.panel.thresholds;
80-
81-
// set threshold defaults
82-
this.thresholds.warn = this.getThresholdWithDefaults(this.thresholds, 'warn', {});
83-
this.thresholds.crit = this.getThresholdWithDefaults(this.thresholds, 'crit', {});
84-
85-
this.panelCtrl.editingAlert = true;
86-
this.panelCtrl.render();
87-
}
88-
8972
initModel() {
9073
var alert = this.alert = this.panel.alert = this.panel.alert || {};
9174

9275
// set threshold defaults
9376
alert.thresholds = alert.thresholds || {};
94-
alert.thresholds.warn = this.getThresholdWithDefaults(alert.thresholds, 'warn', this.panel.thresholds);
95-
alert.thresholds.crit = this.getThresholdWithDefaults(alert.thresholds, 'crit', this.panel.thresholds);
77+
alert.thresholds.warn = this.getThresholdWithDefaults(alert.thresholds, 'warn');
78+
alert.thresholds.crit = this.getThresholdWithDefaults(alert.thresholds, 'crit');
9679

9780
alert.frequency = alert.frequency || '60s';
9881
alert.handler = alert.handler || 1;
@@ -150,21 +133,18 @@ export class AlertTabCtrl {
150133
}
151134

152135
delete() {
153-
delete this.alert;
154-
delete this.panel.alert;
155-
// clear thresholds
156-
if (this.panel.thresholds) {
157-
this.panel.thresholds = {};
158-
}
136+
// keep threshold object (instance used by graph handles)
137+
var thresholds = this.alert.thresholds;
138+
thresholds.warn.value = undefined;
139+
thresholds.crit.value = undefined;
140+
141+
// reset model but keep thresholds instance
142+
this.alert = this.panel.alert = {thresholds: thresholds};
159143
this.initModel();
160144
}
161145

162146
enable() {
163-
if (this.thresholds) {
164-
delete this.thresholds;
165-
this.panelCtrl.
166-
}
167-
this.panel.alert = {};
147+
this.alert.enabled = true;
168148
this.initModel();
169149
}
170150

public/app/plugins/panel/graph/graph.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,11 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) {
333333
}
334334

335335
function addGridThresholds(options, panel) {
336-
var thresholds = panel.thresholds;
337-
338-
// use alert thresholds if there are any
339-
if (panel.alert) {
340-
thresholds = panel.alert.thresholds;
336+
if (!panel.alert || !panel.alert.thresholds) {
337+
return;
341338
}
342339

340+
var thresholds = panel.alert.thresholds;
343341
var crit = thresholds.crit;
344342
var warn = thresholds.warn;
345343
var critEdge = Infinity;

public/app/plugins/panel/graph/partials/tab_alerting.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<div ng-if="ctrl.thresholds">
2+
<div ng-if="!ctrl.alert.enabled">
33
<div class="gf-form-group">
44
<h5 class="section-heading">Visual Thresholds</h5>
55
<div class="gf-form-inline">
@@ -8,22 +8,22 @@ <h5 class="section-heading">Visual Thresholds</h5>
88
<i class="icon-gf icon-gf-warn alert-icon-critical"></i>
99
Critcal if
1010
</span>
11-
<metric-segment-model property="ctrl.thresholds.crit.op" options="ctrl.operatorList" custom="false" css-class="query-segment-operator" on-change="ctrl.thresholdsUpdated()"></metric-segment-model>
12-
<input class="gf-form-input max-width-7" type="number" ng-model="ctrl.thresholds.crit.value" ng-change="ctrl.thresholdsUpdated()"></input>
11+
<metric-segment-model property="ctrl.alert.thresholds.crit.op" options="ctrl.operatorList" custom="false" css-class="query-segment-operator" on-change="ctrl.thresholdsUpdated()"></metric-segment-model>
12+
<input class="gf-form-input max-width-7" type="number" ng-model="ctrl.alert.thresholds.crit.value" ng-change="ctrl.thresholdsUpdated()"></input>
1313
</div>
1414
<div class="gf-form">
1515
<span class="gf-form-label">
1616
<i class="icon-gf icon-gf-warn alert-icon-warn"></i>
1717
Warn if
1818
</span>
19-
<metric-segment-model property="ctrl.thresholds.warn.op" options="ctrl.operatorList" custom="false" css-class="query-segment-operator" on-change="ctrl.thresholdsUpdated()"></metric-segment-model>
20-
<input class="gf-form-input max-width-7" type="number" ng-model="ctrl.thresholds.warn.value" ng-change="ctrl.thresholdsUpdated()"></input>
19+
<metric-segment-model property="ctrl.alert.thresholds.warn.op" options="ctrl.operatorList" custom="false" css-class="query-segment-operator" on-change="ctrl.thresholdsUpdated()"></metric-segment-model>
20+
<input class="gf-form-input max-width-7" type="number" ng-model="ctrl.alert.thresholds.warn.value" ng-change="ctrl.thresholdsUpdated()"></input>
2121
</div>
2222
</div>
2323
</div>
2424
</div>
2525

26-
<div ng-if="ctrl.alert">
26+
<div ng-if="ctrl.alert.enabled">
2727
<div class="editor-row">
2828
<div class="gf-form-group section" >
2929
<h5 class="section-heading">Alert Query</h5>
@@ -135,8 +135,8 @@ <h5 class="section-heading">Information</h5>
135135

136136
<div class="editor-row">
137137
<div class="gf-form-button-row">
138-
<button class="btn btn-danger" ng-click="ctrl.delete()" ng-show="ctrl.alert">Delete</button>
139-
<button class="btn btn-inverse" ng-click="ctrl.enable()" ng-hide="ctrl.alert">
138+
<button class="btn btn-danger" ng-click="ctrl.delete()" ng-show="ctrl.alert.enabled">Delete</button>
139+
<button class="btn btn-inverse" ng-click="ctrl.enable()" ng-hide="ctrl.alert.enabled">
140140
<i class="icon-gf icon-gf-alert"></i>
141141
Create Alert
142142
</button>

public/app/plugins/panel/graph/thresholds.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ThresholdControls {
1111
thresholds: any;
1212

1313
constructor(private panelCtrl) {
14-
this.thresholds = this.panelCtrl.thresholds;
14+
this.thresholds = this.panelCtrl.panel.alert.thresholds;
1515
}
1616

1717
getHandleInnerHtml(type, op, value) {

0 commit comments

Comments
 (0)