2013-12-23 08:05:58 -06:00
|
|
|
define([
|
2015-02-28 01:25:13 -06:00
|
|
|
'plugins/datasource/graphite/parser'
|
2013-12-23 08:05:58 -06:00
|
|
|
], function(Parser) {
|
2014-04-06 03:47:14 -05:00
|
|
|
'use strict';
|
2013-12-23 08:05:58 -06:00
|
|
|
|
2013-12-24 04:13:50 -06:00
|
|
|
describe('when parsing', function() {
|
2013-12-23 08:05:58 -06:00
|
|
|
|
2013-12-23 15:29:52 -06:00
|
|
|
it('simple metric expression', function() {
|
2013-12-23 08:05:58 -06:00
|
|
|
var parser = new Parser('metric.test.*.asd.count');
|
2013-12-23 15:29:52 -06:00
|
|
|
var rootNode = parser.getAst();
|
2013-12-23 08:05:58 -06:00
|
|
|
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.type).to.be('metric');
|
2013-12-23 15:29:52 -06:00
|
|
|
expect(rootNode.segments.length).to.be(5);
|
|
|
|
expect(rootNode.segments[0].value).to.be('metric');
|
|
|
|
});
|
|
|
|
|
2014-01-29 04:00:25 -06:00
|
|
|
it('simple metric expression with numbers in segments', function() {
|
|
|
|
var parser = new Parser('metric.10.15_20.5');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
|
|
|
expect(rootNode.type).to.be('metric');
|
|
|
|
expect(rootNode.segments.length).to.be(4);
|
|
|
|
expect(rootNode.segments[1].value).to.be('10');
|
|
|
|
expect(rootNode.segments[2].value).to.be('15_20');
|
|
|
|
expect(rootNode.segments[3].value).to.be('5');
|
|
|
|
});
|
|
|
|
|
2014-01-21 05:43:32 -06:00
|
|
|
it('simple metric expression with curly braces', function() {
|
|
|
|
var parser = new Parser('metric.se1-{count, max}');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
|
|
|
expect(rootNode.type).to.be('metric');
|
|
|
|
expect(rootNode.segments.length).to.be(2);
|
|
|
|
expect(rootNode.segments[1].value).to.be('se1-{count,max}');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('simple metric expression with curly braces at start of segment and with post chars', function() {
|
|
|
|
var parser = new Parser('metric.{count, max}-something.count');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
|
|
|
expect(rootNode.type).to.be('metric');
|
|
|
|
expect(rootNode.segments.length).to.be(3);
|
|
|
|
expect(rootNode.segments[1].value).to.be('{count,max}-something');
|
|
|
|
});
|
|
|
|
|
2013-12-23 15:29:52 -06:00
|
|
|
it('simple function', function() {
|
|
|
|
var parser = new Parser('sum(test)');
|
|
|
|
var rootNode = parser.getAst();
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.type).to.be('function');
|
2013-12-23 15:29:52 -06:00
|
|
|
expect(rootNode.params.length).to.be(1);
|
|
|
|
});
|
|
|
|
|
2014-02-07 08:17:39 -06:00
|
|
|
it('simple function2', function() {
|
|
|
|
var parser = new Parser('offset(test.metric, -100)');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.type).to.be('function');
|
|
|
|
expect(rootNode.params[0].type).to.be('metric');
|
|
|
|
expect(rootNode.params[1].type).to.be('number');
|
|
|
|
});
|
|
|
|
|
2014-01-20 07:31:00 -06:00
|
|
|
it('simple function with string arg', function() {
|
|
|
|
var parser = new Parser("randomWalk('test')");
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.type).to.be('function');
|
|
|
|
expect(rootNode.params.length).to.be(1);
|
|
|
|
expect(rootNode.params[0].type).to.be('string');
|
|
|
|
});
|
|
|
|
|
2013-12-23 15:29:52 -06:00
|
|
|
it('function with multiple args', function() {
|
|
|
|
var parser = new Parser("sum(test, 1, 'test')");
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.type).to.be('function');
|
2013-12-23 15:29:52 -06:00
|
|
|
expect(rootNode.params.length).to.be(3);
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.params[0].type).to.be('metric');
|
|
|
|
expect(rootNode.params[1].type).to.be('number');
|
|
|
|
expect(rootNode.params[2].type).to.be('string');
|
2013-12-23 08:05:58 -06:00
|
|
|
});
|
|
|
|
|
2013-12-23 15:29:52 -06:00
|
|
|
it('function with nested function', function() {
|
|
|
|
var parser = new Parser("sum(scaleToSeconds(test, 1))");
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.type).to.be('function');
|
2013-12-23 15:29:52 -06:00
|
|
|
expect(rootNode.params.length).to.be(1);
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.params[0].type).to.be('function');
|
2013-12-23 15:29:52 -06:00
|
|
|
expect(rootNode.params[0].name).to.be('scaleToSeconds');
|
|
|
|
expect(rootNode.params[0].params.length).to.be(2);
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.params[0].params[0].type).to.be('metric');
|
|
|
|
expect(rootNode.params[0].params[1].type).to.be('number');
|
2013-12-23 15:29:52 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('function with multiple series', function() {
|
|
|
|
var parser = new Parser("sum(test.test.*.count, test.timers.*.count)");
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.type).to.be('function');
|
2013-12-23 15:29:52 -06:00
|
|
|
expect(rootNode.params.length).to.be(2);
|
2013-12-24 02:32:51 -06:00
|
|
|
expect(rootNode.params[0].type).to.be('metric');
|
|
|
|
expect(rootNode.params[1].type).to.be('metric');
|
2013-12-23 15:29:52 -06:00
|
|
|
});
|
2013-12-23 08:05:58 -06:00
|
|
|
|
2014-01-01 11:40:25 -06:00
|
|
|
it('function with templated series', function() {
|
|
|
|
var parser = new Parser("sum(test.[[server]].count)");
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
2014-04-06 03:47:14 -05:00
|
|
|
expect(rootNode.message).to.be(undefined);
|
2014-01-01 11:40:25 -06:00
|
|
|
expect(rootNode.params[0].type).to.be('metric');
|
2014-08-18 02:35:13 -05:00
|
|
|
expect(rootNode.params[0].segments[1].type).to.be('segment');
|
|
|
|
expect(rootNode.params[0].segments[1].value).to.be('[[server]]');
|
2014-01-01 11:40:25 -06:00
|
|
|
});
|
|
|
|
|
2013-12-24 04:13:50 -06:00
|
|
|
it('invalid metric expression', function() {
|
|
|
|
var parser = new Parser('metric.test.*.asd.');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
2013-12-28 04:40:58 -06:00
|
|
|
expect(rootNode.message).to.be('Expected metric identifier instead found end of string');
|
|
|
|
expect(rootNode.pos).to.be(19);
|
2013-12-24 04:13:50 -06:00
|
|
|
});
|
|
|
|
|
2015-07-05 20:22:40 -05:00
|
|
|
it('invalid function expression missing closing parenthesis', function() {
|
2013-12-24 04:13:50 -06:00
|
|
|
var parser = new Parser('sum(test');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
2015-07-05 20:22:40 -05:00
|
|
|
expect(rootNode.message).to.be('Expected closing parenthesis instead found end of string');
|
2013-12-28 04:40:58 -06:00
|
|
|
expect(rootNode.pos).to.be(9);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('unclosed string in function', function() {
|
|
|
|
var parser = new Parser("sum('test)");
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
|
|
|
|
expect(rootNode.message).to.be('Unclosed string parameter');
|
|
|
|
expect(rootNode.pos).to.be(11);
|
2013-12-24 04:13:50 -06:00
|
|
|
});
|
|
|
|
|
2014-02-07 08:17:39 -06:00
|
|
|
it('handle issue #69', function() {
|
|
|
|
var parser = new Parser('cactiStyle(offset(scale(net.192-168-1-1.192-168-1-9.ping_value.*,0.001),-100))');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.type).to.be('function');
|
|
|
|
});
|
|
|
|
|
2014-08-01 02:28:57 -05:00
|
|
|
it('handle float function arguments', function() {
|
2014-03-24 06:20:28 -05:00
|
|
|
var parser = new Parser('scale(test, 0.002)');
|
2014-04-06 03:47:14 -05:00
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.type).to.be('function');
|
2014-03-24 06:20:28 -05:00
|
|
|
expect(rootNode.params[1].type).to.be('number');
|
|
|
|
expect(rootNode.params[1].value).to.be(0.002);
|
|
|
|
});
|
2014-02-07 08:17:39 -06:00
|
|
|
|
2014-08-01 02:28:57 -05:00
|
|
|
it('handle curly brace pattern at start', function() {
|
|
|
|
var parser = new Parser('{apps}.test');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.type).to.be('metric');
|
|
|
|
expect(rootNode.segments[0].value).to.be('{apps}');
|
|
|
|
expect(rootNode.segments[1].value).to.be('test');
|
|
|
|
});
|
|
|
|
|
2014-09-02 13:59:54 -05:00
|
|
|
it('series parameters', function() {
|
|
|
|
var parser = new Parser('asPercent(#A, #B)');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.type).to.be('function');
|
|
|
|
expect(rootNode.params[0].type).to.be('series-ref');
|
|
|
|
expect(rootNode.params[0].value).to.be('#A');
|
|
|
|
expect(rootNode.params[1].value).to.be('#B');
|
|
|
|
});
|
|
|
|
|
2014-12-15 04:36:08 -06:00
|
|
|
it('should parse metric expression with ip number segments', function() {
|
|
|
|
var parser = new Parser('5.10.123.5');
|
|
|
|
var rootNode = parser.getAst();
|
|
|
|
expect(rootNode.segments[0].value).to.be('5');
|
|
|
|
expect(rootNode.segments[1].value).to.be('10');
|
|
|
|
expect(rootNode.segments[2].value).to.be('123');
|
|
|
|
expect(rootNode.segments[3].value).to.be('5');
|
|
|
|
});
|
2014-09-02 13:59:54 -05:00
|
|
|
|
2013-12-23 08:05:58 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|