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

Commit 6fcfe82

Browse files
committed
A few flow type fixes for #29 and fixed a bug where throttledRead was getting applied the throttledWrite value
1 parent f4a6da2 commit 6fcfe82

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/capacity/CapacityCalculatorBase.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CloudWatch from '../aws/CloudWatch';
44
import type {
55
TableConsumedCapacityDescription,
66
StatisticSettings,
7-
ConsumedCapacityDesc
7+
ConsumedCapacityDesc,
88
} from '../flow/FlowTypes';
99
import type {
1010
TableDescription,
@@ -54,8 +54,8 @@ export default class CapacityCalculatorBase {
5454
let gsiWrites = (params.GlobalSecondaryIndexes || [])
5555
.map(gsi => this.getConsumedCapacityAsync(false, params.TableName, gsi.IndexName));
5656

57-
let tableTRead = this.getThrottledEventsAsync(true, params.TableName, null)
58-
let tableTWrites = this.getThrottledEventsAsync(false, params.TableName, null)
57+
let tableTRead = this.getThrottledEventsAsync(true, params.TableName, null);
58+
let tableTWrites = this.getThrottledEventsAsync(false, params.TableName, null);
5959

6060
let gsiTReads = (params.GlobalSecondaryIndexes || [])
6161
.map(gsi => this.getThrottledEventsAsync(true, params.TableName, gsi.IndexName));
@@ -79,17 +79,18 @@ export default class CapacityCalculatorBase {
7979
let gsis = gsiConsumedReads.map((read, i) => {
8080
let write = gsiConsumedWrites[i];
8181
let throttledWrite = gsiThrottledWrites[i];
82-
let throttledRead = gsiThrottledReads[i]
82+
let throttledRead = gsiThrottledReads[i];
83+
let gsiIndexName = read.globalSecondaryIndexName;
84+
invariant(gsiIndexName != null, '\'gsiIndexName\' was null');
8385
return {
84-
// $FlowIgnore: The indexName is not null in this case
85-
IndexName: read.globalSecondaryIndexName,
86+
IndexName: gsiIndexName,
8687
ConsumedThroughput: {
8788
ReadCapacityUnits: read.value,
8889
WriteCapacityUnits: write.value
8990
},
9091
ThrottledEvents: {
9192
ThrottledReadEvents: throttledRead,
92-
ThrottledWriteEvents: throttledRead
93+
ThrottledWriteEvents: throttledWrite
9394
}
9495
};
9596
});
@@ -189,19 +190,19 @@ export default class CapacityCalculatorBase {
189190
Unit: 'Count'
190191
};
191192

192-
let statistics = await this.cw.getMetricStatisticsAsync(params);
193-
let value = this.getProjectedValue(settings, statistics);
194-
195-
return value;
196-
} catch (ex) {
197-
warning(JSON.stringify({
198-
class: 'CapacityCalculator',
199-
function: 'getThrottledEventsAsync',
200-
isRead, tableName, globalSecondaryIndexName,
201-
}, null, json.padding));
202-
throw ex;
193+
let statistics = await this.cw.getMetricStatisticsAsync(params);
194+
let value = this.getProjectedValue(settings, statistics);
195+
196+
return value;
197+
} catch (ex) {
198+
warning(JSON.stringify({
199+
class: 'CapacityCalculator',
200+
function: 'getThrottledEventsAsync',
201+
isRead, tableName, globalSecondaryIndexName,
202+
}, null, json.padding));
203+
throw ex;
204+
}
203205
}
204-
}
205206

206207
getDimensions(tableName: string, globalSecondaryIndexName: ?string): Dimension[] {
207208
if (globalSecondaryIndexName) {

src/flow/FlowTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ export type TableProvisionedAndConsumedThroughput = {
1717
export type GlobalSecondaryIndexConsumedThroughput = {
1818
IndexName: string,
1919
ConsumedThroughput: Throughput,
20+
ThrottledEvents: ThrottledEventsDescription,
2021
};
2122

2223
export type TableConsumedCapacityDescription = {
2324
TableName: string,
2425
ConsumedThroughput: Throughput,
2526
GlobalSecondaryIndexes: GlobalSecondaryIndexConsumedThroughput[],
26-
ThrottledEvents: ThrottledEventsDescription
27+
ThrottledEvents: ThrottledEventsDescription,
2728
};
2829

2930
export type ConsumedCapacityDesc = {

src/provisioning/ProvisionerConfigurableBase.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export default class ProvisionerConfigurableBase extends ProvisionerBase {
174174
.GlobalSecondaryIndexes
175175
.find(i => i.IndexName === gsi.IndexName);
176176

177+
invariant(gsicc != null, 'Specified GSI could not be found');
177178
let provisionedThroughput = this.getUpdatedProvisionedThroughput({
178179
TableName: tableDescription.TableName,
179180
IndexName: gsicc.IndexName,

0 commit comments

Comments
 (0)