diff --git a/public/app/plugins/datasource/influxdb/query_builder.js b/public/app/plugins/datasource/influxdb/query_builder.js index b4508707aad..4b45d9bf6a6 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.js +++ b/public/app/plugins/datasource/influxdb/query_builder.js @@ -56,8 +56,11 @@ function (_) { query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/'; } } else if (type === 'FIELDS') { - query = 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"'; - return query; + if (!this.target.measurement.match('^/.*/')) { + return 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"'; + } else { + return 'SHOW FIELD KEYS FROM ' + this.target.measurement; + } } else if (type === 'RETENTION POLICIES') { query = 'SHOW RETENTION POLICIES on "' + this.database + '"'; return query; 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 c10f9019f40..b075a1ef544 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts @@ -88,6 +88,12 @@ describe('InfluxQueryBuilder', function() { expect(query).to.be('SHOW FIELD KEYS FROM "cpu"'); }); + it('should build show field query with regexp', function() { + var builder = new InfluxQueryBuilder({measurement: '/$var/', tags: [{key: 'app', value: 'email'}]}); + var query = builder.buildExploreQuery('FIELDS'); + expect(query).to.be('SHOW FIELD KEYS FROM /$var/'); + }); + it('should build show retention policies query', function() { var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: []}, 'site'); var query = builder.buildExploreQuery('RETENTION POLICIES');