From 7c09a140c7e59a1739339932d663130a44ec7686 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 20 Jun 2016 10:06:18 +0200 Subject: [PATCH] test(alerting): fixes broken tests for alerting thresholds --- public/app/plugins/panel/graph/graph.js | 10 +- public/app/plugins/panel/graph/module.ts | 8 +- .../plugins/panel/graph/specs/graph_specs.ts | 96 ++++++++++++++----- 3 files changed, 82 insertions(+), 32 deletions(-) diff --git a/public/app/plugins/panel/graph/graph.js b/public/app/plugins/panel/graph/graph.js index 6c59bd63cea..109a85f6957 100755 --- a/public/app/plugins/panel/graph/graph.js +++ b/public/app/plugins/panel/graph/graph.js @@ -340,7 +340,6 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) { var crit = panel.alert.crit; var warn = panel.alert.warn; var critEdge = Infinity; - var warnEdge = crit.value; if (_.isNumber(crit.value)) { if (crit.op === '<') { @@ -361,8 +360,13 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholds) { } if (_.isNumber(warn.value)) { - // if (warn.op === '<') { - // } + //var warnEdge = crit.value || Infinity; + var warnEdge; + if (crit.value) { + warnEdge = crit.value; + } else { + warnEdge = warn.op === '<' ? -Infinity : Infinity; + } // fill options.grid.markings.push({ diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 88446ceb70e..a165589a8c5 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -54,9 +54,9 @@ class GraphCtrl extends MetricsPanelCtrl { xaxis: { show: true }, - thresholds: { - warn: {op: '>', level: undefined}, - crit: {op: '>', level: undefined}, + alert: { + warn: {op: '>', value: undefined}, + crit: {op: '>', value: undefined}, }, // show/hide lines lines : true, @@ -113,7 +113,7 @@ class GraphCtrl extends MetricsPanelCtrl { _.defaults(this.panel, this.panelDefaults); _.defaults(this.panel.tooltip, this.panelDefaults.tooltip); - _.defaults(this.panel.thresholds, this.panelDefaults.thresholds); + _.defaults(this.panel.alert, this.panelDefaults.alert); _.defaults(this.panel.legend, this.panelDefaults.legend); this.colors = $scope.$root.colors; diff --git a/public/app/plugins/panel/graph/specs/graph_specs.ts b/public/app/plugins/panel/graph/specs/graph_specs.ts index b9c9362e5de..e2631ea35d0 100644 --- a/public/app/plugins/panel/graph/specs/graph_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_specs.ts @@ -113,55 +113,101 @@ describe('grafanaGraph', function() { graphScenario('grid thresholds 100, 200', function(ctx) { ctx.setup(function(ctrl) { - ctrl.panel.grid = { - threshold1: 100, - threshold1Color: "#111", - threshold2: 200, - threshold2Color: "#222", + ctrl.panel.alert = { + warn: { op: ">", value: 100}, + crit: { op: ">", value: 200} }; }); - it('should add grid markings', function() { + it('should add crit fill', function() { var markings = ctx.plotOptions.grid.markings; - expect(markings[0].yaxis.from).to.be(100); - expect(markings[0].yaxis.to).to.be(200); - expect(markings[0].color).to.be('#111'); + + expect(markings[0].yaxis.from).to.be(200); + expect(markings[0].yaxis.to).to.be(Infinity); + expect(markings[0].color).to.be('rgba(234, 112, 112, 0.10)'); + }); + + it('should add crit line', function() { + var markings = ctx.plotOptions.grid.markings; + expect(markings[1].yaxis.from).to.be(200); - expect(markings[1].yaxis.to).to.be(Infinity); + expect(markings[1].yaxis.to).to.be(200); + expect(markings[1].color).to.be('#ed2e18'); + }); + + it('should add warn fill', function() { + var markings = ctx.plotOptions.grid.markings; + + expect(markings[2].yaxis.from).to.be(100); + expect(markings[2].yaxis.to).to.be(200); + expect(markings[2].color).to.be('rgba(216, 200, 27, 0.10)'); + }); + + it('should add warn line', function() { + var markings = ctx.plotOptions.grid.markings; + expect(markings[3].yaxis.from).to.be(100); + expect(markings[3].yaxis.to).to.be(100); + expect(markings[3].color).to.be('#F79520'); }); }); graphScenario('inverted grid thresholds 200, 100', function(ctx) { ctx.setup(function(ctrl) { - ctrl.panel.grid = { - threshold1: 200, - threshold1Color: "#111", - threshold2: 100, - threshold2Color: "#222", + ctrl.panel.alert = { + warn: { op: "<", value: 200}, + crit: { op: "<", value: 100} }; }); - it('should add grid markings', function() { + it('should add crit fill', function() { + var markings = ctx.plotOptions.grid.markings; + expect(markings[0].yaxis.from).to.be(100); + expect(markings[0].yaxis.to).to.be(-Infinity); + expect(markings[0].color).to.be('rgba(234, 112, 112, 0.10)'); + }); + + it('should add crit line', function() { var markings = ctx.plotOptions.grid.markings; - expect(markings[0].yaxis.from).to.be(200); - expect(markings[0].yaxis.to).to.be(100); - expect(markings[0].color).to.be('#111'); expect(markings[1].yaxis.from).to.be(100); - expect(markings[1].yaxis.to).to.be(-Infinity); + expect(markings[1].yaxis.to).to.be(100); + expect(markings[1].color).to.be('#ed2e18'); + }); + + it('should add warn fill', function() { + var markings = ctx.plotOptions.grid.markings; + expect(markings[2].yaxis.from).to.be(200); + expect(markings[2].yaxis.to).to.be(100); + expect(markings[2].color).to.be('rgba(216, 200, 27, 0.10)'); + }); + + it('should add warn line', function() { + var markings = ctx.plotOptions.grid.markings; + expect(markings[3].yaxis.from).to.be(200); + expect(markings[3].yaxis.to).to.be(200); + expect(markings[3].color).to.be('#F79520'); }); }); - graphScenario('grid thresholds from zero', function(ctx) { + graphScenario('grid warn thresholds from zero', function(ctx) { ctx.setup(function(ctrl) { - ctrl.panel.grid = { - threshold1: 0, - threshold1Color: "#111", + ctrl.panel.alert = { + warn: { op: ">", value: 0}, + crit: { op: ">", value: undefined} }; }); - it('should add grid markings', function() { + it('should add warn fill', function() { var markings = ctx.plotOptions.grid.markings; expect(markings[0].yaxis.from).to.be(0); + expect(markings[0].yaxis.to).to.be(Infinity); + expect(markings[0].color).to.be('rgba(216, 200, 27, 0.10)'); + }); + + it('should add warn line', function() { + var markings = ctx.plotOptions.grid.markings; + expect(markings[1].yaxis.from).to.be(0); + expect(markings[1].yaxis.to).to.be(0); + expect(markings[1].color).to.be('#F79520'); }); });