@@ -47,10 +47,6 @@ export default class Provisioner extends ProvisionerConfigurableBase {
47
47
invariant ( data != null , 'Parameter \'data\' is not set' ) ;
48
48
49
49
let config = this . getTableConfig ( data ) ;
50
- if ( config . ReadCapacity . Increment == null ) {
51
- return false ;
52
- }
53
-
54
50
let adjustmentContext = this . getReadCapacityIncrementAdjustmentContext ( data , config ) ;
55
51
return this . isCapacityAdjustmentRequired ( data , adjustmentContext ) ;
56
52
}
@@ -67,12 +63,8 @@ export default class Provisioner extends ProvisionerConfigurableBase {
67
63
invariant ( data != null , 'Parameter \'data\' is not set' ) ;
68
64
69
65
let config = this . getTableConfig ( data ) ;
70
- if ( config . ReadCapacity . Decrement == null ) {
71
- return false ;
72
- }
73
-
74
66
let adjustmentContext = this . getReadCapacityDecrementAdjustmentContext ( data , config ) ;
75
- return this . isCapacityAdjustmentRequired ( data , adjustmentContext , d => this . calculateDecrementedReadCapacityValue ( d ) ) ;
67
+ return this . isCapacityAdjustmentRequired ( data , adjustmentContext ) ;
76
68
}
77
69
78
70
calculateDecrementedReadCapacityValue ( data : TableProvisionedAndConsumedThroughput ) : number {
@@ -87,10 +79,6 @@ export default class Provisioner extends ProvisionerConfigurableBase {
87
79
invariant ( data != null , 'Parameter \'data\' is not set' ) ;
88
80
89
81
let config = this . getTableConfig ( data ) ;
90
- if ( config . WriteCapacity . Increment == null ) {
91
- return false ;
92
- }
93
-
94
82
let adjustmentContext = this . getWriteCapacityIncrementAdjustmentContext ( data , config ) ;
95
83
return this . isCapacityAdjustmentRequired ( data , adjustmentContext ) ;
96
84
}
@@ -107,12 +95,8 @@ export default class Provisioner extends ProvisionerConfigurableBase {
107
95
invariant ( data != null , 'Parameter \'data\' is not set' ) ;
108
96
109
97
let config = this . getTableConfig ( data ) ;
110
- if ( config . WriteCapacity . Decrement == null ) {
111
- return false ;
112
- }
113
-
114
98
let adjustmentContext = this . getWriteCapacityDecrementAdjustmentContext ( data , config ) ;
115
- return this . isCapacityAdjustmentRequired ( data , adjustmentContext , this . calculateDecrementedWriteCapacityValue ) ;
99
+ return this . isCapacityAdjustmentRequired ( data , adjustmentContext ) ;
116
100
}
117
101
118
102
calculateDecrementedWriteCapacityValue ( data : TableProvisionedAndConsumedThroughput ) : number {
@@ -124,85 +108,122 @@ export default class Provisioner extends ProvisionerConfigurableBase {
124
108
}
125
109
126
110
getReadCapacityIncrementAdjustmentContext ( data : TableProvisionedAndConsumedThroughput , config : ProvisionerConfig ) : AdjustmentContext {
127
- invariant ( config . ReadCapacity . Increment != null , 'Increment cannot be null' ) ;
111
+ invariant ( data != null , 'Argument \'data\' cannot be null' ) ;
112
+ invariant ( config != null , 'Argument \'config\' cannot be null' ) ;
128
113
129
- return {
114
+ let context = {
130
115
TableName : data . TableName ,
131
116
IndexName : data . IndexName ,
132
117
CapacityType : 'read' ,
133
118
AdjustmentType : 'increment' ,
134
119
ProvisionedValue : data . ProvisionedThroughput . ReadCapacityUnits ,
135
120
ConsumedValue : data . ConsumedThroughput . ReadCapacityUnits ,
121
+ ThrottledEvents : data . ThrottledEvents . ThrottledReadEvents ,
136
122
UtilisationPercent : ( data . ConsumedThroughput . ReadCapacityUnits / data . ProvisionedThroughput . ReadCapacityUnits ) * 100 ,
137
123
CapacityConfig : config . ReadCapacity ,
138
- CapacityAdjustmentConfig : config . ReadCapacity . Increment ,
139
124
} ;
125
+
126
+ if ( config . ReadCapacity . Increment != null ) {
127
+ // $FlowIgnore
128
+ context . CapacityAdjustmentConfig = config . ReadCapacity . Increment ;
129
+ }
130
+
131
+ return context ;
140
132
}
141
133
142
134
getReadCapacityDecrementAdjustmentContext ( data : TableProvisionedAndConsumedThroughput , config : ProvisionerConfig ) : AdjustmentContext {
143
- invariant ( config . ReadCapacity . Decrement != null , 'Decrement cannot be null' ) ;
135
+ invariant ( data != null , 'Argument \'data\' cannot be null' ) ;
136
+ invariant ( config != null , 'Argument \'config\' cannot be null' ) ;
144
137
145
- return {
138
+ let context = {
146
139
TableName : data . TableName ,
147
140
IndexName : data . IndexName ,
148
141
CapacityType : 'read' ,
149
142
AdjustmentType : 'decrement' ,
150
143
ProvisionedValue : data . ProvisionedThroughput . ReadCapacityUnits ,
151
144
ConsumedValue : data . ConsumedThroughput . ReadCapacityUnits ,
145
+ ThrottledEvents : data . ThrottledEvents . ThrottledReadEvents ,
152
146
UtilisationPercent : ( data . ConsumedThroughput . ReadCapacityUnits / data . ProvisionedThroughput . ReadCapacityUnits ) * 100 ,
153
147
CapacityConfig : config . ReadCapacity ,
154
- CapacityAdjustmentConfig : config . ReadCapacity . Decrement ,
155
148
} ;
149
+
150
+ if ( config . ReadCapacity . Decrement != null ) {
151
+ // $FlowIgnore
152
+ context . CapacityAdjustmentConfig = config . ReadCapacity . Decrement ;
153
+ }
154
+
155
+ return context ;
156
156
}
157
157
158
158
getWriteCapacityIncrementAdjustmentContext ( data : TableProvisionedAndConsumedThroughput , config : ProvisionerConfig ) : AdjustmentContext {
159
- invariant ( config . WriteCapacity . Increment != null , 'Increment cannot be null' ) ;
159
+ invariant ( data != null , 'Argument \'data\' cannot be null' ) ;
160
+ invariant ( config != null , 'Argument \'config\' cannot be null' ) ;
160
161
161
- return {
162
+ let context = {
162
163
TableName : data . TableName ,
163
164
IndexName : data . IndexName ,
164
165
CapacityType : 'write' ,
165
166
AdjustmentType : 'increment' ,
166
167
ProvisionedValue : data . ProvisionedThroughput . WriteCapacityUnits ,
167
168
ConsumedValue : data . ConsumedThroughput . WriteCapacityUnits ,
169
+ ThrottledEvents : data . ThrottledEvents . ThrottledWriteEvents ,
168
170
UtilisationPercent : ( data . ConsumedThroughput . WriteCapacityUnits / data . ProvisionedThroughput . WriteCapacityUnits ) * 100 ,
169
171
CapacityConfig : config . WriteCapacity ,
170
- CapacityAdjustmentConfig : config . WriteCapacity . Increment ,
171
172
} ;
173
+
174
+ if ( config . WriteCapacity . Increment != null ) {
175
+ // $FlowIgnore
176
+ context . CapacityAdjustmentConfig = config . WriteCapacity . Increment ;
177
+ }
178
+
179
+ return context ;
172
180
}
173
181
174
182
getWriteCapacityDecrementAdjustmentContext ( data : TableProvisionedAndConsumedThroughput , config : ProvisionerConfig ) : AdjustmentContext {
175
- invariant ( config . WriteCapacity . Decrement != null , 'Decrement cannot be null' ) ;
183
+ invariant ( data != null , 'Argument \'data\' cannot be null' ) ;
184
+ invariant ( config != null , 'Argument \'config\' cannot be null' ) ;
176
185
177
- return {
186
+ let context = {
178
187
TableName : data . TableName ,
179
188
IndexName : data . IndexName ,
180
189
CapacityType : 'write' ,
181
190
AdjustmentType : 'decrement' ,
182
191
ProvisionedValue : data . ProvisionedThroughput . WriteCapacityUnits ,
183
192
ConsumedValue : data . ConsumedThroughput . WriteCapacityUnits ,
193
+ ThrottledEvents : data . ThrottledEvents . ThrottledWriteEvents ,
184
194
UtilisationPercent : ( data . ConsumedThroughput . WriteCapacityUnits / data . ProvisionedThroughput . WriteCapacityUnits ) * 100 ,
185
195
CapacityConfig : config . WriteCapacity ,
186
- CapacityAdjustmentConfig : config . WriteCapacity . Decrement ,
187
196
} ;
197
+
198
+ if ( config . WriteCapacity . Decrement != null ) {
199
+ // $FlowIgnore
200
+ context . CapacityAdjustmentConfig = config . WriteCapacity . Decrement ;
201
+ }
202
+
203
+ return context ;
188
204
}
189
205
190
206
isCapacityAdjustmentRequired ( data : TableProvisionedAndConsumedThroughput , adjustmentContext : AdjustmentContext ) : boolean {
191
207
192
208
// Determine if an adjustment is wanted
193
- let isAboveMax = this . isAboveMax ( adjustmentContext ) ;
194
- let isBelowMin = this . isBelowMin ( adjustmentContext ) ;
195
- let isAboveThreshold = this . isAboveThreshold ( adjustmentContext ) ;
196
- let isBelowThreshold = this . isBelowThreshold ( adjustmentContext ) ;
197
- let isAdjustmentWanted = ( isAboveMax || isBelowMin || isAboveThreshold || isBelowThreshold ) ;
209
+ let isProvAboveMax = adjustmentContext . CapacityConfig . Max == null ? false : adjustmentContext . ProvisionedValue > adjustmentContext . CapacityConfig . Max ;
210
+ let isProvBelowMax = adjustmentContext . CapacityConfig . Max == null ? true : adjustmentContext . ProvisionedValue < adjustmentContext . CapacityConfig . Max ;
211
+ let isProvBelowMin = adjustmentContext . CapacityConfig . Min == null ? adjustmentContext . ProvisionedValue < 1 : adjustmentContext . ProvisionedValue < adjustmentContext . CapacityConfig . Min ;
212
+ let isProvAboveMin = adjustmentContext . CapacityConfig . Min == null ? adjustmentContext . ProvisionedValue > 1 : adjustmentContext . ProvisionedValue > adjustmentContext . CapacityConfig . Min ;
213
+ let isUtilAboveThreshold = this . isAboveThreshold ( adjustmentContext ) ;
214
+ let isUtilBelowThreshold = this . isBelowThreshold ( adjustmentContext ) ;
215
+ let isThrottledEventsAboveThreshold = this . isThrottledEventsAboveThreshold ( adjustmentContext ) ;
216
+ let isAdjustmentWanted = adjustmentContext . AdjustmentType === 'increment' ?
217
+ ( isProvBelowMin || isUtilAboveThreshold || isUtilBelowThreshold || isThrottledEventsAboveThreshold ) && isProvBelowMax :
218
+ ( isProvAboveMax || isUtilAboveThreshold || isUtilBelowThreshold ) && isProvAboveMin ;
198
219
199
220
// Determine if an adjustment is allowed under the rate limiting rules
200
- let isAfterLastDecreaseGracePeriod = this . isAfterLastAdjustmentGracePeriod (
201
- data . ProvisionedThroughput . LastDecreaseDateTime ,
202
- adjustmentContext . CapacityAdjustmentConfig . When . AfterLastDecrementMinutes ) ;
203
- let isAfterLastIncreaseGracePeriod = this . isAfterLastAdjustmentGracePeriod (
204
- data . ProvisionedThroughput . LastIncreaseDateTime ,
205
- adjustmentContext . CapacityAdjustmentConfig . When . AfterLastIncrementMinutes ) ;
221
+ let isAfterLastDecreaseGracePeriod = adjustmentContext . CapacityAdjustmentConfig == null ||
222
+ this . isAfterLastAdjustmentGracePeriod ( data . ProvisionedThroughput . LastDecreaseDateTime ,
223
+ adjustmentContext . CapacityAdjustmentConfig . When . AfterLastDecrementMinutes ) ;
224
+ let isAfterLastIncreaseGracePeriod = adjustmentContext . CapacityAdjustmentConfig == null ||
225
+ this . isAfterLastAdjustmentGracePeriod ( data . ProvisionedThroughput . LastIncreaseDateTime ,
226
+ adjustmentContext . CapacityAdjustmentConfig . When . AfterLastIncrementMinutes ) ;
206
227
207
228
let isReadDecrementAllowed = adjustmentContext . AdjustmentType === 'decrement' ?
208
229
RateLimitedDecrement . isDecrementAllowed ( data , adjustmentContext , d => this . calculateDecrementedReadCapacityValue ( d ) ) :
@@ -213,10 +234,11 @@ export default class Provisioner extends ProvisionerConfigurableBase {
213
234
// Package up the configuration and the results so that we can produce
214
235
// some effective logs
215
236
let adjustmentData = {
216
- isAboveMax,
217
- isBelowMin,
218
- isAboveThreshold,
219
- isBelowThreshold,
237
+ isAboveMax : isProvAboveMax ,
238
+ isBelowMin : isProvBelowMin ,
239
+ isAboveThreshold : isUtilAboveThreshold ,
240
+ isBelowThreshold : isUtilBelowThreshold ,
241
+ isAboveThrottledEventThreshold : isThrottledEventsAboveThreshold ,
220
242
isAfterLastDecreaseGracePeriod,
221
243
isAfterLastIncreaseGracePeriod,
222
244
isAdjustmentWanted,
@@ -228,58 +250,41 @@ export default class Provisioner extends ProvisionerConfigurableBase {
228
250
return isAdjustmentWanted && isAdjustmentAllowed ;
229
251
}
230
252
231
- isAboveThreshold ( context : AdjustmentContext ) : boolean {
253
+ isThrottledEventsAboveThreshold ( context : AdjustmentContext ) : boolean {
232
254
invariant ( context != null , 'Parameter \'context\' is not set' ) ;
233
255
234
- if ( context . CapacityAdjustmentConfig . When . UtilisationIsAbovePercent == null ) {
235
- return false ;
236
- }
237
-
238
- if ( context . CapacityConfig . Max != null &&
239
- context . ProvisionedValue >= context . CapacityConfig . Max ) {
240
- // Already at maximum allowed ProvisionedValue
256
+ if ( context . CapacityAdjustmentConfig == null ||
257
+ context . CapacityAdjustmentConfig . When . ThrottledEventsPerMinuteIsAbove == null ||
258
+ context . AdjustmentType === 'decrement' ) {
241
259
return false ;
242
260
}
243
261
244
- let utilisationPercent = ( context . ConsumedValue / context . ProvisionedValue ) * 100 ;
245
- return utilisationPercent > context . CapacityAdjustmentConfig . When . UtilisationIsAbovePercent ;
262
+ return context . ThrottledEvents >
263
+ context . CapacityAdjustmentConfig . When . ThrottledEventsPerMinuteIsAbove ;
246
264
}
247
265
248
- isBelowThreshold ( context : AdjustmentContext ) : boolean {
266
+ isAboveThreshold ( context : AdjustmentContext ) : boolean {
249
267
invariant ( context != null , 'Parameter \'context\' is not set' ) ;
250
268
251
- if ( context . CapacityAdjustmentConfig . When . UtilisationIsBelowPercent == null ) {
252
- return false ;
253
- }
254
-
255
- let min = context . CapacityConfig . Min != null ? context . CapacityConfig . Min : 1 ;
256
- if ( context . ProvisionedValue <= min ) {
257
- // Already at minimum allowed ProvisionedValue
269
+ if ( context . CapacityAdjustmentConfig == null ||
270
+ context . CapacityAdjustmentConfig . When . UtilisationIsAbovePercent == null ) {
258
271
return false ;
259
272
}
260
273
261
274
let utilisationPercent = ( context . ConsumedValue / context . ProvisionedValue ) * 100 ;
262
- return utilisationPercent < context . CapacityAdjustmentConfig . When . UtilisationIsBelowPercent ;
263
- }
264
-
265
- isAboveMax ( context : AdjustmentContext ) : boolean {
266
- invariant ( context != null , 'Parameter \'context\' is not set' ) ;
267
-
268
- if ( context . CapacityConfig . Max == null ) {
269
- return false ;
270
- }
271
-
272
- return context . ProvisionedValue > context . CapacityConfig . Max ;
275
+ return utilisationPercent > context . CapacityAdjustmentConfig . When . UtilisationIsAbovePercent ;
273
276
}
274
277
275
- isBelowMin ( context : AdjustmentContext ) : boolean {
278
+ isBelowThreshold ( context : AdjustmentContext ) : boolean {
276
279
invariant ( context != null , 'Parameter \'context\' is not set' ) ;
277
280
278
- if ( context . CapacityConfig . Min == null ) {
281
+ if ( context . CapacityAdjustmentConfig == null ||
282
+ context . CapacityAdjustmentConfig . When . UtilisationIsBelowPercent == null ) {
279
283
return false ;
280
284
}
281
285
282
- return context . ProvisionedValue < context . CapacityConfig . Min ;
286
+ let utilisationPercent = ( context . ConsumedValue / context . ProvisionedValue ) * 100 ;
287
+ return utilisationPercent < context . CapacityAdjustmentConfig . When . UtilisationIsBelowPercent ;
283
288
}
284
289
285
290
isAfterLastAdjustmentGracePeriod ( lastAdjustmentDateTime : string , afterLastAdjustmentMinutes ?: number ) : boolean {
0 commit comments