@@ -54,21 +54,42 @@ export default class CapacityCalculatorBase {
54
54
let gsiWrites = ( params . GlobalSecondaryIndexes || [ ] )
55
55
. map ( gsi => this . getConsumedCapacityAsync ( false , params . TableName , gsi . IndexName ) ) ;
56
56
57
+ let tableTRead = this . getThrottledEventsAsync ( true , params . TableName , null )
58
+ let tableTWrites = this . getThrottledEventsAsync ( false , params . TableName , null )
59
+
60
+ let gsiTReads = ( params . GlobalSecondaryIndexes || [ ] )
61
+ . map ( gsi => this . getThrottledEventsAsync ( true , params . TableName , gsi . IndexName ) ) ;
62
+
63
+ let gsiTWrites = ( params . GlobalSecondaryIndexes || [ ] )
64
+ . map ( gsi => this . getThrottledEventsAsync ( false , params . TableName , gsi . IndexName ) ) ;
65
+
57
66
// Await on the results
58
67
let tableConsumedRead = await tableRead ;
59
68
let tableConsumedWrite = await tableWrite ;
60
69
let gsiConsumedReads = await Promise . all ( gsiReads ) ;
61
70
let gsiConsumedWrites = await Promise . all ( gsiWrites ) ;
62
71
72
+ // Await on throttled info
73
+ let tableThrottledRead = await tableTRead ;
74
+ let tableThrottledWrite = await tableTWrites ;
75
+ let gsiThrottledReads = await Promise . all ( gsiTReads ) ;
76
+ let gsiThrottledWrites = await Promise . all ( gsiTWrites ) ;
77
+
63
78
// Format results
64
79
let gsis = gsiConsumedReads . map ( ( read , i ) => {
65
80
let write = gsiConsumedWrites [ i ] ;
81
+ let throttledWrite = gsiThrottledWrites [ i ] ;
82
+ let throttledRead = gsiThrottledReads [ i ]
66
83
return {
67
84
// $FlowIgnore: The indexName is not null in this case
68
85
IndexName : read . globalSecondaryIndexName ,
69
86
ConsumedThroughput : {
70
87
ReadCapacityUnits : read . value ,
71
88
WriteCapacityUnits : write . value
89
+ } ,
90
+ ThrottledEvents : {
91
+ ThrottledReadEvents : throttledRead ,
92
+ ThrottledWriteEvents : throttledRead
72
93
}
73
94
} ;
74
95
} ) ;
@@ -79,6 +100,10 @@ export default class CapacityCalculatorBase {
79
100
ReadCapacityUnits : tableConsumedRead . value ,
80
101
WriteCapacityUnits : tableConsumedWrite . value
81
102
} ,
103
+ ThrottledEvents : {
104
+ ThrottledReadEvents : tableThrottledRead ,
105
+ ThrottledWriteEvents : tableThrottledWrite
106
+ } ,
82
107
GlobalSecondaryIndexes : gsis
83
108
} ;
84
109
} catch ( ex ) {
@@ -138,6 +163,46 @@ export default class CapacityCalculatorBase {
138
163
}
139
164
}
140
165
166
+ async getThrottledEventsAsync (
167
+ isRead : boolean , tableName : string , globalSecondaryIndexName : ?string ) :
168
+ Promise < number > {
169
+ try {
170
+ invariant ( isRead != null , 'Parameter \'isRead\' is not set' ) ;
171
+ invariant ( tableName != null , 'Parameter \'tableName\' is not set' ) ;
172
+
173
+ let settings = this . getStatisticSettings ( ) ;
174
+
175
+ let EndTime = new Date ( ) ;
176
+ let StartTime = new Date ( ) ;
177
+ StartTime . setTime ( EndTime - ( 60000 * settings . spanMinutes * settings . count ) ) ;
178
+ let MetricName = isRead ? 'ReadThrottleEvents' : 'WriteThrottleEvents' ;
179
+ let Dimensions = this . getDimensions ( tableName , globalSecondaryIndexName ) ;
180
+ let period = ( settings . spanMinutes * 60 ) ;
181
+ let params = {
182
+ Namespace : 'AWS/DynamoDB' ,
183
+ MetricName,
184
+ Dimensions,
185
+ StartTime,
186
+ EndTime,
187
+ Period : period ,
188
+ Statistics : [ settings . type ] ,
189
+ Unit : 'Count'
190
+ } ;
191
+
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 ;
203
+ }
204
+ }
205
+
141
206
getDimensions ( tableName : string , globalSecondaryIndexName : ?string ) : Dimension [ ] {
142
207
if ( globalSecondaryIndexName ) {
143
208
return [
0 commit comments