diff --git a/public/app/plugins/datasource/graphite/lexer.js b/public/app/plugins/datasource/graphite/lexer.js index 457100b163e..2b8affd04e2 100644 --- a/public/app/plugins/datasource/graphite/lexer.js +++ b/public/app/plugins/datasource/graphite/lexer.js @@ -367,6 +367,14 @@ define([ } switch (id) { + case 'true': { + type = 'bool'; + break; + } + case 'false': { + type = 'bool'; + break; + } default: type = "identifier"; } @@ -379,7 +387,7 @@ define([ }, - /* + /* * Extract a numeric literal out of the next sequence of * characters or return 'null' if its not possible. This method * supports all numeric literals described in section 7.8.3 diff --git a/public/app/plugins/datasource/graphite/parser.js b/public/app/plugins/datasource/graphite/parser.js index 2ff15cda5b0..43fd148f1ea 100644 --- a/public/app/plugins/datasource/graphite/parser.js +++ b/public/app/plugins/datasource/graphite/parser.js @@ -156,6 +156,17 @@ define([ return node; }, + boolExpression: function() { + if (!this.match('bool')) { + return null; + } + + return { + type: 'bool', + value: this.consumeToken().value === 'true', + }; + }, + functionParameters: function () { if (this.match(')') || this.match('')) { return []; @@ -165,6 +176,7 @@ define([ this.functionCall() || this.numericLiteral() || this.seriesRefExpression() || + this.boolExpression() || this.metricExpression() || this.stringLiteral(); diff --git a/public/app/plugins/datasource/graphite/queryCtrl.js b/public/app/plugins/datasource/graphite/queryCtrl.js index c3ed7fe32a1..0880dc23dc9 100644 --- a/public/app/plugins/datasource/graphite/queryCtrl.js +++ b/public/app/plugins/datasource/graphite/queryCtrl.js @@ -87,6 +87,7 @@ function (angular, _, config, gfunc, Parser) { case 'series-ref': addFunctionParameter(func, astNode.value, index, $scope.segments.length > 0); break; + case 'bool': case 'string': case 'number': if ((index-1) >= func.def.params.length) { diff --git a/public/test/specs/lexer-specs.js b/public/test/specs/lexer-specs.js index b6167314a5a..b04f36740ff 100644 --- a/public/test/specs/lexer-specs.js +++ b/public/test/specs/lexer-specs.js @@ -109,6 +109,14 @@ define([ expect(tokens[4].value).to.be('0.002'); }); + it('should handle bool parameters', function() { + var lexer = new Lexer("alias(metric, true, false)"); + var tokens = lexer.tokenize(); + expect(tokens[4].type).to.be('bool'); + expect(tokens[4].value).to.be('true'); + expect(tokens[6].type).to.be('bool'); + }); + }); }); diff --git a/public/test/specs/parser-specs.js b/public/test/specs/parser-specs.js index d52250a4b1b..bfcb238c3cf 100644 --- a/public/test/specs/parser-specs.js +++ b/public/test/specs/parser-specs.js @@ -165,6 +165,15 @@ define([ expect(rootNode.params[1].value).to.be('#B'); }); + it('series parameters, issue 2788', function() { + var parser = new Parser("summarize(diffSeries(#A, #B), '10m', 'sum', false)"); + var rootNode = parser.getAst(); + expect(rootNode.type).to.be('function'); + expect(rootNode.params[0].type).to.be('function'); + expect(rootNode.params[1].value).to.be('10m'); + expect(rootNode.params[3].type).to.be('bool'); + }); + it('should parse metric expression with ip number segments', function() { var parser = new Parser('5.10.123.5'); var rootNode = parser.getAst();