Prechádzať zdrojové kódy

Graphite: movingAverage / movingMedian parameter type impovement, now handles int and interval parameter, Fixes #1207

Torkel Ödegaard 11 rokov pred
rodič
commit
acd944a649

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 **Fixes**
 - [Issue #1199](https://github.com/grafana/grafana/issues/1199). Graph: fix for series tooltip when one series is hidden/disabled
+- [Issue #1207](https://github.com/grafana/grafana/issues/1207). Graphite: movingAverage / movingMedian parameter type impovement, now handles int and interval parameter
 
 # 1.9.0 (2014-12-02)
 

+ 9 - 5
src/app/services/graphite/gfunc.js

@@ -1,7 +1,8 @@
 define([
-  'lodash'
+  'lodash',
+  'jquery'
 ],
-function (_) {
+function (_, $) {
   'use strict';
 
   var index = [];
@@ -501,15 +502,15 @@ function (_) {
   addFuncDef({
     name: 'movingAverage',
     category: categories.Filter,
-    params: [{ name: "window size", type: "int" }],
+    params: [{ name: "windowSize", type: "int_or_interval", options: ['5', '7', '10', '5min', '10min', '30min', '1hour'] }],
     defaultParams: [10]
   });
 
   addFuncDef({
     name: 'movingMedian',
     category: categories.Filter,
-    params: [{ name: "windowSize", type: "select", options: ['1min', '5min', '15min', '30min', '1hour'] }],
-    defaultParams: ['1min']
+    params: [{ name: "windowSize", type: "int_or_interval", options: ['5', '7', '10', '5min', '10min', '30min', '1hour'] }],
+    defaultParams: ['5']
   });
 
   addFuncDef({
@@ -595,6 +596,9 @@ function (_) {
       if (paramType === 'int' || paramType === 'value_or_series' || paramType === 'boolean') {
         return value;
       }
+      else if (paramType === 'int_or_interval' && $.isNumeric(value)) {
+        return value;
+      }
 
       return "'" + value + "'";
 

+ 12 - 0
src/test/specs/gfunc-specs.js

@@ -46,6 +46,18 @@ define([
       expect(func.render('hello')).to.equal("scaleToSeconds(hello, 1)");
     });
 
+    it('should handle int or interval params with number', function() {
+      var func = gfunc.createFuncInstance('movingMedian');
+      func.params[0] = '5';
+      expect(func.render('hello')).to.equal("movingMedian(hello, 5)");
+    });
+
+    it('should handle int or interval params with interval string', function() {
+      var func = gfunc.createFuncInstance('movingMedian');
+      func.params[0] = '5min';
+      expect(func.render('hello')).to.equal("movingMedian(hello, '5min')");
+    });
+
     it('should handle metric param and int param and string param', function() {
       var func = gfunc.createFuncInstance('groupByNode');
       func.params[0] = 5;