فهرست منبع

Merge branch 'master' of https://github.com/omki2005/grafana into omki2005-master

Torkel Ödegaard 8 سال پیش
والد
کامیت
4b76c6d652

+ 20 - 4
public/app/plugins/datasource/influxdb/query_builder.js

@@ -42,13 +42,16 @@ function (_) {
   p.buildExploreQuery = function(type, withKey, withMeasurementFilter) {
   p.buildExploreQuery = function(type, withKey, withMeasurementFilter) {
     var query;
     var query;
     var measurement;
     var measurement;
+    var policy;
 
 
     if (type === 'TAG_KEYS') {
     if (type === 'TAG_KEYS') {
       query = 'SHOW TAG KEYS';
       query = 'SHOW TAG KEYS';
       measurement = this.target.measurement;
       measurement = this.target.measurement;
+      policy = this.target.policy;
     } else if (type === 'TAG_VALUES') {
     } else if (type === 'TAG_VALUES') {
       query = 'SHOW TAG VALUES';
       query = 'SHOW TAG VALUES';
       measurement = this.target.measurement;
       measurement = this.target.measurement;
+      policy = this.target.policy;
     } else if (type === 'MEASUREMENTS') {
     } else if (type === 'MEASUREMENTS') {
       query = 'SHOW MEASUREMENTS';
       query = 'SHOW MEASUREMENTS';
       if (withMeasurementFilter)
       if (withMeasurementFilter)
@@ -56,11 +59,18 @@ function (_) {
         query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/';
         query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/';
       }
       }
     } else if (type === 'FIELDS') {
     } 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') {
     } else if (type === 'RETENTION POLICIES') {
       query = 'SHOW RETENTION POLICIES on "' + this.database + '"';
       query = 'SHOW RETENTION POLICIES on "' + this.database + '"';
       return query;
       return query;
@@ -70,6 +80,12 @@ function (_) {
       if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
       if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
         measurement = '"' + measurement+ '"';
         measurement = '"' + measurement+ '"';
       }
       }
+      if (policy) {
+        if (!policy.match('^/.*/') && !policy.match(/^merge\(.*\)/)) {
+          policy = '"' + policy + '"';
+        }
+        measurement = policy + '.' + measurement;
+      }
       query += ' FROM ' + measurement;
       query += ' FROM ' + measurement;
     }
     }
 
 

+ 11 - 0
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\'');
       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() {
     it('should switch to regex operator in tag condition', function() {
       var builder = new InfluxQueryBuilder({
       var builder = new InfluxQueryBuilder({
         measurement: 'cpu',
         measurement: 'cpu',