Browse Source

Fix for graphite queries with glob syntax ([1-9] and ?) that made
the graphite parser / query editor bail and fallback to text edit mode.

Torkel Ödegaard 11 years ago
parent
commit
ffd73e8bfb

+ 2 - 1
CHANGELOG.md

@@ -6,7 +6,8 @@
 - [Issue #672](https://github.com/grafana/grafana/issues/672). Dashboard: panel fullscreen & edit state is present in url, can now link to graph in edit & fullscreen mode.
 - [Issue #672](https://github.com/grafana/grafana/issues/672). Dashboard: panel fullscreen & edit state is present in url, can now link to graph in edit & fullscreen mode.
 
 
 **Fixes**
 **Fixes**
-- [Issue #696](https://github.com/grafana/grafana/issues/696). Graph: fix for y-axis format 'none' when values are in scientific notation (ex 2.3e-13)
+- [Issue #696](https://github.com/grafana/grafana/issues/696). Graph: Fix for y-axis format 'none' when values are in scientific notation (ex 2.3e-13)
+- [Issue #697](https://github.com/grafana/grafana/issues/697). Graphite: Fix for Glob syntax in graphite queries ([1-9] and ?) that made the query editor / parser bail and fallback to a text box.
 
 
 **Tech**
 **Tech**
 - Upgraded from angularjs 1.1.5 to 1.3 beta 17;
 - Upgraded from angularjs 1.1.5 to 1.3 beta 17;

+ 3 - 2
src/app/directives/ngModelOnBlur.js

@@ -7,13 +7,14 @@ function (angular) {
     .directive('ngModelOnblur', function() {
     .directive('ngModelOnblur', function() {
       return {
       return {
         restrict: 'A',
         restrict: 'A',
+        priority: 1,
         require: 'ngModel',
         require: 'ngModel',
         link: function(scope, elm, attr, ngModelCtrl) {
         link: function(scope, elm, attr, ngModelCtrl) {
           if (attr.type === 'radio' || attr.type === 'checkbox') {
           if (attr.type === 'radio' || attr.type === 'checkbox') {
             return;
             return;
           }
           }
 
 
-          elm.unbind('input').unbind('keydown').unbind('change');
+          elm.off('input keydown change');
           elm.bind('blur', function() {
           elm.bind('blur', function() {
             scope.$apply(function() {
             scope.$apply(function() {
               ngModelCtrl.$setViewValue(elm.val());
               ngModelCtrl.$setViewValue(elm.val());
@@ -22,4 +23,4 @@ function (angular) {
         }
         }
       };
       };
     });
     });
-});
+});

+ 3 - 0
src/app/services/graphite/lexer.js

@@ -124,6 +124,9 @@ define([
       i === 45 ||           // -
       i === 45 ||           // -
       i === 42 ||           // *
       i === 42 ||           // *
       i === 58 ||           // :
       i === 58 ||           // :
+      i === 91 ||           // templateStart [
+      i === 93 ||           // templateEnd ]
+      i === 63 ||           // ?
       i === 37 ||           // %
       i === 37 ||           // %
       i >= 97 && i <= 122;  // a-z
       i >= 97 && i <= 122;  // a-z
   }
   }

+ 11 - 4
src/test/specs/lexer-specs.js

@@ -71,10 +71,17 @@ define([
     it('should tokenize metric with template parameter', function() {
     it('should tokenize metric with template parameter', function() {
       var lexer = new Lexer("metric.[[server]].test");
       var lexer = new Lexer("metric.[[server]].test");
       var tokens = lexer.tokenize();
       var tokens = lexer.tokenize();
-      expect(tokens[2].type).to.be('templateStart');
-      expect(tokens[3].type).to.be('identifier');
-      expect(tokens[3].value).to.be('server');
-      expect(tokens[4].type).to.be('templateEnd');
+      expect(tokens[2].type).to.be('identifier');
+      expect(tokens[2].value).to.be('[[server]]');
+      expect(tokens[4].type).to.be('identifier');
+    });
+
+    it('should tokenize metric with question mark', function() {
+      var lexer = new Lexer("metric.server_??.test");
+      var tokens = lexer.tokenize();
+      expect(tokens[2].type).to.be('identifier');
+      expect(tokens[2].value).to.be('server_??');
+      expect(tokens[4].type).to.be('identifier');
     });
     });
 
 
     it('should handle error with unterminated string', function() {
     it('should handle error with unterminated string', function() {

+ 2 - 2
src/test/specs/parser-specs.js

@@ -106,8 +106,8 @@ define([
 
 
       expect(rootNode.message).to.be(undefined);
       expect(rootNode.message).to.be(undefined);
       expect(rootNode.params[0].type).to.be('metric');
       expect(rootNode.params[0].type).to.be('metric');
-      expect(rootNode.params[0].segments[1].type).to.be('template');
-      expect(rootNode.params[0].segments[1].value).to.be('server');
+      expect(rootNode.params[0].segments[1].type).to.be('segment');
+      expect(rootNode.params[0].segments[1].value).to.be('[[server]]');
     });
     });
 
 
     it('invalid metric expression', function() {
     it('invalid metric expression', function() {