From dfd1d09641cb67afe99ec8de7c811fcde2d40e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sat, 22 Mar 2014 13:45:02 +0100 Subject: [PATCH 1/9] added unit tests for filterSrv --- src/app/services/datasourceSrv.js | 2 - src/app/services/filterSrv.js | 13 +++-- src/test/karma.conf.js | 3 +- src/test/mocks/dashboard-mock.js | 40 +++++++++++++++ src/test/specs/ctrl-specs.js | 26 ---------- src/test/specs/filterSrv-specs.js | 60 ++++++++++++++++++++++ src/test/specs/graphiteTargetCtrl-specs.js | 60 ++++++++++++++++++++++ src/test/test-main.js | 25 ++++++--- 8 files changed, 185 insertions(+), 44 deletions(-) create mode 100644 src/test/mocks/dashboard-mock.js delete mode 100644 src/test/specs/ctrl-specs.js create mode 100644 src/test/specs/filterSrv-specs.js create mode 100644 src/test/specs/graphiteTargetCtrl-specs.js diff --git a/src/app/services/datasourceSrv.js b/src/app/services/datasourceSrv.js index d05bd11e278..77f0f9f1142 100644 --- a/src/app/services/datasourceSrv.js +++ b/src/app/services/datasourceSrv.js @@ -13,10 +13,8 @@ function (angular, _, config) { module.service('datasourceSrv', function($q, filterSrv, $http, GraphiteDatasource, InfluxDatasource) { this.init = function() { - var defaultDatasource = _.findWhere(_.values(config.datasources), { default: true } ); this.default = this.datasourceFactory(defaultDatasource); - }; this.datasourceFactory = function(ds) { diff --git a/src/app/services/filterSrv.js b/src/app/services/filterSrv.js index c62015a6927..aeb2ef71344 100644 --- a/src/app/services/filterSrv.js +++ b/src/app/services/filterSrv.js @@ -32,12 +32,12 @@ define([ }; if (self.list.length) { - this.updateTemplateData(true); + this._updateTemplateData(true); } }; - this.updateTemplateData = function(initial) { - self.filterTemplateData = {}; + this._updateTemplateData = function(initial) { + self._filterTemplateData = {}; _.each(self.list, function(filter) { if (initial) { @@ -46,18 +46,17 @@ define([ filter.current = { text: urlValue, value: urlValue }; } } - if (!filter.current || !filter.current.value) { return; } - self.filterTemplateData[filter.name] = filter.current.value; + self._filterTemplateData[filter.name] = filter.current.value; }); }; this.filterOptionSelected = function(filter, option) { filter.current = option; - this.updateTemplateData(); + this._updateTemplateData(); dashboard.refresh(); }; @@ -70,7 +69,7 @@ define([ return target; } - return _.template(target, self.filterTemplateData, self.templateSettings); + return _.template(target, self._filterTemplateData, self.templateSettings); }; this.remove = function(filter) { diff --git a/src/test/karma.conf.js b/src/test/karma.conf.js index 765511a30ff..10547493cfa 100644 --- a/src/test/karma.conf.js +++ b/src/test/karma.conf.js @@ -14,8 +14,7 @@ module.exports = function(config) { ], // list of files to exclude - exclude: [ - ], + exclude: [], reporters: ['progress'], port: 9876, diff --git a/src/test/mocks/dashboard-mock.js b/src/test/mocks/dashboard-mock.js new file mode 100644 index 00000000000..64294f98848 --- /dev/null +++ b/src/test/mocks/dashboard-mock.js @@ -0,0 +1,40 @@ +define([], + function() { + + return { + create: function() { + return { + refresh: function() {}, + + current: { + title: "", + tags: [], + style: "dark", + timezone: 'browser', + editable: true, + failover: false, + panel_hints: true, + rows: [], + pulldowns: [ { type: 'templating' }, { type: 'annotations' } ], + nav: [ { type: 'timepicker' } ], + services: {}, + loader: { + save_gist: false, + save_elasticsearch: true, + save_local: true, + save_default: true, + save_temp: true, + save_temp_ttl_enable: true, + save_temp_ttl: '30d', + load_gist: false, + load_elasticsearch: true, + load_elasticsearch_size: 20, + load_local: false, + hide: false + }, + refresh: false + } + } + } + } +}); diff --git a/src/test/specs/ctrl-specs.js b/src/test/specs/ctrl-specs.js deleted file mode 100644 index 2bd2f21d79c..00000000000 --- a/src/test/specs/ctrl-specs.js +++ /dev/null @@ -1,26 +0,0 @@ -define([ - 'angular', - 'angularMocks', - 'panels/graphite/module' -], function(angular) { - - /* describe('controller', function() { - var scope, metricCtrl; - - beforeEach(function() { - angular.mock.inject(function($rootScope, $controller) { - scope = $rootScope.$new(); - metricCtrl = $controller('kibana.panels.graphite.graphite', { - $scope: scope - }); - }); - }); - - it('should work', function() { - metricCtrl.toggleYAxis({alias:'myAlias'}); - scope.panel.aliasYAxis['myAlias'].should.be(2); - }); - - });*/ - -}); diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js new file mode 100644 index 00000000000..f4a38065abd --- /dev/null +++ b/src/test/specs/filterSrv-specs.js @@ -0,0 +1,60 @@ +define([ + 'mocks/dashboard-mock', + 'underscore', + 'services/filterSrv' +], function(dashboardMock, _) { + + describe('filterSrv', function() { + var _filterSrv; + + beforeEach(module('kibana.services')); + beforeEach(module(function($provide){ + $provide.value('dashboard', dashboardMock.create()); + })); + + beforeEach(inject(function(filterSrv) { + _filterSrv = filterSrv; + })); + + describe('init', function() { + beforeEach(function() { + _filterSrv.add({ name: 'test', current: { value: 'oogle' } }); + _filterSrv.init(); + }); + + it('should initialize template data', function() { + var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); + expect(target).to.be('this.oogle.filters'); + }); + }); + + describe.only('filterOptionSelected', function() { + beforeEach(function() { + _filterSrv.add({ name: 'test' }); + _filterSrv.filterOptionSelected(_filterSrv.list[0], { value: 'muuuu' }); + }); + it('should set current value and update template data', function() { + var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); + expect(target).to.be('this.muuuu.filters'); + }); + }); + + describe('timeRange', function() { + it('should return unparsed when parse is false', function() { + _filterSrv.setTime({from: 'now', to: 'now-1h' }); + var time = _filterSrv.timeRange(false); + expect(time.from).to.be('now'); + expect(time.to).to.be('now-1h'); + }); + + it('should return parsed when parse is true', function() { + _filterSrv.setTime({from: 'now', to: 'now-1h' }); + var time = _filterSrv.timeRange(true); + expect(_.isDate(time.from)).to.be(true); + expect(_.isDate(time.to)).to.be(true); + }); + }); + + }); + +}); diff --git a/src/test/specs/graphiteTargetCtrl-specs.js b/src/test/specs/graphiteTargetCtrl-specs.js new file mode 100644 index 00000000000..f4a38065abd --- /dev/null +++ b/src/test/specs/graphiteTargetCtrl-specs.js @@ -0,0 +1,60 @@ +define([ + 'mocks/dashboard-mock', + 'underscore', + 'services/filterSrv' +], function(dashboardMock, _) { + + describe('filterSrv', function() { + var _filterSrv; + + beforeEach(module('kibana.services')); + beforeEach(module(function($provide){ + $provide.value('dashboard', dashboardMock.create()); + })); + + beforeEach(inject(function(filterSrv) { + _filterSrv = filterSrv; + })); + + describe('init', function() { + beforeEach(function() { + _filterSrv.add({ name: 'test', current: { value: 'oogle' } }); + _filterSrv.init(); + }); + + it('should initialize template data', function() { + var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); + expect(target).to.be('this.oogle.filters'); + }); + }); + + describe.only('filterOptionSelected', function() { + beforeEach(function() { + _filterSrv.add({ name: 'test' }); + _filterSrv.filterOptionSelected(_filterSrv.list[0], { value: 'muuuu' }); + }); + it('should set current value and update template data', function() { + var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); + expect(target).to.be('this.muuuu.filters'); + }); + }); + + describe('timeRange', function() { + it('should return unparsed when parse is false', function() { + _filterSrv.setTime({from: 'now', to: 'now-1h' }); + var time = _filterSrv.timeRange(false); + expect(time.from).to.be('now'); + expect(time.to).to.be('now-1h'); + }); + + it('should return parsed when parse is true', function() { + _filterSrv.setTime({from: 'now', to: 'now-1h' }); + var time = _filterSrv.timeRange(true); + expect(_.isDate(time.from)).to.be(true); + expect(_.isDate(time.to)).to.be(true); + }); + }); + + }); + +}); diff --git a/src/test/test-main.js b/src/test/test-main.js index 4042c0e186e..ec18e3877d3 100644 --- a/src/test/test-main.js +++ b/src/test/test-main.js @@ -3,6 +3,7 @@ require.config({ paths: { specs: '../test/specs', + mocks: '../test/mocks', config: '../config.sample', kbn: 'components/kbn', @@ -102,10 +103,20 @@ require.config({ }); require([ - 'specs/lexer-specs', - 'specs/parser-specs', - 'specs/gfunc-specs', - 'specs/ctrl-specs', -], function () { - window.__karma__.start(); -}); \ No newline at end of file + 'angular', + 'angularMocks', +], function(angular) { + + angular.module('kibana', []); + angular.module('kibana.services', []); + + require([ + 'specs/lexer-specs', + 'specs/parser-specs', + 'specs/gfunc-specs', + 'specs/filterSrv-specs', + ], function () { + window.__karma__.start(); + }); + +}); From 06fe57211391b30f446e43241097554b8d5a6b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 23 Mar 2014 07:03:25 +0100 Subject: [PATCH 2/9] more work on filterSrv unit tests --- src/test/specs/filterSrv-specs.js | 2 +- src/test/specs/graphiteTargetCtrl-specs.js | 37 +--------------------- tasks/options/karma.js | 7 +++- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/src/test/specs/filterSrv-specs.js b/src/test/specs/filterSrv-specs.js index f4a38065abd..bfd5faf3329 100644 --- a/src/test/specs/filterSrv-specs.js +++ b/src/test/specs/filterSrv-specs.js @@ -28,7 +28,7 @@ define([ }); }); - describe.only('filterOptionSelected', function() { + describe('filterOptionSelected', function() { beforeEach(function() { _filterSrv.add({ name: 'test' }); _filterSrv.filterOptionSelected(_filterSrv.list[0], { value: 'muuuu' }); diff --git a/src/test/specs/graphiteTargetCtrl-specs.js b/src/test/specs/graphiteTargetCtrl-specs.js index f4a38065abd..8516438a210 100644 --- a/src/test/specs/graphiteTargetCtrl-specs.js +++ b/src/test/specs/graphiteTargetCtrl-specs.js @@ -4,7 +4,7 @@ define([ 'services/filterSrv' ], function(dashboardMock, _) { - describe('filterSrv', function() { + describe('graphiteTargetCtrl', function() { var _filterSrv; beforeEach(module('kibana.services')); @@ -21,40 +21,5 @@ define([ _filterSrv.add({ name: 'test', current: { value: 'oogle' } }); _filterSrv.init(); }); - - it('should initialize template data', function() { - var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); - expect(target).to.be('this.oogle.filters'); - }); }); - - describe.only('filterOptionSelected', function() { - beforeEach(function() { - _filterSrv.add({ name: 'test' }); - _filterSrv.filterOptionSelected(_filterSrv.list[0], { value: 'muuuu' }); - }); - it('should set current value and update template data', function() { - var target = _filterSrv.applyFilterToTarget('this.[[test]].filters'); - expect(target).to.be('this.muuuu.filters'); - }); - }); - - describe('timeRange', function() { - it('should return unparsed when parse is false', function() { - _filterSrv.setTime({from: 'now', to: 'now-1h' }); - var time = _filterSrv.timeRange(false); - expect(time.from).to.be('now'); - expect(time.to).to.be('now-1h'); - }); - - it('should return parsed when parse is true', function() { - _filterSrv.setTime({from: 'now', to: 'now-1h' }); - var time = _filterSrv.timeRange(true); - expect(_.isDate(time.from)).to.be(true); - expect(_.isDate(time.to)).to.be(true); - }); - }); - - }); - }); diff --git a/tasks/options/karma.js b/tasks/options/karma.js index 39f93b5be08..67fce60144e 100644 --- a/tasks/options/karma.js +++ b/tasks/options/karma.js @@ -3,6 +3,11 @@ module.exports = function(config) { dev: { configFile: 'src/test/karma.conf.js', singleRun: false, + browsers: ['PhantomJS'] + }, + debug: { + configFile: 'src/test/karma.conf.js', + singleRun: true, browsers: ['Chrome'] }, test: { @@ -11,4 +16,4 @@ module.exports = function(config) { browsers: ['PhantomJS'] } }; -}; \ No newline at end of file +}; From 69b91892204c96589e2b411c575ab4c8bf682214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 23 Mar 2014 16:04:21 +0100 Subject: [PATCH 3/9] fixed build issues with last commit (spec file syntax error) --- src/test/specs/graphiteTargetCtrl-specs.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/specs/graphiteTargetCtrl-specs.js b/src/test/specs/graphiteTargetCtrl-specs.js index 8516438a210..1265c933723 100644 --- a/src/test/specs/graphiteTargetCtrl-specs.js +++ b/src/test/specs/graphiteTargetCtrl-specs.js @@ -9,11 +9,13 @@ define([ beforeEach(module('kibana.services')); beforeEach(module(function($provide){ - $provide.value('dashboard', dashboardMock.create()); + $provide.value('filterSrv',{}); })); - beforeEach(inject(function(filterSrv) { - _filterSrv = filterSrv; + beforeEach(inject(function($controller, $rootScope) { + _targetCtrl = $controller({ + $scope: $rootScope.$new() + }); })); describe('init', function() { @@ -22,4 +24,5 @@ define([ _filterSrv.init(); }); }); + }); }); From f35baffbef2ade738885e98b3a3725df56294f31 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 23 Mar 2014 18:52:56 +0100 Subject: [PATCH 4/9] Added more query function in InfluxDB --- src/app/partials/influxdb/editor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index 4a6927e5984..2210aa140ce 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -74,7 +74,7 @@ function
  • - +
  • group by time From 6fb36acc9a668cfc19e7680c3e158d10492a8082 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Sun, 23 Mar 2014 20:20:18 +0100 Subject: [PATCH 5/9] Moved function definition out of template. --- src/app/controllers/influxTargetCtrl.js | 1 + src/app/partials/influxdb/editor.html | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/controllers/influxTargetCtrl.js b/src/app/controllers/influxTargetCtrl.js index 66439c5e757..5d96a280470 100644 --- a/src/app/controllers/influxTargetCtrl.js +++ b/src/app/controllers/influxTargetCtrl.js @@ -15,6 +15,7 @@ function (angular) { $scope.target.function = 'mean'; } + $scope.functions = ['count', 'mean', 'sum', 'min', 'max', 'mode', 'distinct', 'median', 'derivative', 'stddev', 'first', 'last']; $scope.oldSeries = $scope.target.series; $scope.$on('typeahead-updated', function(){ $timeout($scope.get_data); diff --git a/src/app/partials/influxdb/editor.html b/src/app/partials/influxdb/editor.html index 2210aa140ce..d34d6ab5f9b 100644 --- a/src/app/partials/influxdb/editor.html +++ b/src/app/partials/influxdb/editor.html @@ -74,7 +74,11 @@ function
  • - + +
  • group by time From 6f9c2211fa0f2ee6ed250804903bac03732936db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 24 Mar 2014 09:57:03 +0100 Subject: [PATCH 6/9] aliasByNode support for second node param, Closes #167 --- src/app/directives/graphiteFuncEditor.js | 52 +++++++++++++++++++----- src/app/services/graphite/gfunc.js | 35 ++++++++++++++-- src/test/specs/gfunc-specs.js | 37 ++++++++++++++++- 3 files changed, 108 insertions(+), 16 deletions(-) diff --git a/src/app/directives/graphiteFuncEditor.js b/src/app/directives/graphiteFuncEditor.js index 10516f1ca7c..7767d097c04 100644 --- a/src/app/directives/graphiteFuncEditor.js +++ b/src/app/directives/graphiteFuncEditor.js @@ -29,6 +29,8 @@ function (angular, _, $) { var $funcControls = $(funcControlsTemplate); var func = $scope.func; var funcDef = func.def; + var scheduledRelink = false; + var paramCountAtLink = 0; function clickFuncParam(paramIndex) { /*jshint validthis:true */ @@ -51,17 +53,33 @@ function (angular, _, $) { } } + function scheduledRelinkIfNeeded() { + if (paramCountAtLink === func.params.length) { + return; + } + + if (!scheduledRelink) { + scheduledRelink = true; + setTimeout(function() { + relink(); + scheduledRelink = false; + }, 200); + } + } + function inputBlur(paramIndex) { /*jshint validthis:true */ var $input = $(this); var $link = $input.prev(); - if ($input.val() !== '') { + if ($input.val() !== '' || func.def.params[paramIndex].optional) { $link.text($input.val()); - + func.updateParam($input.val(), paramIndex); - $scope.$apply($scope.targetChanged); + scheduledRelinkIfNeeded(); + + $scope.$apply($scope.targetChanged); } $input.hide(); @@ -129,9 +147,19 @@ function (angular, _, $) { $funcLink.appendTo(elem); _.each(funcDef.params, function(param, index) { + if (param.optional && !func.params[index]) { + return; + } + + if (index > 0) { + $(', ').appendTo(elem); + } + var $paramLink = $('' + func.params[index] + ''); var $input = $(paramTemplate); + paramCountAtLink++; + $paramLink.appendTo(elem); $input.appendTo(elem); @@ -140,10 +168,6 @@ function (angular, _, $) { $input.keypress(_.partial(inputKeyPress, index)); $paramLink.click(_.partial(clickFuncParam, index)); - if (index !== funcDef.params.length - 1) { - $(', ').appendTo(elem); - } - if (funcDef.params[index].options) { addTypeahead($input, index); } @@ -200,10 +224,16 @@ function (angular, _, $) { }); } - addElementsAndCompile(); - ifJustAddedFocusFistParam(); - registerFuncControlsToggle(); - registerFuncControlsActions(); + function relink() { + elem.children().remove(); + + addElementsAndCompile(); + ifJustAddedFocusFistParam(); + registerFuncControlsToggle(); + registerFuncControlsActions(); + } + + relink(); } }; diff --git a/src/app/services/graphite/gfunc.js b/src/app/services/graphite/gfunc.js index 9902e7c15d6..dadfb736e93 100644 --- a/src/app/services/graphite/gfunc.js +++ b/src/app/services/graphite/gfunc.js @@ -132,7 +132,10 @@ function (_) { addFuncDef({ name: 'aliasByNode', category: categories.Special, - params: [ { name: "node", type: "int", options: [0,1,2,3,4,5,6,7,8,9,10,12] } ], + params: [ + { name: "node", type: "int", options: [0,1,2,3,4,5,6,7,8,9,10,12] }, + { name: "node", type: "int", options: [0,-1,-2,-3,-4,-5,-6,-7], optional: true }, + ], defaultParams: [3] }); @@ -340,13 +343,33 @@ function (_) { return str + parameters.join(',') + ')'; }; - FuncInstance.prototype.updateParam = function(strValue, index) { - if (this.def.params[index].type === 'int') { + FuncInstance.prototype._hasMultipleParamsInString = function(strValue, index) { + if (strValue.indexOf(',') === -1) { + return false; + } + + return this.def.params[index + 1] && this.def.params[index + 1].optional; + }; + + FuncInstance.prototype.updateParam = function(strValue, index) { + // handle optional parameters + // if string contains ',' and next param is optional, split and update both + if (this._hasMultipleParamsInString(strValue, index)) { + _.each(strValue.split(','), function(partVal, idx) { + this.updateParam(partVal.trim(), idx); + }, this); + return; + } + + if (strValue === '' && this.def.params[index].optional) { + this.params.splice(index, 1); + } + else if (this.def.params[index].type === 'int') { this.params[index] = parseInt(strValue, 10); } else { this.params[index] = strValue; - } + } this.updateText(); }; @@ -359,6 +382,10 @@ function (_) { var text = this.def.name + '('; _.each(this.def.params, function(param, index) { + if (param.optional && this.params[index] === undefined) { + return; + } + text += this.params[index] + ', '; }, this); text = text.substring(0, text.length - 2); diff --git a/src/test/specs/gfunc-specs.js b/src/test/specs/gfunc-specs.js index b66c05fe08c..942f098fdea 100644 --- a/src/test/specs/gfunc-specs.js +++ b/src/test/specs/gfunc-specs.js @@ -57,12 +57,47 @@ define([ }); describe('when requesting function categories', function() { - it('should return function categories', function() { var catIndex = gfunc.getCategories(); expect(catIndex.Special.length).to.be.greaterThan(8); }); + }); + + describe('when updating func param', function() { + it('should update param value and update text representation', function() { + var func = gfunc.createFuncInstance('summarize'); + func.updateParam('1h', 0); + expect(func.params[0]).to.be('1h'); + expect(func.text).to.be('summarize(1h, sum)'); + }); + }); + describe('when updating func param with optional second parameter', function() { + it('should update value and text', function() { + var func = gfunc.createFuncInstance('aliasByNode'); + func.updateParam('1', 0); + expect(func.params[0]).to.be(1); + }); + + it('should slit text and put value in second param', function() { + var func = gfunc.createFuncInstance('aliasByNode'); + func.updateParam('4,-5', 0); + expect(func.params[0]).to.be(4); + expect(func.params[1]).to.be(-5); + expect(func.text).to.be('aliasByNode(4, -5)'); + }); + + it('should remove second param when empty string is set', function() { + var func = gfunc.createFuncInstance('aliasByNode'); + func.updateParam('4,-5', 0); + func.updateParam('', 1); + expect(func.params[0]).to.be(4); + expect(func.params[1]).to.be(undefined); + expect(func.text).to.be('aliasByNode(4)'); + }); + }); + }); + From 1e79e3916128e7106117efc3366259143bd173c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 24 Mar 2014 12:20:28 +0100 Subject: [PATCH 7/9] Fixes #223, float arguments to functions like scale should now work as expected --- src/app/services/graphite/gfunc.js | 2 +- src/test/specs/gfunc-specs.js | 6 +++++- src/test/specs/lexer-specs.js | 6 ++++++ src/test/specs/parser-specs.js | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/services/graphite/gfunc.js b/src/app/services/graphite/gfunc.js index dadfb736e93..56bb83667f4 100644 --- a/src/app/services/graphite/gfunc.js +++ b/src/app/services/graphite/gfunc.js @@ -365,7 +365,7 @@ function (_) { this.params.splice(index, 1); } else if (this.def.params[index].type === 'int') { - this.params[index] = parseInt(strValue, 10); + this.params[index] = parseFloat(strValue, 10); } else { this.params[index] = strValue; diff --git a/src/test/specs/gfunc-specs.js b/src/test/specs/gfunc-specs.js index 942f098fdea..1e396ae3e6d 100644 --- a/src/test/specs/gfunc-specs.js +++ b/src/test/specs/gfunc-specs.js @@ -71,7 +71,11 @@ define([ expect(func.text).to.be('summarize(1h, sum)'); }); - + it('should parse numbers as float', function() { + var func = gfunc.createFuncInstance('scale'); + func.updateParam('0.001', 0); + expect(func.params[0]).to.be(0.001); + }); }); describe('when updating func param with optional second parameter', function() { diff --git a/src/test/specs/lexer-specs.js b/src/test/specs/lexer-specs.js index 8cdb5531c26..a9cbe089f03 100644 --- a/src/test/specs/lexer-specs.js +++ b/src/test/specs/lexer-specs.js @@ -88,6 +88,12 @@ define([ expect(tokens[4].pos).to.be(20); }); + it('should handle float parameters', function() { + var lexer = new Lexer("alias(metric, 0.002)"); + var tokens = lexer.tokenize(); + expect(tokens[4].type).to.be('number'); + expect(tokens[4].value).to.be('0.002'); + }); }); diff --git a/src/test/specs/parser-specs.js b/src/test/specs/parser-specs.js index 5614fd090da..b705ef68dc9 100644 --- a/src/test/specs/parser-specs.js +++ b/src/test/specs/parser-specs.js @@ -139,6 +139,13 @@ define([ expect(rootNode.type).to.be('function'); }); + it('handle float function arguments', function() { + var parser = new Parser('scale(test, 0.002)'); + var rootNode = parser.getAst(); + expect(rootNode.type).to.be('function'); + expect(rootNode.params[1].type).to.be('number'); + expect(rootNode.params[1].value).to.be(0.002); + }); }); From 94fea502b9acf7a43aa832e6f3db79828cf5a7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 24 Mar 2014 12:51:32 +0100 Subject: [PATCH 8/9] Closes #209, sub folder with project name and version suffix in release zip files --- CHANGELOG.md | 26 ++++++++++++++++++++++++-- package.json | 2 +- tasks/options/compress.js | 8 ++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c0392e55a6..960e8a2db8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ +# 1.5.2 (2013-03-24) +### New Features and improvements +- Support for second optional params for functions like aliasByNode (Issue #167). Read the wiki on the [Function Editor](https://github.com/torkelo/grafana/wiki/Graphite-Function-Editor) for more info. +- More functions added to InfluxDB query editor (Issue #218) +- Filters can now be used inside other filters (templated segments) (Issue #128) +- More graphite functions added + +### Fixes +- Float arguments now work for functions like scale (Issue #223) +- Fix for graphite function editor, the graph & target was not updated after adding a function and leaving default params as is #191 + +The zip files now contains a sub folder with project name and version prefix. (Issue #209) + +# 1.5.1 (2013-03-10) +### Fixes +- maxDataPoints must be an integer #184 (thanks @frejsoya for fixing this) + +For people who are find Grafana slow for large time spans or high resolution metrics. This is most likely due to graphite returning a large number of datapoints. The maxDataPoints parameter solves this issue. For maxDataPoints to work you need to run the latest graphite-web (some builds of 0.9.12 does not include this feature). + +Read this for more info: +[Performance for large time spans](https://github.com/torkelo/grafana/wiki/Performance-for-large-time-spans) + # 1.5.0 (2013-03-09) -###New Features and improvements +### New Features and improvements - New function editor [video demo](http://youtu.be/I90WHRwE1ZM) (Issue #178) - Links to function documentation from function editor (Issue #3) - Reorder functions (Issue #130) @@ -18,7 +40,7 @@ - Fix to annotations with graphite source & null values (Issue #138) # 1.4.0 (2013-02-21) -###New Features +### New Features - #44 Annotations! Required a lot of work to get right. Read wiki article for more info. Supported annotations data sources are graphite metrics and graphite events. Support for more will be added in the future! - #35 Support for multiple graphite servers! (Read wiki article for more) - #116 Back to dashboard link in top menu to easily exist full screen / edit mode. diff --git a/package.json b/package.json index 4bcf2142694..5892cf1b662 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "company": "Coding Instinct AB" }, "name": "grafana", - "version": "1.5.1", + "version": "1.5.2", "repository": { "type": "git", "url": "http://github.com/torkelo/grafana.git" diff --git a/tasks/options/compress.js b/tasks/options/compress.js index e29810f7982..7a03cff052f 100644 --- a/tasks/options/compress.js +++ b/tasks/options/compress.js @@ -9,9 +9,11 @@ module.exports = function(config) { expand: true, cwd: '<%= destDir %>', src: ['**/*'], + dest: '<%= pkg.name %>/', }, { expand: true, + dest: '<%= pkg.name %>/', src: ['LICENSE.md', 'README.md', 'NOTICE.md'], } ] @@ -25,10 +27,12 @@ module.exports = function(config) { expand: true, cwd: '<%= destDir %>', src: ['**/*'], + dest: '<%= pkg.name %>/', }, { expand: true, src: ['LICENSE.md', 'README.md', 'NOTICE.md'], + dest: '<%= pkg.name %>/', } ] }, @@ -41,10 +45,12 @@ module.exports = function(config) { expand: true, cwd: '<%= destDir %>', src: ['**/*'], + dest: '<%= pkg.name %>-<%= pkg.version %>/', }, { expand: true, src: ['LICENSE.md', 'README.md', 'NOTICE.md'], + dest: '<%= pkg.name %>-<%= pkg.version %>/', } ] }, @@ -57,10 +63,12 @@ module.exports = function(config) { expand: true, cwd: '<%= destDir %>', src: ['**/*'], + dest: '<%= pkg.name %>-<%= pkg.version %>/', }, { expand: true, src: ['LICENSE.md', 'README.md', 'NOTICE.md'], + dest: '<%= pkg.name %>-<%= pkg.version %>/', } ] } From ed9e336c51b451f4a3cc500fd203d57fd3ef3b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 24 Mar 2014 13:17:27 +0100 Subject: [PATCH 9/9] Fixes #225, grid min not sent to graphite png renderer when set to 0 --- src/app/directives/grafanaGraph.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/directives/grafanaGraph.js b/src/app/directives/grafanaGraph.js index 3eecd64727d..1e5d20c8f7c 100644 --- a/src/app/directives/grafanaGraph.js +++ b/src/app/directives/grafanaGraph.js @@ -318,7 +318,7 @@ function (angular, $, kbn, moment, _) { } }); - function render_panel_as_graphite_png(url) { + function render_panel_as_graphite_png(url) { url += '&width=' + elem.width(); url += '&height=' + elem.css('height').replace('px', ''); url += '&bgcolor=1f1f1f'; // @grayDarker & @kibanaPanelBackground @@ -327,8 +327,8 @@ function (angular, $, kbn, moment, _) { url += scope.panel.fill !== 0 ? ('&areaAlpha=' + (scope.panel.fill/10).toFixed(1)) : ''; url += scope.panel.linewidth !== 0 ? '&lineWidth=' + scope.panel.linewidth : ''; url += scope.panel.legend ? '' : '&hideLegend=true'; - url += scope.panel.grid.min ? '&yMin=' + scope.panel.grid.min : ''; - url += scope.panel.grid.max ? '&yMax=' + scope.panel.grid.max : ''; + url += scope.panel.grid.min !== null ? '&yMin=' + scope.panel.grid.min : ''; + url += scope.panel.grid.max !== null ? '&yMax=' + scope.panel.grid.max : ''; url += scope.panel['x-axis'] ? '' : '&hideAxes=true'; url += scope.panel['y-axis'] ? '' : '&hideYAxis=true';