From 02af2dbe7314a991635c6ec02c91610bfc28a972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 18 Apr 2014 16:06:21 +0200 Subject: [PATCH] Added rounding for graphites from and to time range filters for very short absolute ranges (Fixes #320) --- CHANGELOG.md | 4 ++++ .../services/graphite/graphiteDatasource.js | 21 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e66b077a1c..720f9ddfd27 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js index fdc7d4e84b9..4aa757c4a17 100644 --- a/src/app/services/graphite/graphiteDatasource.js +++ b/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(); }