@@ -54,21 +54,42 @@ 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 )
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+
5766 // Await on the results
5867 let tableConsumedRead = await tableRead ;
5968 let tableConsumedWrite = await tableWrite ;
6069 let gsiConsumedReads = await Promise . all ( gsiReads ) ;
6170 let gsiConsumedWrites = await Promise . all ( gsiWrites ) ;
6271
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+
6378 // Format results
6479 let gsis = gsiConsumedReads . map ( ( read , i ) => {
6580 let write = gsiConsumedWrites [ i ] ;
81+ let throttledWrite = gsiThrottledWrites [ i ] ;
82+ let throttledRead = gsiThrottledReads [ i ]
6683 return {
6784 // $FlowIgnore: The indexName is not null in this case
6885 IndexName : read . globalSecondaryIndexName ,
6986 ConsumedThroughput : {
7087 ReadCapacityUnits : read . value ,
7188 WriteCapacityUnits : write . value
89+ } ,
90+ ThrottledEvents : {
91+ ThrottledReadEvents : throttledRead ,
92+ ThrottledWriteEvents : throttledRead
7293 }
7394 } ;
7495 } ) ;
@@ -79,6 +100,10 @@ export default class CapacityCalculatorBase {
79100 ReadCapacityUnits : tableConsumedRead . value ,
80101 WriteCapacityUnits : tableConsumedWrite . value
81102 } ,
103+ ThrottledEvents : {
104+ ThrottledReadEvents : tableThrottledRead ,
105+ ThrottledWriteEvents : tableThrottledWrite
106+ } ,
82107 GlobalSecondaryIndexes : gsis
83108 } ;
84109 } catch ( ex ) {
@@ -138,6 +163,46 @@ export default class CapacityCalculatorBase {
138163 }
139164 }
140165
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+
141206 getDimensions ( tableName : string , globalSecondaryIndexName : ?string ) : Dimension [ ] {
142207 if ( globalSecondaryIndexName ) {
143208 return [
0 commit comments