diff --git a/public/app/core/directives/metric_segment.js b/public/app/core/directives/metric_segment.js
index ebb5a256d6c..9257f3c6a79 100644
--- a/public/app/core/directives/metric_segment.js
+++ b/public/app/core/directives/metric_segment.js
@@ -76,10 +76,8 @@ function (_, $, coreModule) {
};
$scope.source = function(query, callback) {
- if (options) { return options; }
-
$scope.$apply(function() {
- $scope.getOptions().then(function(altSegments) {
+ $scope.getOptions({ measurementFilter: query }).then(function(altSegments) {
$scope.altSegments = altSegments;
options = _.map($scope.altSegments, function(alt) { return alt.value; });
diff --git a/public/app/plugins/datasource/influxdb/partials/query.editor.html b/public/app/plugins/datasource/influxdb/partials/query.editor.html
index df5c326b962..f718fbc5d29 100644
--- a/public/app/plugins/datasource/influxdb/partials/query.editor.html
+++ b/public/app/plugins/datasource/influxdb/partials/query.editor.html
@@ -11,7 +11,7 @@
-
+
diff --git a/public/app/plugins/datasource/influxdb/query_builder.js b/public/app/plugins/datasource/influxdb/query_builder.js
index 07d920350d7..b4508707aad 100644
--- a/public/app/plugins/datasource/influxdb/query_builder.js
+++ b/public/app/plugins/datasource/influxdb/query_builder.js
@@ -39,7 +39,7 @@ function (_) {
return this.target.rawQuery ? this._modifyRawQuery() : this._buildQuery();
};
- p.buildExploreQuery = function(type, withKey) {
+ p.buildExploreQuery = function(type, withKey, withMeasurementFilter) {
var query;
var measurement;
@@ -51,6 +51,10 @@ function (_) {
measurement = this.target.measurement;
} else if (type === 'MEASUREMENTS') {
query = 'SHOW MEASUREMENTS';
+ if (withMeasurementFilter)
+ {
+ query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/';
+ }
} else if (type === 'FIELDS') {
query = 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"';
return query;
diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.ts b/public/app/plugins/datasource/influxdb/query_ctrl.ts
index aad613b8d5f..26f09d26d29 100644
--- a/public/app/plugins/datasource/influxdb/query_ctrl.ts
+++ b/public/app/plugins/datasource/influxdb/query_ctrl.ts
@@ -191,8 +191,8 @@ export class InfluxQueryCtrl extends QueryCtrl {
this.target.rawQuery = !this.target.rawQuery;
}
- getMeasurements() {
- var query = this.queryBuilder.buildExploreQuery('MEASUREMENTS');
+ getMeasurements(measurementFilter) {
+ var query = this.queryBuilder.buildExploreQuery('MEASUREMENTS', undefined, measurementFilter);
return this.datasource.metricFindQuery(query)
.then(this.transformToSegments(true))
.catch(this.handleQueryError.bind(this));
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 0d13f159eb9..c10f9019f40 100644
--- a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
+++ b/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts
@@ -37,6 +37,24 @@ describe('InfluxQueryBuilder', function() {
expect(query).to.be('SHOW MEASUREMENTS');
});
+ it('should have no conditions in measurement query for query with no tags and empty query', function() {
+ var builder = new InfluxQueryBuilder({ measurement: '', tags: [] });
+ var query = builder.buildExploreQuery('MEASUREMENTS', undefined, '');
+ expect(query).to.be('SHOW MEASUREMENTS');
+ });
+
+ it('should have WITH MEASUREMENT in measurement query for non-empty query with no tags', function() {
+ var builder = new InfluxQueryBuilder({ measurement: '', tags: [] });
+ var query = builder.buildExploreQuery('MEASUREMENTS', undefined, 'something');
+ expect(query).to.be('SHOW MEASUREMENTS WITH MEASUREMENT =~ /something/');
+ });
+
+ it('should have WITH MEASUREMENT WHERE in measurement query for non-empty query with tags', function() {
+ var builder = new InfluxQueryBuilder({ measurement: '', tags: [{key: 'app', value: 'email'}] });
+ var query = builder.buildExploreQuery('MEASUREMENTS', undefined, 'something');
+ expect(query).to.be("SHOW MEASUREMENTS WITH MEASUREMENT =~ /something/ WHERE \"app\" = 'email'");
+ });
+
it('should have where condition in measurement query for query with tags', function() {
var builder = new InfluxQueryBuilder({measurement: '', tags: [{key: 'app', value: 'email'}]});
var query = builder.buildExploreQuery('MEASUREMENTS');