Переглянути джерело

Made opentsdb query_ctrl robust

utkarshcmu 9 роки тому
батько
коміт
18c57ea230

+ 14 - 1
public/app/plugins/datasource/opentsdb/datasource.js

@@ -224,7 +224,7 @@ function (angular, _, dateMath) {
     this.getAggregators = function() {
       if (aggregatorsPromise) { return aggregatorsPromise; }
 
-      aggregatorsPromise =  this._get('/api/aggregators').then(function(result) {
+      aggregatorsPromise = this._get('/api/aggregators').then(function(result) {
         if (result.data && _.isArray(result.data)) {
           return result.data.sort();
         }
@@ -233,6 +233,19 @@ function (angular, _, dateMath) {
       return aggregatorsPromise;
     };
 
+    var filterTypesPromise = null;
+    this.getFilterTypes = function() {
+      if (filterTypesPromise) { return filterTypesPromise; }
+
+      filterTypesPromise = this._get('/api/config/filters').then(function(result) {
+        if (result.data) {
+          return Object.keys(result.data).sort();
+        }
+        return [];
+      });
+      return filterTypesPromise;
+    };
+
     function transformMetricData(md, groupByTags, target, options) {
       var metricLabel = createMetricLabel(md, target, groupByTags, options);
       var dps = [];

+ 10 - 2
public/app/plugins/datasource/opentsdb/query_ctrl.ts

@@ -45,7 +45,15 @@ export class OpenTsQueryCtrl extends QueryCtrl {
     }
 
     this.datasource.getAggregators().then((aggs) => {
-      this.aggregators = aggs;
+      if (aggs.length !== 0) {
+        this.aggregators = aggs;
+      }
+    });
+
+    this.datasource.getFilterTypes().then((filterTypes) => {
+      if (filterTypes.length !== 0) {
+        this.filterTypes = filterTypes;
+      }
     });
 
     // needs to be defined here as it is called from typeahead
@@ -135,7 +143,7 @@ export class OpenTsQueryCtrl extends QueryCtrl {
     }
 
     if (!this.target.currentFilterType) {
-      this.target.currentFilterType = 'literal_or';
+      this.target.currentFilterType = 'iliteral_or';
     }
 
     if (!this.target.currentFilterGroupBy) {

+ 1 - 0
public/app/plugins/datasource/opentsdb/specs/query-ctrl-specs.ts

@@ -17,6 +17,7 @@ describe('OpenTsQueryCtrl', function() {
     ctx.panelCtrl = {panel: {}};
     ctx.panelCtrl.refresh = sinon.spy();
     ctx.datasource.getAggregators = sinon.stub().returns(ctx.$q.when([]));
+    ctx.datasource.getFilterTypes = sinon.stub().returns(ctx.$q.when([]));
 
     ctx.ctrl = $controller(OpenTsQueryCtrl, {$scope: ctx.scope}, {
       panelCtrl: ctx.panelCtrl,