Przeglądaj źródła

Initial graphite tags support (#9239)

* graphite: initial seriesByTag() support

* graphite: groupByTags() function

* graphite: aliasByTags() function

* graphite: fix optional params update, issue #9238

* graphite: fix tag-related functions version

* graphite: add 1.1.x version to config

* graphite: fix seriesByTag() series parsing
Alexander Zobnin 8 lat temu
rodzic
commit
f8b8907cc4

+ 1 - 0
public/app/plugins/datasource/graphite/config_ctrl.ts

@@ -16,6 +16,7 @@ export class GraphiteConfigCtrl {
   graphiteVersions = [
     {name: '0.9.x', value: '0.9'},
     {name: '1.0.x', value: '1.0'},
+    {name: '1.1.x', value: '1.1'},
   ];
 }
 

+ 44 - 1
public/app/plugins/datasource/graphite/gfunc.js

@@ -822,6 +822,49 @@ function (_, $) {
     version: '1.0'
   });
 
+  addFuncDef({
+    name: 'seriesByTag',
+    category: categories.Special,
+    params: [
+      { name: "tagExpression", type: "string" },
+      { name: "tagExpression", type: "string", optional: true },
+      { name: "tagExpression", type: "string", optional: true },
+      { name: "tagExpression", type: "string", optional: true },
+    ],
+    version: '1.1'
+  });
+
+  addFuncDef({
+    name: "groupByTags",
+    category: categories.Special,
+    params: [
+      {
+        name: "function",
+        type: "string",
+        options: ['sum', 'avg', 'maxSeries']
+      },
+      { name: "tag", type: "string" },
+      { name: "tag", type: "string", optional: true },
+      { name: "tag", type: "string", optional: true },
+      { name: "tag", type: "string", optional: true },
+    ],
+    defaultParams: ["sum", "tag"],
+    version: '1.1'
+  });
+
+  addFuncDef({
+    name: "aliasByTags",
+    category: categories.Special,
+    params: [
+      { name: "tag", type: "string" },
+      { name: "tag", type: "string", optional: true },
+      { name: "tag", type: "string", optional: true },
+      { name: "tag", type: "string", optional: true },
+    ],
+    defaultParams: ["tag"],
+    version: '1.1'
+  });
+
   _.each(categories, function(funcList, catName) {
     categories[catName] = _.sortBy(funcList, 'name');
   });
@@ -873,7 +916,7 @@ function (_, $) {
     // 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.updateParam(partVal.trim(), index + idx);
       }.bind(this));
       return;
     }

+ 6 - 1
public/app/plugins/datasource/graphite/query_ctrl.ts

@@ -96,7 +96,8 @@ export class GraphiteQueryCtrl extends QueryCtrl {
         if ((index-1) >= func.def.params.length) {
           throw { message: 'invalid number of parameters to method ' + func.def.name };
         }
-        this.addFunctionParameter(func, astNode.value, index, true);
+        var shiftBack = this.isShiftParamsBack(func);
+        this.addFunctionParameter(func, astNode.value, index, shiftBack);
       break;
       case 'metric':
         if (this.segments.length > 0) {
@@ -113,6 +114,10 @@ export class GraphiteQueryCtrl extends QueryCtrl {
     }
   }
 
+  isShiftParamsBack(func) {
+    return func.def.name !== 'seriesByTag';
+  }
+
   getSegmentPathUpTo(index) {
     var arr = this.segments.slice(0, index);