From 9740752c1e5859c42e27c9e4097fe6d5dd5b3a2d Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 16 Nov 2016 18:50:33 +0900 Subject: [PATCH] (cloudwatch) long retention support (#6547) --- .../plugins/datasource/cloudwatch/datasource.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.js b/public/app/plugins/datasource/cloudwatch/datasource.js index 105b08c2b17..07648779648 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.js +++ b/public/app/plugins/datasource/cloudwatch/datasource.js @@ -37,7 +37,8 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) { query.dimensions = self.convertDimensionFormat(target.dimensions, options.scopedVars); query.statistics = target.statistics; - var period = this._getPeriod(target, query, options, start, end); + var now = Math.round(Date.now() / 1000); + var period = this._getPeriod(target, query, options, start, end, now); target.period = period; query.period = period; @@ -67,11 +68,19 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) { }); }; - this._getPeriod = function(target, query, options, start, end) { + this._getPeriod = function(target, query, options, start, end, now) { var period; var range = end - start; - if (!target.period) { + var daySec = 60 * 60 * 24; + var periodUnit = 60; + if (now - start > (daySec * 15)) { // until 63 days ago + periodUnit = period = 60 * 5; + } else if (now - start > (daySec * 63)) { // until 455 days ago + periodUnit = period = 60 * 60; + } else if (now - start > (daySec * 455)) { // over 455 days, should return error, but try to long period + periodUnit = period = 60 * 60; + } else if (!target.period) { period = (query.namespace === 'AWS/EC2') ? 300 : 60; } else if (/^\d+$/.test(target.period)) { period = parseInt(target.period, 10); @@ -82,7 +91,7 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) { period = 60; } if (range / period >= 1440) { - period = Math.ceil(range / 1440 / 60) * 60; + period = Math.ceil(range / 1440 / periodUnit) * periodUnit; } return period;