@@ -3,9 +3,10 @@ define([
3
3
'lodash' ,
4
4
'moment' ,
5
5
'app/core/utils/datemath' ,
6
+ 'app/core/utils/kbn' ,
6
7
'./annotation_query' ,
7
8
] ,
8
- function ( angular , _ , moment , dateMath , CloudWatchAnnotationQuery ) {
9
+ function ( angular , _ , moment , dateMath , kbn , CloudWatchAnnotationQuery ) {
9
10
'use strict' ;
10
11
11
12
/** @ngInject */
@@ -36,12 +37,9 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) {
36
37
query . dimensions = self . convertDimensionFormat ( target . dimensions , options . scopedVars ) ;
37
38
query . statistics = target . statistics ;
38
39
39
- var range = end - start ;
40
- query . period = parseInt ( target . period , 10 ) || ( query . namespace === 'AWS/EC2' ? 300 : 60 ) ;
41
- if ( range / query . period >= 1440 ) {
42
- query . period = Math . ceil ( range / 1440 / 60 ) * 60 ;
43
- }
44
- target . period = query . period ;
40
+ var period = this . _getPeriod ( target , query , options , start , end ) ;
41
+ target . period = period ;
42
+ query . period = period ;
45
43
46
44
queries . push ( query ) ;
47
45
} . bind ( this ) ) ;
@@ -69,6 +67,27 @@ function (angular, _, moment, dateMath, CloudWatchAnnotationQuery) {
69
67
} ) ;
70
68
} ;
71
69
70
+ this . _getPeriod = function ( target , query , options , start , end ) {
71
+ var period ;
72
+ var range = end - start ;
73
+
74
+ if ( ! target . period ) {
75
+ period = ( query . namespace === 'AWS/EC2' ) ? 300 : 60 ;
76
+ } else if ( / ^ \d + $ / . test ( target . period ) ) {
77
+ period = parseInt ( target . period , 10 ) ;
78
+ } else {
79
+ period = kbn . interval_to_seconds ( templateSrv . replace ( target . period , options . scopedVars ) ) ;
80
+ }
81
+ if ( query . period < 60 ) {
82
+ period = 60 ;
83
+ }
84
+ if ( range / query . period >= 1440 ) {
85
+ period = Math . ceil ( range / 1440 / 60 ) * 60 ;
86
+ }
87
+
88
+ return period ;
89
+ } ;
90
+
72
91
this . performTimeSeriesQuery = function ( query , start , end ) {
73
92
return this . awsRequest ( {
74
93
region : query . region ,
0 commit comments