浏览代码

Added rounding for graphites from and to time range filters
for very short absolute ranges (Fixes #320)

Torkel Ödegaard 11 年之前
父节点
当前提交
02af2dbe73
共有 2 个文件被更改,包括 22 次插入3 次删除
  1. 4 0
      CHANGELOG.md
  2. 18 3
      src/app/services/graphite/graphiteDatasource.js

+ 4 - 0
CHANGELOG.md

@@ -1,3 +1,7 @@
+# vNext
+- Added rounding for graphites from and to time range filters
+  for very short absolute ranges (Issue #320)
+
 # 1.5.3 (2014-04-17)
 - Add support for async scripted dashboards (Issue #274)
 - Text panel now accepts html (for links to other dashboards, etc) (Issue #236)

+ 18 - 3
src/app/services/graphite/graphiteDatasource.js

@@ -24,8 +24,8 @@ function (angular, _, $, config, kbn, moment) {
     GraphiteDatasource.prototype.query = function(options) {
       try {
         var graphOptions = {
-          from: this.translateTime(options.range.from),
-          until: this.translateTime(options.range.to),
+          from: this.translateTime(options.range.from, 'round-down'),
+          until: this.translateTime(options.range.to, 'round-up'),
           targets: options.targets,
           format: options.format,
           maxDataPoints: options.maxDataPoints,
@@ -68,7 +68,7 @@ function (angular, _, $, config, kbn, moment) {
       }
     };
 
-    GraphiteDatasource.prototype.translateTime = function(date) {
+    GraphiteDatasource.prototype.translateTime = function(date, rounding) {
       if (_.isString(date)) {
         if (date === 'now') {
           return 'now';
@@ -85,6 +85,21 @@ function (angular, _, $, config, kbn, moment) {
 
       date = moment.utc(date);
 
+      if (rounding === 'round-up') {
+        if (date.get('s')) {
+          date.add('m', 1);
+        }
+      }
+      else if (rounding === 'round-down') {
+        // graphite' s from filter is exclusive
+        // here we step back one minute in order
+        // to guarantee that we get all the data that
+        // exists for the specified range
+        if (date.get('s')) {
+          date.subtract('m', 1);
+        }
+      }
+
       if (dashboard.current.timezone === 'browser') {
         date = date.local();
       }