Torkel Ödegaard 10 лет назад
Родитель
Сommit
1adb7b286c

+ 4 - 0
pkg/api/frontendsettings.go

@@ -89,6 +89,10 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
 			dsMap["index"] = ds.Database
 		}
 
+		if ds.Type == m.DS_INFLUXDB {
+			dsMap["database"] = ds.Database
+		}
+
 		if ds.Type == m.DS_PROMETHEUS {
 			// add unproxied server URL for link to Prometheus web UI
 			dsMap["directUrl"] = ds.Url

+ 1 - 1
public/app/plugins/datasource/influxdb/influx_query.ts

@@ -179,7 +179,7 @@ export default class InfluxQuery {
 
     var measurement = target.measurement;
     if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
-measurement = '"' + measurement+ '"';
+      measurement = '"' + measurement+ '"';
     }
 
     query += ' FROM ' + measurement + ' WHERE ';

+ 3 - 11
public/app/plugins/datasource/influxdb/query_builder.js

@@ -4,17 +4,9 @@ define([
 function (_) {
   'use strict';
 
-  function InfluxQueryBuilder(target, queryModel) {
+  function InfluxQueryBuilder(target, database) {
     this.target = target;
-    this.model = queryModel;
-
-    if (target.groupByTags) {
-      target.groupBy = [{type: 'time', interval: 'auto'}];
-      for (var i in target.groupByTags) {
-        target.groupBy.push({type: 'tag', key: target.groupByTags[i]});
-      }
-      delete target.groupByTags;
-    }
+    this.database = database;
   }
 
   function renderTagCondition (tag, index) {
@@ -63,7 +55,7 @@ function (_) {
       query = 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"';
       return query;
     } else if (type === 'RETENTION POLICIES') {
-      query = 'SHOW RETENTION POLICIES';
+      query = 'SHOW RETENTION POLICIES on "' + this.database + '"';
       return query;
     }
 

+ 1 - 1
public/app/plugins/datasource/influxdb/query_ctrl.js

@@ -21,7 +21,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
 
       $scope.target = $scope.target;
       $scope.queryModel = new InfluxQuery($scope.target);
-      $scope.queryBuilder = new InfluxQueryBuilder($scope.target);
+      $scope.queryBuilder = new InfluxQueryBuilder($scope.target, $scope.datasource.database);
       $scope.groupBySegment = uiSegmentSrv.newPlusButton();
       $scope.resultFormats = [
          {text: 'Time series', value: 'time_series'},

+ 2 - 2
public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts

@@ -71,9 +71,9 @@ describe('InfluxQueryBuilder', function() {
     });
 
     it('should build show retention policies query', function() {
-      var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: []});
+      var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: []}, 'site');
       var query = builder.buildExploreQuery('RETENTION POLICIES');
-      expect(query).to.be('SHOW RETENTION POLICIES');
+      expect(query).to.be('SHOW RETENTION POLICIES on "site"');
     });
   });
 });