Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit 4a827b9

Browse files
committed
Fix for #18
1 parent e0c65f4 commit 4a827b9

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

flow/aws-sdk-promise.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ declare module 'aws-sdk-promise' {
467467
declare type Datapoint = {
468468
Timestamp: string,
469469
Average: number,
470+
Sum: number,
470471
Unit: string,
471472
};
472473
}

src/CapacityCalculator.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export default class CapacityCalculator extends CapacityCalculatorBase {
1515
return {
1616
count: 5,
1717
spanMinutes: 1,
18-
type: 'Average',
18+
type: 'Sum',
1919
};
2020
}
2121

2222
// Gets the projected capacity value based on the cloudwatch datapoints
23-
getProjectedValue(data: GetMetricStatisticsResponse) {
23+
getProjectedValue(settings: StatisticSettings, data: GetMetricStatisticsResponse) {
2424
invariant(data != null, 'Parameter \'data\' is not set');
2525

2626
if (data.Datapoints.length === 0) {
@@ -30,7 +30,9 @@ export default class CapacityCalculator extends CapacityCalculatorBase {
3030
// Default algorithm for projecting a good value for the current ConsumedThroughput is:
3131
// 1. Query 5 average readings each spanning a minute
3232
// 2. Select the Max value from those 5 readings
33-
let averages = data.Datapoints.map(dp => dp.Sum / data.period);
34-
return Math.max(...averages);
33+
let spanSeconds = settings.spanMinutes * 60;
34+
let averages = data.Datapoints.map(dp => dp.Sum / spanSeconds);
35+
let projectedValue = Math.max(...averages);
36+
return projectedValue;
3537
}
3638
}

src/capacity/CapacityCalculatorBase.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class CapacityCalculatorBase {
3131

3232
// Gets the projected capacity value based on the cloudwatch datapoints
3333
// eslint-disable-next-line no-unused-vars
34-
getProjectedValue(data: GetMetricStatisticsResponse): number {
34+
getProjectedValue(settings: StatisticSettings, data: GetMetricStatisticsResponse): number {
3535
invariant(false, 'The method \'getProjectedValue\' was not implemented');
3636
}
3737

@@ -100,31 +100,27 @@ export default class CapacityCalculatorBase {
100100
invariant(isRead != null, 'Parameter \'isRead\' is not set');
101101
invariant(tableName != null, 'Parameter \'tableName\' is not set');
102102

103-
// These values determine how many minutes worth of metrics
104-
let statisticCount = 5;
105-
let statisticSpanMinutes = 1;
106-
let statisticType = 'Sum';
103+
let settings = this.getStatisticSettings();
107104

108105
let EndTime = new Date();
109106
let StartTime = new Date();
110-
StartTime.setTime(EndTime - (60000 * statisticSpanMinutes * statisticCount));
107+
StartTime.setTime(EndTime - (60000 * settings.spanMinutes * settings.count));
111108
let MetricName = isRead ? 'ConsumedReadCapacityUnits' : 'ConsumedWriteCapacityUnits';
112109
let Dimensions = this.getDimensions(tableName, globalSecondaryIndexName);
113-
let period = (statisticSpanMinutes * 60);
110+
let period = (settings.spanMinutes * 60);
114111
let params = {
115112
Namespace: 'AWS/DynamoDB',
116113
MetricName,
117114
Dimensions,
118115
StartTime,
119116
EndTime,
120117
Period: period,
121-
Statistics: [ statisticType ],
118+
Statistics: [ settings.type ],
122119
Unit: 'Count'
123120
};
124121

125122
let statistics = await this.cw.getMetricStatisticsAsync(params);
126-
statistics.period = period;
127-
let value = this.getProjectedValue(statistics);
123+
let value = this.getProjectedValue(settings, statistics);
128124
let result: ConsumedCapacityDesc = {
129125
tableName,
130126
globalSecondaryIndexName,

0 commit comments

Comments
 (0)