Commit f91f74be by cmartin0077 Committed by Torkel Ödegaard

fix(influxdb) autocomplete measurement while typing, fixes #4278 (#5931)

parent 3c92f78e
...@@ -76,10 +76,8 @@ function (_, $, coreModule) { ...@@ -76,10 +76,8 @@ function (_, $, coreModule) {
}; };
$scope.source = function(query, callback) { $scope.source = function(query, callback) {
if (options) { return options; }
$scope.$apply(function() { $scope.$apply(function() {
$scope.getOptions().then(function(altSegments) { $scope.getOptions({ measurementFilter: query }).then(function(altSegments) {
$scope.altSegments = altSegments; $scope.altSegments = altSegments;
options = _.map($scope.altSegments, function(alt) { return alt.value; }); options = _.map($scope.altSegments, function(alt) { return alt.value; });
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<label class="gf-form-label query-keyword width-7">FROM</label> <label class="gf-form-label query-keyword width-7">FROM</label>
<metric-segment segment="ctrl.policySegment" get-options="ctrl.getPolicySegments()" on-change="ctrl.policyChanged()"></metric-segment> <metric-segment segment="ctrl.policySegment" get-options="ctrl.getPolicySegments()" on-change="ctrl.policyChanged()"></metric-segment>
<metric-segment segment="ctrl.measurementSegment" get-options="ctrl.getMeasurements()" on-change="ctrl.measurementChanged()"></metric-segment> <metric-segment segment="ctrl.measurementSegment" get-options="ctrl.getMeasurements(measurementFilter)" on-change="ctrl.measurementChanged()"></metric-segment>
</div> </div>
<div class="gf-form"> <div class="gf-form">
......
...@@ -39,7 +39,7 @@ function (_) { ...@@ -39,7 +39,7 @@ function (_) {
return this.target.rawQuery ? this._modifyRawQuery() : this._buildQuery(); return this.target.rawQuery ? this._modifyRawQuery() : this._buildQuery();
}; };
p.buildExploreQuery = function(type, withKey) { p.buildExploreQuery = function(type, withKey, withMeasurementFilter) {
var query; var query;
var measurement; var measurement;
...@@ -51,6 +51,10 @@ function (_) { ...@@ -51,6 +51,10 @@ function (_) {
measurement = this.target.measurement; measurement = this.target.measurement;
} else if (type === 'MEASUREMENTS') { } else if (type === 'MEASUREMENTS') {
query = 'SHOW MEASUREMENTS'; query = 'SHOW MEASUREMENTS';
if (withMeasurementFilter)
{
query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/';
}
} else if (type === 'FIELDS') { } else if (type === 'FIELDS') {
query = 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"'; query = 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"';
return query; return query;
......
...@@ -191,8 +191,8 @@ export class InfluxQueryCtrl extends QueryCtrl { ...@@ -191,8 +191,8 @@ export class InfluxQueryCtrl extends QueryCtrl {
this.target.rawQuery = !this.target.rawQuery; this.target.rawQuery = !this.target.rawQuery;
} }
getMeasurements() { getMeasurements(measurementFilter) {
var query = this.queryBuilder.buildExploreQuery('MEASUREMENTS'); var query = this.queryBuilder.buildExploreQuery('MEASUREMENTS', undefined, measurementFilter);
return this.datasource.metricFindQuery(query) return this.datasource.metricFindQuery(query)
.then(this.transformToSegments(true)) .then(this.transformToSegments(true))
.catch(this.handleQueryError.bind(this)); .catch(this.handleQueryError.bind(this));
......
...@@ -37,6 +37,24 @@ describe('InfluxQueryBuilder', function() { ...@@ -37,6 +37,24 @@ describe('InfluxQueryBuilder', function() {
expect(query).to.be('SHOW MEASUREMENTS'); 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() { it('should have where condition in measurement query for query with tags', function() {
var builder = new InfluxQueryBuilder({measurement: '', tags: [{key: 'app', value: 'email'}]}); var builder = new InfluxQueryBuilder({measurement: '', tags: [{key: 'app', value: 'email'}]});
var query = builder.buildExploreQuery('MEASUREMENTS'); var query = builder.buildExploreQuery('MEASUREMENTS');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment