diff --git a/public/app/plugins/datasource/influxdb/query_builder.js b/public/app/plugins/datasource/influxdb/query_builder.js index d8051338838..b0691605ded 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.js +++ b/public/app/plugins/datasource/influxdb/query_builder.js @@ -42,13 +42,16 @@ function (_) { p.buildExploreQuery = function(type, withKey, withMeasurementFilter) { var query; var measurement; + var policy; if (type === 'TAG_KEYS') { query = 'SHOW TAG KEYS'; measurement = this.target.measurement; + policy = this.target.policy; } else if (type === 'TAG_VALUES') { query = 'SHOW TAG VALUES'; measurement = this.target.measurement; + policy = this.target.policy; } else if (type === 'MEASUREMENTS') { query = 'SHOW MEASUREMENTS'; if (withMeasurementFilter) @@ -56,11 +59,18 @@ function (_) { query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/'; } } else if (type === 'FIELDS') { - if (!this.target.measurement.match('^/.*/')) { - return 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"'; - } else { - return 'SHOW FIELD KEYS FROM ' + this.target.measurement; + measurement = this.target.measurement; + policy = this.target.policy; + if (!measurement.match('^/.*/')) { + measurement = '"' + measurement + '"'; + if (policy) { + if (!policy.match('^/.*/')) { + policy = '"' + policy + '"'; + } + measurement = policy + '.' + measurement; + } } + return 'SHOW FIELD KEYS FROM ' + measurement; } else if (type === 'RETENTION POLICIES') { query = 'SHOW RETENTION POLICIES on "' + this.database + '"'; return query; @@ -70,6 +80,12 @@ function (_) { if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) { measurement = '"' + measurement+ '"'; } + if (policy) { + if (!policy.match('^/.*/') && !policy.match(/^merge\(.*\)/)) { + policy = '"' + policy + '"'; + } + measurement = policy + '.' + measurement; + } query += ' FROM ' + measurement; } 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 86b1d4f08dd..ed2bba31f96 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts @@ -73,6 +73,17 @@ describe('InfluxQueryBuilder', function() { expect(query).to.be('SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE "host" = \'server1\''); }); + it ('should select from policy correctly if policy is specified', function() { + var builder = new InfluxQueryBuilder({ + measurement: 'cpu', + policy: 'one_week', + tags: [{key: 'app', value: 'email'}, + {key: 'host', value: 'server1'}] + }); + var query = builder.buildExploreQuery('TAG_VALUES', 'app'); + expect(query).to.be('SHOW TAG VALUES FROM "one_week"."cpu" WITH KEY = "app" WHERE "host" = \'server1\''); + }); + it('should switch to regex operator in tag condition', function() { var builder = new InfluxQueryBuilder({ measurement: 'cpu',