Skip to content

Commit 96ca69c

Browse files
committed
tech(cloudwatch): extract method
1 parent 6b70157 commit 96ca69c

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

public/app/plugins/datasource/cloudwatch/datasource.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,9 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) {
3737
query.dimensions = self.convertDimensionFormat(target.dimensions, options.scopedVars);
3838
query.statistics = target.statistics;
3939

40-
var range = end - start;
41-
if (!target.period) {
42-
query.period = (query.namespace === 'AWS/EC2') ? 300 : 60;
43-
} else if (/^\d+$/.test(target.period)) {
44-
query.period = parseInt(target.period, 10);
45-
} else {
46-
query.period = kbn.interval_to_seconds(templateSrv.replace(target.period, options.scopedVars));
47-
}
48-
if (query.period < 60) {
49-
query.period = 60;
50-
}
51-
if (range / query.period >= 1440) {
52-
query.period = Math.ceil(range / 1440 / 60) * 60;
53-
}
54-
target.period = query.period;
40+
var period = this._getPeriod(target, query, options, start, end);
41+
target.period = period;
42+
query.period = period;
5543

5644
queries.push(query);
5745
}.bind(this));
@@ -79,6 +67,27 @@ function (angular, _, moment, dateMath, kbn, CloudWatchAnnotationQuery) {
7967
});
8068
};
8169

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+
8291
this.performTimeSeriesQuery = function(query, start, end) {
8392
return this.awsRequest({
8493
region: query.region,

0 commit comments

Comments
 (0)