diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index 0f9cdee02a9..7bea0b6338c 100644 --- a/pkg/api/frontendsettings.go +++ b/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 diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 6108040fd66..6066951e9b0 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/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 '; diff --git a/public/app/plugins/datasource/influxdb/query_builder.js b/public/app/plugins/datasource/influxdb/query_builder.js index fb6a4066ebc..1921c672ba6 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.js +++ b/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; } diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.js b/public/app/plugins/datasource/influxdb/query_ctrl.js index eb47c17129c..adb0acb2218 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.js +++ b/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'}, diff --git a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts b/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts index 87b96775e38..0d13f159eb9 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts +++ b/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"'); }); }); });