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

This commit is contained in:
cmartin0077 2016-09-15 10:11:38 -04:00 committed by Torkel Ödegaard
parent 3c92f78ee7
commit f91f74be04
5 changed files with 27 additions and 7 deletions

View File

@ -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; });

View File

@ -11,7 +11,7 @@
<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.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 class="gf-form">

View File

@ -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;

View File

@ -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));

View File

@ -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');