Skip to content

Commit 7c09a14

Browse files
committed
test(alerting): fixes broken tests for alerting thresholds
1 parent c961082 commit 7c09a14

File tree

3 files changed

+82
-32
lines changed

3 files changed

+82
-32
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) {
340340
var crit = panel.alert.crit;
341341
var warn = panel.alert.warn;
342342
var critEdge = Infinity;
343-
var warnEdge = crit.value;
344343

345344
if (_.isNumber(crit.value)) {
346345
if (crit.op === '<') {
@@ -361,8 +360,13 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) {
361360
}
362361

363362
if (_.isNumber(warn.value)) {
364-
// if (warn.op === '<') {
365-
// }
363+
//var warnEdge = crit.value || Infinity;
364+
var warnEdge;
365+
if (crit.value) {
366+
warnEdge = crit.value;
367+
} else {
368+
warnEdge = warn.op === '<' ? -Infinity : Infinity;
369+
}
366370

367371
// fill
368372
options.grid.markings.push({

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ class GraphCtrl extends MetricsPanelCtrl {
5454
xaxis: {
5555
show: true
5656
},
57-
thresholds: {
58-
warn: {op: '>', level: undefined},
59-
crit: {op: '>', level: undefined},
57+
alert: {
58+
warn: {op: '>', value: undefined},
59+
crit: {op: '>', value: undefined},
6060
},
6161
// show/hide lines
6262
lines : true,
@@ -113,7 +113,7 @@ class GraphCtrl extends MetricsPanelCtrl {
113113

114114
_.defaults(this.panel, this.panelDefaults);
115115
_.defaults(this.panel.tooltip, this.panelDefaults.tooltip);
116-
_.defaults(this.panel.thresholds, this.panelDefaults.thresholds);
116+
_.defaults(this.panel.alert, this.panelDefaults.alert);
117117
_.defaults(this.panel.legend, this.panelDefaults.legend);
118118

119119
this.colors = $scope.$root.colors;

public/app/plugins/panel/graph/specs/graph_specs.ts

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -113,55 +113,101 @@ describe('grafanaGraph', function() {
113113

114114
graphScenario('grid thresholds 100, 200', function(ctx) {
115115
ctx.setup(function(ctrl) {
116-
ctrl.panel.grid = {
117-
threshold1: 100,
118-
threshold1Color: "#111",
119-
threshold2: 200,
120-
threshold2Color: "#222",
116+
ctrl.panel.alert = {
117+
warn: { op: ">", value: 100},
118+
crit: { op: ">", value: 200}
121119
};
122120
});
123121

124-
it('should add grid markings', function() {
122+
it('should add crit fill', function() {
125123
var markings = ctx.plotOptions.grid.markings;
126-
expect(markings[0].yaxis.from).to.be(100);
127-
expect(markings[0].yaxis.to).to.be(200);
128-
expect(markings[0].color).to.be('#111');
124+
125+
expect(markings[0].yaxis.from).to.be(200);
126+
expect(markings[0].yaxis.to).to.be(Infinity);
127+
expect(markings[0].color).to.be('rgba(234, 112, 112, 0.10)');
128+
});
129+
130+
it('should add crit line', function() {
131+
var markings = ctx.plotOptions.grid.markings;
132+
129133
expect(markings[1].yaxis.from).to.be(200);
130-
expect(markings[1].yaxis.to).to.be(Infinity);
134+
expect(markings[1].yaxis.to).to.be(200);
135+
expect(markings[1].color).to.be('#ed2e18');
136+
});
137+
138+
it('should add warn fill', function() {
139+
var markings = ctx.plotOptions.grid.markings;
140+
141+
expect(markings[2].yaxis.from).to.be(100);
142+
expect(markings[2].yaxis.to).to.be(200);
143+
expect(markings[2].color).to.be('rgba(216, 200, 27, 0.10)');
144+
});
145+
146+
it('should add warn line', function() {
147+
var markings = ctx.plotOptions.grid.markings;
148+
expect(markings[3].yaxis.from).to.be(100);
149+
expect(markings[3].yaxis.to).to.be(100);
150+
expect(markings[3].color).to.be('#F79520');
131151
});
132152
});
133153

134154
graphScenario('inverted grid thresholds 200, 100', function(ctx) {
135155
ctx.setup(function(ctrl) {
136-
ctrl.panel.grid = {
137-
threshold1: 200,
138-
threshold1Color: "#111",
139-
threshold2: 100,
140-
threshold2Color: "#222",
156+
ctrl.panel.alert = {
157+
warn: { op: "<", value: 200},
158+
crit: { op: "<", value: 100}
141159
};
142160
});
143161

144-
it('should add grid markings', function() {
162+
it('should add crit fill', function() {
163+
var markings = ctx.plotOptions.grid.markings;
164+
expect(markings[0].yaxis.from).to.be(100);
165+
expect(markings[0].yaxis.to).to.be(-Infinity);
166+
expect(markings[0].color).to.be('rgba(234, 112, 112, 0.10)');
167+
});
168+
169+
it('should add crit line', function() {
145170
var markings = ctx.plotOptions.grid.markings;
146-
expect(markings[0].yaxis.from).to.be(200);
147-
expect(markings[0].yaxis.to).to.be(100);
148-
expect(markings[0].color).to.be('#111');
149171
expect(markings[1].yaxis.from).to.be(100);
150-
expect(markings[1].yaxis.to).to.be(-Infinity);
172+
expect(markings[1].yaxis.to).to.be(100);
173+
expect(markings[1].color).to.be('#ed2e18');
174+
});
175+
176+
it('should add warn fill', function() {
177+
var markings = ctx.plotOptions.grid.markings;
178+
expect(markings[2].yaxis.from).to.be(200);
179+
expect(markings[2].yaxis.to).to.be(100);
180+
expect(markings[2].color).to.be('rgba(216, 200, 27, 0.10)');
181+
});
182+
183+
it('should add warn line', function() {
184+
var markings = ctx.plotOptions.grid.markings;
185+
expect(markings[3].yaxis.from).to.be(200);
186+
expect(markings[3].yaxis.to).to.be(200);
187+
expect(markings[3].color).to.be('#F79520');
151188
});
152189
});
153190

154-
graphScenario('grid thresholds from zero', function(ctx) {
191+
graphScenario('grid warn thresholds from zero', function(ctx) {
155192
ctx.setup(function(ctrl) {
156-
ctrl.panel.grid = {
157-
threshold1: 0,
158-
threshold1Color: "#111",
193+
ctrl.panel.alert = {
194+
warn: { op: ">", value: 0},
195+
crit: { op: ">", value: undefined}
159196
};
160197
});
161198

162-
it('should add grid markings', function() {
199+
it('should add warn fill', function() {
163200
var markings = ctx.plotOptions.grid.markings;
164201
expect(markings[0].yaxis.from).to.be(0);
202+
expect(markings[0].yaxis.to).to.be(Infinity);
203+
expect(markings[0].color).to.be('rgba(216, 200, 27, 0.10)');
204+
});
205+
206+
it('should add warn line', function() {
207+
var markings = ctx.plotOptions.grid.markings;
208+
expect(markings[1].yaxis.from).to.be(0);
209+
expect(markings[1].yaxis.to).to.be(0);
210+
expect(markings[1].color).to.be('#F79520');
165211
});
166212
});
167213

0 commit comments

Comments
 (0)