Parcourir la source

fix(influxdb): fixed handling of relative time ranges like last x years, or last x months, fixes #3067

Torkel Ödegaard il y a 10 ans
Parent
commit
13760b1bdd

+ 1 - 0
CHANGELOG.md

@@ -6,6 +6,7 @@
 
 ### Bug Fixes
 * **dashboard**: fix for collapse row by clicking on row title, fixes [#3065](https://github.com/grafana/grafana/issues/3065)
+* **influxdb**: fix for relative time ranges `last x months` and `last x years`, fixes [#3067](https://github.com/grafana/grafana/issues/3067)
 
 # 2.5 (2015-10-28)
 

+ 6 - 2
public/app/plugins/datasource/influxdb/datasource.js

@@ -192,8 +192,12 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) {
         if (date === 'now') {
           return 'now()';
         }
-        if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
-          return date.replace('now', 'now()').replace('-', ' - ');
+
+        var parts = /^now-(\d+)([d|h|m|s])$/.exec(date);
+        if (parts) {
+          var amount = parseInt(parts[1]);
+          var unit = parts[2];
+          return 'now() - ' + amount + unit;
         }
         date = dateMath.parse(date, roundUp);
       }

+ 7 - 2
public/app/plugins/datasource/influxdb_08/datasource.js

@@ -270,9 +270,14 @@ function (angular, _, dateMath, InfluxSeries, InfluxQueryBuilder) {
         if (date === 'now') {
           return 'now()';
         }
-        if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
-          return date.replace('now', 'now()');
+
+        var parts = /^now-(\d+)([d|h|m|s])$/.exec(date);
+        if (parts) {
+          var amount = parseInt(parts[1]);
+          var unit = parts[2];
+          return 'now()-' + amount + unit;
         }
+
         date = dateMath.parse(date, roundUp);
       }
       return (date.valueOf() / 1000).toFixed(0) + 's';