Browse Source

feat(influxdb): add support for 0.11.0 tags

this change is backwards compatible.

closes #4392
bergquist 9 years ago
parent
commit
b73d196c6b
1 changed files with 9 additions and 3 deletions
  1. 9 3
      public/app/plugins/datasource/influxdb/datasource.ts

+ 9 - 3
public/app/plugins/datasource/influxdb/datasource.ts

@@ -109,7 +109,7 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
       return $q.reject(err);
     }
 
-    return this._seriesQuery(interpolated).then(function (results) {
+    return this._seriesQuery(interpolated).then((results) => {
       if (!results || results.results.length === 0) { return []; }
 
       var influxResults = results.results[0];
@@ -118,9 +118,9 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
       }
 
       var series = influxResults.series[0];
-      return _.map(series.values, function(value) {
+      return _.map(series.values, (value) => {
         if (_.isArray(value)) {
-          return { text: value[0] };
+          return { text: this.getValueBasedOnInfluxVersion(value) };
         } else {
           return { text: value };
         }
@@ -128,6 +128,12 @@ export function InfluxDatasource(instanceSettings, $q, backendSrv, templateSrv)
     });
   };
 
+  this.getValueBasedOnInfluxVersion = function(value) {
+    //influxdb 0.10.0 sends the value in first position
+    //influxdb 0.11.0 sends the value in second position
+    return value[1] || value[0];
+  };
+
   this._seriesQuery = function(query) {
     return this._influxRequest('GET', '/query', {q: query, epoch: 'ms'});
   };